iec104.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #ifndef _IEC104_H
  2. #define _IEC104_H
  3. #include "iec10x.h"
  4. #include "iec10x_conf.h"
  5. #include "iec10x_type.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 SendSn : 15;
  62. iec_32u Reserve : 1;
  63. iec_32u RecvSn : 15;
  64. } IEC104_CTRL_I_T, *PIEC104_CTRL_I_T;
  65. /* Control filed S type */
  66. typedef struct
  67. {
  68. iec_32u Type1 : 1;
  69. iec_32u Type2 : 1;
  70. iec_32u Reserve : 15;
  71. iec_32u RecvSn : 15;
  72. } IEC104_CTRL_S_T, *PEC104_CTRL_S_TP;
  73. /* Control filed U type */
  74. typedef struct
  75. {
  76. iec_32u Type1 : 1;
  77. iec_32u Type2 : 1;
  78. iec_32u Startdt : 1;
  79. iec_32u StartdtAck : 1;
  80. iec_32u Stopdt : 1;
  81. iec_32u StopdtAck : 1;
  82. iec_32u Tester : 1;
  83. iec_32u TesterAck : 1;
  84. iec_32u Reserve : 24;
  85. } IEC104_CTRL_U_T, *PIEC104_CTRL_U_T;
  86. /* Control filed type */
  87. typedef struct
  88. {
  89. iec_32u Type1 : 1;
  90. iec_32u Type2 : 1;
  91. iec_32u Reserve : 30;
  92. } IEC104_CTRLType_T, *PIEC104_CTRLType_T;
  93. /* Control filed type */
  94. typedef struct
  95. {
  96. iec_32u Func : 8;
  97. iec_32u Reserve : 24;
  98. } IEC104_CTRLFunc_T, *PIEC104_CTRLFunc_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_CTRLType_T Type;
  105. IEC104_CTRLFunc_T Func;
  106. } IEC104_CTRL_T, *PIEC104_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, *PIEC104_DATA_T;
  114. typedef struct
  115. {
  116. float Current;
  117. float Temperature;
  118. } Iec10x_DevA_Info_T, *PIec10x_DevA_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_StateMachine(void);
  167. iec_8u IEC104_BuildSignal_Spon(iec_8u TimeFlag, iec_8u signalV, iec_16u addrV);
  168. iec_8u IEC104_BuildDetectF_Spont(iec_8u TimeFlag, float detectV, iec_16u addrV);
  169. void Iex104_Receive(iec_8u *buf, iec_16u len);
  170. iec_8u IEC104_BuildDetect_Spont(iec_8u TimeFlag, PIEC10X_DETECT_T detectV, iec_16u addrV);
  171. #endif