Skip to content

Commit f4e6858

Browse files
committed
Optimize flash usage
1 parent d3a6bb8 commit f4e6858

File tree

1 file changed

+18
-38
lines changed

1 file changed

+18
-38
lines changed

src/main.cpp

+18-38
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,24 @@ void isrRxDataAvailable(void)
5959
// enter deep sleep until packet is received (for low power digirepeating)
6060
void enterDeepSleep()
6161
{
62-
LOG_INFO(F("Enter sleep"));
62+
LOG_INFO(F("Sleep"));
6363
sleep_enable();
6464
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
6565
digitalWrite(LED_BUILTIN, LOW);
6666
delay(1000);
6767
sleep_cpu();
6868
digitalWrite(LED_BUILTIN, HIGH);
69-
LOG_INFO(F("Exit sleep"));
69+
LOG_INFO(F("Unsleep"));
7070
}
7171

7272
// configura radio with given parameters
73+
#if CFG_MOD == CFG_MOD_LORA
7374
void setupRadio(long loraFreq, long bw, int sf, int cr, int pwr, int sync, int crcBytes, bool isExplicit)
7475
{
7576
// setup lora
7677
int state = radio_.begin((float)loraFreq / 1e6, (float)bw / 1e3, sf, cr, sync, pwr);
7778
if (state != RADIOLIB_ERR_NONE) {
78-
LOG_ERROR(F("Radio start failure"), state);
79+
LOG_ERROR(F("Radio failed"), state);
7980
while(true);
8081
}
8182
if (isExplicit && sf > 6)
@@ -85,33 +86,23 @@ void setupRadio(long loraFreq, long bw, int sf, int cr, int pwr, int sync, int c
8586
radio_.setCRC(crcBytes);
8687
radio_.setPreambleLength(CFG_LORA_PREAMBLE);
8788
radio_.setDio0Action(isrRxDataAvailable);
88-
89-
// start lora receive
90-
state = radio_.startReceive();
91-
if (state != RADIOLIB_ERR_NONE) {
92-
LOG_ERROR(F("Receive start error:"), state);
93-
while(true);
94-
}
89+
radio_.startReceive();
9590
}
91+
#endif
9692

9793
// configura radio with given parameters
94+
#if CFG_MOD == CFG_MOD_FSK
9895
void setupRadioFsk(long loraFreq, float bitRate, float freqDev, float rxBw, int pwr)
9996
{
10097
// setup lora
10198
int state = radio_.beginFSK((float)loraFreq / 1e6, bitRate, freqDev, rxBw, pwr);
10299
if (state != RADIOLIB_ERR_NONE) {
103-
LOG_ERROR(F("Radio start failure"), state);
104-
while(true);
100+
return;
105101
}
106102
radio_.setDio0Action(isrRxDataAvailable);
107-
108-
// start lora receive
109-
state = radio_.startReceive();
110-
if (state != RADIOLIB_ERR_NONE) {
111-
LOG_ERROR(F("Receive start error:"), state);
112-
while(true);
113-
}
103+
radio_.startReceive();
114104
}
105+
#endif
115106

116107
// arduino default setup
117108
void setup()
@@ -162,25 +153,19 @@ size_t receiveLoraPacket()
162153
return 0;
163154
}
164155
if (packetLength > CFG_MAX_PACKET_SIZE) {
165-
LOG_ERROR(F("Packet size is too large:"), packetLength);
156+
//LOG_ERROR(F("Packet size is too large:"), packetLength);
166157
packetLength = 0;
167158
} else {
168159
// read packet
169160
int state = radio_.readData(pktBufRx_, packetLength);
170161
if (state != RADIOLIB_ERR_NONE) {
171-
LOG_ERROR(F("Read pkt error:"), state);
162+
//LOG_ERROR(F("Read pkt error:"), state);
172163
packetLength = 0;
173164
}
174165
}
175166

176167
isLoraRxDataAvailable_ = false;
177-
178-
// start lora receive
179-
int state = radio_.startReceive();
180-
if (state != RADIOLIB_ERR_NONE) {
181-
LOG_ERROR(F("Receive start error:"), state);
182-
}
183-
168+
radio_.startReceive();
184169
return packetLength;
185170
}
186171

@@ -192,17 +177,12 @@ void sendLoraPacket(size_t packetLength)
192177
// send out
193178
int state = radio_.transmit(pktBufTx_, packetLength);
194179
if (state != RADIOLIB_ERR_NONE) {
195-
LOG_ERROR(F("Failed to transmit"), state);
180+
//LOG_ERROR(F("Failed to transmit"), state);
196181
}
197182
radio_.finishTransmit();
198183

199184
isRxIsrEnabled_ = true;
200-
201-
// start lora receive
202-
state = radio_.startReceive();
203-
if (state != RADIOLIB_ERR_NONE) {
204-
LOG_ERROR(F("Receive start error:"), state);
205-
}
185+
radio_.startReceive();
206186
}
207187

208188
// read lora packet and transfer to modem
@@ -396,21 +376,21 @@ void processLoraPacketAsRpt()
396376
// parse packet
397377
AX25::Payload payload(pktBufRx_, packetLength);
398378
if (!payload.IsValid()) {
399-
LOG_WARN(F("Failed to parse rx packet, not ax25"));
379+
LOG_WARN(F("Not ax25"));
400380
return;
401381
}
402382
payload.Dump();
403383

404384
// digireat
405385
if (!payload.Digirepeat(myCallsign_)) {
406-
LOG_INFO(F("Digirepeating skipped"));
386+
LOG_INFO(F("RPT skip"));
407387
return;
408388
}
409389

410390
// serialize to ax25 packet
411391
int txPacketLength = payload.ToBinary(pktBufRx_, CFG_MAX_PACKET_SIZE);
412392
if (txPacketLength <= 0) {
413-
LOG_WARN(F("Failed to convert to AX25 to binary"));
393+
LOG_WARN(F("AX25 to bin fail"));
414394
return;
415395
}
416396

0 commit comments

Comments
 (0)