NbusSlave.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @file AppBridge.h
  3. * @brief nBus Slave module declaration.
  4. * @date Nov 26, 2025
  5. * @author Juraj Dudak, Matus Necas
  6. */
  7. #ifndef SRC_APPSLAVE_H_
  8. #define SRC_APPSLAVE_H_
  9. #include "inttypes.h"
  10. #include "dataframe.h"
  11. #include "NbusCommunicator.h"
  12. /** @brief Class for nBus slave communication
  13. */
  14. class NbusSlave
  15. {
  16. public:
  17. /** Set nBus communicator.
  18. * @param nbus_comm: communicator to set
  19. */
  20. void setCommunicator(NbusCommunicator* nbus_comm);
  21. /** Set nBus address.
  22. * @param addr: address to set
  23. */
  24. void setAddress(uint8_t addr);
  25. /** Get slave active status.
  26. * @return: active status (1 = active, 0 = inactive)
  27. */
  28. bool isActive();
  29. /** Get nBus module address.
  30. * @return: actual address (0 if not set)
  31. */
  32. uint8_t getModuleAddress();
  33. /** Send any nBus request and get response.
  34. * @param slave_frame: data to send
  35. * @return: response data frame
  36. */
  37. DataFrame * cmdProcessAnyRequest(DataFrame *slave_frame);
  38. /** Send nBus request and get sensor data.
  39. * @return: response data frame
  40. */
  41. DataFrame * cmdGetData();
  42. /** Send nBus request and get sensor count.
  43. * @param check_hw: 1 = load from bus, 0 = use local cache
  44. * @return: response data frame
  45. */
  46. uint8_t nbusSlaveCmd_getSensorCnt(bool check_hw);
  47. private:
  48. /** Make nBus packet for selected function code.
  49. * @param fc: function code
  50. * @return: _slave_cache
  51. */
  52. DataFrame* _makePacket(Nbus_FC_e fc);
  53. NbusCommunicator* _communicator{nullptr}; ///< hardware bus communicator
  54. uint8_t _sensor_count{0}; ///< number of sensors
  55. Nbus_PDU_t _pdu{0, 0, FC_ECHO}; ///< slave PDU
  56. uint8_t _slave_cache[NBUS_SLAVE_CACHE_SIZE]{0}; ///< slave temporary data
  57. DataFrame _cache_frame{_slave_cache, NBUS_SLAVE_CACHE_SIZE, TYPE_PLAIN, CRC_ON}; ///< data frame of _slave_cache
  58. };
  59. #endif /* SRC_APPSLAVE_H_ */