Studer Innotec Xtender Serial Communication C Library 1.5.0

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Enumerations Enumerator Macros Pages
scom_data_link.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2014 Studer Innotec SA
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 */
22
27 #ifndef SCOM_DATA_LINK_H
28 #define SCOM_DATA_LINK_H
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /* ---------- code to work on different compilers and architectures -------------------- */
35
36 #if defined(__GNUC__) /* current gcc and g++ have enough C99 support to use this port */ \
37 || (defined(_MSC_VER) && defined(__cplusplus)) /* Microsoft Visual Studio as a C++ compiler supports enough C99 to compile */
38
39 #include "scom_port_c99.h"
40 #else
41 #error "target or compiler not supported"
42 #endif
43
44
45 /* ------------------------- helper macros -------------------------------------- */
46
52 #define SCOM_NBR_ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
53
58 #define SCOM_MIN(a, b) ((a) < (b) ? (a) : (b))
59
64 #define SCOM_MAX(a, b) ((a) > (b) ? (a) : (b))
65
66
67 /* ------------------------- helper macros -------------------------------------- */
68
73 #define SCOM_FRAME_HEADER_SIZE 14
74
78 typedef enum {
79 SCOM_ERROR_NO_ERROR = 0x0000,
81 /* data link errors */
82 SCOM_ERROR_INVALID_FRAME = 0x0001,
83 SCOM_ERROR_DEVICE_NOT_FOUND = 0x0002,
84 SCOM_ERROR_RESPONSE_TIMEOUT = 0x0003,
86 /* service errors */
87 SCOM_ERROR_SERVICE_NOT_SUPPORTED = 0x0011,
88 SCOM_ERROR_INVALID_SERVICE_ARGUMENT = 0x0012,
89 SCOM_ERROR_GATEWAY_BUSY = 0x0013,
91 /* read/write property errors */
92 SCOM_ERROR_TYPE_NOT_SUPPORTED = 0x0021,
93 SCOM_ERROR_OBJECT_ID_NOT_FOUND = 0x0022,
94 SCOM_ERROR_PROPERTY_NOT_SUPPORTED = 0x0023,
95 SCOM_ERROR_INVALID_DATA_LENGTH = 0x0024,
97 /* write property errors */
98 SCOM_ERROR_PROPERTY_IS_READ_ONLY = 0x0025,
99 SCOM_ERROR_INVALID_DATA = 0x0026,
100 SCOM_ERROR_DATA_TOO_SMALL = 0x0027,
101 SCOM_ERROR_DATA_TOO_BIG = 0x0028,
102 SCOM_ERROR_WRITE_PROPERTY_FAILED = 0x0029,
103 SCOM_ERROR_READ_PROPERTY_FAILED = 0x002A,
104 SCOM_ERROR_ACCESS_DENIED = 0x002B,
105 SCOM_ERROR_OBJECT_NOT_SUPPORTED = 0x002C,
106 SCOM_ERROR_MULTICAST_READ_NOT_SUPPORTED = 0x002D,
108 /* error in the client application */
109 SCOM_ERROR_INVALID_SHELL_ARG = 0x0081,
110 SCOM_ERROR_STACK_PORT_NOT_FOUND = 0x0082,
111 SCOM_ERROR_STACK_PORT_INIT_FAILED = 0x0083,
112 SCOM_ERROR_STACK_PORT_WRITE_FAILED = 0x0084,
113 SCOM_ERROR_STACK_PORT_READ_FAILED = 0x0085,
114 SCOM_ERROR_STACK_BUFFER_TOO_SMALL = 0x0086,
115 SCOM_ERROR_STACK_PROPERTY_HEADER_DOESNT_MATCH = 0x0087
117 } scom_error_t;
118
119
123 typedef enum {
124 SCOM_READ_PROPERTY_SERVICE = 0x1,
125 SCOM_WRITE_PROPERTY_SERVICE = 0x2
126 } scom_service_t;
127
132 typedef enum {
133 SCOM_FORMAT_INVALID_FORMAT = 0,
134
135 /* 1 byte */
136 SCOM_FORMAT_BOOL = 1,
137
138 /* 2 bytes */
139 SCOM_FORMAT_FORMAT = 2,
140 SCOM_FORMAT_ENUM = 3,
141 SCOM_FORMAT_ERROR = 4,
142
143 /* 4 bytes */
144 SCOM_FORMAT_INT32 = 5,
145 SCOM_FORMAT_FLOAT = 6,
146
147 /* n bytes */
148 SCOM_FORMAT_STRING = 7,
149 SCOM_FORMAT_DYNAMIC = 8,
150 SCOM_FORMAT_BYTE_STREAM = 9
151
152 } scom_format_t;
153
154
158 typedef struct {
159 int reserved7to5:3;
160 int is_new_datalogger_file_present:1;
161 int is_sd_card_full:1;
162 int is_sd_card_present:1;
163 int was_rcc_reseted:1;
164 int is_message_pending:1;
165 } scom_frame_flags_t;
166
167
171 typedef struct {
172 int reserved7to2:6;
173 int is_response:1;
174 int error:1;
175 } scom_service_flags_t;
176
177
183 typedef struct {
184 scom_frame_flags_t frame_flags;
185 uint32_t src_addr;
186 uint32_t dst_addr;
188 scom_service_flags_t service_flags;
189 scom_service_t service_id;
192 size_t data_length;
193
195 scom_error_t last_error;
196
197 char* buffer;
198 size_t buffer_size;
199 } scom_frame_t;
200
201
202 void scom_initialize_frame(scom_frame_t* frame, char* buffer, size_t buffer_size);
203 void scom_encode_request_frame(scom_frame_t* frame);
204 void scom_decode_frame_header(scom_frame_t* frame);
205 void scom_decode_frame_data(scom_frame_t* frame);
206
207 size_t scom_frame_length(scom_frame_t* frame);
208
209
210 #ifdef __cplusplus
211 }
212 #endif
213
214 #endif
215
216
217
218
219
220
221
222
223