Studer Innotec Xtender Serial Communication C Library  1.5.0
 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 {
81  /* data link errors */
86  /* service errors */
91  /* read/write property errors */
97  /* write property errors */
108  /* error in the client application */
117 } scom_error_t;
118 
119 
123 typedef enum {
124  SCOM_READ_PROPERTY_SERVICE = 0x1,
125  SCOM_WRITE_PROPERTY_SERVICE = 0x2
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;
166 
167 
171 typedef struct {
172  int reserved7to2:6;
173  int is_response:1;
174  int error:1;
176 
177 
183 typedef struct {
185  uint32_t src_addr;
186  uint32_t dst_addr;
192  size_t data_length;
193 
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