aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/Core/fsm.c
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-07-01 23:02:21 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-07-01 23:02:21 +0200
commit42ca19997b8a6777702db5ae39c1aa7581a9787f (patch)
tree02f6411a3ec0f0f72116dc3fff30ccc0b5469cdd /src/common/Core/fsm.c
parentcc0301784156543c7c9bec36b6f42df1d2adba28 (diff)
downloadglutte-o-matic-42ca19997b8a6777702db5ae39c1aa7581a9787f.tar.gz
glutte-o-matic-42ca19997b8a6777702db5ae39c1aa7581a9787f.tar.bz2
glutte-o-matic-42ca19997b8a6777702db5ae39c1aa7581a9787f.zip
Add stats beacon
- Add PSK63 and PSK125 functionality - Rename cw_psk31 to cw_psk - Add a new type of long beacon, transmitted at 22:00
Diffstat (limited to 'src/common/Core/fsm.c')
-rw-r--r--src/common/Core/fsm.c174
1 files changed, 129 insertions, 45 deletions
diff --git a/src/common/Core/fsm.c b/src/common/Core/fsm.c
index 9fe2c4c..4daf568 100644
--- a/src/common/Core/fsm.c
+++ b/src/common/Core/fsm.c
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
- * Copyright (c) 2018 Matthias P. Braendli, Maximilien Cuony
+ * Copyright (c) 2019 Matthias P. Braendli, Maximilien Cuony
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -27,6 +27,7 @@
#include <stdint.h>
#include "Core/common.h"
#include "Core/fsm.h"
+#include "Core/stats.h"
#include "GPIO/usart.h"
#include "GPIO/temperature.h"
#include "GPIO/analog.h"
@@ -44,8 +45,18 @@ 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];
+#define BALISE_MESSAGE_LEN 64
+static char balise_message[BALISE_MESSAGE_LEN];
+
+static int balise_message_empty(void)
+{
+ return balise_message[0] == '\0';
+}
+
+static void balise_message_clear(void)
+{
+ balise_message[0] = '\0';
+}
// Each 20 minutes, send a SHORT_BEACON
@@ -84,6 +95,7 @@ void fsm_init() {
current_state = FSM_OISIF;
balise_state = BALISE_FSM_EVEN_HOUR;
sstv_state = SSTV_FSM_OFF;
+ balise_message[0] = '\0';
qso_info.qso_occurred = 0;
qso_info.qso_start_time = timestamp_now();
@@ -113,6 +125,9 @@ static const char* state_name(fsm_state_t state) {
case FSM_TEXTE_HB9G: return "FSM_TEXTE_HB9G";
case FSM_TEXTE_LONG: return "FSM_TEXTE_LONG";
case FSM_BALISE_LONGUE: return "FSM_BALISE_LONGUE";
+ case FSM_BALISE_STATS1: return "FSM_BALISE_STATS1";
+ case FSM_BALISE_STATS2: return "FSM_BALISE_STATS2";
+ case FSM_BALISE_STATS3: return "FSM_BALISE_STATS3";
case FSM_BALISE_SPECIALE: return "FSM_BALISE_SPECIALE";
case FSM_BALISE_COURTE: return "FSM_BALISE_COURTE";
case FSM_BALISE_COURTE_OPEN: return "FSM_BALISE_COURTE_OPEN";
@@ -141,6 +156,9 @@ static fsm_state_t select_grande_balise(void) {
if (fsm_in.qrp || fsm_in.swr_high) {
return FSM_BALISE_SPECIALE;
}
+ else if (fsm_in.send_stats) {
+ return FSM_BALISE_STATS1;
+ }
else {
return FSM_BALISE_LONGUE;
}
@@ -188,7 +206,7 @@ void fsm_update() {
// Some defaults for the outgoing signals
fsm_out.tx_on = 0;
fsm_out.modulation = 0;
- fsm_out.cw_psk31_trigger = 0;
+ fsm_out.cw_psk_trigger = 0;
fsm_out.cw_dit_duration = 50;
fsm_out.msg_frequency = 960;
fsm_out.require_tone_detector = 0;
@@ -262,9 +280,9 @@ void fsm_update() {
// The letter 'G' is a bit different
fsm_out.msg_frequency = 696;
}
- fsm_out.cw_psk31_trigger = 1;
+ fsm_out.cw_psk_trigger = 1;
- if (fsm_in.cw_psk31_done) {
+ if (fsm_in.cw_psk_done) {
next_state = FSM_ECOUTE;
}
break;
@@ -364,9 +382,10 @@ void fsm_update() {
// Short post-delay to underscore the fact that
// transmission was forcefully cut off.
fsm_out.msg = " HI HI ";
- fsm_out.cw_psk31_trigger = 1;
+ fsm_out.cw_psk_trigger = 1;
- if (fsm_in.cw_psk31_done) {
+ if (fsm_in.cw_psk_done) {
+ stats_anti_bavard_triggered();
next_state = FSM_BLOQUE;
}
break;
@@ -384,13 +403,13 @@ void fsm_update() {
fsm_out.msg_frequency = 696;
fsm_out.cw_dit_duration = 70;
fsm_out.msg = " 73" CW_POSTDELAY;
- fsm_out.cw_psk31_trigger = 1;
+ fsm_out.cw_psk_trigger = 1;
if (fsm_in.sq) {
next_state = FSM_QSO;
qso_info.qso_start_time = timestamp_now();
}
- else if (fsm_in.cw_psk31_done) {
+ else if (fsm_in.cw_psk_done) {
next_state = FSM_OISIF;
}
break;
@@ -403,13 +422,13 @@ void fsm_update() {
fsm_out.cw_dit_duration = 70;
// No need for CW_PREDELAY, since we are already transmitting
fsm_out.msg = " HB9G" CW_POSTDELAY;
- fsm_out.cw_psk31_trigger = 1;
+ fsm_out.cw_psk_trigger = 1;
if (fsm_in.sq) {
next_state = FSM_QSO;
qso_info.qso_start_time = timestamp_now();
}
- else if (fsm_in.cw_psk31_done) {
+ else if (fsm_in.cw_psk_done) {
next_state = FSM_OISIF;
}
break;
@@ -429,28 +448,33 @@ void fsm_update() {
else {
fsm_out.msg = " HB9G JN36BK" CW_POSTDELAY;
}
- fsm_out.cw_psk31_trigger = 1;
+ fsm_out.cw_psk_trigger = 1;
if (fsm_in.sq) {
next_state = FSM_QSO;
qso_info.qso_start_time = timestamp_now();
}
- else if (fsm_in.cw_psk31_done) {
+ else if (fsm_in.cw_psk_done) {
next_state = FSM_OISIF;
}
break;
case FSM_BALISE_LONGUE:
+ case FSM_BALISE_STATS1:
fsm_out.tx_on = 1;
fsm_out.msg_frequency = 588;
- fsm_out.cw_dit_duration = 110;
+#warning "dit duration = 110"
+ fsm_out.cw_dit_duration = 30;
{
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) {
+ const char *eol_info = "73";
+ if (current_state == FSM_BALISE_STATS1) {
+ eol_info = "PSK125";
+ }
+ else if (!fsm_in.wind_generator_ok) {
eol_info = "\\";
// The backslash is the SK digraph
}
@@ -466,32 +490,87 @@ void fsm_update() {
supply_trend = '-';
}
- if (temperature_valid()) {
- snprintf(cw_message_balise, CW_MESSAGE_BALISE_LEN-1,
- CW_PREDELAY "HB9G JN36BK 1628M U %dV%01d %c T %d %s" CW_POSTDELAY,
- supply_decivolts / 10,
- supply_decivolts % 10,
- supply_trend,
- (int)(round_float_to_half_steps(temperature_get())),
- eol_info);
+ if (balise_message_empty()) {
+#warning "only for debug"
+ if (current_state == FSM_BALISE_STATS1) {
+ snprintf(balise_message, BALISE_MESSAGE_LEN-1,
+ CW_PREDELAY "HB9G " CW_POSTDELAY);
+ }
+ else
+ if (temperature_valid()) {
+ snprintf(balise_message, BALISE_MESSAGE_LEN-1,
+ CW_PREDELAY "HB9G JN36BK 1628M U %dV%01d %c T %d %s" CW_POSTDELAY,
+ supply_decivolts / 10,
+ supply_decivolts % 10,
+ supply_trend,
+ (int)(round_float_to_half_steps(temperature_get())),
+ eol_info);
+ }
+ else {
+ snprintf(balise_message, BALISE_MESSAGE_LEN-1,
+ CW_PREDELAY "HB9G JN36BK 1628M U %dV%01d %c %s" CW_POSTDELAY,
+ supply_decivolts / 10,
+ supply_decivolts % 10,
+ supply_trend,
+ eol_info);
+ }
+ }
+
+ fsm_out.msg = balise_message;
+
+ last_supply_voltage_decivolts = supply_decivolts;
+
+ fsm_out.cw_psk_trigger = 1;
+ }
+
+ if (fsm_in.cw_psk_done) {
+ balise_message_clear();
+ fsm_out.cw_psk_trigger = 0;
+ if (current_state == FSM_BALISE_STATS1) {
+ next_state = FSM_BALISE_STATS2;
}
else {
- snprintf(cw_message_balise, CW_MESSAGE_BALISE_LEN-1,
- CW_PREDELAY "HB9G JN36BK 1628M U %dV%01d %c %s" CW_POSTDELAY,
- supply_decivolts / 10,
- supply_decivolts % 10,
- supply_trend,
- eol_info);
+ next_state = FSM_OISIF;
}
+ }
+ break;
+
+ case FSM_BALISE_STATS2:
+ fsm_out.tx_on = 1;
+ fsm_out.msg_frequency = 588;
+ fsm_out.cw_dit_duration = -3; // PSK125
- fsm_out.msg = cw_message_balise;
+ fsm_out.msg = stats_build_text();
+ fsm_out.cw_psk_trigger = 1;
- last_supply_voltage_decivolts = supply_decivolts;
+ if (fsm_in.cw_psk_done) {
+ fsm_out.cw_psk_trigger = 0;
+ next_state = FSM_BALISE_STATS3;
+ }
+ break;
- fsm_out.cw_psk31_trigger = 1;
+ case FSM_BALISE_STATS3:
+ fsm_out.tx_on = 1;
+ fsm_out.msg_frequency = 588;
+ fsm_out.cw_dit_duration = 110;
+
+ if (balise_message_empty()) {
+ const char *eol_info = "73";
+ if (!fsm_in.wind_generator_ok) {
+ eol_info = "\\";
+ // The backslash is the SK digraph
+ }
+ snprintf(balise_message, BALISE_MESSAGE_LEN-1,
+ CW_PREDELAY "%s" CW_POSTDELAY,
+ eol_info);
+ fsm_out.msg = balise_message;
+ fsm_out.cw_psk_trigger = 1;
}
- if (fsm_in.cw_psk31_done) {
+ if (fsm_in.cw_psk_done) {
+ stats_beacon_sent();
+ fsm_out.cw_psk_trigger = 1;
+ balise_message_clear();
next_state = FSM_OISIF;
}
break;
@@ -501,28 +580,30 @@ void fsm_update() {
fsm_out.msg_frequency = 696;
fsm_out.cw_dit_duration = 70;
- {
+ if (balise_message_empty()) {
const float supply_voltage = round_float_to_half_steps(analog_measure_12v());
const int supply_decivolts = supply_voltage * 10.0f;
- char *eol_info = "73";
+ const 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,
+ snprintf(balise_message, BALISE_MESSAGE_LEN-1,
CW_PREDELAY "HB9G U %dV%01d %s" CW_POSTDELAY,
supply_decivolts / 10,
supply_decivolts % 10,
eol_info);
- fsm_out.msg = cw_message_balise;
+ fsm_out.msg = balise_message;
- fsm_out.cw_psk31_trigger = 1;
+ fsm_out.cw_psk_trigger = 1;
}
- if (fsm_in.cw_psk31_done) {
+ if (fsm_in.cw_psk_done) {
+ stats_beacon_sent();
+ balise_message_clear();
next_state = FSM_OISIF;
}
break;
@@ -551,14 +632,15 @@ void fsm_update() {
fsm_out.msg = CW_PREDELAY "HB9G JN36BK 1628M" CW_POSTDELAY;
}
}
- fsm_out.cw_psk31_trigger = 1;
+ fsm_out.cw_psk_trigger = 1;
if (current_state == FSM_BALISE_COURTE) {
- if (fsm_in.cw_psk31_done) {
+ if (fsm_in.cw_psk_done) {
if (fsm_in.sq) {
next_state = FSM_OPEN2;
}
else {
+ stats_beacon_sent();
next_state = FSM_OISIF;
}
}
@@ -567,7 +649,8 @@ void fsm_update() {
}
}
else { //FSM_BALISE_COURTE_OPEN
- if (fsm_in.cw_psk31_done) {
+ if (fsm_in.cw_psk_done) {
+ stats_beacon_sent();
next_state = FSM_OPEN2;
}
}
@@ -626,7 +709,8 @@ void fsm_balise_update() {
break;
case BALISE_FSM_PENDING:
if (current_state == FSM_BALISE_SPECIALE ||
- current_state == FSM_BALISE_LONGUE) {
+ current_state == FSM_BALISE_LONGUE ||
+ current_state == FSM_BALISE_STATS3) {
next_state = BALISE_FSM_EVEN_HOUR;
}
break;