|
|
@ -7,13 +7,20 @@ using namespace transmit_disfection_protocol; |
|
|
|
class PXXPSBus { |
|
|
|
PXXPressureSensorBus psbus; |
|
|
|
bool m_isInitialized = false; |
|
|
|
osTimerId reportTimerId; // 压力传感器数值上报
|
|
|
|
|
|
|
|
public: |
|
|
|
void initialize(UART_HandleTypeDef* huart) { |
|
|
|
psbus.init(huart); |
|
|
|
m_isInitialized = true; |
|
|
|
|
|
|
|
osTimerDef(reportTimer, onTimer); |
|
|
|
reportTimerId = osTimerCreate(osTimer(reportTimer), osTimerPeriodic, this); |
|
|
|
|
|
|
|
BIND_FN(PXXPSBus, this, fn_psbus_read_data); |
|
|
|
BIND_FN(PXXPSBus, this, fn_psbus_scan); |
|
|
|
BIND_FN(PXXPSBus, this, fn_psbus_start_report); |
|
|
|
BIND_FN(PXXPSBus, this, fn_psbus_stop_report); |
|
|
|
} |
|
|
|
bool isInitialized() { return m_isInitialized; } |
|
|
|
|
|
|
@ -38,12 +45,58 @@ class PXXPSBus { |
|
|
|
auto* sensors = psbus.sensors; |
|
|
|
int numSensor = psbus.sensorNum; |
|
|
|
|
|
|
|
ack_psbus_scan_t result = {0}; |
|
|
|
result.numOnlineId = numSensor; |
|
|
|
for (int i = 0; i < numSensor; i++) { |
|
|
|
result.onlineId[i] = sensors[i].id; |
|
|
|
static ack_psbus_scan_t result; |
|
|
|
memset(&result, 0, sizeof(result)); |
|
|
|
static_assert(ZARRAY_SIZE(result.sensor) == ZARRAY_SIZE(psbus.sensors)); |
|
|
|
result.numOnlineId = numSensor; |
|
|
|
for (int i = 0; i < PXX_PRESSURE_SENSOR_NUM; i++) { |
|
|
|
if (sensors[i].online) { |
|
|
|
result.sensor[0].ptype = sensors[i].type; |
|
|
|
result.sensor[0].subid = sensors[i].id; |
|
|
|
result.sensor[0].isOnline = 1; |
|
|
|
result.sensor[0].precision = sensors[i].p100_sensor_info.precision; |
|
|
|
result.sensor[0].zero = sensors[i].p100_sensor_info.zero_point; |
|
|
|
result.sensor[0].full = sensors[i].p100_sensor_info.range_full_point; |
|
|
|
} |
|
|
|
} |
|
|
|
zcanbus_send_ack(cxt->packet, (uint8_t*)&result, sizeof(result)); |
|
|
|
} |
|
|
|
|
|
|
|
void fn_psbus_start_report(ProcessContext* cxt) { |
|
|
|
int period = GET_PARAM(0); |
|
|
|
if (period < 100) period = 100; |
|
|
|
osTimerStop(reportTimerId); |
|
|
|
osTimerStart(reportTimerId, period); |
|
|
|
zcanbus_send_ack(cxt->packet, nullptr, 0); |
|
|
|
} |
|
|
|
|
|
|
|
void fn_psbus_stop_report(ProcessContext* cxt) { |
|
|
|
osTimerStop(reportTimerId); |
|
|
|
zcanbus_send_ack(cxt->packet, nullptr, 0); |
|
|
|
} |
|
|
|
|
|
|
|
public: |
|
|
|
static void onTimer(const void* tid) { |
|
|
|
PXXPSBus* bus = (PXXPSBus*)pvTimerGetTimerID((TimerHandle_t)tid); |
|
|
|
bus->onTimer(); |
|
|
|
} |
|
|
|
void onTimer() { |
|
|
|
int16_t val = 0; |
|
|
|
|
|
|
|
static uint8_t report_buf[100]; |
|
|
|
report_pressure_data_t* reportData = (report_pressure_data_t*)report_buf; |
|
|
|
|
|
|
|
reportData->sensorDataNum = 0; |
|
|
|
for (int i = 0; i < psbus.sensorNum; i++) { |
|
|
|
if (psbus.sensors[i].online) { |
|
|
|
psbus.readData(i, &val); |
|
|
|
reportData->data[i].subid = psbus.sensors[i].id; |
|
|
|
reportData->data[i].pressureVal = val; |
|
|
|
reportData->sensorDataNum++; |
|
|
|
} |
|
|
|
} |
|
|
|
zcanbus_send_report(kreport_pressure_data, (uint8_t*)reportData, //
|
|
|
|
sizeof(*reportData) + sizeof(reportData->data[0]) * reportData->sensorDataNum, 30); |
|
|
|
} |
|
|
|
}; |
|
|
|
} // namespace iflytop
|