|
|
@ -31,6 +31,9 @@ using namespace iflytop; |
|
|
|
static osTimerId HeartReportTimerId; |
|
|
|
static osThreadId PacketRxThreadId; |
|
|
|
|
|
|
|
static osTimerId PressureSensorDataReportTimerId; // 压力传感器数值上报
|
|
|
|
static uint32_t m_pressureSensorDataReportPeriodMs = 3000; |
|
|
|
|
|
|
|
/***********************************************************************************************************************
|
|
|
|
* FUNCTION_IMPL * |
|
|
|
***********************************************************************************************************************/ |
|
|
@ -78,7 +81,7 @@ static void basic_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t |
|
|
|
static report_heatpacket_data_t heatpacket; |
|
|
|
heatpacket.boardType = deviceInfo_getBoardType(); |
|
|
|
heatpacket.heartIndex = GET_PARAM(packet->params, 0); |
|
|
|
zcanbus_send_report(kreport_heatpacket_pong, (uint8_t*)&heatpacket, sizeof(heatpacket)); |
|
|
|
zcanbus_send_report(kreport_heatpacket_pong, (uint8_t*)&heatpacket, sizeof(heatpacket), 30); |
|
|
|
} |
|
|
|
// 触发一次强制上报事件
|
|
|
|
if (packet->function_id == kcmd_force_report) { |
|
|
@ -208,9 +211,39 @@ static void others_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_ |
|
|
|
|
|
|
|
// 压力传感器数据上报
|
|
|
|
else if (packet->function_id == kcmd_read_pressure_data) { |
|
|
|
CHECK_PARAM_LEN(paramNum, 1); |
|
|
|
int32_t index = GET_PARAM(packet->params, 0); |
|
|
|
|
|
|
|
int16_t val = 0; |
|
|
|
int32_t reportVal = 0; |
|
|
|
bool suc = Hardware::ins().pressureSensorBus()->readData(index, &val); |
|
|
|
|
|
|
|
reportVal = val; |
|
|
|
|
|
|
|
if (suc) { |
|
|
|
zcanbus_send_ack(packet, (uint8_t*)&reportVal, sizeof(reportVal)); |
|
|
|
} else { |
|
|
|
zcanbus_send_errorack(packet, kerr_subdevice_offline); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
// 压力传感器数据上报
|
|
|
|
else if (packet->function_id == kcmd_set_pressure_data_report_period_ms) { |
|
|
|
CHECK_PARAM_LEN(paramNum, 1); |
|
|
|
int32_t period = GET_PARAM(packet->params, 0); |
|
|
|
|
|
|
|
ZLOGI(TAG, "set pressure sensor data report period %d ms", period); |
|
|
|
|
|
|
|
if (period != 0) { |
|
|
|
if (period < 200) period = 200; |
|
|
|
osTimerStop(PressureSensorDataReportTimerId); |
|
|
|
osTimerStart(PressureSensorDataReportTimerId, period); |
|
|
|
m_pressureSensorDataReportPeriodMs = period; |
|
|
|
} else { |
|
|
|
osTimerStop(PressureSensorDataReportTimerId); |
|
|
|
} |
|
|
|
|
|
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -241,6 +274,30 @@ static void zcanbus_on_connected(bool connected) { |
|
|
|
ZLOGI(TAG, "disconnected from host"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void onPressureSensorDataReportTimer(void const* argument) { |
|
|
|
// 压力传感器数据上报
|
|
|
|
static uint8_t reportcache[100]; |
|
|
|
static report_pressure_data_t* report = (report_pressure_data_t*)reportcache; |
|
|
|
|
|
|
|
int sensorNum = 0; |
|
|
|
|
|
|
|
for (size_t i = 0; i < PXX_PRESSURE_SENSOR_NUM; i++) { |
|
|
|
int16_t val = 0; |
|
|
|
bool suc = Hardware::ins().pressureSensorBus()->readData(i, &val); |
|
|
|
|
|
|
|
if (suc) { |
|
|
|
report->data[sensorNum].subid = i; |
|
|
|
report->data[sensorNum].pressureVal = val; |
|
|
|
sensorNum++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
report->sensorDataNum = sensorNum; |
|
|
|
zcanbus_send_report(kreport_pressure_data, (uint8_t*)report, //
|
|
|
|
sizeof(report_pressure_data_t) + sensorNum * sizeof(report->data[0]), 10); |
|
|
|
} |
|
|
|
|
|
|
|
/***********************************************************************************************************************
|
|
|
|
* EXT * |
|
|
|
***********************************************************************************************************************/ |
|
|
@ -253,9 +310,9 @@ void protocol_impl_service_init() { // |
|
|
|
zcanbus_reglistener(zcanbus_on_rx); |
|
|
|
zcanbus_reg_on_connected_listener(zcanbus_on_connected); |
|
|
|
|
|
|
|
// osTimerDef(HeartReportTimer, onHeartReportTimer);
|
|
|
|
// HeartReportTimerId = osTimerCreate(osTimer(HeartReportTimer), osTimerPeriodic, NULL);
|
|
|
|
// osTimerStart(HeartReportTimerId, HEART_PACKET_PERIOD_MS);
|
|
|
|
osTimerDef(PressureSensorDataReportTimer, onPressureSensorDataReportTimer); |
|
|
|
PressureSensorDataReportTimerId = osTimerCreate(osTimer(PressureSensorDataReportTimer), osTimerPeriodic, NULL); |
|
|
|
osTimerStart(PressureSensorDataReportTimerId, m_pressureSensorDataReportPeriodMs); |
|
|
|
|
|
|
|
osThreadDef(PacketRxThread, onPacketRxThreadStart, osPriorityNormal, 0, 1024); |
|
|
|
PacketRxThreadId = osThreadCreate(osThread(PacketRxThread), NULL); |
|
|
|