aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2020-06-01 13:32:38 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2020-06-01 13:32:38 +0200
commit6bc1091c102cbb1c6839d46dda50bd2aa1a3433b (patch)
tree933cb2849faf4e868e2cc77fd0490c0fedca7174
parent6f4df1f901ff9d56b9a8523c78f5099ebd458fd5 (diff)
downloadrenard_hb9hi-6bc1091c102cbb1c6839d46dda50bd2aa1a3433b.tar.gz
renard_hb9hi-6bc1091c102cbb1c6839d46dda50bd2aa1a3433b.tar.bz2
renard_hb9hi-6bc1091c102cbb1c6839d46dda50bd2aa1a3433b.zip
Implement timeslot mechanism for renard sync
-rw-r--r--src/testapp1/README.md23
-rw-r--r--src/testapp1/main.c77
-rw-r--r--src/testapp1/morse.c13
-rw-r--r--src/testapp1/morse.h6
4 files changed, 106 insertions, 13 deletions
diff --git a/src/testapp1/README.md b/src/testapp1/README.md
index 7099b6a..92c8206 100644
--- a/src/testapp1/README.md
+++ b/src/testapp1/README.md
@@ -1,5 +1,26 @@
testapp1
========
-This only sends MOS in morse code on PB0
+On startup, transmit callsign, then start transmitting CW codes:
+
++--------+-----------+
+| sign | timeslot |
++--------+-----------+
+| E | 1 |
+| I | 2 |
+| S | 3 |
+| H | 4 |
+| err | permanent |
++--------+-----------+
+
+CW is output on PB0, noninverted logic.
+
+When SYNCn input on PB2 goes to zero, transmission stops, and the internal time is set to 0.
+
+Modes
+-----
+
+When internal time < 10 minutes, transmit only sign without "MO", in short timeslots, then stay silent 30s.
+
+If internal time >= 10 minutes, transmit "MO<sign>" for a full minute timeslot.
diff --git a/src/testapp1/main.c b/src/testapp1/main.c
index b305372..117551a 100644
--- a/src/testapp1/main.c
+++ b/src/testapp1/main.c
@@ -6,18 +6,45 @@
#include "delay.h"
#include "morse.h"
-
+/* Definitions for pins */
#define PORTB_PTT (1 << 0)
+#define PORTB_SYNCn (1 << 2)
#define PORTB_LED (1 << 4)
-volatile uint8_t Timer; /* Timer (100Hz increment) */
+/* Specify ID here */
+static const uint8_t renard_id = 0;
+
+static const uint8_t num_renards_cycle = 4;
+// colon (:) represents ERROR
+static const char letters[] = "eish:";
+static const char unique_letter = letters[renard_id];
+
+volatile uint8_t reset_time;
+volatile uint8_t systick; /* Timer (100Hz increment) */
+volatile uint8_t seconds;
+volatile uint16_t minutes;
/*---------------------------------------------------------*/
/* 100Hz timer interrupt generated by OC2 */
/*---------------------------------------------------------*/
ISR(TIMER1_COMPA_vect)
{
- Timer++;
+ systick++;
+ if (systick == 10) {
+ systick = 0;
+ seconds += 1;
+ }
+
+ if (seconds == 60) {
+ seconds = 0;
+ minutes++;
+ }
+
+ if (reset_time) {
+ reset_time = 0;
+ seconds = 0;
+ minutes = 0;
+ }
}
static int inittimer(void)
@@ -76,6 +103,11 @@ void dit(void)
int main(void)
{
+ systick = 0;
+ seconds = 0;
+ minutes = 0;
+ reset_time = 0;
+
/* Enable PTT output on PB0 */
#if PTT_LOGIC_LOW
PORTB = PORTB_PTT;
@@ -86,14 +118,45 @@ int main(void)
/* initialise timer interrupt */
inittimer();
+ static char *morse_string = "MO ";
+ morse_string[2] = unique_letter;
+
+ const int permanent = (unique_letter == ':');
+
delay_ms(12*DIT_DURATION);
- morse("HB9EGM");
+ morse("HB9HI");
delay_ms(12*DIT_DURATION);
while (1) {
- // morse code !
- morse("MOH");
- delay_ms(6*DIT_DURATION);
+ if ((PINB & PORTB_SYNCn) == 0) {
+ reset_time = 1;
+ }
+
+ if (permanent) {
+ morse(morse_string);
+ delay_ms(6*DIT_DURATION);
+ }
+ else if (minutes >= 10) { // see README.md
+ /* renard id 0: start at (k * num_renards_cycle) * 60, end at (k * num_renards_cycle) * 60 + 55 */
+ const int in_timeslot = (minutes % num_renards_cycle) == renard_id;
+
+ if (in_timeslot && seconds < 55) {
+ morse(morse_string);
+ delay_ms(6*DIT_DURATION);
+ }
+ else {
+ delay_ms(DIT_DURATION);
+ }
+ }
+ else {
+ /* renard id 0: start every 30s, with an additional 2s offset depending on renard_id */
+ const uint32_t second_offset = seconds % 30;
+
+ if (second_offset == 2 * renard_id) {
+ morse_char(unique_letter);
+ delay_ms(1000); // avoid retrigger in same second
+ }
+ }
}
return 0;
diff --git a/src/testapp1/morse.c b/src/testapp1/morse.c
index cb06b4a..65b27cd 100644
--- a/src/testapp1/morse.c
+++ b/src/testapp1/morse.c
@@ -6,7 +6,7 @@
#include "delay.h"
#include "morse.h"
-const uint8_t morse_mapping[60] PROGMEM =
+const uint16_t morse_mapping[60] PROGMEM =
{
// Read bits from right to left
@@ -28,10 +28,12 @@ const uint8_t morse_mapping[60] PROGMEM =
0b111000,
0b110000, // 9, ASCII 57
+ // the colon stands in as error
+ 0b111111111, // :
+
// The following are mostly invalid, but
// required to fill the gap in ASCII between
// numerals and capital letters
- 0b10, // :
0b10, // ;
0b10, // <
0b10, // =
@@ -90,9 +92,6 @@ void morse_symbol(uint8_t sym)
delay_ms(4*DIT_DURATION);
}
-// Transmit a string in morse code. Supported range:
-// All ASCII between '+' and '\', which includes
-// numerals and capital letters.
void morse(char* text)
{
char* sym = text;
@@ -102,3 +101,7 @@ void morse(char* text)
} while (*sym != '\0');
}
+void morse_char(char letter)
+{
+ morse_symbol(letter - '+');
+}
diff --git a/src/testapp1/morse.h b/src/testapp1/morse.h
index 68cebb1..b2c78db 100644
--- a/src/testapp1/morse.h
+++ b/src/testapp1/morse.h
@@ -3,7 +3,13 @@
#define DIT_DURATION 100 // ms
+// Transmit a string or a single char in morse code.
+//
+// Supported range:
+// All ASCII between '+' and '\', which includes
+// numerals and capital letters.
void morse(char* text);
+void morse_char(char letter);
void dah(void);
void dit(void);