aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/fsm/src/common.h31
-rw-r--r--src/fsm/src/fsm.c41
-rw-r--r--src/fsm/src/fsm.h82
3 files changed, 154 insertions, 0 deletions
diff --git a/src/fsm/src/common.h b/src/fsm/src/common.h
new file mode 100644
index 0000000..5381be0
--- /dev/null
+++ b/src/fsm/src/common.h
@@ -0,0 +1,31 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Matthias P. Braendli
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+*/
+
+#include <stdint.h>
+
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+#endif // _COMMON_H_
+
diff --git a/src/fsm/src/fsm.c b/src/fsm/src/fsm.c
new file mode 100644
index 0000000..6de1fe4
--- /dev/null
+++ b/src/fsm/src/fsm.c
@@ -0,0 +1,41 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Matthias P. Braendli
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+*/
+
+#include <string.h>
+#include "common.h"
+#include "fsm.h"
+
+static struct fsm_input_signals_t fsm_in;
+static struct fsm_output_signals_t fsm_out;
+
+// Keep track of when we last entered a given state
+static uint64_t time_state[_NUM_FSM_STATES];
+
+void fsm_init() {
+ memset(&fsm_in, 0, sizeof(fsm_in));
+ memset(&fsm_out, 0, sizeof(fsm_out));
+
+ memset(time_state, 0, _NUM_FSM_STATES * sizeof(*time_state));
+}
+
diff --git a/src/fsm/src/fsm.h b/src/fsm/src/fsm.h
new file mode 100644
index 0000000..869c2c1
--- /dev/null
+++ b/src/fsm/src/fsm.h
@@ -0,0 +1,82 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Matthias P. Braendli
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+*/
+
+#ifndef _FSM_H_
+#define _FSM_H_
+
+// List of all states the FSM of the relay can be in
+enum fsm_state_t {
+ FSM_OISIF = 0, // Idle
+ FSM_OPEN1, // 1750 Hz received and squelch open
+ FSM_OPEN2, // Squelch closed
+ FSM_LETTRE, // Transmit single status letter
+ FSM_ECOUTE, // Repeater open, waiting for QSO
+ FSM_ATTENTE, // No QSO after a short while
+ FSM_QSO, // QSO ongoing
+ FSM_ANTI_BAVARD, // QSO too long, cut transmission
+ FSM_BLOQUE, // Backoff after ANTI_BAVARD
+ FSM_LONG_TEXTE, // Transmit long notice after QSO
+ FSM_TEXTE_HB9G, // Transmit short notice after QSO
+ FSM_BALISE_LONGUE, // Full-length 2-hour beacon
+ FSM_BALISE_SPECIALE, // 2-hour beacon when in QRP or with high power return mode
+ FSM_BALISE_COURTE, // Short intermittent beacon
+ _NUM_FSM_STATES // Dummy state to count the number of states
+};
+
+// All signals that the FSM can read, most of them are actually booleans
+struct fsm_input_signals_t {
+ /* Signals coming from repeater electronics */
+ int sq; // Squelch detection
+ int discrim_u; // FM discriminator says RX is too high in frequency
+ int carrier; // RX carrier detection
+ int qrp; // The relay is currently running with low power
+ int start_tm; // 2-hour pulse
+ float temp; // temperature in degrees C
+ float humidity; // relative humidity, range [0-100] %
+ int wind_generator_ok; // false if the generator is folded out of the wind
+ int discrim_d; // FM discriminator says RX is too low in frequency
+ int tone_1750; // Detect 1750Hz tone
+
+ /* Signals coming from CW generator */
+ int cw_done; // The CW generator has finished transmitting the message
+};
+
+// All signals the FSM has to control
+struct fsm_output_signals_t {
+ /* Signals to the repeater electronics */
+ int qrp; // Place the repeater in QRP mode
+ int tx_on; // Enable TX circuitry
+ int modulation; // Enable repeater RX to TX modulation
+
+ /* Signals to the CW generator */
+ const char* cw_msg; // The message to transmit
+ int cw_frequency; // What audio frequency for the CW message
+ int cw_trigger; // Set to true to trigger a transmission
+};
+
+// Initialise local structures
+void fsm_init();
+
+#endif // _FSM_H_
+