Add getDeviceFromClass

This commit is contained in:
Terra 2022-04-24 15:22:11 +02:00
parent 914dfdb1f3
commit 17b6e0487b
3 changed files with 22 additions and 9 deletions

View File

@ -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<uint8_t*>(device) + 4, &configuration_memory[pointer], sizeof(AnalogInput) - 4); // There is some 4 bytes extra at the beginning
return device;
memcpy(reinterpret_cast<uint8_t*>(device) + 4, &configuration_memory[pointer], device->size());
}
return new Device;
return device;
}
void storeDevice(uint8_t pointer, DeviceBase* device)

View File

@ -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();

View File

@ -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: