From 93fd840343f0f4191b9a82f72e39117c68db6713 Mon Sep 17 00:00:00 2001 From: jimzah Date: Wed, 30 Oct 2024 16:33:03 +0000 Subject: [PATCH 1/7] Temp perams --- GB3TX/config.h | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/GB3TX/config.h b/GB3TX/config.h index 52650ec..947a43f 100644 --- a/GB3TX/config.h +++ b/GB3TX/config.h @@ -10,32 +10,33 @@ #define PIP 3 /* CW ID SETTINGS */ -#define ID "MX0WVV" -#define CW_SPEED 25 -#define CW_PITCH 950 +#define ID "GB3DL" +#define CW_SPEED 20 +#define CW_PITCH 1375 /* PARAMS */ -#define COURTESY CW -#define CLOSEDOWN 1 +#define COURTESY TONE +#define CLOSEDOWN 0 #define GWPIPLEN 1200 / CW_SPEED -#define PIP_LETTER 'W' -#define PIP_GW_LETTER 'X' -#define RFPIP 950 +#define PIP_LETTER 'E' +#define PIP_GW_LETTER 'T' +#define RFPIP 1245 #define RFPIPLEN 1200 / CW_SPEED #define START 0 -#define TAILPIPS true -#define TAILPIP_PITCH 950 +#define TAILPIPS false +#define TAILPIP_PITCH CW_PITCH /* SERIAL */ -#define SERIAL true +#define SERIAL false #define SERIAL_SPEED 115200 /* TIMERS */ -#define HANGTIME 5000 -#define KEYCHUNK_TIME 2500 +#define HANGTIME 2000 +#define KEYCHUNK_TIME 500 #define TIMEOUT 300000 #define IDTIME 300000 -#define PIP_KEYCHUNK 2000 -#define TAIL_PIP_DELAY 1000 +#define LAST_ID_HOLD 30000 +#define PIP_KEYCHUNK 750 +#define TAIL_PIP_DELAY 3000 #endif \ No newline at end of file -- 2.47.1 From ff89787d392c08d7163eaa42d4e4325b9e891cee Mon Sep 17 00:00:00 2001 From: jimzah Date: Wed, 30 Oct 2024 16:33:19 +0000 Subject: [PATCH 2/7] Last ID timer --- GB3TX/GB3TX.ino | 4 ++-- GB3TX/cw.ino | 5 +++-- GB3TX/repeater.h | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/GB3TX/GB3TX.ino b/GB3TX/GB3TX.ino index ccff043..163a9c2 100644 --- a/GB3TX/GB3TX.ino +++ b/GB3TX/GB3TX.ino @@ -67,7 +67,7 @@ void loop() { myrpt->timer.gw_start = millis(); } tot = millis(); - if (myrpt->params.start_up) + if (myrpt->params.start_up && millis() - myrpt->last_id >= LAST_ID_HOLD) sendID(myrpt); } @@ -117,7 +117,7 @@ void loop() { } if (myrpt->state == HANG && millis() - ht > HANGTIME) { - if (myrpt->params.close_down) { + if (myrpt->params.close_down && millis() - myrpt->last_id >= LAST_ID_HOLD) { serial_writer(&myrpt->serial, "REPEATER: CLOSEDOWN ID"); myrpt->state = SLEEP; sendID(myrpt); diff --git a/GB3TX/cw.ino b/GB3TX/cw.ino index 4be4ea3..214448d 100644 --- a/GB3TX/cw.ino +++ b/GB3TX/cw.ino @@ -45,14 +45,15 @@ void sendChar(repeater* myrpt, char c) { void sendID(repeater* myrpt) { myrpt->id_time = millis(); + myrpt->last_id = myrpt->id_time; if (myrpt->callsign == NULL) { return; } delay(500); - if (myrpt->state == SLEEP) - digitalWrite(PIP_ATT, HIGH); + //if (myrpt->state == SLEEP) + // digitalWrite(PIP_ATT, HIGH); for (int i=0; i < sizeof ID/sizeof ID[0]; i++) { sendChar(myrpt, myrpt->callsign[i]); diff --git a/GB3TX/repeater.h b/GB3TX/repeater.h index 7c1a8d6..5aca264 100644 --- a/GB3TX/repeater.h +++ b/GB3TX/repeater.h @@ -70,6 +70,7 @@ typedef struct { char* callsign; gateway gateway; unsigned long id_time; + unsigned long last_id; state last; params params; receiver receiver; -- 2.47.1 From 0ca501dce6d3a042bbc270aafd16674a804e50b3 Mon Sep 17 00:00:00 2001 From: jimzah Date: Wed, 30 Oct 2024 20:25:37 +0000 Subject: [PATCH 3/7] Tidy --- GB3TX/GB3TX.ino | 5 ----- GB3TX/cw.ino | 3 --- GB3TX/repeater.h | 24 ------------------------ GB3TX/repeater.ino | 14 -------------- 4 files changed, 46 deletions(-) diff --git a/GB3TX/GB3TX.ino b/GB3TX/GB3TX.ino index 163a9c2..05565d4 100644 --- a/GB3TX/GB3TX.ino +++ b/GB3TX/GB3TX.ino @@ -44,9 +44,6 @@ void loop() { myrpt->id_time = 0; serial_writer(&myrpt->serial, "READY"); digitalWrite(PIP_ATT, LOW); - myrpt->stats.gw_time = 0; - myrpt->stats.tx_time = 0; - myrpt->stats.rx_time = 0; while (1) { serial_command(&myrpt->serial, myrpt); rx(myrpt); @@ -64,7 +61,6 @@ void loop() { } else { myrpt->state = GW; serial_writer(&myrpt->serial, "RX: GATEWAY"); - myrpt->timer.gw_start = millis(); } tot = millis(); if (myrpt->params.start_up && millis() - myrpt->last_id >= LAST_ID_HOLD) @@ -79,7 +75,6 @@ void loop() { if ((myrpt->receiver.rx && myrpt->gateway.receiver.rx) && myrpt->state > HANG) { serial_writer(&myrpt->serial, "HANG"); if (myrpt->state == GW) - myrpt->stats.gw_time += millis() - myrpt->timer.gw_start; delay(500); myrpt->last = myrpt->state; myrpt->state = HANG; diff --git a/GB3TX/cw.ino b/GB3TX/cw.ino index 214448d..6cb9e69 100644 --- a/GB3TX/cw.ino +++ b/GB3TX/cw.ino @@ -52,9 +52,6 @@ void sendID(repeater* myrpt) { delay(500); - //if (myrpt->state == SLEEP) - // digitalWrite(PIP_ATT, HIGH); - for (int i=0; i < sizeof ID/sizeof ID[0]; i++) { sendChar(myrpt, myrpt->callsign[i]); delay(myrpt->params.cw_speed * 3); diff --git a/GB3TX/repeater.h b/GB3TX/repeater.h index 5aca264..e1e3a39 100644 --- a/GB3TX/repeater.h +++ b/GB3TX/repeater.h @@ -32,27 +32,13 @@ typedef struct { int start_up; }params; -typedef struct { - unsigned long tx_start; - unsigned long rx_start; - unsigned long gw_start; -}timer; - -typedef struct { - unsigned long tx_time; - unsigned long rx_time; - unsigned long gw_time; -}stats; - typedef struct { bool tx; - unsigned long long tx_time; }transmitter; typedef struct { int id; bool rx; - unsigned long long rx_time; }receiver; typedef struct { @@ -75,19 +61,9 @@ typedef struct { params params; receiver receiver; serial serial; - stats stats; state state; - timer timer; transmitter transmitter; unsigned long tail; }repeater; -typedef struct { - byte type; - stats* stats; - bool transmitter; - bool receiver; - bool gateway; -}info; - #endif \ No newline at end of file diff --git a/GB3TX/repeater.ino b/GB3TX/repeater.ino index d859866..2f1e5f1 100644 --- a/GB3TX/repeater.ino +++ b/GB3TX/repeater.ino @@ -4,14 +4,12 @@ void tx(repeater* myrpt) { myrpt->transmitter.tx = true; digitalWrite(PTT,LOW); delay(100); - myrpt->timer.tx_start = millis(); return; } if (myrpt->state < KEYCHUNK && myrpt->transmitter.tx) { serial_writer(&myrpt->serial, "REPEATER: TX OFF"); myrpt->transmitter.tx = false; - myrpt->stats.tx_time += millis() - myrpt->timer.tx_start; digitalWrite(PTT,HIGH); } } @@ -24,14 +22,12 @@ void rx(repeater* myrpt) { serial_writer(&myrpt->serial, "REPEATER: COS"); digitalWrite(GWPTT, true); myrpt->gateway.transmitter.tx = true; - myrpt->timer.rx_start = millis(); return; } if (myrpt->receiver.rx && myrpt->gateway.transmitter.tx) { digitalWrite(GWPTT, false); myrpt->gateway.transmitter.tx = false; - myrpt->stats.rx_time += millis() - myrpt->timer.rx_start; } } @@ -87,21 +83,11 @@ void serial_command(serial* s, repeater* myrpt) { } break; case '3': - Serial.print("RX: "); Serial.println((myrpt->stats.rx_time /1000)); - Serial.print("TX: "); Serial.println((myrpt->stats.tx_time /1000)); - Serial.print("GW: "); Serial.println((myrpt->stats.gw_time /1000)); Serial.print("RX Status: "); Serial.println(!myrpt->receiver.rx); Serial.print("TX Status: "); Serial.println(myrpt->transmitter.tx); Serial.print("GW Status: "); Serial.println(!myrpt->gateway.receiver.rx); break; case '4': - info inf; - inf.type = 254; - inf.stats = &myrpt->stats; - inf.receiver = !myrpt->receiver.rx; - inf.transmitter = myrpt->transmitter.tx; - inf.gateway = !myrpt->gateway.receiver.rx; - Serial.write((byte*)&inf, sizeof(info) + sizeof(stats) - 4); default: break; } -- 2.47.1 From 71248ea83ed0d38b9ba1b0dc672c6914e5ecae6a Mon Sep 17 00:00:00 2001 From: jimzah Date: Wed, 30 Oct 2024 20:52:59 +0000 Subject: [PATCH 4/7] Better time stamp --- GB3TX/GB3TX.ino | 5 ++--- GB3TX/cw.ino | 2 -- GB3TX/repeater.h | 7 ++++++- GB3TX/repeater.ino | 10 +++++++++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/GB3TX/GB3TX.ino b/GB3TX/GB3TX.ino index 05565d4..06f60a5 100644 --- a/GB3TX/GB3TX.ino +++ b/GB3TX/GB3TX.ino @@ -54,7 +54,7 @@ void loop() { kc = millis(); } - if (myrpt->state == KEYCHUNK && millis() - kc > KEYCHUNK_TIME) { + if (myrpt->state == KEYCHUNK && compareStamp(&myrpt->receiver.timestamp, KEYCHUNK_TIME)) { if (!myrpt->receiver.rx) { myrpt->state = TT; serial_writer(&myrpt->serial, "RX: RF"); @@ -74,13 +74,12 @@ void loop() { if ((myrpt->receiver.rx && myrpt->gateway.receiver.rx) && myrpt->state > HANG) { serial_writer(&myrpt->serial, "HANG"); - if (myrpt->state == GW) delay(500); myrpt->last = myrpt->state; myrpt->state = HANG; ht = millis(); myrpt->tail = ht; - if (ht - tot < PIP_KEYCHUNK || busy(myrpt)) + if (!compareStamp(&myrpt->receiver.timestamp, PIP_KEYCHUNK) || busy(myrpt)) continue; courtesyTone(myrpt); } diff --git a/GB3TX/cw.ino b/GB3TX/cw.ino index 6cb9e69..f525305 100644 --- a/GB3TX/cw.ino +++ b/GB3TX/cw.ino @@ -50,8 +50,6 @@ void sendID(repeater* myrpt) { return; } - delay(500); - for (int i=0; i < sizeof ID/sizeof ID[0]; i++) { sendChar(myrpt, myrpt->callsign[i]); delay(myrpt->params.cw_speed * 3); diff --git a/GB3TX/repeater.h b/GB3TX/repeater.h index e1e3a39..557c1c4 100644 --- a/GB3TX/repeater.h +++ b/GB3TX/repeater.h @@ -32,6 +32,11 @@ typedef struct { int start_up; }params; +typedef struct { + unsigned long start; + unsigned long end; +}t_stamp; + typedef struct { bool tx; }transmitter; @@ -39,6 +44,7 @@ typedef struct { typedef struct { int id; bool rx; + t_stamp timestamp; }receiver; typedef struct { @@ -47,7 +53,6 @@ typedef struct { }serial; typedef struct { - bool enable; receiver receiver; transmitter transmitter; }gateway; diff --git a/GB3TX/repeater.ino b/GB3TX/repeater.ino index 2f1e5f1..224d747 100644 --- a/GB3TX/repeater.ino +++ b/GB3TX/repeater.ino @@ -20,14 +20,18 @@ void rx(repeater* myrpt) { if (!myrpt->receiver.rx && !myrpt->gateway.transmitter.tx) { serial_writer(&myrpt->serial, "REPEATER: COS"); + myrpt->receiver.timestamp.start = millis(); digitalWrite(GWPTT, true); myrpt->gateway.transmitter.tx = true; return; } - if (myrpt->receiver.rx && myrpt->gateway.transmitter.tx) { + if (myrpt->receiver.rx) { + myrpt->receiver.timestamp.end = millis(); + if (myrpt->gateway.transmitter.tx) { digitalWrite(GWPTT, false); myrpt->gateway.transmitter.tx = false; + } } } @@ -36,6 +40,10 @@ bool busy(repeater* myrpt) { return (!myrpt->receiver.rx || !myrpt->gateway.receiver.rx); } +bool compareStamp(t_stamp* ts, unsigned long cmp) { + return ts->end - ts->start > cmp; +} + void courtesyTone(repeater* myrpt) { switch(myrpt->params.courtesy) { case TONE: -- 2.47.1 From bfdaae8c1cf11a1ea4ff491172e506303cd623ff Mon Sep 17 00:00:00 2001 From: jimzah Date: Wed, 30 Oct 2024 21:45:42 +0000 Subject: [PATCH 5/7] Start timestamp compare, better timeout countdown --- GB3TX/GB3TX.ino | 34 +++++++++++++++++++++++----------- GB3TX/config.h | 19 ++++++++++++++----- GB3TX/repeater.h | 3 ++- GB3TX/repeater.ino | 8 ++++++-- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/GB3TX/GB3TX.ino b/GB3TX/GB3TX.ino index 06f60a5..e65cea3 100644 --- a/GB3TX/GB3TX.ino +++ b/GB3TX/GB3TX.ino @@ -2,12 +2,9 @@ #include "repeater.h" void setup() { - pinMode(3, OUTPUT); - pinMode(8, OUTPUT); - pinMode(9, OUTPUT); - pinMode(7, INPUT_PULLUP); - pinMode(6, INPUT_PULLUP); - pinMode(PIP_ATT, OUTPUT); + for (int i=0; istate == KEYCHUNK && compareStamp(&myrpt->receiver.timestamp, KEYCHUNK_TIME)) { + if (myrpt->state == KEYCHUNK && compareStart(&myrpt->receiver.timestamp, KEYCHUNK_TIME)) { if (!myrpt->receiver.rx) { myrpt->state = TT; serial_writer(&myrpt->serial, "RX: RF"); @@ -103,11 +100,9 @@ void loop() { tot = millis(); } - if (millis() - tot >= TIMEOUT && (myrpt->state == TT || myrpt->state == GW)) { + if (compareStart(&myrpt->receiver.timestamp, TOTIME) && myrpt->state == TT ) { serial_writer(&myrpt->serial, "REPEATER: TIMEOUT"); - myrpt->state = TIMEOUT; - tone(PIP, 440, 1000); - delay(1000); + myrpt->state = PEN_T; } if (myrpt->state == HANG && millis() - ht > HANGTIME) { @@ -121,6 +116,23 @@ void loop() { myrpt->state = IDLE; } + if (myrpt->state == PEN_T) { + if (!busy(myrpt)) + myrpt->state = HANG; + static unsigned long pc; + static int c = 0; + unsigned long tick = millis(); + if (tick - pc < 1000) + continue; + + pc = tick; + tone(PIP, 1750, 50); + c++; + if (c >= 10) { + myrpt->state = TIMEOUT; + } + } + if (myrpt->state == TIMEOUT) { myrpt->state = IDLE; tx(myrpt); diff --git a/GB3TX/config.h b/GB3TX/config.h index 947a43f..34101b7 100644 --- a/GB3TX/config.h +++ b/GB3TX/config.h @@ -9,9 +9,18 @@ #define GWPTT 9 #define PIP 3 +uint8_t io[6][2] = { + {PIP_ATT, OUTPUT}, + {GW_COS, INPUT_PULLUP}, + {COS, INPUT_PULLUP}, + {PTT, OUTPUT}, + {GWPTT, OUTPUT}, + {PIP, OUTPUT} +}; + /* CW ID SETTINGS */ #define ID "GB3DL" -#define CW_SPEED 20 +#define CW_SPEED 22 #define CW_PITCH 1375 /* PARAMS */ @@ -32,11 +41,11 @@ /* TIMERS */ #define HANGTIME 2000 -#define KEYCHUNK_TIME 500 -#define TIMEOUT 300000 +#define KEYCHUNK_TIME 750 +#define TOTIME 300000 #define IDTIME 300000 -#define LAST_ID_HOLD 30000 -#define PIP_KEYCHUNK 750 +#define LAST_ID_HOLD 60000 +#define PIP_KEYCHUNK 1000 #define TAIL_PIP_DELAY 3000 #endif \ No newline at end of file diff --git a/GB3TX/repeater.h b/GB3TX/repeater.h index 557c1c4..02b8954 100644 --- a/GB3TX/repeater.h +++ b/GB3TX/repeater.h @@ -8,7 +8,8 @@ typedef enum { HANG, GW, TT, - TOT, + PEN_T, + TIMEOUT, }state; typedef enum { diff --git a/GB3TX/repeater.ino b/GB3TX/repeater.ino index 224d747..41f9e22 100644 --- a/GB3TX/repeater.ino +++ b/GB3TX/repeater.ino @@ -29,8 +29,8 @@ void rx(repeater* myrpt) { if (myrpt->receiver.rx) { myrpt->receiver.timestamp.end = millis(); if (myrpt->gateway.transmitter.tx) { - digitalWrite(GWPTT, false); - myrpt->gateway.transmitter.tx = false; + digitalWrite(GWPTT, false); + myrpt->gateway.transmitter.tx = false; } } } @@ -44,6 +44,10 @@ bool compareStamp(t_stamp* ts, unsigned long cmp) { return ts->end - ts->start > cmp; } +bool compareStart(t_stamp* ts, unsigned long cmp) { + return millis() - ts->start > cmp; +} + void courtesyTone(repeater* myrpt) { switch(myrpt->params.courtesy) { case TONE: -- 2.47.1 From c8d544cbebd198b2bcf04a9d194704b61d94aa24 Mon Sep 17 00:00:00 2001 From: JimZAH Date: Sun, 1 Dec 2024 20:53:57 +0000 Subject: [PATCH 6/7] running --- GB3TX/GB3TX.ino | 2 +- GB3TX/config.h | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/GB3TX/GB3TX.ino b/GB3TX/GB3TX.ino index e65cea3..adf4cc9 100644 --- a/GB3TX/GB3TX.ino +++ b/GB3TX/GB3TX.ino @@ -84,7 +84,7 @@ void loop() { if (myrpt->state == HANG && TAILPIPS) { if (millis() - myrpt->tail >= TAIL_PIP_DELAY && !busy(myrpt)) { myrpt->tail = millis(); - tone(PIP, TAILPIP_PITCH, myrpt->params.pip_length); + tone(PIP, TAILPIP_PITCH, TAIL_LEN); } } diff --git a/GB3TX/config.h b/GB3TX/config.h index 34101b7..1a60562 100644 --- a/GB3TX/config.h +++ b/GB3TX/config.h @@ -19,20 +19,20 @@ uint8_t io[6][2] = { }; /* CW ID SETTINGS */ -#define ID "GB3DL" -#define CW_SPEED 22 -#define CW_PITCH 1375 +#define ID "GB3DL H" +#define CW_SPEED 20 +#define CW_PITCH 1000 /* PARAMS */ #define COURTESY TONE #define CLOSEDOWN 0 -#define GWPIPLEN 1200 / CW_SPEED +#define GWPIPLEN 150 #define PIP_LETTER 'E' #define PIP_GW_LETTER 'T' -#define RFPIP 1245 -#define RFPIPLEN 1200 / CW_SPEED +#define RFPIP CW_PITCH +#define RFPIPLEN 300 #define START 0 -#define TAILPIPS false +#define TAILPIPS true #define TAILPIP_PITCH CW_PITCH /* SERIAL */ @@ -40,12 +40,13 @@ uint8_t io[6][2] = { #define SERIAL_SPEED 115200 /* TIMERS */ -#define HANGTIME 2000 -#define KEYCHUNK_TIME 750 +#define HANGTIME 7000 +#define KEYCHUNK_TIME 1500 #define TOTIME 300000 -#define IDTIME 300000 +#define IDTIME 500000 #define LAST_ID_HOLD 60000 #define PIP_KEYCHUNK 1000 -#define TAIL_PIP_DELAY 3000 +#define TAIL_PIP_DELAY 2500 +#define TAIL_LEN 300 #endif \ No newline at end of file -- 2.47.1 From e07ccbe2ebad334567868de2873c9e37b3be53aa Mon Sep 17 00:00:00 2001 From: jim Date: Wed, 11 Dec 2024 21:42:42 +0000 Subject: [PATCH 7/7] general fixes --- GB3TX/GB3TX.ino | 40 +++++-------------- GB3TX/config.h | 18 ++++----- GB3TX/cw.ino | 6 +-- GB3TX/repeater.h | 7 +--- GB3TX/repeater.ino | 98 +++++++++++++++++----------------------------- 5 files changed, 58 insertions(+), 111 deletions(-) diff --git a/GB3TX/GB3TX.ino b/GB3TX/GB3TX.ino index adf4cc9..4887cef 100644 --- a/GB3TX/GB3TX.ino +++ b/GB3TX/GB3TX.ino @@ -13,10 +13,6 @@ void loop() { myrpt = &rpt; myrpt->callsign = ID; myrpt->params.cw_pitch = CW_PITCH; - myrpt->serial.enable = SERIAL; - myrpt->serial.speed = 115200; - if (myrpt->serial.enable) - Serial.begin(myrpt->serial.speed); /* Setup params */ myrpt->params.cw_speed = 1200 / CW_SPEED; @@ -30,55 +26,46 @@ void loop() { myrpt->params.pip_gw_letter = PIP_GW_LETTER; myrpt->params.start_up = START; + myrpt->receiver.id = 0; + myrpt->gateway.receiver.id = 1; + delay(1000); myrpt->transmitter.tx = true; - sendID(myrpt); + send_id(myrpt); myrpt->state = SLEEP; unsigned long ht = millis(); unsigned long tot = ht; - unsigned long kc; myrpt->id_time = 0; - serial_writer(&myrpt->serial, "READY"); digitalWrite(PIP_ATT, LOW); while (1) { - serial_command(&myrpt->serial, myrpt); rx(myrpt); if (busy(myrpt) && myrpt->state < KEYCHUNK) { myrpt->state = KEYCHUNK; - serial_writer(&myrpt->serial, "KEYCHUNK"); - kc = millis(); } - if (myrpt->state == KEYCHUNK && compareStart(&myrpt->receiver.timestamp, KEYCHUNK_TIME)) { + if (myrpt->state == KEYCHUNK && cmp_keychunk(myrpt, KEYCHUNK_TIME)) { if (!myrpt->receiver.rx) { myrpt->state = TT; - serial_writer(&myrpt->serial, "RX: RF"); } else { myrpt->state = GW; - serial_writer(&myrpt->serial, "RX: GATEWAY"); } tot = millis(); if (myrpt->params.start_up && millis() - myrpt->last_id >= LAST_ID_HOLD) - sendID(myrpt); + send_id(myrpt); } if ((myrpt->receiver.rx && myrpt->gateway.receiver.rx) && myrpt->state == KEYCHUNK) { - serial_writer(&myrpt->serial, "SHORT SIGNAL"); myrpt->state = IDLE; } if ((myrpt->receiver.rx && myrpt->gateway.receiver.rx) && myrpt->state > HANG) { - serial_writer(&myrpt->serial, "HANG"); - delay(500); myrpt->last = myrpt->state; myrpt->state = HANG; ht = millis(); myrpt->tail = ht; - if (!compareStamp(&myrpt->receiver.timestamp, PIP_KEYCHUNK) || busy(myrpt)) - continue; - courtesyTone(myrpt); + courtesy_tone(myrpt); } if (myrpt->state == HANG && TAILPIPS) { @@ -89,30 +76,25 @@ void loop() { } if (!myrpt->receiver.rx && myrpt->state == HANG) { - serial_writer(&myrpt->serial, "RX: RF"); myrpt->state = TT; tot = millis(); } if (!myrpt->gateway.receiver.rx && myrpt->state == HANG) { - serial_writer(&myrpt->serial, "RX: GATEWAY"); myrpt->state = GW; tot = millis(); } - if (compareStart(&myrpt->receiver.timestamp, TOTIME) && myrpt->state == TT ) { - serial_writer(&myrpt->serial, "REPEATER: TIMEOUT"); + if (cmp_start(&myrpt->receiver.timestamp, TOTIME) && myrpt->state == TT ) { myrpt->state = PEN_T; } if (myrpt->state == HANG && millis() - ht > HANGTIME) { if (myrpt->params.close_down && millis() - myrpt->last_id >= LAST_ID_HOLD) { - serial_writer(&myrpt->serial, "REPEATER: CLOSEDOWN ID"); myrpt->state = SLEEP; - sendID(myrpt); + send_id(myrpt); continue; } - serial_writer(&myrpt->serial, "REPEATER: IDLE"); myrpt->state = IDLE; } @@ -141,7 +123,6 @@ void loop() { if (myrpt->receiver.rx && myrpt->gateway.receiver.rx) break; } - serial_writer(&myrpt->serial, "REPEATER: TIMEOUT RESET"); } if (myrpt->state > SLEEP && millis() - myrpt->id_time >= (IDTIME - 60000)) { @@ -160,9 +141,8 @@ void loop() { tx(myrpt); myrpt->state = SLEEP; } - serial_writer(&myrpt->serial, "REPEATER: ID"); delay(250); - sendID(myrpt); + send_id(myrpt); } tx(myrpt); diff --git a/GB3TX/config.h b/GB3TX/config.h index 1a60562..04c2f9d 100644 --- a/GB3TX/config.h +++ b/GB3TX/config.h @@ -20,20 +20,20 @@ uint8_t io[6][2] = { /* CW ID SETTINGS */ #define ID "GB3DL H" -#define CW_SPEED 20 -#define CW_PITCH 1000 +#define CW_SPEED 18 +#define CW_PITCH 1200 /* PARAMS */ -#define COURTESY TONE +#define COURTESY CW #define CLOSEDOWN 0 #define GWPIPLEN 150 #define PIP_LETTER 'E' -#define PIP_GW_LETTER 'T' +#define PIP_GW_LETTER 'S' #define RFPIP CW_PITCH #define RFPIPLEN 300 #define START 0 #define TAILPIPS true -#define TAILPIP_PITCH CW_PITCH +#define TAILPIP_PITCH CW_PITCH - 225 /* SERIAL */ #define SERIAL false @@ -41,12 +41,12 @@ uint8_t io[6][2] = { /* TIMERS */ #define HANGTIME 7000 -#define KEYCHUNK_TIME 1500 +#define KEYCHUNK_TIME 3000 #define TOTIME 300000 #define IDTIME 500000 #define LAST_ID_HOLD 60000 -#define PIP_KEYCHUNK 1000 -#define TAIL_PIP_DELAY 2500 -#define TAIL_LEN 300 +#define PIP_KEYCHUNK 2000 +#define TAIL_PIP_DELAY 1000 +#define TAIL_LEN 70 #endif \ No newline at end of file diff --git a/GB3TX/cw.ino b/GB3TX/cw.ino index f525305..d6e8940 100644 --- a/GB3TX/cw.ino +++ b/GB3TX/cw.ino @@ -1,6 +1,6 @@ #include "cw.h" -void sendChar(repeater* myrpt, char c) { +void send_char(repeater* myrpt, char c) { if (c < 47 || c > 90) { delay(myrpt->params.cw_speed * 3 * 2); return; @@ -43,7 +43,7 @@ void sendChar(repeater* myrpt, char c) { } } -void sendID(repeater* myrpt) { +void send_id(repeater* myrpt) { myrpt->id_time = millis(); myrpt->last_id = myrpt->id_time; if (myrpt->callsign == NULL) { @@ -51,7 +51,7 @@ void sendID(repeater* myrpt) { } for (int i=0; i < sizeof ID/sizeof ID[0]; i++) { - sendChar(myrpt, myrpt->callsign[i]); + send_char(myrpt, myrpt->callsign[i]); delay(myrpt->params.cw_speed * 3); } if (digitalRead(PIP_ATT)) diff --git a/GB3TX/repeater.h b/GB3TX/repeater.h index 02b8954..b691889 100644 --- a/GB3TX/repeater.h +++ b/GB3TX/repeater.h @@ -48,11 +48,6 @@ typedef struct { t_stamp timestamp; }receiver; -typedef struct { - bool enable; - unsigned long speed; -}serial; - typedef struct { receiver receiver; transmitter transmitter; @@ -60,13 +55,13 @@ typedef struct { typedef struct { char* callsign; + int last_caller; gateway gateway; unsigned long id_time; unsigned long last_id; state last; params params; receiver receiver; - serial serial; state state; transmitter transmitter; unsigned long tail; diff --git a/GB3TX/repeater.ino b/GB3TX/repeater.ino index 41f9e22..8af4735 100644 --- a/GB3TX/repeater.ino +++ b/GB3TX/repeater.ino @@ -1,6 +1,5 @@ void tx(repeater* myrpt) { if (myrpt->state > IDLE && !myrpt->transmitter.tx) { - serial_writer(&myrpt->serial, "REPEATER: TX ON"); myrpt->transmitter.tx = true; digitalWrite(PTT,LOW); delay(100); @@ -8,31 +7,45 @@ void tx(repeater* myrpt) { } if (myrpt->state < KEYCHUNK && myrpt->transmitter.tx) { - serial_writer(&myrpt->serial, "REPEATER: TX OFF"); myrpt->transmitter.tx = false; digitalWrite(PTT,HIGH); } } void rx(repeater* myrpt) { - myrpt->receiver.rx = digitalRead(COS); - myrpt->gateway.receiver.rx = digitalRead(GW_COS); - - if (!myrpt->receiver.rx && !myrpt->gateway.transmitter.tx) { - serial_writer(&myrpt->serial, "REPEATER: COS"); + + /* TODO: This is terrible and needs cleaning! */ + if (myrpt->receiver.rx && !digitalRead(COS)) { + myrpt->receiver.rx = digitalRead(COS); myrpt->receiver.timestamp.start = millis(); digitalWrite(GWPTT, true); myrpt->gateway.transmitter.tx = true; + myrpt->last_caller = myrpt->receiver.id; return; } - if (myrpt->receiver.rx) { + if (!myrpt->receiver.rx && digitalRead(COS)) { + myrpt->receiver.rx = digitalRead(COS); myrpt->receiver.timestamp.end = millis(); if (myrpt->gateway.transmitter.tx) { digitalWrite(GWPTT, false); myrpt->gateway.transmitter.tx = false; } } + + if (myrpt->gateway.receiver.rx && !digitalRead(GW_COS)) { + myrpt->gateway.receiver.rx = digitalRead(GW_COS); + myrpt->last_caller = myrpt->gateway.receiver.id; + myrpt->gateway.receiver.timestamp.start = millis(); + } + + if (!myrpt->gateway.receiver.rx && digitalRead(GW_COS)) { + myrpt->gateway.receiver.rx = digitalRead(GW_COS); + myrpt->last_caller = myrpt->gateway.receiver.id; + myrpt->gateway.receiver.timestamp.end = millis(); + } + + } bool busy(repeater* myrpt) { @@ -40,75 +53,34 @@ bool busy(repeater* myrpt) { return (!myrpt->receiver.rx || !myrpt->gateway.receiver.rx); } -bool compareStamp(t_stamp* ts, unsigned long cmp) { - return ts->end - ts->start > cmp; +bool cmp_keychunk(repeater* myrpt, unsigned long cmp) { + if (myrpt->last_caller == 0) { + return (cmp_start(&myrpt->receiver.timestamp, cmp)); + } else { + return (cmp_start(&myrpt->gateway.receiver.timestamp, cmp)); + } } -bool compareStart(t_stamp* ts, unsigned long cmp) { +bool cmp_start(t_stamp* ts, unsigned long cmp) { return millis() - ts->start > cmp; } -void courtesyTone(repeater* myrpt) { +void courtesy_tone(repeater* myrpt) { + delay(500); + /* Did the last caller beat the timer? */ + if (!cmp_keychunk(myrpt, PIP_KEYCHUNK) || busy(myrpt)) + return; + switch(myrpt->params.courtesy) { case TONE: myrpt->last == TT ? tone(PIP, myrpt->params.pip_pitch, myrpt->params.pip_length) : tone(PIP, myrpt->params.pip_gw_pitch, myrpt->params.pip_gw_length); break; case CW: - myrpt->last == TT ? sendChar(myrpt, myrpt->params.pip_letter) : sendChar(myrpt, myrpt->params.pip_gw_letter); + myrpt->last == TT ? send_char(myrpt, myrpt->params.pip_letter) : send_char(myrpt, myrpt->params.pip_gw_letter); break; default: break; } if (TAILPIPS) delay(myrpt->params.pip_length); -} - -void serial_command(serial* s, repeater* myrpt) { - char cmd[5]; - if (Serial.available() > 0) { - Serial.readBytes(cmd, 5); - switch (cmd[0]) { - case '0': - serial_writer(s, "SEND STATS"); - break; - case '1': - tone(PIP, 1000, 100); - break; - case '2': - serial_writer(s, "CONFIG: Set tone | (0) OFF | (1) CW | (2) TONE |"); - serial_writer(s, "Entered"); - switch (cmd[1]) { - case '0': - serial_writer(s, "Courtesy OFF"); - myrpt->params.courtesy = NONE; - break; - case '1': - serial_writer(s, "Courtesy CW"); - myrpt->params.courtesy = CW; - break; - case '2': - serial_writer(s, "Courtesy TONE"); - myrpt->params.courtesy = TONE; - break; - default: - break; - } - break; - case '3': - Serial.print("RX Status: "); Serial.println(!myrpt->receiver.rx); - Serial.print("TX Status: "); Serial.println(myrpt->transmitter.tx); - Serial.print("GW Status: "); Serial.println(!myrpt->gateway.receiver.rx); - break; - case '4': - default: - break; - } - } -} - -void serial_writer(serial* s, char* buff) { - if (!s->enable) - return; - Serial.write(buff); - Serial.write('\n'); } \ No newline at end of file -- 2.47.1