#ifndef RMIC_CONTROL_H #define RMIC_CONTROL_H #include #include #include #define RMIC_CONTROL_FRAME_SIZE 20u #define RMIC_CONTROL_TIMEOUT_MS 100u /* Channel order: forward, strafe-right, yaw-right, pitch-up. Speed: -1000..1000. */ typedef struct { int16_t channel[4]; bool enabled; bool debug; bool fire; } rmic_control; typedef struct { uint8_t buffer[RMIC_CONTROL_FRAME_SIZE]; size_t used; bool synchronized; uint32_t sequence; uint32_t last_valid_ms; rmic_control control; } rmic_receiver; void rmic_receiver_init(rmic_receiver *receiver); /* Call from one task/context only; feed arbitrary UART chunks, never assume frame alignment. * Returns number of accepted fresh frames. Noise/bad/duplicate frames do not renew timeout. * now_ms is a monotonic uint32 clock (wraparound is supported). */ size_t rmic_receiver_feed(rmic_receiver *receiver, const uint8_t *data, size_t length, uint32_t now_ms); /* Call at least once per control-loop iteration, including when UART is silent. * This function stops all channels/fire after 100ms and requires a neutral frame to resync. * Use only this returned state when applying motor/gimbal/launcher setpoints. */ rmic_control rmic_receiver_poll(rmic_receiver *receiver, uint32_t now_ms); #endif