general fixes

This commit is contained in:
jim 2024-12-11 21:42:42 +00:00
parent c8d544cbeb
commit e07ccbe2eb
5 changed files with 58 additions and 111 deletions

View File

@ -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);

View File

@ -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

View File

@ -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))

View File

@ -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;

View File

@ -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,21 +53,30 @@ 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;
@ -62,53 +84,3 @@ void courtesyTone(repeater* myrpt) {
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');
}