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
Diff: distantio.cpp
- Revision:
- 5:e8936f38a338
- Parent:
- 4:d675ad9c57ff
- Child:
- 6:72d46dbdbe7a
--- a/distantio.cpp Tue Oct 13 12:20:44 2015 +0000 +++ b/distantio.cpp Wed Oct 14 09:42:32 2015 +0000 @@ -178,6 +178,65 @@ encode(buffer,FRAMESIZE); } + void dIO_emergency_send(void* ptr, uint16_t size, dio_type type, char* name, float recordingtime, uint16_t index) + { + + static uint8_t buffer[FRAMESIZE]; + + // Response code 0x09 + buffer[0] = 0x09; + + // Write variable ID + uint8_t * temp_ptr = (uint8_t*)(name); + buffer[1] = *(temp_ptr + 1); + buffer[2] = *(temp_ptr); + + // Write variable type + buffer[3] = type; + + // Extra identifier 1 + temp_ptr = (uint8_t*)(&recordingtime); + buffer[4] = *(temp_ptr + 3); + buffer[5] = *(temp_ptr + 2); + buffer[6] = *(temp_ptr + 1); + buffer[7] = *(temp_ptr ); + + // Extra identifier 2 + temp_ptr = (uint8_t*)(&index); + buffer[8] = *(temp_ptr + 1); + buffer[9] = *(temp_ptr ); + + uint16_t i = 10; + + // Write data + for(uint16_t k = 0 ; k < DATASIZE ; k++) + { + uint16_t off = DATASIZE - 1 - k; + + // Fill buffer with data + if(off < size) + { + temp_ptr = (uint8_t*)(ptr) + off ; + buffer[i++] = *temp_ptr; + } + // Fill remaining bits with 0 + else + { + buffer[i++] = 0; + } + } + + // Compute crc + uint16_t crc_value = crc16(buffer,i); + + // Write crc into buffer's last byte + buffer[i++] = (crc_value >> 8) & 0xFF; + buffer[i++] = crc_value & 0xFF; + + // Encode frame + encode(buffer,i); + } + /* ------------------- PRIVATE FUNCTIONS ------------------ */ void _dIO_send_descriptor(uint16_t index)