start of serial

This commit is contained in:
Jim Colderwood 2024-04-04 11:30:37 +01:00
parent d78d3c11c9
commit 7c1ea015a8
4 changed files with 39 additions and 6 deletions

View File

@ -17,6 +17,10 @@ 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;
@ -31,7 +35,7 @@ void loop() {
delay(1000);
myrpt->transmitter.tx = true;
sendID(myrpt);
//sendID(myrpt);
myrpt->state = SLEEP;
unsigned long ht = millis();
@ -43,23 +47,28 @@ void loop() {
if (((!myrpt->receiver.rx || !myrpt->gateway.receiver.rx)) && myrpt->state < 2) {
myrpt->state = KEYCHUNK;
serial_writer(&myrpt->serial, "KEYCHUNK");
kc = millis();
}
if (myrpt->state == KEYCHUNK && millis() - kc > 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->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(350);
myrpt->last = myrpt->state;
myrpt->state = HANG;
@ -78,20 +87,24 @@ 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 (myrpt->state == HANG && millis() - ht > HANGTIME) {
serial_writer(&myrpt->serial, "REPEATER: IDLE");
myrpt->state = IDLE;
}
if (millis() - tot >= TIMEOUT && (myrpt->state == TT || myrpt->state == GW)) {
serial_writer(&myrpt->serial, "REPEATER: TIMEOUT");
myrpt->state = TIMEOUT;
tone(3, 440, 1000);
delay(1000);
@ -105,12 +118,14 @@ void loop() {
if (myrpt->receiver.rx && myrpt->gateway.receiver.rx)
break;
}
serial_writer(&myrpt->serial, "REPEATER: TIMEOUT RESET");
}
tx(myrpt);
if (myrpt->state > SLEEP && millis() - id >= IDTIME) {
/* Repeater is IDLE, bring the transmitter up */
serial_writer(&myrpt->serial, "REPEATER: ID");
if (!myrpt->transmitter.tx) {
myrpt->state = HANG;
tx(myrpt);

View File

@ -15,21 +15,25 @@
/* PARAMS */
#define COURTESY CW
#define GWPIP 875
#define GWPIP 1200
#define GWPIPLEN 120
#define PIP_LETTER 'R'
#define PIP_GW_LETTER 'I'
#define PIP_SPEED 18
#define PIP_GW_LETTER 'E'
#define PIP_SPEED 20
#define RFPIP 1200
#define RFPIPLEN 80
#define TAILPIPS true
#define TAILPIP_PITCH 500
/* SERIAL */
#define SERIAL false
#define SERIAL_SPEED 115200
/* TIMERS */
#define HANGTIME 3000
#define HANGTIME 5000
#define KEYCHUNK_TIME 1000
#define TIMEOUT 300000
#define IDTIME 300000
#define PIP_KEYCHUNK 1500
#define PIP_KEYCHUNK 1500
#endif

View File

@ -40,6 +40,11 @@ typedef struct {
unsigned long long rx_time;
}receiver;
typedef struct {
bool enable;
unsigned long speed;
}serial;
typedef struct {
bool enable;
receiver receiver;
@ -55,6 +60,7 @@ typedef struct {
state last;
params params;
receiver receiver;
serial serial;
state state;
transmitter transmitter;
}repeater;

View File

@ -1,5 +1,6 @@
void tx(repeater* myrpt) {
if (myrpt->state > 1 && !myrpt->transmitter.tx) {
serial_writer(&myrpt->serial, "REPEATER: TX ON");
myrpt->transmitter.tx = true;
digitalWrite(PTT,LOW);
delay(100);
@ -9,6 +10,7 @@ void tx(repeater* myrpt) {
if (!myrpt->transmitter.tx)
return;
serial_writer(&myrpt->serial, "REPEATER: TX OFF");
myrpt->transmitter.tx = false;
digitalWrite(PTT,HIGH);
}
@ -18,6 +20,7 @@ void rx(repeater* myrpt) {
myrpt->gateway.receiver.rx = digitalRead(GW_COS);
if (!myrpt->receiver.rx && !myrpt->gateway.transmitter.tx) {
serial_writer(&myrpt->serial, "REPEATER: COS");
digitalWrite(GWPTT, true);
myrpt->gateway.transmitter.tx = true;
return;
@ -45,4 +48,9 @@ void courtesyTone(repeater* myrpt) {
myrpt->last == TT ? sendChar(myrpt->params.pip_speed,myrpt->params.pip_pitch,myrpt->params.pip_letter) : sendChar(myrpt->params.pip_speed,myrpt->params.pip_gw_pitch, myrpt->params.pip_gw_letter);
break;
}
}
void serial_writer(serial* s, char* buff) {
Serial.write(buff);
Serial.write('\n');
}