general fixes
This commit is contained in:
parent
c8d544cbeb
commit
e07ccbe2eb
@ -13,10 +13,6 @@ void loop() {
|
|||||||
myrpt = &rpt;
|
myrpt = &rpt;
|
||||||
myrpt->callsign = ID;
|
myrpt->callsign = ID;
|
||||||
myrpt->params.cw_pitch = CW_PITCH;
|
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 */
|
/* Setup params */
|
||||||
myrpt->params.cw_speed = 1200 / CW_SPEED;
|
myrpt->params.cw_speed = 1200 / CW_SPEED;
|
||||||
@ -30,55 +26,46 @@ void loop() {
|
|||||||
myrpt->params.pip_gw_letter = PIP_GW_LETTER;
|
myrpt->params.pip_gw_letter = PIP_GW_LETTER;
|
||||||
myrpt->params.start_up = START;
|
myrpt->params.start_up = START;
|
||||||
|
|
||||||
|
myrpt->receiver.id = 0;
|
||||||
|
myrpt->gateway.receiver.id = 1;
|
||||||
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
myrpt->transmitter.tx = true;
|
myrpt->transmitter.tx = true;
|
||||||
sendID(myrpt);
|
send_id(myrpt);
|
||||||
myrpt->state = SLEEP;
|
myrpt->state = SLEEP;
|
||||||
|
|
||||||
unsigned long ht = millis();
|
unsigned long ht = millis();
|
||||||
unsigned long tot = ht;
|
unsigned long tot = ht;
|
||||||
unsigned long kc;
|
|
||||||
myrpt->id_time = 0;
|
myrpt->id_time = 0;
|
||||||
serial_writer(&myrpt->serial, "READY");
|
|
||||||
digitalWrite(PIP_ATT, LOW);
|
digitalWrite(PIP_ATT, LOW);
|
||||||
while (1) {
|
while (1) {
|
||||||
serial_command(&myrpt->serial, myrpt);
|
|
||||||
rx(myrpt);
|
rx(myrpt);
|
||||||
|
|
||||||
if (busy(myrpt) && myrpt->state < KEYCHUNK) {
|
if (busy(myrpt) && myrpt->state < KEYCHUNK) {
|
||||||
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) {
|
if (!myrpt->receiver.rx) {
|
||||||
myrpt->state = TT;
|
myrpt->state = TT;
|
||||||
serial_writer(&myrpt->serial, "RX: RF");
|
|
||||||
} else {
|
} else {
|
||||||
myrpt->state = GW;
|
myrpt->state = GW;
|
||||||
serial_writer(&myrpt->serial, "RX: GATEWAY");
|
|
||||||
}
|
}
|
||||||
tot = millis();
|
tot = millis();
|
||||||
if (myrpt->params.start_up && millis() - myrpt->last_id >= LAST_ID_HOLD)
|
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) {
|
if ((myrpt->receiver.rx && myrpt->gateway.receiver.rx) && myrpt->state == KEYCHUNK) {
|
||||||
serial_writer(&myrpt->serial, "SHORT SIGNAL");
|
|
||||||
myrpt->state = IDLE;
|
myrpt->state = IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((myrpt->receiver.rx && myrpt->gateway.receiver.rx) && myrpt->state > HANG) {
|
if ((myrpt->receiver.rx && myrpt->gateway.receiver.rx) && myrpt->state > HANG) {
|
||||||
serial_writer(&myrpt->serial, "HANG");
|
|
||||||
delay(500);
|
|
||||||
myrpt->last = myrpt->state;
|
myrpt->last = myrpt->state;
|
||||||
myrpt->state = HANG;
|
myrpt->state = HANG;
|
||||||
ht = millis();
|
ht = millis();
|
||||||
myrpt->tail = ht;
|
myrpt->tail = ht;
|
||||||
if (!compareStamp(&myrpt->receiver.timestamp, PIP_KEYCHUNK) || busy(myrpt))
|
courtesy_tone(myrpt);
|
||||||
continue;
|
|
||||||
courtesyTone(myrpt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myrpt->state == HANG && TAILPIPS) {
|
if (myrpt->state == HANG && TAILPIPS) {
|
||||||
@ -89,30 +76,25 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!myrpt->receiver.rx && myrpt->state == HANG) {
|
if (!myrpt->receiver.rx && myrpt->state == HANG) {
|
||||||
serial_writer(&myrpt->serial, "RX: RF");
|
|
||||||
myrpt->state = TT;
|
myrpt->state = TT;
|
||||||
tot = millis();
|
tot = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!myrpt->gateway.receiver.rx && myrpt->state == HANG) {
|
if (!myrpt->gateway.receiver.rx && myrpt->state == HANG) {
|
||||||
serial_writer(&myrpt->serial, "RX: GATEWAY");
|
|
||||||
myrpt->state = GW;
|
myrpt->state = GW;
|
||||||
tot = millis();
|
tot = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compareStart(&myrpt->receiver.timestamp, TOTIME) && myrpt->state == TT ) {
|
if (cmp_start(&myrpt->receiver.timestamp, TOTIME) && myrpt->state == TT ) {
|
||||||
serial_writer(&myrpt->serial, "REPEATER: TIMEOUT");
|
|
||||||
myrpt->state = PEN_T;
|
myrpt->state = PEN_T;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myrpt->state == HANG && millis() - ht > HANGTIME) {
|
if (myrpt->state == HANG && millis() - ht > HANGTIME) {
|
||||||
if (myrpt->params.close_down && millis() - myrpt->last_id >= LAST_ID_HOLD) {
|
if (myrpt->params.close_down && millis() - myrpt->last_id >= LAST_ID_HOLD) {
|
||||||
serial_writer(&myrpt->serial, "REPEATER: CLOSEDOWN ID");
|
|
||||||
myrpt->state = SLEEP;
|
myrpt->state = SLEEP;
|
||||||
sendID(myrpt);
|
send_id(myrpt);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
serial_writer(&myrpt->serial, "REPEATER: IDLE");
|
|
||||||
myrpt->state = IDLE;
|
myrpt->state = IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +123,6 @@ void loop() {
|
|||||||
if (myrpt->receiver.rx && myrpt->gateway.receiver.rx)
|
if (myrpt->receiver.rx && myrpt->gateway.receiver.rx)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
serial_writer(&myrpt->serial, "REPEATER: TIMEOUT RESET");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myrpt->state > SLEEP && millis() - myrpt->id_time >= (IDTIME - 60000)) {
|
if (myrpt->state > SLEEP && millis() - myrpt->id_time >= (IDTIME - 60000)) {
|
||||||
@ -160,9 +141,8 @@ void loop() {
|
|||||||
tx(myrpt);
|
tx(myrpt);
|
||||||
myrpt->state = SLEEP;
|
myrpt->state = SLEEP;
|
||||||
}
|
}
|
||||||
serial_writer(&myrpt->serial, "REPEATER: ID");
|
|
||||||
delay(250);
|
delay(250);
|
||||||
sendID(myrpt);
|
send_id(myrpt);
|
||||||
}
|
}
|
||||||
|
|
||||||
tx(myrpt);
|
tx(myrpt);
|
||||||
|
@ -20,20 +20,20 @@ uint8_t io[6][2] = {
|
|||||||
|
|
||||||
/* CW ID SETTINGS */
|
/* CW ID SETTINGS */
|
||||||
#define ID "GB3DL H"
|
#define ID "GB3DL H"
|
||||||
#define CW_SPEED 20
|
#define CW_SPEED 18
|
||||||
#define CW_PITCH 1000
|
#define CW_PITCH 1200
|
||||||
|
|
||||||
/* PARAMS */
|
/* PARAMS */
|
||||||
#define COURTESY TONE
|
#define COURTESY CW
|
||||||
#define CLOSEDOWN 0
|
#define CLOSEDOWN 0
|
||||||
#define GWPIPLEN 150
|
#define GWPIPLEN 150
|
||||||
#define PIP_LETTER 'E'
|
#define PIP_LETTER 'E'
|
||||||
#define PIP_GW_LETTER 'T'
|
#define PIP_GW_LETTER 'S'
|
||||||
#define RFPIP CW_PITCH
|
#define RFPIP CW_PITCH
|
||||||
#define RFPIPLEN 300
|
#define RFPIPLEN 300
|
||||||
#define START 0
|
#define START 0
|
||||||
#define TAILPIPS true
|
#define TAILPIPS true
|
||||||
#define TAILPIP_PITCH CW_PITCH
|
#define TAILPIP_PITCH CW_PITCH - 225
|
||||||
|
|
||||||
/* SERIAL */
|
/* SERIAL */
|
||||||
#define SERIAL false
|
#define SERIAL false
|
||||||
@ -41,12 +41,12 @@ uint8_t io[6][2] = {
|
|||||||
|
|
||||||
/* TIMERS */
|
/* TIMERS */
|
||||||
#define HANGTIME 7000
|
#define HANGTIME 7000
|
||||||
#define KEYCHUNK_TIME 1500
|
#define KEYCHUNK_TIME 3000
|
||||||
#define TOTIME 300000
|
#define TOTIME 300000
|
||||||
#define IDTIME 500000
|
#define IDTIME 500000
|
||||||
#define LAST_ID_HOLD 60000
|
#define LAST_ID_HOLD 60000
|
||||||
#define PIP_KEYCHUNK 1000
|
#define PIP_KEYCHUNK 2000
|
||||||
#define TAIL_PIP_DELAY 2500
|
#define TAIL_PIP_DELAY 1000
|
||||||
#define TAIL_LEN 300
|
#define TAIL_LEN 70
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,6 +1,6 @@
|
|||||||
#include "cw.h"
|
#include "cw.h"
|
||||||
|
|
||||||
void sendChar(repeater* myrpt, char c) {
|
void send_char(repeater* myrpt, char c) {
|
||||||
if (c < 47 || c > 90) {
|
if (c < 47 || c > 90) {
|
||||||
delay(myrpt->params.cw_speed * 3 * 2);
|
delay(myrpt->params.cw_speed * 3 * 2);
|
||||||
return;
|
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->id_time = millis();
|
||||||
myrpt->last_id = myrpt->id_time;
|
myrpt->last_id = myrpt->id_time;
|
||||||
if (myrpt->callsign == NULL) {
|
if (myrpt->callsign == NULL) {
|
||||||
@ -51,7 +51,7 @@ void sendID(repeater* myrpt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0; i < sizeof ID/sizeof ID[0]; i++) {
|
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);
|
delay(myrpt->params.cw_speed * 3);
|
||||||
}
|
}
|
||||||
if (digitalRead(PIP_ATT))
|
if (digitalRead(PIP_ATT))
|
||||||
|
@ -48,11 +48,6 @@ typedef struct {
|
|||||||
t_stamp timestamp;
|
t_stamp timestamp;
|
||||||
}receiver;
|
}receiver;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool enable;
|
|
||||||
unsigned long speed;
|
|
||||||
}serial;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
receiver receiver;
|
receiver receiver;
|
||||||
transmitter transmitter;
|
transmitter transmitter;
|
||||||
@ -60,13 +55,13 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char* callsign;
|
char* callsign;
|
||||||
|
int last_caller;
|
||||||
gateway gateway;
|
gateway gateway;
|
||||||
unsigned long id_time;
|
unsigned long id_time;
|
||||||
unsigned long last_id;
|
unsigned long last_id;
|
||||||
state last;
|
state last;
|
||||||
params params;
|
params params;
|
||||||
receiver receiver;
|
receiver receiver;
|
||||||
serial serial;
|
|
||||||
state state;
|
state state;
|
||||||
transmitter transmitter;
|
transmitter transmitter;
|
||||||
unsigned long tail;
|
unsigned long tail;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
void tx(repeater* myrpt) {
|
void tx(repeater* myrpt) {
|
||||||
if (myrpt->state > IDLE && !myrpt->transmitter.tx) {
|
if (myrpt->state > IDLE && !myrpt->transmitter.tx) {
|
||||||
serial_writer(&myrpt->serial, "REPEATER: TX ON");
|
|
||||||
myrpt->transmitter.tx = true;
|
myrpt->transmitter.tx = true;
|
||||||
digitalWrite(PTT,LOW);
|
digitalWrite(PTT,LOW);
|
||||||
delay(100);
|
delay(100);
|
||||||
@ -8,31 +7,45 @@ void tx(repeater* myrpt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (myrpt->state < KEYCHUNK && myrpt->transmitter.tx) {
|
if (myrpt->state < KEYCHUNK && myrpt->transmitter.tx) {
|
||||||
serial_writer(&myrpt->serial, "REPEATER: TX OFF");
|
|
||||||
myrpt->transmitter.tx = false;
|
myrpt->transmitter.tx = false;
|
||||||
digitalWrite(PTT,HIGH);
|
digitalWrite(PTT,HIGH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void rx(repeater* myrpt) {
|
void rx(repeater* myrpt) {
|
||||||
myrpt->receiver.rx = digitalRead(COS);
|
|
||||||
myrpt->gateway.receiver.rx = digitalRead(GW_COS);
|
/* TODO: This is terrible and needs cleaning! */
|
||||||
|
if (myrpt->receiver.rx && !digitalRead(COS)) {
|
||||||
if (!myrpt->receiver.rx && !myrpt->gateway.transmitter.tx) {
|
myrpt->receiver.rx = digitalRead(COS);
|
||||||
serial_writer(&myrpt->serial, "REPEATER: COS");
|
|
||||||
myrpt->receiver.timestamp.start = millis();
|
myrpt->receiver.timestamp.start = millis();
|
||||||
digitalWrite(GWPTT, true);
|
digitalWrite(GWPTT, true);
|
||||||
myrpt->gateway.transmitter.tx = true;
|
myrpt->gateway.transmitter.tx = true;
|
||||||
|
myrpt->last_caller = myrpt->receiver.id;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myrpt->receiver.rx) {
|
if (!myrpt->receiver.rx && digitalRead(COS)) {
|
||||||
|
myrpt->receiver.rx = digitalRead(COS);
|
||||||
myrpt->receiver.timestamp.end = millis();
|
myrpt->receiver.timestamp.end = millis();
|
||||||
if (myrpt->gateway.transmitter.tx) {
|
if (myrpt->gateway.transmitter.tx) {
|
||||||
digitalWrite(GWPTT, false);
|
digitalWrite(GWPTT, false);
|
||||||
myrpt->gateway.transmitter.tx = 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) {
|
bool busy(repeater* myrpt) {
|
||||||
@ -40,75 +53,34 @@ bool busy(repeater* myrpt) {
|
|||||||
return (!myrpt->receiver.rx || !myrpt->gateway.receiver.rx);
|
return (!myrpt->receiver.rx || !myrpt->gateway.receiver.rx);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool compareStamp(t_stamp* ts, unsigned long cmp) {
|
bool cmp_keychunk(repeater* myrpt, unsigned long cmp) {
|
||||||
return ts->end - ts->start > 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;
|
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) {
|
switch(myrpt->params.courtesy) {
|
||||||
case TONE:
|
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);
|
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;
|
break;
|
||||||
case CW:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (TAILPIPS)
|
if (TAILPIPS)
|
||||||
delay(myrpt->params.pip_length);
|
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');
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user