diff --git a/MultiNode/MNLib.cpp b/MultiNode/MNLib.cpp index 7daf215..6034b97 100644 --- a/MultiNode/MNLib.cpp +++ b/MultiNode/MNLib.cpp @@ -317,26 +317,38 @@ void initializeDevices() } } +DeviceBase* getDeviceFromClass(uint8_t class_type) +{ + switch (class_type) + { + case 0: + return new Device; + break; + case 1: + return new AnalogInput; + break; + default: + return new Device; + break; + } +} + DeviceBase* getDevice(uint8_t pointer) { uint8_t class_type = configuration_memory[pointer]; + DeviceBase* device = getDeviceFromClass(class_type); if (class_type == 0) { - DeviceBase* device = new Device; device->class_type = 0; device->sensor_type = 0xFF; device->pin = 0xFF; - return device; } - if (class_type == 1) + else { - DeviceBase* device = new AnalogInput; - //memcpy(device + 4, &configuration_memory[pointer], sizeof(AnalogInput) - 4); // There is some 4 bytes extra at the beginning - memcpy(reinterpret_cast(device) + 4, &configuration_memory[pointer], sizeof(AnalogInput) - 4); // There is some 4 bytes extra at the beginning - return device; + memcpy(reinterpret_cast(device) + 4, &configuration_memory[pointer], device->size()); } - return new Device; + return device; } void storeDevice(uint8_t pointer, DeviceBase* device) diff --git a/MultiNode/MNLib.h b/MultiNode/MNLib.h index 0d34745..4bafcfc 100644 --- a/MultiNode/MNLib.h +++ b/MultiNode/MNLib.h @@ -183,6 +183,7 @@ void errorBlink(int n); // Quickly blink n times bool send(uint8_t data[], uint8_t len); bool receive(); void initializeDevices(); +DeviceBase* getDeviceFromClass(uint8_t class_type); DeviceBase* getDevice(uint8_t pointer); // Gets the device at the specified location from cfgmem void storeDevice(uint8_t pointer, DeviceBase* device); // Stores a device at the specified location in cfgmem (not in flash) void loopMN(); diff --git a/RasPi/MultiNode.py b/RasPi/MultiNode.py index 17d8c99..e76c05d 100644 --- a/RasPi/MultiNode.py +++ b/RasPi/MultiNode.py @@ -94,6 +94,7 @@ class MultiNode: self.devices[rx_id] = {"last_message_id": msg_id} self.decode_packet(self.devices[rx_id], data) + self.print_data() # print(f"{tx_id} #{msg_id}: {decode_packet(data):.3f} V, {payload.rssi} dB(?) RSSI, {payload.snr} dB(?) SNR {(time.clock_gettime_ns(0)) / 1e9}") # print(f"{tx_id} #{msg_id}: {data.hex()} {self.decode_packet(data)}, {payload.rssi} dB(?) RSSI, {payload.snr} dB(?) SNR {(time.clock_gettime_ns(0)) / 1e9}") @@ -116,7 +117,6 @@ class MultiNode: self.lora.send(payload, 255) self.lora.set_mode_rx() - self.print_data() def print_data(self): for device_id in self.devices: