全司美特-单片机程序
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.

48 lines
1.3 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #pragma once
  2. #include "base/appdep.hpp"
  3. namespace iflytop {
  4. using namespace transmit_disfection_protocol;
  5. class PXXPSBus {
  6. PXXPressureSensorBus psbus;
  7. bool m_isInitialized = false;
  8. public:
  9. void initialize(UART_HandleTypeDef* huart) {
  10. psbus.init(huart);
  11. m_isInitialized = true;
  12. BIND_FN(PXXPSBus, this, fn_psbus_read_data);
  13. BIND_FN(PXXPSBus, this, fn_psbus_scan);
  14. }
  15. bool isInitialized() { return m_isInitialized; }
  16. private:
  17. void fn_psbus_read_data(ProcessContext* cxt) {
  18. CHECK_PARAM_LEN(PRAAM_LEN(), 1);
  19. int32_t index = GET_PARAM(0);
  20. int16_t val = 0;
  21. int32_t reportVal = 0;
  22. bool suc = psbus.readData(index, &val);
  23. reportVal = val;
  24. if (suc) {
  25. zcanbus_send_ack(cxt->packet, (uint8_t*)&reportVal, sizeof(reportVal));
  26. } else {
  27. zcanbus_send_errorack(cxt->packet, kerr_subdevice_offline);
  28. }
  29. }
  30. void fn_psbus_scan(ProcessContext* cxt) {
  31. auto* sensors = psbus.sensors;
  32. int numSensor = psbus.sensorNum;
  33. ack_psbus_scan_t result = {0};
  34. result.numOnlineId = numSensor;
  35. for (int i = 0; i < numSensor; i++) {
  36. result.onlineId[i] = sensors[i].id;
  37. }
  38. zcanbus_send_ack(cxt->packet, (uint8_t*)&result, sizeof(result));
  39. }
  40. };
  41. } // namespace iflytop