iec60870_common.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. /*
  2. * Copyright 2016-2022 Michael Zillgith
  3. *
  4. * This file is part of lib60870-C
  5. *
  6. * lib60870-C is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * lib60870-C is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with lib60870-C. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * See COPYING file for the complete license text.
  20. */
  21. #ifndef _IEC60870_COMMON_H_
  22. #define _IEC60870_COMMON_H_
  23. #include <stdint.h>
  24. #include <stdbool.h>
  25. #include "iec_include.h"
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /**
  30. * \file iec60870_common.h
  31. * \brief Common definitions for IEC 60870-5-101/104
  32. * These types are used by CS101/CS104 master and slaves
  33. */
  34. /**
  35. * @addtogroup COMMON Common API functions
  36. *
  37. * @{
  38. */
  39. #define IEC_60870_5_104_DEFAULT_PORT 2404
  40. #define IEC_60870_5_104_DEFAULT_TLS_PORT 19998
  41. #define LIB60870_VERSION_MAJOR 2
  42. #define LIB60870_VERSION_MINOR 3
  43. #define LIB60870_VERSION_PATCH 3
  44. /**
  45. * \brief lib60870 version information
  46. */
  47. typedef struct {
  48. int major;
  49. int minor;
  50. int patch;
  51. } Lib60870VersionInfo;
  52. /**
  53. * \brief link layer mode for serial link layers
  54. */
  55. typedef enum {
  56. IEC60870_LINK_LAYER_BALANCED = 0,
  57. IEC60870_LINK_LAYER_UNBALANCED = 1
  58. } IEC60870_LinkLayerMode;
  59. /** \brief State of the link layer */
  60. typedef enum {
  61. /** The link layer is idle, there is no communication */
  62. LL_STATE_IDLE,
  63. /** An error has occurred at the link layer, the link may not be usable */
  64. LL_STATE_ERROR,
  65. /** The link layer is busy and therefore no usable */
  66. LL_STATE_BUSY,
  67. /** The link is available for user data transmission and reception */
  68. LL_STATE_AVAILABLE
  69. } LinkLayerState;
  70. /**
  71. * \brief Callback handler for link layer state changes
  72. *
  73. * \param parameter user provided parameter that is passed to the handler
  74. * \param address slave address used by the link layer state machine (only relevant for unbalanced master)
  75. * \param newState the new link layer state
  76. */
  77. typedef void (*IEC60870_LinkLayerStateChangedHandler) (void* parameter, int address, LinkLayerState newState);
  78. /**
  79. * \brief Callback handler for sent and received messages
  80. *
  81. * This callback handler provides access to the raw message buffer of received or sent
  82. * messages. It can be used for debugging purposes. Usually it is not used nor required
  83. * for applications.
  84. *
  85. * \param parameter user provided parameter
  86. * \param msg the message buffer
  87. * \param msgSize size of the message
  88. * \param sent indicates if the message was sent or received
  89. */
  90. typedef void (*IEC60870_RawMessageHandler) (void* parameter, uint8_t* msg, int msgSize, bool sent);
  91. /**
  92. * \brief Parameters for the CS101/CS104 application layer
  93. */
  94. typedef struct sCS101_AppLayerParameters* CS101_AppLayerParameters;
  95. struct sCS101_AppLayerParameters {
  96. int sizeOfTypeId; /* size of the type id (default = 1 - don't change) */
  97. int sizeOfVSQ; /* don't change */
  98. int sizeOfCOT; /* size of COT (1/2 - default = 2 -> COT includes OA) */
  99. int originatorAddress; /* originator address (OA) to use (0-255) */
  100. int sizeOfCA; /* size of common address (CA) of ASDU (1/2 - default = 2) */
  101. int sizeOfIOA; /* size of information object address (IOA) (1/2/3 - default = 3) */
  102. int maxSizeOfASDU; /* maximum size of the ASDU that is generated - the maximum maximum value is 249 for IEC 104 and 254 for IEC 101 */
  103. };
  104. /**
  105. * \brief Message type IDs
  106. */
  107. typedef enum {
  108. M_SP_NA_1 = 1,
  109. M_SP_TA_1 = 2,
  110. M_DP_NA_1 = 3,
  111. M_DP_TA_1 = 4,
  112. M_ST_NA_1 = 5,
  113. M_ST_TA_1 = 6,
  114. M_BO_NA_1 = 7,
  115. M_BO_TA_1 = 8,
  116. M_ME_NA_1 = 9,
  117. M_ME_TA_1 = 10,
  118. M_ME_NB_1 = 11,
  119. M_ME_TB_1 = 12,
  120. M_ME_NC_1 = 13,
  121. M_ME_TC_1 = 14,
  122. M_IT_NA_1 = 15,
  123. M_IT_TA_1 = 16,
  124. M_EP_TA_1 = 17,
  125. M_EP_TB_1 = 18,
  126. M_EP_TC_1 = 19,
  127. M_PS_NA_1 = 20,
  128. M_ME_ND_1 = 21,
  129. M_SP_TB_1 = 30,
  130. M_DP_TB_1 = 31,
  131. M_ST_TB_1 = 32,
  132. M_BO_TB_1 = 33,
  133. M_ME_TD_1 = 34,
  134. M_ME_TE_1 = 35,
  135. M_ME_TF_1 = 36,
  136. M_IT_TB_1 = 37,
  137. M_EP_TD_1 = 38,
  138. M_EP_TE_1 = 39,
  139. M_EP_TF_1 = 40,
  140. S_IT_TC_1 = 41,
  141. C_SC_NA_1 = 45,
  142. C_DC_NA_1 = 46,
  143. C_RC_NA_1 = 47,
  144. C_SE_NA_1 = 48,
  145. C_SE_NB_1 = 49,
  146. C_SE_NC_1 = 50,
  147. C_BO_NA_1 = 51,
  148. C_SC_TA_1 = 58,
  149. C_DC_TA_1 = 59,
  150. C_RC_TA_1 = 60,
  151. C_SE_TA_1 = 61,
  152. C_SE_TB_1 = 62,
  153. C_SE_TC_1 = 63,
  154. C_BO_TA_1 = 64,
  155. M_EI_NA_1 = 70,
  156. S_CH_NA_1 = 81,
  157. S_RP_NA_1 = 82,
  158. S_AR_NA_1 = 83,
  159. S_KR_NA_1 = 84,
  160. S_KS_NA_1 = 85,
  161. S_KC_NA_1 = 86,
  162. S_ER_NA_1 = 87,
  163. S_US_NA_1 = 90,
  164. S_UQ_NA_1 = 91,
  165. S_UR_NA_1 = 92,
  166. S_UK_NA_1 = 93,
  167. S_UA_NA_1 = 94,
  168. S_UC_NA_1 = 95,
  169. C_IC_NA_1 = 100,
  170. C_CI_NA_1 = 101,
  171. C_RD_NA_1 = 102,
  172. C_CS_NA_1 = 103,
  173. C_TS_NA_1 = 104,
  174. C_RP_NA_1 = 105,
  175. C_CD_NA_1 = 106,
  176. C_TS_TA_1 = 107,
  177. P_ME_NA_1 = 110,
  178. P_ME_NB_1 = 111,
  179. P_ME_NC_1 = 112,
  180. P_AC_NA_1 = 113,
  181. F_FR_NA_1 = 120,
  182. F_SR_NA_1 = 121,
  183. F_SC_NA_1 = 122,
  184. F_LS_NA_1 = 123,
  185. F_AF_NA_1 = 124,
  186. F_SG_NA_1 = 125,
  187. F_DR_TA_1 = 126,
  188. F_SC_NB_1 = 127
  189. } IEC60870_5_TypeID;
  190. typedef IEC60870_5_TypeID TypeID;
  191. typedef struct sInformationObject* InformationObject;
  192. /**
  193. * \brief Application Service Data Unit (ASDU) for the CS101/CS104 application layer
  194. */
  195. typedef struct sCS101_ASDU* CS101_ASDU;
  196. typedef struct {
  197. CS101_AppLayerParameters parameters;
  198. uint8_t* asdu;
  199. int asduHeaderLength;
  200. uint8_t* payload;
  201. int payloadSize;
  202. uint8_t encodedData[256];
  203. } sCS101_StaticASDU;
  204. typedef sCS101_StaticASDU* CS101_StaticASDU;
  205. typedef struct sCP16Time2a* CP16Time2a;
  206. struct sCP16Time2a {
  207. uint8_t encodedValue[2];
  208. };
  209. typedef struct sCP24Time2a* CP24Time2a;
  210. struct sCP24Time2a {
  211. uint8_t encodedValue[3];
  212. };
  213. typedef struct sCP32Time2a* CP32Time2a;
  214. /**
  215. * \brief 4 byte binary time
  216. */
  217. struct sCP32Time2a {
  218. uint8_t encodedValue[4];
  219. };
  220. /**
  221. * \brief 7 byte binary time
  222. */
  223. typedef struct sCP56Time2a* CP56Time2a;
  224. struct sCP56Time2a {
  225. uint8_t encodedValue[7];
  226. };
  227. /**
  228. * \brief Base type for counter readings
  229. */
  230. typedef struct sBinaryCounterReading* BinaryCounterReading;
  231. struct sBinaryCounterReading {
  232. uint8_t encodedValue[5];
  233. };
  234. /**
  235. * \brief Parameters for CS104 connections - APCI (application protocol control information)
  236. */
  237. typedef struct sCS104_APCIParameters* CS104_APCIParameters;
  238. struct sCS104_APCIParameters {
  239. int k;
  240. int w;
  241. int t0;
  242. int t1;
  243. int t2;
  244. int t3;
  245. };
  246. #include "cs101_information_objects.h"
  247. typedef enum {
  248. CS101_COT_PERIODIC = 1,
  249. CS101_COT_BACKGROUND_SCAN = 2,
  250. CS101_COT_SPONTANEOUS = 3,
  251. CS101_COT_INITIALIZED = 4,
  252. CS101_COT_REQUEST = 5,
  253. CS101_COT_ACTIVATION = 6,
  254. CS101_COT_ACTIVATION_CON = 7,
  255. CS101_COT_DEACTIVATION = 8,
  256. CS101_COT_DEACTIVATION_CON = 9,
  257. CS101_COT_ACTIVATION_TERMINATION = 10,
  258. CS101_COT_RETURN_INFO_REMOTE = 11,
  259. CS101_COT_RETURN_INFO_LOCAL = 12,
  260. CS101_COT_FILE_TRANSFER = 13,
  261. CS101_COT_AUTHENTICATION = 14,
  262. CS101_COT_MAINTENANCE_OF_AUTH_SESSION_KEY = 15,
  263. CS101_COT_MAINTENANCE_OF_USER_ROLE_AND_UPDATE_KEY = 16,
  264. CS101_COT_INTERROGATED_BY_STATION = 20,
  265. CS101_COT_INTERROGATED_BY_GROUP_1 = 21,
  266. CS101_COT_INTERROGATED_BY_GROUP_2 = 22,
  267. CS101_COT_INTERROGATED_BY_GROUP_3 = 23,
  268. CS101_COT_INTERROGATED_BY_GROUP_4 = 24,
  269. CS101_COT_INTERROGATED_BY_GROUP_5 = 25,
  270. CS101_COT_INTERROGATED_BY_GROUP_6 = 26,
  271. CS101_COT_INTERROGATED_BY_GROUP_7 = 27,
  272. CS101_COT_INTERROGATED_BY_GROUP_8 = 28,
  273. CS101_COT_INTERROGATED_BY_GROUP_9 = 29,
  274. CS101_COT_INTERROGATED_BY_GROUP_10 = 30,
  275. CS101_COT_INTERROGATED_BY_GROUP_11 = 31,
  276. CS101_COT_INTERROGATED_BY_GROUP_12 = 32,
  277. CS101_COT_INTERROGATED_BY_GROUP_13 = 33,
  278. CS101_COT_INTERROGATED_BY_GROUP_14 = 34,
  279. CS101_COT_INTERROGATED_BY_GROUP_15 = 35,
  280. CS101_COT_INTERROGATED_BY_GROUP_16 = 36,
  281. CS101_COT_REQUESTED_BY_GENERAL_COUNTER = 37,
  282. CS101_COT_REQUESTED_BY_GROUP_1_COUNTER = 38,
  283. CS101_COT_REQUESTED_BY_GROUP_2_COUNTER = 39,
  284. CS101_COT_REQUESTED_BY_GROUP_3_COUNTER = 40,
  285. CS101_COT_REQUESTED_BY_GROUP_4_COUNTER = 41,
  286. CS101_COT_UNKNOWN_TYPE_ID = 44,
  287. CS101_COT_UNKNOWN_COT = 45,
  288. CS101_COT_UNKNOWN_CA = 46,
  289. CS101_COT_UNKNOWN_IOA = 47
  290. } CS101_CauseOfTransmission;
  291. const char*
  292. CS101_CauseOfTransmission_toString(CS101_CauseOfTransmission self);
  293. void
  294. Lib60870_enableDebugOutput(bool value);
  295. Lib60870VersionInfo
  296. Lib60870_getLibraryVersionInfo(void);
  297. /**
  298. * \brief Check if the test flag of the ASDU is set
  299. */
  300. bool
  301. CS101_ASDU_isTest(CS101_ASDU self);
  302. /**
  303. * \brief Set the test flag of the ASDU
  304. */
  305. void
  306. CS101_ASDU_setTest(CS101_ASDU self, bool value);
  307. /**
  308. * \brief Check if the negative flag of the ASDU is set
  309. */
  310. bool
  311. CS101_ASDU_isNegative(CS101_ASDU self);
  312. /**
  313. * \brief Set the negative flag of the ASDU
  314. */
  315. void
  316. CS101_ASDU_setNegative(CS101_ASDU self, bool value);
  317. /**
  318. * \brief get the OA (originator address) of the ASDU.
  319. */
  320. int
  321. CS101_ASDU_getOA(CS101_ASDU self);
  322. /**
  323. * \brief Get the cause of transmission (COT) of the ASDU
  324. */
  325. CS101_CauseOfTransmission
  326. CS101_ASDU_getCOT(CS101_ASDU self);
  327. /**
  328. * \brief Set the cause of transmission (COT) of the ASDU
  329. */
  330. void
  331. CS101_ASDU_setCOT(CS101_ASDU self, CS101_CauseOfTransmission value);
  332. /**
  333. * \brief Get the common address (CA) of the ASDU
  334. */
  335. int
  336. CS101_ASDU_getCA(CS101_ASDU self);
  337. /**
  338. * \brief Set the common address (CA) of the ASDU
  339. *
  340. * \param ca the ca in unstructured form
  341. */
  342. void
  343. CS101_ASDU_setCA(CS101_ASDU self, int ca);
  344. /**
  345. * \brief Get the type ID of the ASDU
  346. *
  347. * \return the type ID to identify the ASDU type
  348. */
  349. IEC60870_5_TypeID
  350. CS101_ASDU_getTypeID(CS101_ASDU self);
  351. /**
  352. * \brief Set the type ID of the ASDU
  353. *
  354. * NOTE: Usually it is not required to call this function as the type is determined when the
  355. * ASDU is parsed or when a new information object is added with \ref CS101_ASDU_addInformationObject
  356. * The function is intended to be used by library extensions of for creating private ASDU types.
  357. *
  358. * \param typeId the type ID to identify the ASDU type
  359. */
  360. void
  361. CS101_ASDU_setTypeID(CS101_ASDU self, IEC60870_5_TypeID typeId);
  362. /**
  363. * \brief Check if the ASDU contains a sequence of consecutive information objects
  364. *
  365. * NOTE: in a sequence of consecutive information objects only the first information object address
  366. * is encoded. The following information objects ahve consecutive information object addresses.
  367. *
  368. * \return true when the ASDU represents a sequence of consecutive information objects, false otherwise
  369. */
  370. bool
  371. CS101_ASDU_isSequence(CS101_ASDU self);
  372. /**
  373. * \brief Set the ASDU to represent a sequence of consecutive information objects
  374. *
  375. * NOTE: It is not required to use this function when constructing ASDUs as this information is
  376. * already provided when calling one of the constructors \ref CS101_ASDU_create or \ref CS101_ASDU_initializeStatic
  377. *
  378. * \param isSequence specify if the ASDU represents a sequence of consecutive information objects
  379. */
  380. void
  381. CS101_ASDU_setSequence(CS101_ASDU self, bool isSequence);
  382. /**
  383. * \brief Get the number of information objects (elements) in the ASDU
  384. *
  385. * \return the number of information objects/element (valid range 0 - 127)
  386. */
  387. int
  388. CS101_ASDU_getNumberOfElements(CS101_ASDU self);
  389. /**
  390. * \brief Set the number of information objects (elements) in the ASDU
  391. *
  392. * NOTE: Usually it is not required to call this function as the number of elements is set when the
  393. * ASDU is parsed or when a new information object is added with \ref CS101_ASDU_addInformationObject
  394. * The function is intended to be used by library extensions of for creating private ASDU types.
  395. *
  396. * \param numberOfElements the number of information objects/element (valid range 0 - 127)
  397. */
  398. void
  399. CS101_ASDU_setNumberOfElements(CS101_ASDU self, int numberOfElements);
  400. /**
  401. * \brief Get the information object with the given index
  402. *
  403. * \param index the index of the information object (starting with 0)
  404. *
  405. * \return the information object, or NULL if there is no information object with the given index
  406. */
  407. InformationObject
  408. CS101_ASDU_getElement(CS101_ASDU self, int index);
  409. /**
  410. * \brief Get the information object with the given index and store it in the provided information object instance
  411. *
  412. * \param io if not NULL use the provided information object instance to store the information, has to be of correct type.
  413. * \param index the index of the information object (starting with 0)
  414. *
  415. * \return the information object, or NULL if there is no information object with the given index
  416. */
  417. InformationObject
  418. CS101_ASDU_getElementEx(CS101_ASDU self, InformationObject io, int index);
  419. /**
  420. * \brief Create a new ASDU. The type ID will be derived from the first InformationObject that will be added
  421. *
  422. * \param parameters the application layer parameters used to encode the ASDU
  423. * \param isSequence if the information objects will be encoded as a compact sequence of information objects with subsequent IOA values
  424. * \param cot cause of transmission (COT)
  425. * \param oa originator address (OA) to be used
  426. * \param ca the common address (CA) of the ASDU
  427. * \param isTest if the test flag will be set or not
  428. * \param isNegative if the negative falg will be set or not
  429. *
  430. * \return the new CS101_ASDU instance
  431. */
  432. CS101_ASDU
  433. CS101_ASDU_create(CS101_AppLayerParameters parameters, bool isSequence, CS101_CauseOfTransmission cot, int oa, int ca,
  434. bool isTest, bool isNegative);
  435. /**
  436. * \brief Create a new ASDU and store it in the provided static ASDU structure.
  437. *
  438. * NOTE: The type ID will be derived from the first InformationObject that will be added.
  439. *
  440. * \param self pointer to the statically allocated data structure
  441. * \param parameters the application layer parameters used to encode the ASDU
  442. * \param isSequence if the information objects will be encoded as a compact sequence of information objects with subsequent IOA values
  443. * \param cot cause of transmission (COT)
  444. * \param oa originator address (OA) to be used
  445. * \param ca the common address (CA) of the ASDU
  446. * \param isTest if the test flag will be set or not
  447. * \param isNegative if the negative falg will be set or not
  448. *
  449. * \return the new CS101_ASDU instance
  450. */
  451. CS101_ASDU
  452. CS101_ASDU_initializeStatic(CS101_StaticASDU self, CS101_AppLayerParameters parameters, bool isSequence, CS101_CauseOfTransmission cot, int oa, int ca,
  453. bool isTest, bool isNegative);
  454. /**
  455. * \brief Create a new ASDU that is an exact copy of the ASDU
  456. *
  457. * \param self ASDU instance to be copied
  458. * \param clone static ASDU instance where to store the cloned ASDU or NULL. When this parameter is NULL the function will allocate the memory for the clone
  459. *
  460. * \return the cloned ASDU instance
  461. */
  462. CS101_ASDU
  463. CS101_ASDU_clone(CS101_ASDU self, CS101_StaticASDU clone);
  464. /**
  465. * Get the ASDU payload
  466. *
  467. * The payload is the ASDU message part after the ASDU header (type ID, VSQ, COT, CASDU)
  468. *
  469. * \return the ASDU payload buffer
  470. */
  471. uint8_t*
  472. CS101_ASDU_getPayload(CS101_ASDU self);
  473. /**
  474. * \brief Append the provided data to the ASDU payload
  475. *
  476. * NOTE: Usually it is not required to call this function as the payload is set when the
  477. * ASDU is parsed or when a new information object is added with \ref CS101_ASDU_addInformationObject
  478. * The function is intended to be only used by library extensions of for creating private ASDU types.
  479. *
  480. * \param buffer pointer to the payload data to add
  481. * \param size number of bytes to append to the payload
  482. *
  483. * \return true when data has been added, false otherwise
  484. */
  485. bool
  486. CS101_ASDU_addPayload(CS101_ASDU self, uint8_t* buffer, int size);
  487. /**
  488. * Get the ASDU payload buffer size
  489. *
  490. * The payload is the ASDU message part after the ASDU header (type ID, VSQ, COT, CASDU)
  491. *
  492. * \return the ASDU payload buffer size
  493. */
  494. int
  495. CS101_ASDU_getPayloadSize(CS101_ASDU self);
  496. /**
  497. * \brief Destroy the ASDU object (release all resources)
  498. */
  499. void
  500. CS101_ASDU_destroy(CS101_ASDU self);
  501. /**
  502. * \brief add an information object to the ASDU
  503. *
  504. * NOTE: Only information objects of the exact same type can be added to a single ASDU!
  505. *
  506. * \param self ASDU object instance
  507. * \param io information object to be added
  508. *
  509. * \return true when added, false when there not enough space left in the ASDU or IO cannot be added to the sequence because of wrong IOA, or wrong type.
  510. */
  511. bool
  512. CS101_ASDU_addInformationObject(CS101_ASDU self, InformationObject io);
  513. /**
  514. * \brief remove all information elements from the ASDU object
  515. *
  516. * \param self ASDU object instance
  517. */
  518. void
  519. CS101_ASDU_removeAllElements(CS101_ASDU self);
  520. /**
  521. * \brief Get the elapsed time in ms
  522. */
  523. int
  524. CP16Time2a_getEplapsedTimeInMs(const CP16Time2a self);
  525. /**
  526. * \brief set the elapsed time in ms
  527. */
  528. void
  529. CP16Time2a_setEplapsedTimeInMs(CP16Time2a self, int value);
  530. /**
  531. * \brief Get the millisecond part of the time value
  532. */
  533. int
  534. CP24Time2a_getMillisecond(const CP24Time2a self);
  535. /**
  536. * \brief Set the millisecond part of the time value
  537. */
  538. void
  539. CP24Time2a_setMillisecond(CP24Time2a self, int value);
  540. /**
  541. * \brief Get the second part of the time value
  542. */
  543. int
  544. CP24Time2a_getSecond(const CP24Time2a self);
  545. /**
  546. * \brief Set the second part of the time value
  547. */
  548. void
  549. CP24Time2a_setSecond(CP24Time2a self, int value);
  550. /**
  551. * \brief Get the minute part of the time value
  552. */
  553. int
  554. CP24Time2a_getMinute(const CP24Time2a self);
  555. /**
  556. * \brief Set the minute part of the time value
  557. */
  558. void
  559. CP24Time2a_setMinute(CP24Time2a self, int value);
  560. /**
  561. * \brief Check if the invalid flag of the time value is set
  562. */
  563. bool
  564. CP24Time2a_isInvalid(const CP24Time2a self);
  565. /**
  566. * \brief Set the invalid flag of the time value
  567. */
  568. void
  569. CP24Time2a_setInvalid(CP24Time2a self, bool value);
  570. /**
  571. * \brief Check if the substituted flag of the time value is set
  572. */
  573. bool
  574. CP24Time2a_isSubstituted(const CP24Time2a self);
  575. /**
  576. * \brief Set the substituted flag of the time value
  577. */
  578. void
  579. CP24Time2a_setSubstituted(CP24Time2a self, bool value);
  580. /**
  581. * \brief Create a 7 byte time from a UTC ms timestamp
  582. */
  583. CP56Time2a
  584. CP56Time2a_createFromMsTimestamp(CP56Time2a self, uint64_t timestamp);
  585. CP32Time2a
  586. CP32Time2a_create(CP32Time2a self);
  587. void
  588. CP32Time2a_setFromMsTimestamp(CP32Time2a self, uint64_t timestamp);
  589. int
  590. CP32Time2a_getMillisecond(const CP32Time2a self);
  591. void
  592. CP32Time2a_setMillisecond(CP32Time2a self, int value);
  593. int
  594. CP32Time2a_getSecond(const CP32Time2a self);
  595. void
  596. CP32Time2a_setSecond(CP32Time2a self, int value);
  597. int
  598. CP32Time2a_getMinute(const CP32Time2a self);
  599. void
  600. CP32Time2a_setMinute(CP32Time2a self, int value);
  601. bool
  602. CP32Time2a_isInvalid(const CP32Time2a self);
  603. void
  604. CP32Time2a_setInvalid(CP32Time2a self, bool value);
  605. bool
  606. CP32Time2a_isSubstituted(const CP32Time2a self);
  607. void
  608. CP32Time2a_setSubstituted(CP32Time2a self, bool value);
  609. int
  610. CP32Time2a_getHour(const CP32Time2a self);
  611. void
  612. CP32Time2a_setHour(CP32Time2a self, int value);
  613. bool
  614. CP32Time2a_isSummerTime(const CP32Time2a self);
  615. void
  616. CP32Time2a_setSummerTime(CP32Time2a self, bool value);
  617. /**
  618. * \brief Set the time value of a 7 byte time from a UTC ms timestamp
  619. */
  620. void
  621. CP56Time2a_setFromMsTimestamp(CP56Time2a self, uint64_t timestamp);
  622. /**
  623. * \brief Convert a 7 byte time to a ms timestamp
  624. */
  625. uint64_t
  626. CP56Time2a_toMsTimestamp(const CP56Time2a self);
  627. /**
  628. * \brief Get the ms part of a time value
  629. */
  630. int
  631. CP56Time2a_getMillisecond(const CP56Time2a self);
  632. /**
  633. * \brief Set the ms part of a time value
  634. */
  635. void
  636. CP56Time2a_setMillisecond(CP56Time2a self, int value);
  637. int
  638. CP56Time2a_getSecond(const CP56Time2a self);
  639. void
  640. CP56Time2a_setSecond(CP56Time2a self, int value);
  641. int
  642. CP56Time2a_getMinute(const CP56Time2a self);
  643. void
  644. CP56Time2a_setMinute(CP56Time2a self, int value);
  645. int
  646. CP56Time2a_getHour(const CP56Time2a self);
  647. void
  648. CP56Time2a_setHour(CP56Time2a self, int value);
  649. int
  650. CP56Time2a_getDayOfWeek(const CP56Time2a self);
  651. void
  652. CP56Time2a_setDayOfWeek(CP56Time2a self, int value);
  653. int
  654. CP56Time2a_getDayOfMonth(const CP56Time2a self);
  655. void
  656. CP56Time2a_setDayOfMonth(CP56Time2a self, int value);
  657. /**
  658. * \brief Get the month field of the time
  659. *
  660. * \return value the month (1..12)
  661. */
  662. int
  663. CP56Time2a_getMonth(const CP56Time2a self);
  664. /**
  665. * \brief Set the month field of the time
  666. *
  667. * \param value the month (1..12)
  668. */
  669. void
  670. CP56Time2a_setMonth(CP56Time2a self, int value);
  671. /**
  672. * \brief Get the year (range 0..99)
  673. *
  674. * \param value the year (0..99)
  675. */
  676. int
  677. CP56Time2a_getYear(const CP56Time2a self);
  678. /**
  679. * \brief Set the year
  680. *
  681. * \param value the year
  682. */
  683. void
  684. CP56Time2a_setYear(CP56Time2a self, int value);
  685. bool
  686. CP56Time2a_isSummerTime(const CP56Time2a self);
  687. void
  688. CP56Time2a_setSummerTime(CP56Time2a self, bool value);
  689. bool
  690. CP56Time2a_isInvalid(const CP56Time2a self);
  691. void
  692. CP56Time2a_setInvalid(CP56Time2a self, bool value);
  693. bool
  694. CP56Time2a_isSubstituted(const CP56Time2a self);
  695. void
  696. CP56Time2a_setSubstituted(CP56Time2a self, bool value);
  697. BinaryCounterReading
  698. BinaryCounterReading_create(BinaryCounterReading self, int32_t value, int seqNumber,
  699. bool hasCarry, bool isAdjusted, bool isInvalid);
  700. void
  701. BinaryCounterReading_destroy(BinaryCounterReading self);
  702. int32_t
  703. BinaryCounterReading_getValue(BinaryCounterReading self);
  704. void
  705. BinaryCounterReading_setValue(BinaryCounterReading self, int32_t value);
  706. int
  707. BinaryCounterReading_getSequenceNumber(BinaryCounterReading self);
  708. bool
  709. BinaryCounterReading_hasCarry(BinaryCounterReading self);
  710. bool
  711. BinaryCounterReading_isAdjusted(BinaryCounterReading self);
  712. bool
  713. BinaryCounterReading_isInvalid(BinaryCounterReading self);
  714. void
  715. BinaryCounterReading_setSequenceNumber(BinaryCounterReading self, int value);
  716. void
  717. BinaryCounterReading_setCarry(BinaryCounterReading self, bool value);
  718. void
  719. BinaryCounterReading_setAdjusted(BinaryCounterReading self, bool value);
  720. void
  721. BinaryCounterReading_setInvalid(BinaryCounterReading self, bool value);
  722. /**
  723. * @}
  724. */
  725. typedef struct sFrame* Frame;
  726. void
  727. Frame_destroy(Frame self);
  728. void
  729. Frame_resetFrame(Frame self);
  730. void
  731. Frame_setNextByte(Frame self, uint8_t byte);
  732. void
  733. Frame_appendBytes(Frame self, uint8_t* bytes, int numberOfBytes);
  734. int
  735. Frame_getMsgSize(Frame self);
  736. uint8_t*
  737. Frame_getBuffer(Frame self);
  738. int
  739. Frame_getSpaceLeft(Frame self);
  740. #ifdef __cplusplus
  741. }
  742. #endif
  743. #endif /* SRC_INC_IEC60870_COMMON_H_ */