iec101.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*******************************************************************
  2. Copyright (C):
  3. File name : Iec101.h
  4. DESCRIPTION :
  5. AUTHOR :
  6. Version : 1.0
  7. Date : 2014/07/23
  8. Others :
  9. History :
  10. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  11. 1) Date: 2014/07/23 Author: ChenDajie
  12. content:
  13. *******************************************************************/
  14. #ifndef _IEC101_H
  15. #define _IEC101_H
  16. #include "iec10x.h"
  17. #include "iec10x_conf.h"
  18. #include "iec10x_prio_queue.h"
  19. #include "iec10x_type.h"
  20. #include <stdio.h>
  21. #include <string.h>
  22. #ifdef IEC101_STM32
  23. #define ARM_PACK __packed
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. /*
  29. *********************************************************************************************************
  30. * FUNCTION CODE
  31. *********************************************************************************************************
  32. */
  33. /*
  34. * down
  35. * */
  36. #define IEC101_CTRL_RESET_LINK 0
  37. #define IEC101_CTRL_PULSE 2
  38. #define IEC101_CTRL_SEND_USR_DATA_ACK 3
  39. #define IEC101_CTRL_SEND_DATA 4
  40. #define IEC101_CTRL_REQ_LINK_STATUS 9
  41. /*
  42. * up
  43. * */
  44. #define IEC101_CTRL_RES_CONFIRM 0x00
  45. #define IEC101_CTRL_RES_LINK_STATUS 0x0B
  46. /*
  47. * DIR, PRM, FCB, FCV, ACD, DFC
  48. * */
  49. #define IEC101_CTRL_DIR_DOWN 0x01
  50. #define IEC101_CTRL_DIR_UP 0x00
  51. #define IEC101_CTRL_FCB_OPPO_BIT 0x01
  52. #define IEC101_CTRL_FCB_OPPO_NONE 0x00
  53. #define IEC101_CTRL_PRM_MASTER 0x01
  54. #define IEC101_CTRL_PRM_SLAVE 0x00
  55. #define IEC101_CTRL_FCV_ENABLE 0x01
  56. #define IEC101_CTRL_FCV_DISABLE 0x00
  57. #define IEC101_CTRL_ACD_WITH_DATA 0x01
  58. #define IEC101_CTRL_ACD_NONE_DATA 0x00
  59. #define IEC101_CTRL_DFC_CAN_REC 0x00
  60. #define IEC101_CTRL_DFC_CANNOT_REC 0x01
  61. /*
  62. *********************************************************************************************************
  63. * FRAME VALUE
  64. *********************************************************************************************************
  65. */
  66. #define IEC101_STABLE_BEGING 0X10
  67. #define IEC101_STABLE_END 0X16
  68. #define IEC101_STABLE_LEN 0X06
  69. /*
  70. * variable
  71. * */
  72. #define IEC101_VARIABLE_BEGING 0X68
  73. #define IEC101_VARIABLE_END 0X16
  74. /*
  75. * length of variable
  76. * */
  77. #define IEC101_VARIABLE_HEAD_LEN (sizeof(IEC101_68_T) - 1)
  78. #define IEC101_VARIABLE_ASDU_LEN (sizeof(IEC10X_ASDU_T) - 1)
  79. #define IEC101_VARIABLE_INFO_LEN (sizeof(ASDU_INFO_T) - 1)
  80. #define IEC101_VARIABLE_LEN (IEC101_VARIABLE_HEAD_LEN + IEC101_VARIABLE_ASDU_LEN + IEC101_VARIABLE_INFO_LEN + 2) /*add cs+end*/
  81. #pragma pack(1)
  82. #define IEC101_MAX_BUF_LEN 256
  83. /*
  84. * Control Code
  85. * */
  86. typedef __packed struct
  87. {
  88. iec_8u _func : 4; /* function */
  89. iec_8u _fcv : 1;
  90. iec_8u _fcb : 1; /* Frame calculate bit */
  91. iec_8u _prm : 1; /* 1:from start station, 0:from end station */
  92. iec_8u _dir : 1;
  93. } CTRL_DOWN_T;
  94. typedef __packed struct
  95. {
  96. iec_8u _func : 4; /*function*/
  97. iec_8u _dfc : 1;
  98. iec_8u _acd : 1;
  99. iec_8u _prm : 1;
  100. iec_8u _dir : 1;
  101. } CTRL_UP_T;
  102. typedef __packed union
  103. {
  104. CTRL_UP_T up;
  105. CTRL_DOWN_T down;
  106. iec_8u val;
  107. } CTRL_T, *PCTRL_T;
  108. /*
  109. * regular frame head:10
  110. * */
  111. typedef __packed struct
  112. {
  113. iec_8u _begin;
  114. CTRL_T _ctrl;
  115. iec_16u _addr;
  116. iec_8u _cs;
  117. iec_8u _end;
  118. } IEC101_10_T, *PIEC101_10_T;
  119. /*
  120. * variable fram head:68
  121. * */
  122. typedef __packed struct
  123. {
  124. iec_8u _begin;
  125. iec_8u _len;
  126. iec_8u _len_cfm;
  127. iec_8u _begin_cfm;
  128. CTRL_T _ctrl;
  129. iec_16u _addr;
  130. iec_8u _asdu[1];
  131. } IEC101_68_T, *PIEC101_68_T;
  132. #pragma pack()
  133. /* IEC101 STATE-MACHINE */
  134. enum
  135. {
  136. IEC101_FLAG_LINK_CLOSED,
  137. IEC101_FLAG_LINK_IDLE,
  138. IEC101_FLAG_INIT_LINK,
  139. IEC101_FLAG_RESET_LINK,
  140. IEC101_FLAG_REQ_LINK,
  141. IEC101_FLAG_RESET_REMOTE_LINK,
  142. IEC101_FLAG_INIT_FIN,
  143. IEC101_FLAG_CALL_ACT,
  144. IEC101_FLAG_CALL_ACT_FIN,
  145. IEC101_FLAG_CALL_ACT_RET,
  146. IEC101_FLAG_CALL_SIG_TOTAL,
  147. IEC101_FLAG_CALL_DET_TOTAL,
  148. IEC101_FLAG_DELAY_ACT,
  149. IEC101_FLAG_CLOCK_SYS,
  150. IEC101_FLAG_PULSE,
  151. IEC101_FLAG_CALL_GROUP,
  152. IEC101_FLAG_CONNECT_OK,
  153. };
  154. /*
  155. *********************************************************************************************************
  156. * GLOABLE VARIABLE
  157. *********************************************************************************************************
  158. */
  159. extern iec_16u IEC101_Pulse_Cnt;
  160. extern iec_8u IEC101_STATE_FLAG_INIT;
  161. /*
  162. *********************************************************************************************************
  163. * FUNCTION PROTOTYPES
  164. *********************************************************************************************************
  165. */
  166. void Iex101_main(iec_8u *buf, iec_16u len);
  167. iec_8u Iec101_StateMachine(void);
  168. iec_8u IEC101_BuildSignal_Spont(iec_8u TimeFlag, iec_8u signalV, iec_16u addrV);
  169. iec_8u IEC101_BuildDetect_Spont(iec_8u TimeFlag, PIEC10X_DETECT_T detectV, iec_16u addrV);
  170. iec_8u IEC101_BuildDetectF_Spont(iec_8u TimeFlag, float detectV, iec_16u addrV);
  171. #ifdef __cplusplus
  172. }
  173. #endif /*IEC101_STM32*/
  174. #endif
  175. #endif /*_IEC101_H*/