typedefs.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*******************************************************************************
  2. * Copyright (c) 2009, Rockwell Automation, Inc.
  3. * All rights reserved.
  4. *
  5. ******************************************************************************/
  6. #ifndef OPENER_TYPEDEFS_H_
  7. #define OPENER_TYPEDEFS_H_
  8. #include <inttypes.h>
  9. #include <stddef.h>
  10. #include <stdbool.h>
  11. /** @file typedefs.h
  12. Do not use interface types for internal variables, such as "int i;", which is
  13. commonly used for loop counters or counting things.
  14. Do not over-constrain data types. Prefer the use of the native "int" and
  15. "unsigned" types.
  16. Use char for native character strings.
  17. Do not use "char" for data buffers - use "unsigned char" instead. Using char
  18. for data buffers can occasionally blow up in your face rather nastily.
  19. */
  20. /** @brief EIP Data type definitions
  21. */
  22. typedef uint8_t EipByte; /**< 8-bit bit string */
  23. typedef int8_t EipInt8; /**< 8-bit signed number */
  24. typedef int16_t EipInt16; /**< 16-bit signed number */
  25. typedef int32_t EipInt32; /**< 32-bit signed number */
  26. typedef uint8_t EipUint8; /**< 8-bit unsigned number */
  27. typedef uint16_t EipUint16; /**< 16-bit unsigned number */
  28. typedef uint32_t EipUint32; /**< 32-bit unsigned number */
  29. typedef float EipFloat; /**< IEEE 754 32-bit floating point number */
  30. typedef double EipDfloat; /**< IEEE 754 64-bit floating point number */
  31. typedef uint8_t EipBool8; /**< bool data types */
  32. /** @brief Data types as defined in the CIP Specification Vol 1 Appendix C
  33. */
  34. typedef uint8_t CipOctet; /**< 8 bit value that indicates particular data type */
  35. typedef uint8_t CipBool; /**< Boolean data type */
  36. typedef uint8_t CipByte; /**< 8-bit bit string */
  37. typedef uint16_t CipWord; /**< 16-bit bit string */
  38. typedef uint32_t CipDword; /**< 32-bit bit string */
  39. typedef uint8_t CipUsint; /**< 8-bit unsigned integer */
  40. typedef uint16_t CipUint; /**< CipUint 16-bit unsigned integer */
  41. typedef uint32_t CipUdint; /**< CipUdint 32-bit unsigned integer */
  42. typedef int8_t CipSint; /**< 8-bit signed integer */
  43. typedef int16_t CipInt; /**< 16-bit signed integer */
  44. typedef int32_t CipDint; /**< 32-bit signed integer */
  45. typedef float CipReal; /**< 32-bit IEEE 754 floating point */
  46. typedef double CipLreal; /**< 64-bit IEEE 754 floating point */
  47. #ifdef OPENER_SUPPORT_64BIT_DATATYPES
  48. typedef int64_t EipInt64; /**< 64-bit signed number */
  49. typedef uint64_t EipUint64; /**< 64-bit unsigned number */
  50. typedef int64_t CipLint; /**< 64-bit signed integer */
  51. typedef uint64_t CipUlint; /**< 64-bit unsigned integer */
  52. typedef uint64_t CipLword; /**< 64-bit bit string */
  53. #endif /* OPENER_SUPPORT_64BIT_DATATYPES */
  54. /** @brief Constant identifying if a socket descriptor is invalid
  55. */
  56. static const int kEipInvalidSocket = -1;
  57. typedef unsigned long MilliSeconds;
  58. typedef unsigned long long MicroSeconds;
  59. /**
  60. The following are generally true regarding return status:
  61. -1 ... an error occurred
  62. 0 ... success
  63. Occasionally there is a variation on this:
  64. -1 ... an error occurred
  65. 0 .. success and there is no reply to send
  66. 1 ... success and there is a reply to send
  67. For both of these cases EIP_STATUS is the return type.
  68. Other return type are:
  69. -- return pointer to thing, 0 if error (return type is "pointer to thing")
  70. -- return count of something, -1 if error, (return type is int)
  71. */
  72. /** @brief EIP stack status enum
  73. *
  74. */
  75. typedef enum {
  76. kEipStatusOk = 0, /**< Stack is ok */
  77. kEipStatusOkSend = 1, /**< Stack is ok, after send */
  78. kEipStatusError = -1 /**< Stack is in error */
  79. } EipStatus;
  80. /** @brief Communication direction of an UDP socket; consuming is receiver,
  81. * producing is sender
  82. *
  83. * These are used as array indexes, watch out if changing these values
  84. */
  85. typedef enum {
  86. kUdpCommuncationDirectionConsuming = 0, /**< Consuming direction; receiver */
  87. kUdpCommuncationDirectionProducing = 1 /**< Producing direction; sender */
  88. } UdpCommuncationDirection;
  89. #ifndef __cplusplus
  90. /** @brief If we don't have C++ define a C++ -like "bool" keyword defines
  91. */
  92. //typedef enum {
  93. // false = 0, /**< defines "false" as 0 */
  94. // true = 1 /**< defines "true" as 1 */
  95. //} BoolKeywords;
  96. #endif /* __cplusplus */
  97. #endif /* OPENER_TYPEDEFS_H_ */