From 6450d3e8a64b04f7fd929d1d1253cc5216b61590 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Sun, 14 May 2017 12:45:32 +0200 Subject: [PATCH] Send data in network endianness Add information to README about the data packet format. --- v04/README | 30 +++++++++++++++++++++++++++++- v04/main.c | 14 +++++++------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/v04/README b/v04/README index 6ce3aeb..d686ea5 100644 --- a/v04/README +++ b/v04/README @@ -49,13 +49,41 @@ format is : # addr type [other data] 0x23 (0x01 to 0x1F) (0x00 to 0xFF) [....] Valid types are : - - 'a' : all - request to send all available sensor data to host. + - 'a' : get all - request to send all available sensor data to host, no data. - 'l' : set led color - set the sensor led color. Three bytes of data (RGB). + - 'c' : get compensation data from BME280 sensor. (TO BE DEFINED) It is also possible to broadcast a message to all sensors by sending to address 255 (0xFF) +The response for the "get all" request has the following format : + # (addr | sensors) data + 0x23 1 byte 18 bytes + +The second byte holds the address on the fist 5 bits (LSB), and information on +available sensors on the three top bits : +addr | sensors : (0x01 to 0x1F) | (got_tsl << 5) | (got_veml << 6) | (got_bme << 7) + got_tsl : Set if TSL256x sensor is present and configured + got_veml : Set if VEML6070 sensor is present and configured + got_bme : Set if BME280 sensor is present and configured + +data is a set of nine 16bits values, in network (big) endian order, with the +following meaning, in this order : + - raw_humidity from soil moisture sensor + - lux value from TSL256x + - ir value from TSL256x + - uv value from VEML6070 + - pressure from BME280 + - comp_temp from BME280 + - humidity from BME280 + - unused - should be 0 (nul) + - unused - should be 0 (nul) + + +The response for the "get compensation data" request has to be defined. + + To set the sensor address using a serial line from a linux host, you can use these commands (sensor connected to ttyUSB0) : diff --git a/v04/main.c b/v04/main.c index e63189c..be8d52f 100644 --- a/v04/main.c +++ b/v04/main.c @@ -484,13 +484,13 @@ int main(void) buff[0] = '#'; buff[1] = address | (got_tsl << 5) | (got_veml << 6) | (got_bme << 7); - data[1] = (uint16_t)raw_humidity; - data[2] = (uint16_t)lux; - data[3] = (uint16_t)ir; - data[4] = (uint16_t)uv; - data[5] = (uint16_t)pressure; - data[6] = (uint16_t)comp_temp; - data[7] = (uint16_t)humidity; + data[1] = (uint16_t)htons(raw_humidity); + data[2] = (uint16_t)htons(lux); + data[3] = (uint16_t)htons(ir); + data[4] = (uint16_t)htons(uv); + data[5] = (uint16_t)htons(pressure); + data[6] = (uint16_t)htons(comp_temp); + data[7] = (uint16_t)htons(humidity); gpio_clear(tx_en); serial_write(UART0, buff, 20); -- 2.43.0