You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.3 KiB
49 lines
1.3 KiB
#pragma once
|
|
#include "base/appdep.hpp"
|
|
|
|
namespace iflytop {
|
|
using namespace transmit_disfection_protocol;
|
|
|
|
class PXXPSBus {
|
|
PXXPressureSensorBus psbus;
|
|
bool m_isInitialized = false;
|
|
|
|
public:
|
|
void initialize(UART_HandleTypeDef* huart) {
|
|
psbus.init(huart);
|
|
m_isInitialized = true;
|
|
BIND_FN(PXXPSBus, this, fn_psbus_read_data);
|
|
BIND_FN(PXXPSBus, this, fn_psbus_scan);
|
|
}
|
|
bool isInitialized() { return m_isInitialized; }
|
|
|
|
private:
|
|
void fn_psbus_read_data(ProcessContext* cxt) {
|
|
CHECK_PARAM_LEN(PRAAM_LEN(), 1);
|
|
int32_t index = GET_PARAM(0);
|
|
|
|
int16_t val = 0;
|
|
int32_t reportVal = 0;
|
|
bool suc = psbus.readData(index, &val);
|
|
|
|
reportVal = val;
|
|
|
|
if (suc) {
|
|
zcanbus_send_ack(cxt->packet, (uint8_t*)&reportVal, sizeof(reportVal));
|
|
} else {
|
|
zcanbus_send_errorack(cxt->packet, kerr_subdevice_offline);
|
|
}
|
|
}
|
|
void fn_psbus_scan(ProcessContext* cxt) {
|
|
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;
|
|
}
|
|
zcanbus_send_ack(cxt->packet, (uint8_t*)&result, sizeof(result));
|
|
}
|
|
};
|
|
} // namespace iflytop
|