iec104.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #ifndef _IEC104_H
  2. #define _IEC104_H
  3. #include "iec104_conf.h"
  4. #include "iec104_queue.h"
  5. #include "iec104_types.h"
  6. #define IEC104_MAX_BUF_LEN 256
  7. #define IEC104_HEAD 0X68
  8. /*
  9. * PRIO
  10. * */
  11. #define IEC104_PRIO_INITLINK 0
  12. #define IEC104_PRIO_CALLALL 1
  13. #define IEC104_PRIO_CALLGROUP 2
  14. #define IEC104_PRIO_CLOCK 3
  15. #define IEC104_PRIO_DELAY 3
  16. #define IEC104_PRIO_PULSE 0
  17. #define IEC104_PRIO_SPON 0
  18. /*
  19. * Ctrl U Function
  20. * */
  21. #define IEC104_U_FUNC_STARTDT 0x07 // 0B00000111
  22. #define IEC104_U_FUNC_STOPDT 0x13 // 0B00010011
  23. #define IEC104_U_FUNC_TESTER 0x43 // 0B01000011
  24. #define IEC104_U_FUNC_STARTDT_ACK 0x0b // 0B00001011
  25. #define IEC104_U_FUNC_STOPDT_ACK 0x23 // 0B00100011
  26. #define IEC104_U_FUNC_TESTER_ACK 0x83 // 0B10000011
  27. /*
  28. * ASDU Type Upload station address
  29. * */
  30. #define IEC104_ASDU_TYPE_M_DTU_INF_1 180
  31. #define IEC104_INFO_SIGNATURE 0XEB90EB90
  32. /*
  33. * Info Address
  34. * */
  35. #define IEC104_DEV_TYPE_HXGF 0X03
  36. #define IEC104_DEV_TYPE_HXTM 0X01
  37. #define IEC104_INFOADDR_VALUE_HXGF 0X004001
  38. #define IEC104_INFOADDR_VALUE_HXTM 0X004201
  39. #define IEC104_INFOADDR_STATE_HXGF 0X000001
  40. #define IEC104_INFOADDR_STATE_HXTM 0X000301
  41. /* base device information */
  42. #define IEC104_INFOADDR_BASE_DEVINFO 0X102001
  43. /*
  44. * device type
  45. */
  46. // #define ENDDEVICE_TYPE_ERR 0
  47. // #define ENDDEVICE_TYPE_HXPF 2
  48. #define ENDDEVICE_TYPE_HXTM 1
  49. #define ENDDEVICE_TYPE_HXGF 3
  50. #define AP_TYPE_BASE_INFO 4
  51. /* COT */
  52. #define AP_COT_BASE_INFO 18
  53. #pragma pack(1)
  54. /*
  55. * Iec104 package
  56. * */
  57. /* Control filed I type */
  58. typedef struct
  59. {
  60. iec_32u type : 1;
  61. iec_32u send_sn : 15;
  62. iec_32u reserve : 1;
  63. iec_32u recv_sn : 15;
  64. } iec104_ctrl_i_t, *p_iec104_ctrl_i_t;
  65. /* Control filed S type */
  66. typedef struct
  67. {
  68. iec_32u type_1 : 1;
  69. iec_32u type_2 : 1;
  70. iec_32u reserve : 15;
  71. iec_32u recv_sn : 15;
  72. } iec104_ctrl_s_t, *p_iec104_ctrl_s_t;
  73. /* Control filed U type */
  74. typedef struct
  75. {
  76. iec_32u type_1 : 1;
  77. iec_32u type_2 : 1;
  78. iec_32u startdt : 1;
  79. iec_32u startdt_ack : 1;
  80. iec_32u stopdt : 1;
  81. iec_32u stopdt_ack : 1;
  82. iec_32u tester : 1;
  83. iec_32u tester_ack : 1;
  84. iec_32u reserve : 24;
  85. } iec104_ctrl_u_t, *p_iec104_ctrl_u_t;
  86. /* Control filed type */
  87. typedef struct
  88. {
  89. iec_32u type_1 : 1;
  90. iec_32u type_2 : 1;
  91. iec_32u reserve : 30;
  92. } iec104_ctrl_type_t, *p_iec104_ctrl_type_t;
  93. /* Control filed type */
  94. typedef struct
  95. {
  96. iec_32u func : 8;
  97. iec_32u reserve : 24;
  98. } iec104_ctrl_func_t, *p_iec104_ctrl_func_t;
  99. typedef union
  100. {
  101. iec104_ctrl_i_t i;
  102. iec104_ctrl_s_t s;
  103. iec104_ctrl_u_t u;
  104. iec104_ctrl_type_t type;
  105. iec104_ctrl_func_t func;
  106. } iec104_ctrl_t, *p_iec104_ctrl_t;
  107. typedef struct
  108. {
  109. iec_8u head;
  110. iec_8u len;
  111. iec104_ctrl_t ctrl;
  112. iec_8u asdu[1];
  113. } iec104_data_t, *p_iec104_data_t;
  114. typedef struct
  115. {
  116. float Current;
  117. float Temperature;
  118. } iec10x_dev_a_info_t, *p_iec10x_dev_a_info_t;
  119. #pragma pack()
  120. /*
  121. * length
  122. * */
  123. #define IEC104_HEAD_LEN (sizeof(iec104_data_t) - 1)
  124. #define IEC104_ASDU_LEN (sizeof(iec10x_asdu_t) - 1)
  125. #define IEC104_INFO_LEN (sizeof(asdu_info_t) - 1)
  126. #define IEC104_DATA_LEN (IEC104_HEAD_LEN + IEC104_ASDU_LEN + IEC104_INFO_LEN)
  127. enum
  128. {
  129. IEC104_FLAG_RECV_CLOSED, /*0*/
  130. IEC104_FLAG_SEND_CLOSED, /*1*/
  131. IEC104_FLAG_CLOSED, /*2*/
  132. IEC104_FLAG_LINK_INIT, /*3*/
  133. IEC104_FLAG_IDLE, /*4*/
  134. IEC104_FLAG_UPLOAD_ADDR, /*5*/
  135. IEC104_FLAG_START_LINK, /*6*/
  136. IEC104_FLAG_REQ_LINK, /*7*/
  137. IEC104_FLAG_RESET_REMOTE_LINK, /*8*/
  138. IEC104_FLAG_INIT_FIN, /*9*/
  139. IEC104_FLAG_CALL_ALLDATA, /*10*/
  140. IEC101_FLAG_CALL_GROURPDATA, /*11*/
  141. IEC104_FLAG_CALL_ACT_FIN, /*12*/
  142. IEC104_FLAG_CALL_SIG_TOTAL, /*13*/
  143. IEC104_FLAG_CALL_DET_TOTAL, /*14*/
  144. IEC104_FLAG_CLOCK_SYS, /*15*/
  145. IEC104_FLAG_TESTER, /*16*/
  146. IEC104_FLAG_TESTER_STOP, /*17*/
  147. IEC104_FLAG_CALL_GROUP, /*18*/
  148. IEC104_FLAG_CONNECT_SUCESS, /*19*/
  149. IEC104_FLAG_S_ACK, /*20*/
  150. };
  151. /*
  152. *********************************************************************************************************
  153. * EXTERN VARIABLE
  154. *********************************************************************************************************
  155. */
  156. extern iec_8u IEC104_STATE_FLAG_INIT;
  157. extern iec_8u IEC104_STATE_FLAG_CALLALL;
  158. extern iec_8u IEC104_STATE_FLAG_GROUP;
  159. extern iec_8u IEC104_STATE_FLAG_CLOCK;
  160. extern iec_8u IEC104_STATE_FLAG_PULSE;
  161. /*
  162. *********************************************************************************************************
  163. * FUNCTION
  164. *********************************************************************************************************
  165. */
  166. iec_8u iec104_state_machine(void);
  167. iec_8u iec104_build_signal_spon(iec_8u TimeFlag, iec_8u signalV, iec_16u addrV);
  168. iec_8u iec104_build_detect_f_spont(iec_8u TimeFlag, float detectV, iec_16u addrV);
  169. void iec104_receive(iec_8u *buf, iec_16u len);
  170. iec_8u iec104_build_detect_spont(iec_8u TimeFlag, PIEC10X_DETECT_T detectV, iec_16u addrV);
  171. #endif