gauteh / sfy

🌊 A lightweight wave buoy for near-shore deployments.
MIT License
44 stars 7 forks source link

Serialization of temperature from IMU is possibly always skipped #144

Open gauteh opened 1 year ago

gauteh commented 1 year ago

I think this gives a double negative:

https://github.com/gauteh/sfy/blob/main/sfy-buoy/src/axl.rs#L68

needs a test, since the notecard does not handle NaN in serialized JSON. Currently the IMU temperature is never sent, which could either mean that this is a bug. Or that there's something disabled in the IMU.

@stianvikanes : maybe something you can look into.

gauteh commented 1 year ago

Suggestion for a test in axl.rs:

    #[test]
    fn temp_not_f32_subnormal() {
        // the notecard does not handle NaN f32's
        let p = AxlPacketMeta::default();

        let v: heapless::String<{10 * 1024}> = serde_json_core::to_string(&p).unwrap();
        dbg!(&v);
        assert!(v.contains("temperature"));

        let mut p = AxlPacketMeta::default();
        p.temperature = f32::NAN;

        let v: heapless::String<{10 * 1024}> = serde_json_core::to_string(&p).unwrap();
        dbg!(&v);
        assert!(!v.contains("temperature"));

        let mut p = AxlPacketMeta::default();
        p.temperature = f32::INFINITY;

        let v: heapless::String<{10 * 1024}> = serde_json_core::to_string(&p).unwrap();
        dbg!(&v);
        assert!(!v.contains("temperature"));
    }