cipstring.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*******************************************************************************
  2. * Copyright (c) 2019, Rockwell Automation, Inc.
  3. * All rights reserved.
  4. *
  5. ******************************************************************************/
  6. /** @file
  7. * @brief Declare functions to operate on CIP string types
  8. *
  9. * Some functions to create CIP string types from C strings or data buffers.
  10. */
  11. #ifndef OPENER_CIPSTRING_H_
  12. #define OPENER_CIPSTRING_H_
  13. #include "typedefs.h"
  14. #include "ciptypes.h"
  15. CipStringN *SetCipStringNByData(CipStringN *const cip_string,
  16. CipUint str_len,
  17. CipUint size,
  18. const CipOctet *const data);
  19. /** @brief Copies the content of C-string to a CipStringN under the expectation, that each C-String element is a StringN octet
  20. *
  21. * @param cip_string Target CipStringN
  22. * @param string Source C-string
  23. * @param symbol_size Size of a symbol in CipStringN instance
  24. *
  25. * @return Target CipStringN
  26. *
  27. */
  28. CipStringN *SetCipStringNByCstr(CipStringN *const cip_string,
  29. const char *const string,
  30. const CipUint symbol_size);
  31. /** @brief Clears the internal structure of a CipStringN
  32. *
  33. * @param cip_string The CipStringN to be freed
  34. *
  35. * @return Returns the address of the cleared CipStringN
  36. *
  37. */
  38. CipStringN *ClearCipStringN(CipStringN *const cip_string);
  39. /** @brief Frees the memory of a CipStringN
  40. *
  41. * @param cip_string The CipStringN to be freed
  42. *
  43. */
  44. void FreeCipStringN(CipStringN *const cip_string);
  45. /** @brief Sets length and data for a CipString2 based on an octet stream and symbol length
  46. *
  47. * @param cip_string The CipString2 to be set
  48. * @param str_len Amount of CipString2 symbols
  49. * @param data The octet stream
  50. *
  51. * @return The CipString2 address
  52. */
  53. CipString2 *SetCipString2ByData(CipString2 *const cip_string,
  54. CipUint str_len,
  55. const CipOctet *const data);
  56. /** @brief Copies the content of C-string to a CipString2 under the expectation, that each C-String element is a CipString2 octet
  57. *
  58. * @param cip_string Target CipString2
  59. * @param string Source C-string
  60. *
  61. * @return Target CipString2
  62. *
  63. */
  64. CipString2 *SetCipString2ByCstr(CipString2 *const cip_string,
  65. const char *const string);
  66. /** @brief Clears the internal structure of a CipString2
  67. *
  68. * @param cip_string The CipString2 to be cleared
  69. *
  70. * @return Returns the address of the cleared CipString2
  71. *
  72. */
  73. CipString2 *ClearCipString2(CipString2 *const cip_string);
  74. /** @brief Frees a CipString2 structure
  75. *
  76. * @param cip_string The CipString2 structure to be freed
  77. *
  78. * @return Freed CipString2 structure
  79. *
  80. */
  81. void FreeCipString2(CipString2 *const cip_string);
  82. /** @brief Clears the internal CipString structure
  83. *
  84. * @param cip_string The CipString structure to be cleared
  85. *
  86. * @return Cleared CipString structure
  87. *
  88. */
  89. CipString *ClearCipString(CipString *const cip_string);
  90. /** @brief Frees a CipString structure
  91. *
  92. * @param cip_string The CipString structure to be freed
  93. *
  94. */
  95. void FreeCipString(CipString *const cip_string);
  96. /** @brief Sets length and data for a CipString based on an octet stream and symbol length
  97. *
  98. * @param cip_string The string to be set
  99. * @param str_len Amount of CipString symbols
  100. * @param data The octet stream
  101. *
  102. * @return The CipString address
  103. */
  104. CipString *SetCipStringByData(CipString *const cip_string,
  105. CipUint str_len,
  106. const CipOctet *const data);
  107. /** @brief Copies the content of C-string to a CipString under the expectation, that each C-String element is a CipString octet
  108. *
  109. * @param cip_string Target CipString
  110. * @param string Source C-string
  111. *
  112. * @return Target CipString
  113. *
  114. */
  115. CipString *SetCipStringByCstr(CipString *const cip_string,
  116. const char *const string);
  117. /** @brief Clears the internal CipShortString structure
  118. *
  119. * @param cip_string The CipShortString structure to be cleared
  120. *
  121. * @return Cleared CipShortString structure
  122. *
  123. */
  124. CipShortString *ClearCipShortString(CipShortString *const cip_string);
  125. /** @brief Frees a CipShortString structure
  126. *
  127. * @param cip_string The CipShortString structure to be freed
  128. *
  129. */
  130. void FreeCipShortString(CipShortString *const cip_string);
  131. /** @brief Sets length and data for a CipShortString based on an octet stream and symbol length
  132. *
  133. * @param cip_string The string to be set
  134. * @param str_len Amount of CipString symbols
  135. * @param data The octet stream
  136. *
  137. * @return The CipShortString address
  138. */
  139. CipShortString *SetCipShortStringByData(CipShortString *const cip_string,
  140. const CipUsint str_len,
  141. const CipOctet *const data);
  142. /** @brief Copies the content of C-string to a CipShortString under the expectation, that each C-String element is a CipShortString octet
  143. *
  144. * @param cip_string Target CipShortString
  145. * @param string Source C-string
  146. *
  147. * @return Target CipShortString
  148. *
  149. */
  150. CipShortString *SetCipShortStringByCstr(CipShortString *const cip_string,
  151. const char *const string);
  152. /** @brief Returns a NUL terminated C-string from a CipShortString
  153. *
  154. * @param string The CipShortString to extract from
  155. * @param buf Pointer to a buffer to store the contents in
  156. * @param len Length of buffer
  157. *
  158. * @return POSIX OK(0) if the complete string fit in @param buf, otherwise non-zero.
  159. */
  160. int GetCstrFromCipShortString(CipShortString *const string, char *buf,
  161. size_t len);
  162. #endif /* of OPENER_CIPSTRING_H_ */