Skip to content

Commit 9707d9e

Browse files
authored
Merge pull request #538 from LeeLeahy2/training-tx-power
Update the training TX power if necessary
2 parents caddb8e + ba776ec commit 9707d9e

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

Firmware/LoRaSerial/Commands.ino

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,8 +1244,8 @@ const COMMAND_ENTRY commands[] =
12441244
{'S', 0, 0, 0, 1, 0, TYPE_BOOL, valInt, "FlowControl", &tempSettings.flowControl},
12451245
{'S', 0, 0, 0, 1, 0, TYPE_BOOL, valInt, "InvertCts", &tempSettings.invertCts},
12461246
{'S', 0, 0, 0, 1, 0, TYPE_BOOL, valInt, "InvertRts", &tempSettings.invertRts},
1247-
{'S', 0, 0, 0, SERIAL_RX_BUFFER_SIZE, 0, TYPE_U16, valInt, "RTSOffBytes", &tempSettings.rtsOffBytes},
1248-
{'S', 0, 0, 0, SERIAL_RX_BUFFER_SIZE, 0, TYPE_U16, valInt, "RTSOnBytes", &tempSettings.rtsOnBytes},
1247+
{'S', 0, 0, 0, SERIAL_RX_BUFFER_SIZE, 0, TYPE_U16, valInt, "RTSOffBytes", &tempSettings.rtsOffBytes},
1248+
{'S', 0, 0, 0, SERIAL_RX_BUFFER_SIZE, 0, TYPE_U16, valInt, "RTSOnBytes", &tempSettings.rtsOnBytes},
12491249
{'S', 0, 0, 10, 2000, 0, TYPE_U16, valInt, "SerialDelay", &tempSettings.serialTimeoutBeforeSendingFrame_ms},
12501250
{'S', 0, 0, 0, 0, 0, TYPE_SPEED_SERIAL, valSpeedSerial, "SerialSpeed", &tempSettings.serialSpeed},
12511251
{'S', 0, 0, 0, 1, 0, TYPE_BOOL, valInt, "UsbSerialWait", &tempSettings.usbSerialWait},
@@ -1254,6 +1254,7 @@ const COMMAND_ENTRY commands[] =
12541254
Ltr, All, reset, min, max, digits, type, validation, name, setting addr */
12551255
{'R', 0, 1, 1, 255, 0, TYPE_U8, valInt, "ClientFindPartnerRetryInterval", &tempSettings.clientFindPartnerRetryInterval},
12561256
{'R', 0, 0, 0, 0, 0, TYPE_KEY, valKey, "TrainingKey", &tempSettings.trainingKey},
1257+
{'R', 0, 1, 14, 30, 0, TYPE_U8, valInt, "TrainingTxPower", &tempSettings.trainingTxPower_dbm},
12571258
{'R', 0, 0, 1, 255, 0, TYPE_U8, valInt, "TrainingTimeout", &tempSettings.trainingTimeout},
12581259

12591260
/*Trigger parameters
@@ -1266,7 +1267,7 @@ const COMMAND_ENTRY commands[] =
12661267

12671268
/*Virtual circuit parameters
12681269
Ltr, All, reset, min, max, digits, type, validation, name, setting addr */
1269-
{'V', 0, 0, 0, MAX_VC - 1, 0, TYPE_U8, valInt, "CmdVC", &cmdVc},
1270+
{'V', 0, 0, 0, MAX_VC - 1, 0, TYPE_U8, valInt, "CmdVC", &cmdVc},
12701271
};
12711272

12721273
const int commandCount = sizeof(commands) / sizeof(commands[0]);

Firmware/LoRaSerial/Radio.ino

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,16 +1183,17 @@ bool xmitDatagramTrainingFindPartner()
11831183
//Add the source (server) ID
11841184
memcpy(endOfTxData, myUniqueId, UNIQUE_ID_BYTES);
11851185
endOfTxData += UNIQUE_ID_BYTES;
1186+
*endOfTxData++ = settings.radioBroadcastPower_dbm;
11861187

11871188
/*
1188-
endOfTxData ---.
1189-
|
1190-
V
1191-
+----------+---------+----------+------------+-----------+----------+
1192-
| Optional | | Optional | Optional | | Optional |
1193-
| NET ID | Control | C-Timer | SF6 Length | Client ID | Trailer |
1194-
| 8 bits | 8 bits | 2 bytes | 8 bits | 16 Bytes | n Bytes |
1195-
+----------+---------+----------+------------+-----------+----------+
1189+
endOfTxData ---.
1190+
|
1191+
V
1192+
+----------+---------+----------+------------+-----------+----------+----------+
1193+
| Optional | | Optional | Optional | | | Optional |
1194+
| NET ID | Control | C-Timer | SF6 Length | Client ID | Tx Power | Trailer |
1195+
| 8 bits | 8 bits | 2 bytes | 8 bits | 16 Bytes | 1 Byte | n Bytes |
1196+
+----------+---------+----------+------------+-----------+----------+----------+
11961197
*/
11971198

11981199
txControl.datagramType = DATAGRAM_TRAINING_FIND_PARTNER;

Firmware/LoRaSerial/States.ino

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,19 @@ void updateRadioState()
17261726
//Save the client ID
17271727
memcpy(trainingPartnerID, rxData, UNIQUE_ID_BYTES);
17281728

1729+
//Increase the TX power if necessary
1730+
if (settings.radioBroadcastPower_dbm < rxData[UNIQUE_ID_BYTES])
1731+
{
1732+
settings.radioBroadcastPower_dbm = rxData[UNIQUE_ID_BYTES];
1733+
systemPrint("Increasing TX power to ");
1734+
systemPrint(settings.radioBroadcastPower_dbm);
1735+
systemPrint(" dB, requested by radio ");
1736+
systemPrintUniqueID(rxData);
1737+
systemPrintln();
1738+
int radioPowerSetting = covertdBmToSetting(settings.radioBroadcastPower_dbm);
1739+
radio.setOutputPower(radioPowerSetting);
1740+
}
1741+
17291742
//Find a slot in the NVM unique ID table
17301743
for (index = 0; index < MAX_VC; index++)
17311744
if (!nvmIsVcUniqueIdSet(index))

Firmware/LoRaSerial/Train.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//Select the training protocol
22
void selectTraining()
33
{
4-
if (settings.server)
4+
if (tempSettings.server)
55
beginTrainingServer();
66
else
77
beginTrainingClient();
@@ -110,7 +110,7 @@ void commonTrainingInitialization()
110110
settings.maxResends = 1; //Don't waste time retransmitting
111111
settings.netID = 'T'; //NetID for training
112112
settings.operatingMode = MODE_MULTIPOINT; //Use datagrams
113-
settings.radioBroadcastPower_dbm = 14; //Minimum, assume radios are near each other
113+
settings.radioBroadcastPower_dbm = trainingSettings.trainingTxPower_dbm; //Minimum, assume radios are near each other
114114
settings.selectLedUse = LEDS_CYLON; //Display the CYLON pattern on the LEDs
115115
settings.verifyRxNetID = true; //Disable netID checking
116116

Firmware/LoRaSerial/settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ typedef struct struct_settings {
465465
uint8_t trainingKey[AES_KEY_BYTES] = { 0x53, 0x70, 0x61, 0x72, 0x6b, 0x46, 0x75, 0x6E, 0x54, 0x72, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67 };
466466

467467
uint8_t trainingTimeout = 1; //Timeout in minutes to complete the training
468+
uint8_t trainingTxPower_dbm = 14; //Transmit power in dBm. Max is 30dBm
468469

469470
//----------------------------------------
470471
//Trigger parameters

0 commit comments

Comments
 (0)