/* HawkHealth — Subsystem Stub Starter (Wokwi, ST Nucleo-C031C6)
*
* This week's two goals, in one sketch:
* (1) Your subsystem's core-logic STUB runs as a real FreeRTOS task.
* (2) You define your FIRST queue type — the message your subsystem PRODUCES —
* and send it on a FreeRTOS queue.
*
* Below is a worked example for a SENSOR-style producer. Everywhere marked // >>> ADAPT
* swap in YOUR subsystem's message type and stub logic. When it runs, the fields you chose
* are exactly the "Produces: <Type> on <yourQ>" line in your interface-spec section.
*
* REQUIRED LIBRARY: Library Manager -> + Add -> "STM32duino FreeRTOS".
* No diagram wiring needed — this uses the Serial Monitor only.
*/
#include <STM32FreeRTOS.h>
/* ---- (2) YOUR FIRST QUEUE TYPE --------------------------------------------
* The message your subsystem produces. Keep it a plain struct of plain fields. */
typedef struct { // >>> ADAPT: rename for your subsystem (e.g. HH_SensorReading_t)
uint32_t timestamp_ms;
float value; // >>> ADAPT: your field(s), e.g. temp_c / spo2_pct / alert level
bool valid;
} MyMsg_t;
static QueueHandle_t myQ; // >>> ADAPT: your queue name (e.g. rawQ, procQ, telemetryQ)
/* ---- (1) YOUR CORE-LOGIC STUB, AS A FreeRTOS TASK -------------------------
* Produce one message per cadence and send it on your queue. Deterministic
* stub data for now — no real hardware, just prove the shape works. */
static void ProducerTask(void *pv) {
(void)pv;
uint32_t n = 0;
for (;;) {
MyMsg_t m; // >>> ADAPT
n++;
m.timestamp_ms = n * 1000u;
m.value = 36.8f + (float)n * 0.01f; // >>> ADAPT: your stub's logic
m.valid = true;
xQueueSend(myQ, &m, portMAX_DELAY); // produce onto your queue
vTaskDelay(pdMS_TO_TICKS(500)); // your cadence
}
}
/* A tiny consumer so you can SEE your messages. In the real HawkHealth pipeline the NEXT
* subsystem consumes your queue; here we just print, to prove your type flows end to end. */
static void PrinterTask(void *pv) {
(void)pv;
MyMsg_t m;
for (;;) {
if (xQueueReceive(myQ, &m, portMAX_DELAY) == pdTRUE) {
Serial.print("produced: t="); Serial.print(m.timestamp_ms);
Serial.print(" value="); Serial.print(m.value);
Serial.print(" valid="); Serial.println(m.valid ? 1 : 0);
}
}
}
void setup() {
Serial.begin(115200);
myQ = xQueueCreate(8, sizeof(MyMsg_t)); // >>> ADAPT: depth + your type
xTaskCreate(ProducerTask, "PROD", 256, NULL, 2, NULL); // your subsystem stub
xTaskCreate(PrinterTask, "PRINT", 256, NULL, 1, NULL); // stand-in consumer
vTaskStartScheduler(); // required (Wokwi STM32 core)
}
void loop() {}