device_params.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*=====================================================================================
  2. * Description:
  3. * C file to define user defined parameters for Modbus example
  4. *====================================================================================*/
  5. #ifndef _DEVICEPARAMS_H_
  6. #define _DEVICEPARAMS_H_
  7. #include "mbcontroller.h" // for common Modbus defines
  8. // Enumeration of modbus device addresses accessed by master device
  9. enum {
  10. MB_DEVICE_ADDR1 = 1,
  11. MB_DEVICE_ADDR2 = 2,
  12. MB_DEVICE_ADDR3 = 3,
  13. };
  14. // Enumeration of all supported CIDs for device (used in parameter definition table)
  15. enum {
  16. CID_DATA_CHAN_0 = 0,
  17. CID_HUMIDITY_1,
  18. CID_TEMPERATURE_1,
  19. CID_HUMIDITY_2,
  20. CID_TEMPERATURE_2,
  21. CID_RELAY_P1,
  22. CID_RELAY_P2,
  23. CID_COUNT,
  24. };
  25. #define DEVICE_PARAM_MAX_SIZE 24
  26. // The structures below define the parameters that will be accessed by Modbus master device.
  27. // These parameters reflect the parameters in the address space of external devices in Modbus network.
  28. // They defined for each modbus register type (coils, discreet inputs, holding registers, input registers).
  29. // These are not required but can be used by user to link characteristic to corresponded field
  30. // See the parameter definition table for more information.
  31. // It is just example and it is responsibility of user to define them as required.
  32. #pragma pack(push, 1)
  33. typedef struct
  34. {
  35. // Parameter: discrete_input0
  36. uint8_t discrete_input0:1;
  37. // Parameter: discrete_input1
  38. uint8_t discrete_input1:1;
  39. // Parameter: discrete_input2
  40. uint8_t discrete_input2:1;
  41. // Parameter: discrete_input3
  42. uint8_t discrete_input3:1;
  43. // Parameter: discrete_input4
  44. uint8_t discrete_input4:1;
  45. // Parameter: discrete_input5
  46. uint8_t discrete_input5:1;
  47. // Parameter: discrete_input6
  48. uint8_t discrete_input6:1;
  49. // Parameter: discrete_input7
  50. uint8_t discrete_input7:1;
  51. uint8_t discrete_input_port1:8;
  52. } discrete_reg_params_t;
  53. #pragma pack(pop)
  54. // Note: For correct access the coils storage for each addressed parameter
  55. // has to include at least 2 byte (register)!
  56. #pragma pack(push, 1)
  57. typedef union
  58. {
  59. struct {
  60. // Parameter: Coil 0 : Coil0
  61. uint8_t coil0:1;
  62. // Parameter: Coil 1 : Coil1
  63. uint8_t coil1:1;
  64. // Parameter: Coil 2 : Coil2
  65. uint8_t coil2:1;
  66. // Parameter: Coil 3 : Coil3
  67. uint8_t coil3:1;
  68. // Parameter: Coil 4 : Coil4
  69. uint8_t coil4:1;
  70. // Parameter: Coil 5 : Coil5
  71. uint8_t coil5:1;
  72. // Parameter: Coil 6 : Coil6
  73. uint8_t coil6:1;
  74. // Parameter: Coil 7 : Coil7
  75. uint8_t coil7:1;
  76. uint8_t coil_port2:8;
  77. };
  78. uint8_t coils_port1;
  79. uint8_t coils_port2;
  80. } coil_reg_params_t;
  81. #pragma pack(pop)
  82. // Input register structure to keep characteristic's values
  83. #pragma pack(push, 1)
  84. typedef struct
  85. {
  86. // Parameter: Data channel 0 : data_chan0
  87. float data_chan0;
  88. // Parameter: Data channel 1 : data_chan1
  89. float data_chan1;
  90. // Parameter: Data channel 2 : data_chan2
  91. float data_chan2;
  92. // Parameter: Data channel 3 : data_chan3
  93. float data_chan3;
  94. } input_reg_params_t;
  95. #pragma pack(pop)
  96. // Holding register structure to keep characteristic's values
  97. #pragma pack(push, 1)
  98. typedef struct
  99. {
  100. // Parameter: Data channel 0 : mb_device1_humidity
  101. float mb_device1_humidity;
  102. // Parameter: Data channel 1 : mb_device1_temperature
  103. float mb_device1_temperature;
  104. // Parameter: Data channel 2 : mb_device2_humidity
  105. float mb_device2_humidity;
  106. // Parameter: Data channel 3 : mb_device2_temperature
  107. float mb_device2_temperature;
  108. // Parameter: Protocol version : protocol_version
  109. uint16_t mb_device1_protocol_version;
  110. // Parameter: Hardware version : hardware_version
  111. uint16_t mb_device1_hardware_version;
  112. // Parameter: Software Version : software_version
  113. uint16_t mb_device1_software_version;
  114. // Parameter: Software Revision : software_revision
  115. uint16_t mb_device1_software_revision;
  116. // Parameter: Device Type : deviceType :
  117. uint16_t mb_device1_device_type;
  118. uint8_t mb_device1_string_test[PARAM_SIZE_ASCII24];
  119. } holding_reg_params_t;
  120. #pragma pack(pop)
  121. extern holding_reg_params_t holding_reg_params;
  122. extern input_reg_params_t input_reg_params;
  123. extern coil_reg_params_t coil_reg_params;
  124. extern discrete_reg_params_t discrete_reg_params;
  125. extern const mb_parameter_descriptor_t device_parameters[];
  126. extern const uint16_t num_device_parameters;
  127. #endif /* _DEVICEPARAMS_H_ */