Framework for reading and writing variables in real time on any MBED platform.

DistantIO

This is the C implementation of the DistantIO slave framework.

Library is working but slight API breaks may occur in the future. C++ version is also in development.

To get the master-side implementation, see https://github.com/Overdrivr/DistantIO

Committer:
Overdrivr
Date:
Thu Oct 08 13:14:32 2015 +0000
Revision:
2:f2c816b681e3
Parent:
1:aaffeb93f99b
Child:
3:135f55b5334e
*Fixed issues with variables/group names > 8; *Added timing management. Variables can either be send all the time, or only after a defined delta. Useful to reduce constraints on datarate for parameters not needed in real time

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Overdrivr 2:f2c816b681e3 1 /*
Overdrivr 2:f2c816b681e3 2 * distantio.c
Overdrivr 2:f2c816b681e3 3 *
Overdrivr 2:f2c816b681e3 4 * Created on: Oct 13, 2014
Overdrivr 2:f2c816b681e3 5 * Author: B48923
Overdrivr 2:f2c816b681e3 6 */
Overdrivr 0:c4676d32d381 7
Overdrivr 0:c4676d32d381 8 #include "distantio.h"
Overdrivr 0:c4676d32d381 9 #include "crc.h"
Overdrivr 0:c4676d32d381 10 #include "string.h"
Overdrivr 0:c4676d32d381 11 #include "protocol.h"
Overdrivr 0:c4676d32d381 12
Overdrivr 2:f2c816b681e3 13 /*
Overdrivr 2:f2c816b681e3 14 * WARNING : IMPLEMENTATION FOR LITTLE-ENDIAN PROCESSOR
Overdrivr 2:f2c816b681e3 15 * TODO : HANDLE BOTH
Overdrivr 2:f2c816b681e3 16 */
Overdrivr 0:c4676d32d381 17
Overdrivr 0:c4676d32d381 18 static log Log;
Overdrivr 0:c4676d32d381 19 uint32_t tmp;
Overdrivr 0:c4676d32d381 20
Overdrivr 0:c4676d32d381 21 void send_variable(uint16_t index);
Overdrivr 0:c4676d32d381 22 uint16_t get_size(dio_type type);
Overdrivr 0:c4676d32d381 23 void send_descriptor(uint16_t index);
Overdrivr 0:c4676d32d381 24 void send_group_descriptor(uint16_t index);
Overdrivr 0:c4676d32d381 25
Overdrivr 0:c4676d32d381 26 /**
Overdrivr 0:c4676d32d381 27 * Inits the distant io framework
Overdrivr 0:c4676d32d381 28 */
Overdrivr 0:c4676d32d381 29 void init_distantio()
Overdrivr 0:c4676d32d381 30 {
Overdrivr 0:c4676d32d381 31 uint16_t i;
Overdrivr 0:c4676d32d381 32 char default_name[] = {"undef. "};
Overdrivr 0:c4676d32d381 33 Log.amount = 0;
Overdrivr 0:c4676d32d381 34 for(i = 0 ; i < VARIABLES_AMOUNT ; i++)
Overdrivr 0:c4676d32d381 35 {
Overdrivr 0:c4676d32d381 36 Log.variables[i].size = 0;
Overdrivr 0:c4676d32d381 37 Log.variables[i].ptr = 0;
Overdrivr 0:c4676d32d381 38 Log.variables[i].writeable = 0;
Overdrivr 0:c4676d32d381 39 Log.variables[i].id = i;
Overdrivr 2:f2c816b681e3 40 strncpy(Log.variables[i].name,default_name,8);
Overdrivr 0:c4676d32d381 41 Log.variables[i].send = 0;
Overdrivr 0:c4676d32d381 42 Log.variables[i].groupID = 0;
Overdrivr 0:c4676d32d381 43 }
Overdrivr 0:c4676d32d381 44 tmp=0;
Overdrivr 0:c4676d32d381 45 Log.current_group_id = 0;
Overdrivr 2:f2c816b681e3 46 strncpy(Log.groups[0].name,"default",8);
Overdrivr 0:c4676d32d381 47 }
Overdrivr 0:c4676d32d381 48
Overdrivr 0:c4676d32d381 49 /**
Overdrivr 0:c4676d32d381 50 * Register a variable exchanged with the computer
Overdrivr 0:c4676d32d381 51 */
Overdrivr 2:f2c816b681e3 52 uint8_t register_var(void* ptr, uint16_t size, dio_type type, uint8_t writeable, char* name, float refresh_rate)
Overdrivr 0:c4676d32d381 53 {
Overdrivr 0:c4676d32d381 54 // Too many variables, aborting
Overdrivr 0:c4676d32d381 55 if(Log.amount >= VARIABLES_AMOUNT)
Overdrivr 0:c4676d32d381 56 return 1;
Overdrivr 0:c4676d32d381 57
Overdrivr 0:c4676d32d381 58 Log.variables[Log.amount].ptr = (uint8_t*) ptr;
Overdrivr 0:c4676d32d381 59 Log.variables[Log.amount].size = get_size(type);
Overdrivr 0:c4676d32d381 60 Log.variables[Log.amount].writeable = writeable;
Overdrivr 0:c4676d32d381 61 Log.variables[Log.amount].type = type;
Overdrivr 0:c4676d32d381 62 Log.variables[Log.amount].groupID = Log.current_group_id;
Overdrivr 2:f2c816b681e3 63 strncpy(Log.variables[Log.amount].name,name,8);
Overdrivr 2:f2c816b681e3 64 Log.variables[Log.amount].refresh_rate = refresh_rate;
Overdrivr 2:f2c816b681e3 65 Log.variables[Log.amount].last_refreshed = 0;
Overdrivr 0:c4676d32d381 66 Log.amount++;
Overdrivr 0:c4676d32d381 67
Overdrivr 0:c4676d32d381 68 return 0;
Overdrivr 0:c4676d32d381 69 }
Overdrivr 0:c4676d32d381 70
Overdrivr 2:f2c816b681e3 71 uint8_t register_var(void* ptr, uint16_t size, dio_type type, uint8_t writeable, char* name)
Overdrivr 2:f2c816b681e3 72 {
Overdrivr 2:f2c816b681e3 73 register_var(ptr,size,type,writeable,name,0.f);
Overdrivr 2:f2c816b681e3 74 }
Overdrivr 2:f2c816b681e3 75
Overdrivr 0:c4676d32d381 76 void start_group(char* groupname)
Overdrivr 0:c4676d32d381 77 {
Overdrivr 0:c4676d32d381 78 Log.current_group_id++;
Overdrivr 2:f2c816b681e3 79 strncpy(Log.groups[Log.current_group_id].name,groupname,8);
Overdrivr 0:c4676d32d381 80 }
Overdrivr 0:c4676d32d381 81
Overdrivr 0:c4676d32d381 82 /**
Overdrivr 0:c4676d32d381 83 * Send var descriptor
Overdrivr 0:c4676d32d381 84 */
Overdrivr 0:c4676d32d381 85
Overdrivr 0:c4676d32d381 86 void send_descriptor(uint16_t index)
Overdrivr 0:c4676d32d381 87 {
Overdrivr 0:c4676d32d381 88 if(index >= Log.amount)
Overdrivr 0:c4676d32d381 89 return;
Overdrivr 0:c4676d32d381 90
Overdrivr 0:c4676d32d381 91 static uint8_t buffer[PAYLOAD_SIZE];
Overdrivr 0:c4676d32d381 92 uint8_t type;
Overdrivr 0:c4676d32d381 93
Overdrivr 0:c4676d32d381 94 // Respond returned-descriptor
Overdrivr 0:c4676d32d381 95 buffer[0] = 0x00;
Overdrivr 0:c4676d32d381 96
Overdrivr 0:c4676d32d381 97 // Write id
Overdrivr 0:c4676d32d381 98 uint16_t ID = ((Log.variables[index].groupID & 0x003F) << 10) + (index & 0x3FF);
Overdrivr 0:c4676d32d381 99 uint8_t * temp_ptr = (uint8_t*)(&ID);
Overdrivr 0:c4676d32d381 100 buffer[1] = *(temp_ptr + 1);
Overdrivr 0:c4676d32d381 101 buffer[2] = *(temp_ptr );
Overdrivr 0:c4676d32d381 102
Overdrivr 0:c4676d32d381 103 // Write type & writeable
Overdrivr 0:c4676d32d381 104
Overdrivr 0:c4676d32d381 105 type = (uint8_t)(Log.variables[index].type);
Overdrivr 0:c4676d32d381 106
Overdrivr 0:c4676d32d381 107 if(Log.variables[index].writeable)
Overdrivr 0:c4676d32d381 108 type += 0xF0;
Overdrivr 0:c4676d32d381 109
Overdrivr 0:c4676d32d381 110 buffer[3] = type;
Overdrivr 0:c4676d32d381 111
Overdrivr 0:c4676d32d381 112 //Write name
Overdrivr 0:c4676d32d381 113 uint16_t i = 4;
Overdrivr 0:c4676d32d381 114 for(uint16_t k = 0 ; k < 8 ; k++)
Overdrivr 0:c4676d32d381 115 {
Overdrivr 0:c4676d32d381 116 if(k < strlen(Log.variables[index].name))
Overdrivr 0:c4676d32d381 117 {
Overdrivr 0:c4676d32d381 118 buffer[i] = Log.variables[index].name[k];
Overdrivr 0:c4676d32d381 119 i++;
Overdrivr 0:c4676d32d381 120 }
Overdrivr 0:c4676d32d381 121 else
Overdrivr 0:c4676d32d381 122 buffer[i++] = 0;
Overdrivr 0:c4676d32d381 123 }
Overdrivr 0:c4676d32d381 124
Overdrivr 0:c4676d32d381 125 // Compute crc
Overdrivr 0:c4676d32d381 126 uint16_t crc_value = crc16(buffer,i);
Overdrivr 0:c4676d32d381 127
Overdrivr 0:c4676d32d381 128 // Write crc into buffer's last byte
Overdrivr 0:c4676d32d381 129 buffer[i++] = (crc_value >> 8) & 0xFF;
Overdrivr 0:c4676d32d381 130 buffer[i++] = crc_value & 0xFF;
Overdrivr 0:c4676d32d381 131
Overdrivr 0:c4676d32d381 132 // Encode frame
Overdrivr 0:c4676d32d381 133 encode(buffer,i);
Overdrivr 0:c4676d32d381 134 }
Overdrivr 0:c4676d32d381 135
Overdrivr 0:c4676d32d381 136 void send_group_descriptor(uint16_t index)
Overdrivr 0:c4676d32d381 137 {
Overdrivr 0:c4676d32d381 138 if(index > Log.current_group_id)
Overdrivr 0:c4676d32d381 139 return;
Overdrivr 0:c4676d32d381 140
Overdrivr 0:c4676d32d381 141 static uint8_t buffer[PAYLOAD_SIZE];
Overdrivr 0:c4676d32d381 142
Overdrivr 0:c4676d32d381 143 // Respond returned-descriptor
Overdrivr 0:c4676d32d381 144 buffer[0] = 0x00;
Overdrivr 0:c4676d32d381 145
Overdrivr 0:c4676d32d381 146 // Write id
Overdrivr 0:c4676d32d381 147 uint16_t ID = (index & 0x3F) << 10;
Overdrivr 0:c4676d32d381 148 uint8_t * temp_ptr = (uint8_t*)(&ID);
Overdrivr 0:c4676d32d381 149 buffer[1] = *(temp_ptr + 1);
Overdrivr 0:c4676d32d381 150 buffer[2] = *(temp_ptr);
Overdrivr 0:c4676d32d381 151
Overdrivr 0:c4676d32d381 152 // Write type
Overdrivr 0:c4676d32d381 153 buffer[3] = 0x07;
Overdrivr 0:c4676d32d381 154
Overdrivr 0:c4676d32d381 155 //Write name
Overdrivr 0:c4676d32d381 156 uint16_t i = 4;
Overdrivr 0:c4676d32d381 157 for(uint16_t k = 0 ; k < 8 ; k++)
Overdrivr 0:c4676d32d381 158 {
Overdrivr 0:c4676d32d381 159 if(k < strlen(Log.groups[index].name))
Overdrivr 0:c4676d32d381 160 {
Overdrivr 0:c4676d32d381 161 buffer[i] = Log.groups[index].name[k];
Overdrivr 0:c4676d32d381 162 i++;
Overdrivr 0:c4676d32d381 163 }
Overdrivr 0:c4676d32d381 164 else
Overdrivr 0:c4676d32d381 165 buffer[i++] = 0;
Overdrivr 0:c4676d32d381 166 }
Overdrivr 0:c4676d32d381 167
Overdrivr 0:c4676d32d381 168 // Compute crc
Overdrivr 0:c4676d32d381 169 uint16_t crc_value = crc16(buffer,i);
Overdrivr 0:c4676d32d381 170
Overdrivr 0:c4676d32d381 171 // Write crc into buffer's last byte
Overdrivr 0:c4676d32d381 172 buffer[i++] = (crc_value >> 8) & 0xFF;
Overdrivr 0:c4676d32d381 173 buffer[i++] = crc_value & 0xFF;
Overdrivr 0:c4676d32d381 174
Overdrivr 0:c4676d32d381 175 // Encode frame
Overdrivr 0:c4676d32d381 176 encode(buffer,i);
Overdrivr 0:c4676d32d381 177 }
Overdrivr 0:c4676d32d381 178
Overdrivr 0:c4676d32d381 179 void distantio_decode(uint8_t* data,uint16_t datasize)
Overdrivr 0:c4676d32d381 180 {
Overdrivr 0:c4676d32d381 181 // First check data size
Overdrivr 0:c4676d32d381 182 // 1 byte cmd + 2 bytes id + 1 byte type + FRAME_SIZE + 2 byte CRC
Overdrivr 0:c4676d32d381 183 if(datasize != PAYLOAD_SIZE)
Overdrivr 0:c4676d32d381 184 return;
Overdrivr 0:c4676d32d381 185
Overdrivr 0:c4676d32d381 186 // Second, check CRC
Overdrivr 0:c4676d32d381 187 uint16_t crc_value = crc16(data,PAYLOAD_SIZE-2);
Overdrivr 0:c4676d32d381 188 uint16_t crc_rx = ((uint16_t)data[PAYLOAD_SIZE-2] << 8) | data[PAYLOAD_SIZE-1];
Overdrivr 0:c4676d32d381 189
Overdrivr 0:c4676d32d381 190 if(crc_value != crc_rx)
Overdrivr 0:c4676d32d381 191 return;
Overdrivr 0:c4676d32d381 192
Overdrivr 0:c4676d32d381 193 // Process frame
Overdrivr 0:c4676d32d381 194 // First, identify command
Overdrivr 0:c4676d32d381 195 uint8_t command = data[0];
Overdrivr 0:c4676d32d381 196
Overdrivr 0:c4676d32d381 197 // Second, identify variable ID
Overdrivr 0:c4676d32d381 198 uint16_t ID = data[2] + (data[1] << 8);
Overdrivr 0:c4676d32d381 199 ID = (ID & 0x3FF);
Overdrivr 0:c4676d32d381 200
Overdrivr 0:c4676d32d381 201 // Third, identify data type
Overdrivr 0:c4676d32d381 202 uint8_t type = data[3];
Overdrivr 0:c4676d32d381 203
Overdrivr 0:c4676d32d381 204 switch(command)
Overdrivr 0:c4676d32d381 205 {
Overdrivr 0:c4676d32d381 206 // User requested descriptors
Overdrivr 0:c4676d32d381 207 case 0x02:
Overdrivr 0:c4676d32d381 208 // Send variables
Overdrivr 0:c4676d32d381 209 for(uint16_t i = 0 ; i < Log.amount ; i++)
Overdrivr 0:c4676d32d381 210 send_descriptor(i);
Overdrivr 0:c4676d32d381 211 // Send groups
Overdrivr 0:c4676d32d381 212 for(uint16_t i = 0 ; i <= Log.current_group_id ; i++)
Overdrivr 0:c4676d32d381 213 send_group_descriptor(i);
Overdrivr 0:c4676d32d381 214 break;
Overdrivr 0:c4676d32d381 215
Overdrivr 0:c4676d32d381 216 // User provided value to write
Overdrivr 0:c4676d32d381 217 case 0x04:
Overdrivr 0:c4676d32d381 218 if(ID >= Log.amount)
Overdrivr 0:c4676d32d381 219 return;
Overdrivr 0:c4676d32d381 220
Overdrivr 0:c4676d32d381 221 if(Log.variables[ID].writeable == 0x00)
Overdrivr 0:c4676d32d381 222 return;
Overdrivr 0:c4676d32d381 223
Overdrivr 0:c4676d32d381 224 if(Log.variables[ID].type != type)
Overdrivr 0:c4676d32d381 225 return;
Overdrivr 0:c4676d32d381 226
Overdrivr 0:c4676d32d381 227 uint16_t start_address = 4 + DATA_SIZE - 1;
Overdrivr 0:c4676d32d381 228
Overdrivr 0:c4676d32d381 229 // Copy contents directly into variable
Overdrivr 0:c4676d32d381 230 for(uint16_t i = 0 ; i < Log.variables[ID].size ; i++)
Overdrivr 0:c4676d32d381 231 {
Overdrivr 0:c4676d32d381 232 // Packet is big-endian, convert to little-endian
Overdrivr 0:c4676d32d381 233 uint8_t offset = start_address - i;
Overdrivr 0:c4676d32d381 234 *(Log.variables[ID].ptr + i) = *(data + offset);
Overdrivr 0:c4676d32d381 235 }
Overdrivr 0:c4676d32d381 236 break;
Overdrivr 0:c4676d32d381 237
Overdrivr 0:c4676d32d381 238 // User requested variable read
Overdrivr 0:c4676d32d381 239 case 0x05:
Overdrivr 0:c4676d32d381 240 if(ID >= Log.amount)
Overdrivr 0:c4676d32d381 241 return;
Overdrivr 0:c4676d32d381 242
Overdrivr 0:c4676d32d381 243 Log.variables[ID].send = 1;
Overdrivr 0:c4676d32d381 244 break;
Overdrivr 0:c4676d32d381 245
Overdrivr 0:c4676d32d381 246 // User requested stop variable read
Overdrivr 0:c4676d32d381 247 case 0x06:
Overdrivr 0:c4676d32d381 248 if(ID >= Log.amount)
Overdrivr 0:c4676d32d381 249 return;
Overdrivr 0:c4676d32d381 250 Log.variables[ID].send = 0;
Overdrivr 0:c4676d32d381 251 break;
Overdrivr 0:c4676d32d381 252
Overdrivr 0:c4676d32d381 253 }
Overdrivr 0:c4676d32d381 254 }
Overdrivr 0:c4676d32d381 255
Overdrivr 2:f2c816b681e3 256 void update(float current_time)
Overdrivr 0:c4676d32d381 257 {
Overdrivr 0:c4676d32d381 258 for(uint16_t i = 0 ; i < Log.amount ; i++)
Overdrivr 0:c4676d32d381 259 {
Overdrivr 0:c4676d32d381 260 if(Log.variables[i].send == 0)
Overdrivr 0:c4676d32d381 261 continue;
Overdrivr 2:f2c816b681e3 262
Overdrivr 2:f2c816b681e3 263 if(current_time < Log.variables[i].last_refreshed + Log.variables[i].refresh_rate)
Overdrivr 2:f2c816b681e3 264 continue;
Overdrivr 2:f2c816b681e3 265
Overdrivr 0:c4676d32d381 266 send_variable(i);
Overdrivr 2:f2c816b681e3 267 Log.variables[i].last_refreshed = current_time;
Overdrivr 0:c4676d32d381 268 }
Overdrivr 0:c4676d32d381 269 }
Overdrivr 0:c4676d32d381 270
Overdrivr 0:c4676d32d381 271 void send_variable(uint16_t index)
Overdrivr 0:c4676d32d381 272 {
Overdrivr 0:c4676d32d381 273 if(index >= Log.amount)
Overdrivr 0:c4676d32d381 274 return;
Overdrivr 0:c4676d32d381 275
Overdrivr 0:c4676d32d381 276 static uint8_t buffer[PAYLOAD_SIZE];
Overdrivr 0:c4676d32d381 277
Overdrivr 0:c4676d32d381 278 // Response code 0x01
Overdrivr 0:c4676d32d381 279 buffer[0] = 0x01;
Overdrivr 0:c4676d32d381 280
Overdrivr 0:c4676d32d381 281 // Write variable ID
Overdrivr 0:c4676d32d381 282 uint16_t ID = ((Log.variables[index].groupID & 0x003F) << 10) + (index & 0x3FF);
Overdrivr 0:c4676d32d381 283 uint8_t * temp_ptr = (uint8_t*)(&ID);
Overdrivr 0:c4676d32d381 284 buffer[1] = *(temp_ptr + 1);
Overdrivr 0:c4676d32d381 285 buffer[2] = *(temp_ptr);
Overdrivr 0:c4676d32d381 286
Overdrivr 0:c4676d32d381 287 // Write variable type
Overdrivr 0:c4676d32d381 288 buffer[3] = Log.variables[index].type;
Overdrivr 0:c4676d32d381 289 //TODO writeable
Overdrivr 0:c4676d32d381 290
Overdrivr 0:c4676d32d381 291 uint16_t i = 4;
Overdrivr 0:c4676d32d381 292
Overdrivr 0:c4676d32d381 293 // Write data
Overdrivr 0:c4676d32d381 294 for(uint16_t k = 0 ; k < DATA_SIZE ; k++)
Overdrivr 0:c4676d32d381 295 {
Overdrivr 0:c4676d32d381 296 uint16_t off = DATA_SIZE - 1 - k;
Overdrivr 0:c4676d32d381 297
Overdrivr 0:c4676d32d381 298 // Fill buffer with data
Overdrivr 0:c4676d32d381 299 if(off < Log.variables[index].size)
Overdrivr 0:c4676d32d381 300 {
Overdrivr 0:c4676d32d381 301 temp_ptr = Log.variables[index].ptr + off ;
Overdrivr 0:c4676d32d381 302 buffer[i++] = *temp_ptr;
Overdrivr 0:c4676d32d381 303 }
Overdrivr 0:c4676d32d381 304 // Fill remaining bits with 0
Overdrivr 0:c4676d32d381 305 else
Overdrivr 0:c4676d32d381 306 {
Overdrivr 0:c4676d32d381 307 buffer[i++] = 0;
Overdrivr 0:c4676d32d381 308 }
Overdrivr 0:c4676d32d381 309 }
Overdrivr 0:c4676d32d381 310
Overdrivr 0:c4676d32d381 311 // Compute crc
Overdrivr 0:c4676d32d381 312 uint16_t crc_value = crc16(buffer,i);
Overdrivr 0:c4676d32d381 313
Overdrivr 0:c4676d32d381 314 // Write crc into buffer's last byte
Overdrivr 0:c4676d32d381 315 buffer[i++] = (crc_value >> 8) & 0xFF;
Overdrivr 0:c4676d32d381 316 buffer[i++] = crc_value & 0xFF;
Overdrivr 0:c4676d32d381 317
Overdrivr 0:c4676d32d381 318 // Encode frame
Overdrivr 0:c4676d32d381 319 encode(buffer,i);
Overdrivr 0:c4676d32d381 320 }
Overdrivr 0:c4676d32d381 321
Overdrivr 0:c4676d32d381 322 void send_alive()
Overdrivr 0:c4676d32d381 323 {
Overdrivr 0:c4676d32d381 324 static uint8_t buffer[PAYLOAD_SIZE] = {0x03,0x00,0x10,0x00,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x00,0x00};
Overdrivr 0:c4676d32d381 325
Overdrivr 0:c4676d32d381 326 uint16_t index = 1;
Overdrivr 0:c4676d32d381 327 uint16_t group = 0;
Overdrivr 0:c4676d32d381 328 uint16_t ID = ((group & 0x003F) << 10) + (index & 0x3FF);
Overdrivr 0:c4676d32d381 329 uint8_t * temp_ptr = (uint8_t*)(&ID);
Overdrivr 0:c4676d32d381 330 buffer[1] = *(temp_ptr + 1);
Overdrivr 0:c4676d32d381 331 buffer[2] = *(temp_ptr );
Overdrivr 0:c4676d32d381 332
Overdrivr 0:c4676d32d381 333 // Compute crc
Overdrivr 0:c4676d32d381 334 uint16_t crc_value = crc16(buffer,PAYLOAD_SIZE - 2);
Overdrivr 0:c4676d32d381 335
Overdrivr 0:c4676d32d381 336 // Write crc into buffer's last byte
Overdrivr 0:c4676d32d381 337 buffer[PAYLOAD_SIZE - 1] = crc_value & 0xFF;
Overdrivr 0:c4676d32d381 338 buffer[PAYLOAD_SIZE - 2] = (crc_value >> 8) & 0xFF;
Overdrivr 0:c4676d32d381 339
Overdrivr 0:c4676d32d381 340 // Send frame to encoding
Overdrivr 0:c4676d32d381 341 encode(buffer,PAYLOAD_SIZE);
Overdrivr 0:c4676d32d381 342 }
Overdrivr 0:c4676d32d381 343
Overdrivr 0:c4676d32d381 344
Overdrivr 0:c4676d32d381 345 /**
Overdrivr 0:c4676d32d381 346 * Returns the size in byte for each variable
Overdrivr 0:c4676d32d381 347 */
Overdrivr 0:c4676d32d381 348
Overdrivr 0:c4676d32d381 349 uint16_t get_size(dio_type type)
Overdrivr 0:c4676d32d381 350 {
Overdrivr 0:c4676d32d381 351 switch(type)
Overdrivr 0:c4676d32d381 352 {
Overdrivr 0:c4676d32d381 353 case dio_type_FLOAT:
Overdrivr 0:c4676d32d381 354 case dio_type_UINT32:
Overdrivr 0:c4676d32d381 355 case dio_type_INT32:
Overdrivr 0:c4676d32d381 356 return 4;
Overdrivr 0:c4676d32d381 357
Overdrivr 0:c4676d32d381 358 case dio_type_UINT16:
Overdrivr 0:c4676d32d381 359 case dio_type_INT16:
Overdrivr 0:c4676d32d381 360 return 2;
Overdrivr 0:c4676d32d381 361
Overdrivr 0:c4676d32d381 362 case dio_type_UINT8:
Overdrivr 0:c4676d32d381 363 case dio_type_INT8:
Overdrivr 0:c4676d32d381 364 default:
Overdrivr 0:c4676d32d381 365 return 1;
Overdrivr 0:c4676d32d381 366 }
Overdrivr 0:c4676d32d381 367 }