IEC101.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #ifndef __IEC101_H
  2. #define __IEC101_H
  3. #include "stm32f2xx.h"
  4. #define SendData USART_232_Send
  5. #define INVALID_DATA 0
  6. #define VARIABLE_DATA 1 // 可变帧
  7. #define STABLE_DATA 2 // 固定帧
  8. //在监视方向上的过程信息
  9. #define NULL 0 //未定义
  10. #define M_SP_NA_1 1 //单点信息
  11. #define M_SP_TA_1 2 //带时标的单点信息
  12. #define M_DP_NA_1 3 //双点信息
  13. #define M_DP_TA_1 4 //带时标的双点信息
  14. #define M_ST_NA_1 5 //步位置信息
  15. #define M_ST_TA_1 6 //带时标的步位置信息
  16. #define M_BO_NA_1 7 //32比特串
  17. #define M_BO_TA_1 8 //带时标的32比特串
  18. #define M_ME_NA_1 9 //测量值,规一化值
  19. #define M_ME_TA_1 10 //测量值,带时标的规一化值
  20. #define M_ME_NB_1 11 //测量值,标度化值
  21. #define M_ME_TB_1 12 //测量值,带时标的标度化值
  22. #define M_ME_NC_1 13 //测量值,短浮点数
  23. #define M_ME_TC_1 14 //测量值,带时标的短浮点数
  24. #define M_IT_NA_1 15 //累计量
  25. #define M_IT_TA_1 16 //带时标的累计量
  26. #define M_EP_TA_1 17 //带时标的继电设备保护事件
  27. #define M_EP_TB_1 18 //时标的继电保护设备成组启动事件
  28. #define M_EP_TC_1 19 //带时标的继电保护设备成组输出电路信息
  29. #define M_PS_NA_1 20 //带变位检出的成组单点信息
  30. #define M_ME_ND_1 21 //测量值,不带品质描述词的规一化值
  31. #define RESERVED_22 22 //为将来兼容定义保留
  32. #define RESERVED_23 23 //为将来兼容定义保留
  33. #define RESERVED_24 24 //为将来兼容定义保留
  34. #define RESERVED_25 25 //为将来兼容定义保留
  35. #define RESERVED_26 26 //为将来兼容定义保留
  36. #define RESERVED_27 27 //为将来兼容定义保留
  37. #define RESERVED_28 28 //为将来兼容定义保留
  38. #define RESERVED_29 29 //为将来兼容定义保留
  39. #define M_SP_TB_1 30 //带CP56Time2a时标的单点信息
  40. #define M_DP_TB_1 31 //带CP56Time2a时标的双点信息
  41. #define M_ST_TB_1 32 //带CP56Time2a时标的步位置信息
  42. #define M_BO_TB_1 33 //带CP56Time2a时标的32比特串
  43. #define M_ME_TD_1 34 //带CP56Time2a时标的测量值, 规一化值
  44. #define M_ME_TE_1 35 //带CP56Time2a时标的测量值, 标度化值
  45. #define M_ME_TF_1 36 //带CP56Time2a时标的测量值, 短浮点数
  46. #define M_IT_TB_1 37 //带CP56Time2a时标的累计量
  47. #define M_EP_TD_1 38 //带CP56Time2a时标的继电保护设备事件
  48. #define M_EP_TE_1 39 //带CP56Time2a时标的继电保护设备成组启动事件
  49. #define M_EP_TF_1 40 //带CP56Time2a时标的继电保护设备成组输出电路信息
  50. #define RESERVED_41 41 //为将来兼容定义保留
  51. #define RESERVED_42 42 //为将来兼容定义保留
  52. #define RESERVED_43 43 //为将来兼容定义保留
  53. #define RESERVED_44 44 //为将来兼容定义保留
  54. //在控制方向上的过程信息
  55. #define C_SC_NA_1 45 //单点命令
  56. #define C_DC_NA_1 46 //双点命令
  57. #define C_RC_NA_1 47 //步调节命令
  58. #define C_SE_NA_1 48 //设定值命令, 规一化值
  59. #define C_SE_NB_1 49 //设定值命令, 标度化值
  60. #define C_SE_NC_1 50 //设定值命令, 短浮点数
  61. #define C_BO_NA_1 51 //32比特串
  62. #define RESERVED_52 52 //为将来兼容定义保留
  63. #define RESERVED_53 53 //为将来兼容定义保留
  64. #define RESERVED_54 54 //为将来兼容定义保留
  65. #define RESERVED_55 55 //为将来兼容定义保留
  66. #define RESERVED_56 56 //为将来兼容定义保留
  67. #define RESERVED_57 57 //为将来兼容定义保留
  68. #define RESERVED_58 58 //为将来兼容定义保留
  69. #define RESERVED_59 59 //为将来兼容定义保留
  70. #define RESERVED_60 60 //为将来兼容定义保留
  71. #define RESERVED_61 61 //为将来兼容定义保留
  72. #define RESERVED_62 62 //为将来兼容定义保留
  73. #define RESERVED_63 63 //为将来兼容定义保留
  74. #define RESERVED_64 64 //为将来兼容定义保留
  75. #define RESERVED_65 65 //为将来兼容定义保留
  76. #define RESERVED_66 66 //为将来兼容定义保留
  77. #define RESERVED_67 67 //为将来兼容定义保留
  78. #define RESERVED_68 68 //为将来兼容定义保留
  79. #define RESERVED_69 69 //为将来兼容定义保留
  80. //在监视方向的系统命令
  81. #define M_EI_NA_1 70 //初始化结束
  82. #define RESERVED_71 71 //为将来兼容定义保留
  83. #define RESERVED_72 72 //为将来兼容定义保留
  84. #define RESERVED_73 73 //为将来兼容定义保留
  85. #define RESERVED_74 74 //为将来兼容定义保留
  86. #define RESERVED_75 75 //为将来兼容定义保留
  87. #define RESERVED_76 76 //为将来兼容定义保留
  88. #define RESERVED_77 77 //为将来兼容定义保留
  89. #define RESERVED_78 78 //为将来兼容定义保留
  90. #define RESERVED_79 79 //为将来兼容定义保留
  91. #define RESERVED_80 80 //为将来兼容定义保留
  92. #define RESERVED_81 81 //为将来兼容定义保留
  93. #define RESERVED_82 82 //为将来兼容定义保留
  94. #define RESERVED_83 83 //为将来兼容定义保留
  95. #define RESERVED_84 84 //为将来兼容定义保留
  96. #define RESERVED_85 85 //为将来兼容定义保留
  97. #define RESERVED_86 86 //为将来兼容定义保留
  98. #define RESERVED_87 87 //为将来兼容定义保留
  99. #define RESERVED_88 88 //为将来兼容定义保留
  100. #define RESERVED_89 89 //为将来兼容定义保留
  101. #define RESERVED_90 90 //为将来兼容定义保留
  102. #define RESERVED_91 91 //为将来兼容定义保留
  103. #define RESERVED_92 92 //为将来兼容定义保留
  104. #define RESERVED_93 93 //为将来兼容定义保留
  105. #define RESERVED_94 94 //为将来兼容定义保留
  106. #define RESERVED_95 95 //为将来兼容定义保留
  107. #define RESERVED_96 96 //为将来兼容定义保留
  108. #define RESERVED_97 97 //为将来兼容定义保留
  109. #define RESERVED_98 98 //为将来兼容定义保留
  110. #define RESERVED_99 99 //为将来兼容定义保留
  111. //在控制方向的系统命令
  112. #define C_IC_NA_1 100 //总召唤命令
  113. #define C_CI_NA_1 101 //计数量召唤命令
  114. #define C_RD_NA_1 102 //读命令
  115. #define C_CS_NA_1 103 //时钟同步命令
  116. #define C_TS_NA_1 104 //测试命今
  117. #define C_RP_NA_1 105 //复位进程命令
  118. #define C_CD_NA_1 106 //延时获得命今
  119. #define RESERVED_107 107 //为将来兼容定义保留
  120. #define RESERVED_108 108 //为将来兼容定义保留
  121. #define RESERVED_109 109 //为将来兼容定义保留
  122. //在控制方向的参数命令
  123. #define P_ME_NA_1 110 //测量值参数, 规一化值
  124. #define P_ME_NB_1 111 //测量值参数, 标度化值
  125. #define P_ME_NC_1 112 //测量值参数, 短浮点数
  126. #define P_AC_NA_1 113 //参数激活
  127. #define RESERVED_114 114 //为将来兼容定义保留
  128. #define RESERVED_115 115 //为将来兼容定义保留
  129. #define RESERVED_116 116 //为将来兼容定义保留
  130. #define RESERVED_117 117 //为将来兼容定义保留
  131. #define RESERVED_118 118 //为将来兼容定义保留
  132. #define RESERVED_119 119 //为将来兼容定义保留
  133. //文件传输
  134. #define F_FR_NA_1 120 //文件准备就绪
  135. #define F_SR_NA_1 121 //节准备就绪
  136. #define F_SC_NA_1 122 //召唤目录, 选择文件, 召唤文件,召唤节
  137. #define F_LS_NA_1 123 //最后的节,最后的段
  138. #define F_AF_NA_1 124 //认可文件,认可节
  139. #define F_SG_NA_1 125 //段
  140. #define F_DR_TA_1 126 //目录
  141. #define RESERVED_127 127 //为将来兼容定义保留
  142. //定义控制域功能码(平衡传输)
  143. //启动站向从动站传输报文控制域的功能码(PRM=1)
  144. #define RST_LINK_FUNC 0x00
  145. #define RST_PROCESS_FUNC 0x01
  146. #define TEST_LINK_FUNC 0x02
  147. #define USER_DATA_FUNC 0x03
  148. #define NO_ANSWER_DATA_FUNC 0x04
  149. #define LINK_STATUS_FUNC 0x09
  150. //从动站向启动站传输报文控制域的功能码(PRM=0)
  151. #define RETURN_OK_FUNC 0x00
  152. #define RETURN_NO_OK_FUNC 0x01
  153. #define ACK_LINK_STATUS 0x0B
  154. #define S2M_DIR 1 //从从站(B站)到主站(A站)DIR为1
  155. #define M2S_DIR 0 //从主站(A站)到从站(B站)DIR为0
  156. typedef struct {
  157. uint8_t TypeID;
  158. uint8_t Qualifier;
  159. uint16_t Reason;
  160. uint16_t ASDU_Address;
  161. uint16_t InfoAddress;
  162. uint8_t InfoData[16];
  163. } ASDU_DataStructure;
  164. typedef struct {
  165. uint8_t Year;
  166. uint8_t Month;
  167. uint8_t Day;
  168. uint8_t Hour;
  169. uint8_t Min;
  170. uint8_t Sec;
  171. uint16_t MilliSec;
  172. } TimeStructure;
  173. extern uint8_t Info[16]; //开关量数量 0/1/2 跌落 3跌落状态 4温度状态 5 欠压 6/7/8/9 漏保
  174. extern uint8_t InfoTemp[8]; //温度
  175. extern uint8_t DataFromGPRSBuffer[128];
  176. extern uint8_t moduleMaskEn; // 模块故障MASK
  177. extern unsigned char Time_Data[8];
  178. extern uint8_t ProtocolRxBuffer[64]; //存储主站发过来的命令
  179. extern uint8_t LINK_ADDRESS; //定义链路地址
  180. void creatTest(void);
  181. uint8_t CheckError(uint8_t* pBuffer);
  182. uint8_t IEC_Protocol(uint8_t* pBuffer);
  183. uint8_t DataProcess(void);
  184. void LinkInit(void);
  185. uint8_t ResponseCallAll(void);
  186. void ChangeUpdate(uint16_t InfoAdress, uint8_t Info, TimeStructure* Time);
  187. void TempChangeUpdate(uint16_t InfoAdress, uint8_t Info, TimeStructure* Time);
  188. #endif //__101_PROTOCOL_H__