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:
Mon Oct 12 13:29:40 2015 +0000
Revision:
3:135f55b5334e
Parent:
2:f2c816b681e3
Child:
4:d675ad9c57ff
New protocol update. DistantIO Protocol now supports 2 extra identifier fields for sending time of recorded value and index for array support. Also, it will enable semi-manual data send for special debugging cases. Longer var/group names too.

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 3:135f55b5334e 21 void send_variable(uint16_t index,float extra_identifier_1,uint16_t extra_identifier_2=0);
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 3:135f55b5334e 40 strncpy(Log.variables[i].name,default_name,NAMESIZE);
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 3:135f55b5334e 46 strncpy(Log.groups[0].name,"default",NAMESIZE);
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 3:135f55b5334e 63 strncpy(Log.variables[Log.amount].name,name,NAMESIZE);
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 3:135f55b5334e 79 strncpy(Log.groups[Log.current_group_id].name,groupname,NAMESIZE);
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 3:135f55b5334e 91 static uint8_t buffer[FRAMESIZE];
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 3:135f55b5334e 114 // TODO : Replace with strncpy
Overdrivr 3:135f55b5334e 115 for(uint16_t k = 0 ; k < NAMESIZE ; k++)
Overdrivr 0:c4676d32d381 116 {
Overdrivr 0:c4676d32d381 117 if(k < strlen(Log.variables[index].name))
Overdrivr 0:c4676d32d381 118 {
Overdrivr 0:c4676d32d381 119 buffer[i] = Log.variables[index].name[k];
Overdrivr 0:c4676d32d381 120 i++;
Overdrivr 0:c4676d32d381 121 }
Overdrivr 0:c4676d32d381 122 else
Overdrivr 0:c4676d32d381 123 buffer[i++] = 0;
Overdrivr 0:c4676d32d381 124 }
Overdrivr 0:c4676d32d381 125
Overdrivr 0:c4676d32d381 126 // Compute crc
Overdrivr 0:c4676d32d381 127 uint16_t crc_value = crc16(buffer,i);
Overdrivr 0:c4676d32d381 128
Overdrivr 0:c4676d32d381 129 // Write crc into buffer's last byte
Overdrivr 0:c4676d32d381 130 buffer[i++] = (crc_value >> 8) & 0xFF;
Overdrivr 0:c4676d32d381 131 buffer[i++] = crc_value & 0xFF;
Overdrivr 0:c4676d32d381 132
Overdrivr 0:c4676d32d381 133 // Encode frame
Overdrivr 0:c4676d32d381 134 encode(buffer,i);
Overdrivr 0:c4676d32d381 135 }
Overdrivr 0:c4676d32d381 136
Overdrivr 0:c4676d32d381 137 void send_group_descriptor(uint16_t index)
Overdrivr 0:c4676d32d381 138 {
Overdrivr 0:c4676d32d381 139 if(index > Log.current_group_id)
Overdrivr 0:c4676d32d381 140 return;
Overdrivr 0:c4676d32d381 141
Overdrivr 3:135f55b5334e 142 static uint8_t buffer[FRAMESIZE];
Overdrivr 0:c4676d32d381 143
Overdrivr 0:c4676d32d381 144 // Respond returned-descriptor
Overdrivr 0:c4676d32d381 145 buffer[0] = 0x00;
Overdrivr 0:c4676d32d381 146
Overdrivr 0:c4676d32d381 147 // Write id
Overdrivr 0:c4676d32d381 148 uint16_t ID = (index & 0x3F) << 10;
Overdrivr 0:c4676d32d381 149 uint8_t * temp_ptr = (uint8_t*)(&ID);
Overdrivr 0:c4676d32d381 150 buffer[1] = *(temp_ptr + 1);
Overdrivr 0:c4676d32d381 151 buffer[2] = *(temp_ptr);
Overdrivr 0:c4676d32d381 152
Overdrivr 0:c4676d32d381 153 // Write type
Overdrivr 0:c4676d32d381 154 buffer[3] = 0x07;
Overdrivr 0:c4676d32d381 155
Overdrivr 0:c4676d32d381 156 //Write name
Overdrivr 0:c4676d32d381 157 uint16_t i = 4;
Overdrivr 3:135f55b5334e 158 for(uint16_t k = 0 ; k < NAMESIZE ; k++)
Overdrivr 0:c4676d32d381 159 {
Overdrivr 0:c4676d32d381 160 if(k < strlen(Log.groups[index].name))
Overdrivr 0:c4676d32d381 161 {
Overdrivr 0:c4676d32d381 162 buffer[i] = Log.groups[index].name[k];
Overdrivr 0:c4676d32d381 163 i++;
Overdrivr 0:c4676d32d381 164 }
Overdrivr 0:c4676d32d381 165 else
Overdrivr 0:c4676d32d381 166 buffer[i++] = 0;
Overdrivr 0:c4676d32d381 167 }
Overdrivr 0:c4676d32d381 168
Overdrivr 0:c4676d32d381 169 // Compute crc
Overdrivr 0:c4676d32d381 170 uint16_t crc_value = crc16(buffer,i);
Overdrivr 0:c4676d32d381 171
Overdrivr 0:c4676d32d381 172 // Write crc into buffer's last byte
Overdrivr 0:c4676d32d381 173 buffer[i++] = (crc_value >> 8) & 0xFF;
Overdrivr 0:c4676d32d381 174 buffer[i++] = crc_value & 0xFF;
Overdrivr 0:c4676d32d381 175
Overdrivr 0:c4676d32d381 176 // Encode frame
Overdrivr 0:c4676d32d381 177 encode(buffer,i);
Overdrivr 0:c4676d32d381 178 }
Overdrivr 0:c4676d32d381 179
Overdrivr 0:c4676d32d381 180 void distantio_decode(uint8_t* data,uint16_t datasize)
Overdrivr 0:c4676d32d381 181 {
Overdrivr 0:c4676d32d381 182 // First check data size
Overdrivr 3:135f55b5334e 183 if(datasize != FRAMESIZE)
Overdrivr 0:c4676d32d381 184 return;
Overdrivr 0:c4676d32d381 185
Overdrivr 0:c4676d32d381 186 // Second, check CRC
Overdrivr 3:135f55b5334e 187 uint16_t crc_value = crc16(data,FRAMESIZE-2);
Overdrivr 3:135f55b5334e 188 uint16_t crc_rx = ((uint16_t)data[FRAMESIZE-2] << 8) | data[FRAMESIZE-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 3:135f55b5334e 227 uint16_t start_address = DATASTART + DATASIZE - 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 3:135f55b5334e 266 send_variable(i,current_time);
Overdrivr 2:f2c816b681e3 267 Log.variables[i].last_refreshed = current_time;
Overdrivr 0:c4676d32d381 268 }
Overdrivr 0:c4676d32d381 269 }
Overdrivr 0:c4676d32d381 270
Overdrivr 3:135f55b5334e 271 void send_variable(uint16_t index,float extra_identifier_1,uint16_t extra_identifier_2)
Overdrivr 0:c4676d32d381 272 {
Overdrivr 0:c4676d32d381 273 if(index >= Log.amount)
Overdrivr 0:c4676d32d381 274 return;
Overdrivr 0:c4676d32d381 275
Overdrivr 3:135f55b5334e 276 static uint8_t buffer[FRAMESIZE];
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 3:135f55b5334e 290
Overdrivr 3:135f55b5334e 291 // Extra identifier 1
Overdrivr 3:135f55b5334e 292 temp_ptr = (uint8_t*)(&extra_identifier_1);
Overdrivr 3:135f55b5334e 293 buffer[4] = *(temp_ptr + 3);
Overdrivr 3:135f55b5334e 294 buffer[5] = *(temp_ptr + 2);
Overdrivr 3:135f55b5334e 295 buffer[6] = *(temp_ptr + 1);
Overdrivr 3:135f55b5334e 296 buffer[7] = *(temp_ptr );
Overdrivr 3:135f55b5334e 297
Overdrivr 3:135f55b5334e 298 // Extra identifier 2
Overdrivr 3:135f55b5334e 299 temp_ptr = (uint8_t*)(&extra_identifier_2);
Overdrivr 3:135f55b5334e 300 buffer[8] = *(temp_ptr + 1);
Overdrivr 3:135f55b5334e 301 buffer[9] = *(temp_ptr );
Overdrivr 3:135f55b5334e 302
Overdrivr 3:135f55b5334e 303 uint16_t i = 10;
Overdrivr 0:c4676d32d381 304
Overdrivr 0:c4676d32d381 305 // Write data
Overdrivr 3:135f55b5334e 306 for(uint16_t k = 0 ; k < DATASIZE ; k++)
Overdrivr 0:c4676d32d381 307 {
Overdrivr 3:135f55b5334e 308 uint16_t off = DATASIZE - 1 - k;
Overdrivr 0:c4676d32d381 309
Overdrivr 0:c4676d32d381 310 // Fill buffer with data
Overdrivr 0:c4676d32d381 311 if(off < Log.variables[index].size)
Overdrivr 0:c4676d32d381 312 {
Overdrivr 0:c4676d32d381 313 temp_ptr = Log.variables[index].ptr + off ;
Overdrivr 0:c4676d32d381 314 buffer[i++] = *temp_ptr;
Overdrivr 0:c4676d32d381 315 }
Overdrivr 0:c4676d32d381 316 // Fill remaining bits with 0
Overdrivr 0:c4676d32d381 317 else
Overdrivr 0:c4676d32d381 318 {
Overdrivr 0:c4676d32d381 319 buffer[i++] = 0;
Overdrivr 0:c4676d32d381 320 }
Overdrivr 0:c4676d32d381 321 }
Overdrivr 0:c4676d32d381 322
Overdrivr 0:c4676d32d381 323 // Compute crc
Overdrivr 0:c4676d32d381 324 uint16_t crc_value = crc16(buffer,i);
Overdrivr 0:c4676d32d381 325
Overdrivr 0:c4676d32d381 326 // Write crc into buffer's last byte
Overdrivr 0:c4676d32d381 327 buffer[i++] = (crc_value >> 8) & 0xFF;
Overdrivr 0:c4676d32d381 328 buffer[i++] = crc_value & 0xFF;
Overdrivr 0:c4676d32d381 329
Overdrivr 0:c4676d32d381 330 // Encode frame
Overdrivr 0:c4676d32d381 331 encode(buffer,i);
Overdrivr 0:c4676d32d381 332 }
Overdrivr 0:c4676d32d381 333
Overdrivr 0:c4676d32d381 334 void send_alive()
Overdrivr 0:c4676d32d381 335 {
Overdrivr 3:135f55b5334e 336 static uint8_t buffer[FRAMESIZE];
Overdrivr 3:135f55b5334e 337 buffer[0] = 0x03;
Overdrivr 3:135f55b5334e 338
Overdrivr 0:c4676d32d381 339 // Compute crc
Overdrivr 3:135f55b5334e 340 uint16_t crc_value = crc16(buffer,FRAMESIZE - 2);
Overdrivr 0:c4676d32d381 341
Overdrivr 0:c4676d32d381 342 // Write crc into buffer's last byte
Overdrivr 3:135f55b5334e 343 buffer[FRAMESIZE - 1] = crc_value & 0xFF;
Overdrivr 3:135f55b5334e 344 buffer[FRAMESIZE - 2] = (crc_value >> 8) & 0xFF;
Overdrivr 0:c4676d32d381 345
Overdrivr 0:c4676d32d381 346 // Send frame to encoding
Overdrivr 3:135f55b5334e 347 encode(buffer,FRAMESIZE);
Overdrivr 0:c4676d32d381 348 }
Overdrivr 0:c4676d32d381 349
Overdrivr 0:c4676d32d381 350
Overdrivr 0:c4676d32d381 351 /**
Overdrivr 0:c4676d32d381 352 * Returns the size in byte for each variable
Overdrivr 0:c4676d32d381 353 */
Overdrivr 0:c4676d32d381 354
Overdrivr 0:c4676d32d381 355 uint16_t get_size(dio_type type)
Overdrivr 0:c4676d32d381 356 {
Overdrivr 0:c4676d32d381 357 switch(type)
Overdrivr 0:c4676d32d381 358 {
Overdrivr 0:c4676d32d381 359 case dio_type_FLOAT:
Overdrivr 0:c4676d32d381 360 case dio_type_UINT32:
Overdrivr 0:c4676d32d381 361 case dio_type_INT32:
Overdrivr 0:c4676d32d381 362 return 4;
Overdrivr 0:c4676d32d381 363
Overdrivr 0:c4676d32d381 364 case dio_type_UINT16:
Overdrivr 0:c4676d32d381 365 case dio_type_INT16:
Overdrivr 0:c4676d32d381 366 return 2;
Overdrivr 0:c4676d32d381 367
Overdrivr 0:c4676d32d381 368 case dio_type_UINT8:
Overdrivr 0:c4676d32d381 369 case dio_type_INT8:
Overdrivr 0:c4676d32d381 370 default:
Overdrivr 0:c4676d32d381 371 return 1;
Overdrivr 0:c4676d32d381 372 }
Overdrivr 0:c4676d32d381 373 }