86 lines
2.4 KiB
C++
86 lines
2.4 KiB
C++
void tx(repeater* myrpt) {
|
|
if (myrpt->state > IDLE && !myrpt->transmitter.tx) {
|
|
myrpt->transmitter.tx = true;
|
|
digitalWrite(PTT,LOW);
|
|
delay(100);
|
|
return;
|
|
}
|
|
|
|
if (myrpt->state < KEYCHUNK && myrpt->transmitter.tx) {
|
|
myrpt->transmitter.tx = false;
|
|
digitalWrite(PTT,HIGH);
|
|
}
|
|
}
|
|
|
|
void rx(repeater* myrpt) {
|
|
|
|
/* 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 && 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) {
|
|
rx(myrpt);
|
|
return (!myrpt->receiver.rx || !myrpt->gateway.receiver.rx);
|
|
}
|
|
|
|
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 cmp_start(t_stamp* ts, unsigned long cmp) {
|
|
return millis() - ts->start > cmp;
|
|
}
|
|
|
|
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 ? 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);
|
|
} |