NbusSlave.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. /** Macro for module-only address. */
  13. #define SLAVE_ADDRESS_MODULE 0
  14. /** Class for nBus slave communication */
  15. class NbusSlave {
  16. private:
  17. NbusCommunicator* _communicator{nullptr}; ///< hardware bus communicator
  18. Nbus_PDU_t _pdu{0, 0, FC_ECHO}; ///< slave PDU
  19. uint8_t _sensor_cache[16]{0}; ///< sensor temporary data
  20. uint8_t _sensor_count{0}; ///< number of sensors
  21. public:
  22. /** Set nBus communicator
  23. * @param nbus_comm: communicator to set
  24. */
  25. void setCommunicator(NbusCommunicator* nbus_comm);
  26. /** Set nBus address
  27. * @param addr: address to set
  28. */
  29. void setAddress(uint8_t addr);
  30. /** Get slave active status
  31. * @return: active status (1 = active, 0 = inactive)
  32. */
  33. bool isActive();
  34. /** Get nBus module address
  35. * @return: actual address (0 if not set)
  36. */
  37. uint8_t getModuleAddress();
  38. /** Send nBus request and get sensor count
  39. * @param check_hw: 1 = load from bus, 0 = use local cache
  40. * @return: response data frame
  41. */
  42. uint8_t nbusSlaveCmd_getSensorCnt(bool check_hw);
  43. /** Send any nBus request and get response
  44. * @param slave_frame: data to send
  45. * @return: response data frame
  46. */
  47. DataFrame * nbusSlaveCmd_processRequest(DataFrame *slave_frame);
  48. /** Send nBus request and get sensor data
  49. * @return: response data frame
  50. */
  51. DataFrame * nbusSlaveCmd_getData();
  52. };
  53. #ifdef __cplusplus
  54. extern "C"
  55. {
  56. #endif
  57. #ifdef __cplusplus
  58. }
  59. #endif
  60. #endif /* SRC_APPSLAVE_H_ */