m0zah/GB3TX/GB3TX.ino
2024-12-11 21:42:42 +00:00

151 lines
3.5 KiB
C++

#include "config.h"
#include "repeater.h"
void setup() {
for (int i=0; i<sizeof(io)/sizeof(io[0]); i++){
pinMode(io[i][0], io[i][1]);
}
}
void loop() {
repeater rpt;
repeater* myrpt;
myrpt = &rpt;
myrpt->callsign = ID;
myrpt->params.cw_pitch = CW_PITCH;
/* Setup params */
myrpt->params.cw_speed = 1200 / CW_SPEED;
myrpt->params.close_down = CLOSEDOWN;
myrpt->params.pip_length = RFPIPLEN;
myrpt->params.pip_pitch = RFPIP;
myrpt->params.pip_gw_pitch = RFPIP;
myrpt->params.pip_gw_length = GWPIPLEN;
myrpt->params.courtesy = COURTESY;
myrpt->params.pip_letter = PIP_LETTER;
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;
send_id(myrpt);
myrpt->state = SLEEP;
unsigned long ht = millis();
unsigned long tot = ht;
myrpt->id_time = 0;
digitalWrite(PIP_ATT, LOW);
while (1) {
rx(myrpt);
if (busy(myrpt) && myrpt->state < KEYCHUNK) {
myrpt->state = KEYCHUNK;
}
if (myrpt->state == KEYCHUNK && cmp_keychunk(myrpt, KEYCHUNK_TIME)) {
if (!myrpt->receiver.rx) {
myrpt->state = TT;
} else {
myrpt->state = GW;
}
tot = millis();
if (myrpt->params.start_up && millis() - myrpt->last_id >= LAST_ID_HOLD)
send_id(myrpt);
}
if ((myrpt->receiver.rx && myrpt->gateway.receiver.rx) && myrpt->state == KEYCHUNK) {
myrpt->state = IDLE;
}
if ((myrpt->receiver.rx && myrpt->gateway.receiver.rx) && myrpt->state > HANG) {
myrpt->last = myrpt->state;
myrpt->state = HANG;
ht = millis();
myrpt->tail = ht;
courtesy_tone(myrpt);
}
if (myrpt->state == HANG && TAILPIPS) {
if (millis() - myrpt->tail >= TAIL_PIP_DELAY && !busy(myrpt)) {
myrpt->tail = millis();
tone(PIP, TAILPIP_PITCH, TAIL_LEN);
}
}
if (!myrpt->receiver.rx && myrpt->state == HANG) {
myrpt->state = TT;
tot = millis();
}
if (!myrpt->gateway.receiver.rx && myrpt->state == HANG) {
myrpt->state = GW;
tot = millis();
}
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) {
myrpt->state = SLEEP;
send_id(myrpt);
continue;
}
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);
while (1) {
rx(myrpt);
if (myrpt->receiver.rx && myrpt->gateway.receiver.rx)
break;
}
}
if (myrpt->state > SLEEP && millis() - myrpt->id_time >= (IDTIME - 60000)) {
/* Check if the repeater is in use
* wait the full ID time
*/
if (myrpt->state > IDLE && millis() - myrpt->id_time < IDTIME) {
continue;
}
/* Repeater is IDLE, bring the transmitter up */
if (!myrpt->transmitter.tx) {
myrpt->state = HANG;
tx(myrpt);
myrpt->state = SLEEP;
}
delay(250);
send_id(myrpt);
}
tx(myrpt);
}
}