iec104.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #ifndef _IEC104_H
  2. #define _IEC104_H
  3. #include "iec10x.h"
  4. #include "project_var.h"
  5. #define IEC104_MAX_BUF_LEN 256
  6. #define IEC104_HEAD 0X68
  7. /*
  8. * PRIO
  9. * */
  10. #define IEC104_PRIO_INITLINK 0
  11. #define IEC104_PRIO_CALLALL 1
  12. #define IEC104_PRIO_CALLGROUP 2
  13. #define IEC104_PRIO_CLOCK 3
  14. #define IEC104_PRIO_DELAY 3
  15. #define IEC104_PRIO_PULSE 0
  16. #define IEC104_PRIO_SPON 0
  17. /*
  18. * Ctrl U Function
  19. * */
  20. #define IEC104_U_FUNC_STARTDT 0x07 //0B00000111
  21. #define IEC104_U_FUNC_STOPDT 0x13 //0B00010011
  22. #define IEC104_U_FUNC_TESTER 0x43 //0B01000011
  23. #define IEC104_U_FUNC_STARTDT_ACK 0x0b //0B00001011
  24. #define IEC104_U_FUNC_STOPDT_ACK 0x23 //0B00100011
  25. #define IEC104_U_FUNC_TESTER_ACK 0x83 //0B10000011
  26. /*
  27. * ASDU Type Upload station address
  28. * */
  29. #define IEC104_ASDU_TYPE_M_DTU_INF_1 180
  30. #define IEC104_INFO_SIGNATURE 0XEB90EB90
  31. /*
  32. * Info Address
  33. * */
  34. #define IEC104_DEV_TYPE_HXGF 0X03
  35. #define IEC104_DEV_TYPE_HXTM 0X01
  36. #define IEC104_INFOADDR_VALUE_HXGF 0X004001
  37. #define IEC104_INFOADDR_VALUE_HXTM 0X004201
  38. #define IEC104_INFOADDR_STATE_HXGF 0X000001
  39. #define IEC104_INFOADDR_STATE_HXTM 0X000301
  40. /* base device information */
  41. #define IEC104_INFOADDR_BASE_DEVINFO 0X102001
  42. /*
  43. * device type
  44. */
  45. //#define ENDDEVICE_TYPE_ERR 0
  46. //#define ENDDEVICE_TYPE_HXPF 2
  47. #define ENDDEVICE_TYPE_HXTM 1
  48. #define ENDDEVICE_TYPE_HXGF 3
  49. #define AP_TYPE_BASE_INFO 4
  50. /* COT */
  51. #define AP_COT_BASE_INFO 18
  52. #pragma pack(1)
  53. /*
  54. * Iec104 package
  55. * */
  56. /* Control filed I type */
  57. typedef struct {
  58. uint32_t Type:1;
  59. uint32_t SendSn:15;
  60. uint32_t Reserve:1;
  61. uint32_t RecvSn:15;
  62. }IEC104_CTRL_I_T, *PIEC104_CTRL_I_T;
  63. /* Control filed S type */
  64. typedef struct {
  65. uint32_t Type1:1;
  66. uint32_t Type2:1;
  67. uint32_t Reserve:15;
  68. uint32_t RecvSn:15;
  69. }IEC104_CTRL_S_T, *PEC104_CTRL_S_TP;
  70. /* Control filed U type */
  71. typedef struct {
  72. uint32_t Type1:1;
  73. uint32_t Type2:1;
  74. uint32_t Startdt:1;
  75. uint32_t StartdtAck:1;
  76. uint32_t Stopdt:1;
  77. uint32_t StopdtAck:1;
  78. uint32_t Tester:1;
  79. uint32_t TesterAck:1;
  80. uint32_t Reserve:24;
  81. }IEC104_CTRL_U_T, *PIEC104_CTRL_U_T;
  82. /* Control filed type */
  83. typedef struct {
  84. uint32_t Type1:1;
  85. uint32_t Type2:1;
  86. uint32_t Reserve:30;
  87. }IEC104_CTRLType_T, *PIEC104_CTRLType_T;
  88. /* Control filed type */
  89. typedef struct {
  90. uint32_t Func:8;
  91. uint32_t Reserve:24;
  92. }IEC104_CTRLFunc_T, *PIEC104_CTRLFunc_T;
  93. typedef union{
  94. IEC104_CTRL_I_T I;
  95. IEC104_CTRL_S_T S;
  96. IEC104_CTRL_U_T U;
  97. IEC104_CTRLType_T Type;
  98. IEC104_CTRLFunc_T Func;
  99. }IEC104_CTRL_T, *PIEC104_CTRL_T;
  100. typedef struct{
  101. uint8_t Head;
  102. uint8_t Len;
  103. IEC104_CTRL_T Ctrl;
  104. uint8_t Asdu[1];
  105. }IEC104_DATA_T,*PIEC104_DATA_T;
  106. typedef struct {
  107. float Current;
  108. float Temperature;
  109. }Iec10x_DevA_Info_T, *PIec10x_DevA_Info_T;
  110. #pragma pack()
  111. /*
  112. * length
  113. * */
  114. #define IEC104_HEAD_LEN (sizeof(IEC104_DATA_T)-1)
  115. #define IEC104_ASDU_LEN (sizeof(IEC10X_ASDU_T)-1)
  116. #define IEC104_INFO_LEN (sizeof(ASDU_INFO_T)-1)
  117. #define IEC104_DATA_LEN (IEC104_HEAD_LEN+IEC104_ASDU_LEN+IEC104_INFO_LEN)
  118. enum {
  119. IEC104_FLAG_RECV_CLOSED, /*0*/
  120. IEC104_FLAG_SEND_CLOSED, /*1*/
  121. IEC104_FLAG_CLOSED, /*2*/
  122. IEC104_FLAG_LINK_INIT, /*3*/
  123. IEC104_FLAG_IDLE, /*4*/
  124. IEC104_FLAG_UPLOAD_ADDR, /*5*/
  125. IEC104_FLAG_START_LINK, /*6*/
  126. IEC104_FLAG_REQ_LINK, /*7*/
  127. IEC104_FLAG_RESET_REMOTE_LINK, /*8*/
  128. IEC104_FLAG_INIT_FIN, /*9*/
  129. IEC104_FLAG_CALL_ALLDATA, /*10*/
  130. IEC101_FLAG_CALL_GROURPDATA, /*11*/
  131. IEC104_FLAG_CALL_ACT_FIN, /*12*/
  132. IEC104_FLAG_CALL_SIG_TOTAL, /*13*/
  133. IEC104_FLAG_CALL_DET_TOTAL, /*14*/
  134. IEC104_FLAG_CLOCK_SYS, /*15*/
  135. IEC104_FLAG_TESTER, /*16*/
  136. IEC104_FLAG_TESTER_STOP, /*17*/
  137. IEC104_FLAG_CALL_GROUP, /*18*/
  138. IEC104_FLAG_CONNECT_SUCESS, /*19*/
  139. IEC104_FLAG_S_ACK, /*20*/
  140. };
  141. /*
  142. *********************************************************************************************************
  143. * EXTERN VARIABLE
  144. *********************************************************************************************************
  145. */
  146. extern uint8_t IEC104_STATE_FLAG_INIT;
  147. extern uint8_t IEC104_STATE_FLAG_CALLALL;
  148. extern uint8_t IEC104_STATE_FLAG_GROUP;
  149. extern uint8_t IEC104_STATE_FLAG_CLOCK;
  150. extern uint8_t IEC104_STATE_FLAG_PULSE;
  151. /*
  152. *********************************************************************************************************
  153. * FUNCTION
  154. *********************************************************************************************************
  155. */
  156. uint8_t Iec104_StateMachine(void);
  157. uint8_t IEC104_BuildSignal_Spon(uint8_t TimeFlag, uint8_t signalV, uint16_t addrV);
  158. uint8_t IEC104_BuildDetectF_Spont(uint8_t TimeFlag, float detectV, uint16_t addrV);
  159. void Iex104_Receive(uint8_t *buf, uint16_t len);
  160. uint8_t IEC104_BuildDetect_Spont(uint8_t TimeFlag, PIEC10X_DETECT_T detectV, uint16_t addrV);
  161. #endif