From 9045f51bf8c837bc68f32e4a6989360182b9c944 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Fri, 27 Jan 2023 12:03:28 +0100 Subject: [PATCH] consider index --- sketch/production.cpp | 26 +++++++++++++++----------- snippets/decoding2.txt | 8 ++++---- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/sketch/production.cpp b/sketch/production.cpp index f110ec4..7349a84 100644 --- a/sketch/production.cpp +++ b/sketch/production.cpp @@ -112,17 +112,21 @@ static void prepareTxFrame( uint8_t port ) msg.status = (DS18B20.getDS18Count() == NUM_OF_SENSORS) ? errorCode : errorCode | ERR_SENSOR_LOST; DS18B20.requestTemperatures(); for (uint8_t i = 0; i < NUM_OF_SENSORS; i++) { - msg.sensors[i].addr = sensors[i].addr; - Serial.printf("%d: %s: %016llx\n\r", i, sensors[i].label, sensors[i].addr); - msg.sensors[i].value = DS18B20.getTemp(((const uint8_t*)(&(sensors[i].addr)))); - Serial.printf("v: %08x\n\r", msg.sensors[i].value); + for (uint8_t j = 0; j < NUM_OF_SENSORS; j++) { + if (sensors[j].index == i) { + msg.sensors[i].addr = sensors[j].addr; + Serial.printf("%d, %d: %s: %016llx\n\r", i, j, sensors[j].label, sensors[j].addr); + msg.sensors[i].value = DS18B20.getTemp(((const uint8_t*)(&(sensors[j].addr)))); + Serial.printf("v: %08x\n\r", msg.sensors[i].value); - float tempC = ((float)msg.sensors[i].value) / 128; - Serial.printf("f: %.2f\n\r", tempC); - char dispbuf[128]; - sprintf(dispbuf, "%s: %.2f °C", sensors[i].label, tempC); - display.drawString(1, i * 16, dispbuf); - Serial.printf("%d, %016llx, %s, %.2f\n\r", sensors[i].index, sensors[i].addr, sensors[i].label, tempC); + float tempC = ((float)msg.sensors[i].value) / 128; + Serial.printf("f: %.2f\n\r", tempC); + char dispbuf[128]; + sprintf(dispbuf, "%s: %.2f °C", sensors[j].label, tempC); + display.drawString(1, i * 16, dispbuf); + Serial.printf("%d, %016llx, %s, %.2f\n\r", sensors[j].index, sensors[j].addr, sensors[j].label, tempC); + } + } } appDataSize = sizeof(msg); memcpy(&appData, (void*)&msg, appDataSize); @@ -200,7 +204,7 @@ void productionSetup() { sprintf(buf, "%d: %s: %016llx", i, sensors[i].label, sensors[i].addr); Serial.println(buf); //display.drawString(1, i*16, buf); - sensors[i].index = 0; + sensors[i].index = i; } } } diff --git a/snippets/decoding2.txt b/snippets/decoding2.txt index c2eb291..b4ac0a6 100644 --- a/snippets/decoding2.txt +++ b/snippets/decoding2.txt @@ -49,14 +49,14 @@ typedef struct { } __attribute__((packed)) sensor_t; 28 8C 4F 6A 0D 00 00 94 -00 +03 53 45 4E 53 30 00 28 19 C3 0A 0D 00 00 B4 -01 +02 53 45 4E 53 31 00 28 35 86 6A 0D 00 00 D4 -02 +01 53 45 4E 53 32 00 28 C7 11 F6 62 20 01 B8 -03 +00 53 45 4E 53 33 00