NubeIO / module-core-loraraw

0 stars 0 forks source link

[Bug] Account for CMAC difference in driver-lora #34

Closed Shiny380 closed 1 month ago

Shiny380 commented 1 month ago

driver-lora has been printing data slightly wrong this whole time and we need to align it to existing firmware. See that ticket here.

This small refactor will require several changes

  1. First, only send the data section to the decoder. This means removing the device address, inner header (4 + 3 = 7) from the start and the CMAC and the RSSI, SNR bytes on the end (4 + 2 = 6) so something like decode(data[7:-6], ...) (Note this is bytes not hex, so double if accounting for hex string).

    You will need to account for this difference in EACH decoder as the location of each byte will be different now.

  2. Remove the RSSI and SNR decoding and writing from EACH decoder and do it in one place instead: AFTER the main decoding and IF the main decoding returns successfully. i.e. here

maharjanaman commented 1 month ago

This means removing the device address, inner header (4 + 3 = 7) from the start and the CMAC and the RSSI, SNR bytes on the end (4 + 2 = 6)

@Shiny380 Don't the payloads for Micro Edge from this comment https://github.com/NubeIO/module-core-loraraw/issues/28#issuecomment-2196103555 have inner header? The current implementation for Micro Edge does not account for inner header and data after the address is decoded as value.

I tried extracting values from the above payloads after removing these bytes from the front and end but the remaining bytes were not sufficient (maybe because of the inner header & cmac). Do you have some test data?

maharjanaman commented 1 month ago

@Shiny380 I've created a draft PR for this issue. The PR is in draft as I'm still confused about the following,

Shiny380 commented 1 month ago

Ah sorry I forgot to account for that. We can detect 2 scenarios like so: (taken from here)

        # +4 for HEADER, +4 for CMAC, +1 for RSSI and +1 for SNR. total = 10 bytes (4+4+1+1)
        if length % 16 == (LORA_RAW_HEADER_LEN + LORA_RAW_CMAC_LEN + RSSI_LEN + SNR_LEN):
            # LoRaRAW Unique device (Rubix, Zip)
        else:
            # Legacy device (Droplet, MicroEdge)

If LoRaRAW device, do new approach, else lets just keep the droplet and microedge decoders as they are. the old legacy devices suck and are a mess haha best to not touch them :sweat_smile: