aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/includes/Core/common.h3
-rw-r--r--src/common/src/Core/common.c7
-rw-r--r--src/common/src/Core/fsm.c102
-rw-r--r--src/common/src/Core/main.c3
4 files changed, 86 insertions, 29 deletions
diff --git a/src/common/includes/Core/common.h b/src/common/includes/Core/common.h
index 92cb977..7e06975 100644
--- a/src/common/includes/Core/common.h
+++ b/src/common/includes/Core/common.h
@@ -66,3 +66,6 @@ void __disable_irq(void);
#else
void hard_fault_handler_c(uint32_t *);
#endif
+
+// Round a value to the nearest 0.5
+float round_float_to_half_steps(float value);
diff --git a/src/common/src/Core/common.c b/src/common/src/Core/common.c
index d231569..dc41f98 100644
--- a/src/common/src/Core/common.c
+++ b/src/common/src/Core/common.c
@@ -28,7 +28,7 @@
#include "timers.h"
#include "GPS/gps.h"
#include <time.h>
-
+#include <math.h>
static uint64_t common_timestamp = 0; // milliseconds since startup
static TimerHandle_t common_timer;
@@ -211,3 +211,8 @@ void trigger_fault(int source)
while (1) {}
}
+float round_float_to_half_steps(float value)
+{
+ return 0.5f * roundf(value * 2.0f);
+}
+
diff --git a/src/common/src/Core/fsm.c b/src/common/src/Core/fsm.c
index 03180e0..9f5e185 100644
--- a/src/common/src/Core/fsm.c
+++ b/src/common/src/Core/fsm.c
@@ -23,10 +23,13 @@
*/
#include <string.h>
+#include <stdio.h>
#include <stdint.h>
#include "Core/common.h"
#include "Core/fsm.h"
#include "GPIO/usart.h"
+#include "GPIO/temperature.h"
+#include "GPIO/analog.h"
static struct fsm_input_signals_t fsm_in;
static struct fsm_output_signals_t fsm_out;
@@ -37,6 +40,11 @@ static fsm_state_t current_state;
// in ms using the timestamp_now() function
static uint64_t timestamp_state[_NUM_FSM_STATES];
+static int last_supply_voltage_decivolts = 0;
+
+#define CW_MESSAGE_BALISE_LEN 64
+static char cw_message_balise[CW_MESSAGE_BALISE_LEN];
+
void fsm_init() {
memset(&fsm_in, 0, sizeof(fsm_in));
memset(&fsm_out, 0, sizeof(fsm_out));
@@ -207,7 +215,7 @@ void fsm_update() {
case FSM_ANTI_BAVARD:
fsm_out.tx_on = 1;
// No modulation!
- fsm_out.msg = "HI HI";
+ fsm_out.msg = " HI HI";
fsm_out.cw_psk31_trigger = 1;
if (fsm_in.cw_psk31_done) {
@@ -226,7 +234,7 @@ void fsm_update() {
fsm_out.modulation = 1;
fsm_out.msg_frequency = 696;
fsm_out.cw_dit_duration = 70;
- fsm_out.msg = "73";
+ fsm_out.msg = " 73";
fsm_out.cw_psk31_trigger = 1;
if (fsm_in.sq) {
@@ -242,7 +250,7 @@ void fsm_update() {
fsm_out.modulation = 1;
fsm_out.msg_frequency = 696;
fsm_out.cw_dit_duration = 70;
- fsm_out.msg = "HB9G";
+ fsm_out.msg = " HB9G";
fsm_out.cw_psk31_trigger = 1;
if (fsm_in.sq) {
@@ -261,10 +269,10 @@ void fsm_update() {
fsm_out.cw_dit_duration = 70;
if (random_bool()) {
- fsm_out.msg = "HB9G 1628M";
+ fsm_out.msg = " HB9G 1628M";
}
else {
- fsm_out.msg = "HB9G JN36BK";
+ fsm_out.msg = " HB9G JN36BK";
}
fsm_out.cw_psk31_trigger = 1;
@@ -282,19 +290,51 @@ void fsm_update() {
fsm_out.cw_dit_duration = 110;
fsm_out.ack_start_tm = 1;
- // TODO transmit humidity
- // TODO read voltage
- if (fsm_in.wind_generator_ok) {
- fsm_out.msg = "HB9G JN36BK 1628M U 10V5 = T 11 73";
+ {
+ const float supply_voltage = round_float_to_half_steps(analog_measure_12v());
+ const int supply_decivolts = supply_voltage * 10.0f;
+
+ char *eol_info = "73";
+ if (!fsm_in.wind_generator_ok) {
+ eol_info = "\\";
+ // The backslash is the SK digraph
+ }
+
+ char supply_trend = '=';
// = means same voltage as previous
// + means higher
// - means lower
+ if (last_supply_voltage_decivolts < supply_decivolts) {
+ supply_trend = '+';
+ }
+ else if (last_supply_voltage_decivolts > supply_decivolts) {
+ supply_trend = '-';
+ }
+
+ if (temperature_valid()) {
+ snprintf(cw_message_balise, CW_MESSAGE_BALISE_LEN-1,
+ " HB9G JN36BK 1628M U %dV%01d %c T %d %s",
+ supply_decivolts / 10,
+ supply_decivolts % 10,
+ supply_trend,
+ (int)(round_float_to_half_steps(temperature_get())),
+ eol_info);
+ }
+ else {
+ snprintf(cw_message_balise, CW_MESSAGE_BALISE_LEN-1,
+ " HB9G JN36BK 1628M U %dV%01d %c %s",
+ supply_decivolts / 10,
+ supply_decivolts % 10,
+ supply_trend,
+ eol_info);
+ }
+
+ fsm_out.msg = cw_message_balise;
+
+ last_supply_voltage_decivolts = supply_decivolts;
+
+ fsm_out.cw_psk31_trigger = 1;
}
- else {
- fsm_out.msg = "HB9G JN36BK 1628M U 10V5 = T 11 #";
- // The # is the SK digraph
- }
- fsm_out.cw_psk31_trigger = 1;
if (fsm_in.cw_psk31_done) {
next_state = FSM_OISIF;
@@ -307,14 +347,26 @@ void fsm_update() {
fsm_out.cw_dit_duration = 70;
fsm_out.ack_start_tm = 1;
- // TODO read voltage
- if (fsm_in.wind_generator_ok) {
- fsm_out.msg = "HB9G U 10V5 73";
- }
- else {
- fsm_out.msg = "HB9G U 10V5 #"; // The # is the SK digraph
+ {
+ const float supply_voltage = round_float_to_half_steps(analog_measure_12v());
+ const int supply_decivolts = supply_voltage * 10.0f;
+
+ char *eol_info = "73";
+ if (!fsm_in.wind_generator_ok) {
+ eol_info = "\\";
+ // The backslash is the SK digraph
+ }
+
+ snprintf(cw_message_balise, CW_MESSAGE_BALISE_LEN-1,
+ " HB9G U %dV%01d %s",
+ supply_decivolts / 10,
+ supply_decivolts % 10,
+ eol_info);
+
+ fsm_out.msg = cw_message_balise;
+
+ fsm_out.cw_psk31_trigger = 1;
}
- fsm_out.cw_psk31_trigger = 1;
if (fsm_in.cw_psk31_done) {
next_state = FSM_OISIF;
@@ -331,16 +383,16 @@ void fsm_update() {
int rand = random_bool() * 2 + random_bool();
if (rand == 0) {
- fsm_out.msg = "HB9G";
+ fsm_out.msg = " HB9G";
}
else if (rand == 1) {
- fsm_out.msg = "HB9G JN36BK";
+ fsm_out.msg = " HB9G JN36BK";
}
else if (rand == 2) {
- fsm_out.msg = "HB9G 1628M";
+ fsm_out.msg = " HB9G 1628M";
}
else {
- fsm_out.msg = "HB9G JN36BK 1628M";
+ fsm_out.msg = " HB9G JN36BK 1628M";
}
}
fsm_out.cw_psk31_trigger = 1;
diff --git a/src/common/src/Core/main.c b/src/common/src/Core/main.c
index 22aca74..9c27b2a 100644
--- a/src/common/src/Core/main.c
+++ b/src/common/src/Core/main.c
@@ -209,9 +209,6 @@ static void launcher_task(void __attribute__ ((unused))*pvParameters)
pio_set_qrp(qrp);
}
-
- const float supply_voltage = analog_measure_12v();
- usart_debug("12V monitor %dmV\r\n", (int32_t)(supply_voltage * 1000.0f));
}
}