* companion radio: removed need for reboot after setting radio params or tx power
This commit is contained in:
@@ -138,6 +138,7 @@ struct NodePrefs { // persisted to file
|
|||||||
|
|
||||||
class MyMesh : public BaseChatMesh {
|
class MyMesh : public BaseChatMesh {
|
||||||
FILESYSTEM* _fs;
|
FILESYSTEM* _fs;
|
||||||
|
RADIO_CLASS* _phy;
|
||||||
NodePrefs _prefs;
|
NodePrefs _prefs;
|
||||||
uint32_t expected_ack_crc; // TODO: keep table of expected ACKs
|
uint32_t expected_ack_crc; // TODO: keep table of expected ACKs
|
||||||
mesh::GroupChannel* _public;
|
mesh::GroupChannel* _public;
|
||||||
@@ -390,8 +391,8 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MyMesh(RadioLibWrapper& radio, mesh::RNG& rng, mesh::RTCClock& rtc, SimpleMeshTables& tables)
|
MyMesh(RADIO_CLASS& phy, RadioLibWrapper& rw, mesh::RNG& rng, mesh::RTCClock& rtc, SimpleMeshTables& tables)
|
||||||
: BaseChatMesh(radio, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables), _serial(NULL)
|
: BaseChatMesh(rw, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables), _serial(NULL), _phy(&phy)
|
||||||
{
|
{
|
||||||
_iter_started = false;
|
_iter_started = false;
|
||||||
offline_queue_len = 0;
|
offline_queue_len = 0;
|
||||||
@@ -407,12 +408,6 @@ public:
|
|||||||
_prefs.tx_power_dbm = LORA_TX_POWER;
|
_prefs.tx_power_dbm = LORA_TX_POWER;
|
||||||
}
|
}
|
||||||
|
|
||||||
float getFreqPref() const { return _prefs.freq; }
|
|
||||||
uint8_t getSFPref() const { return _prefs.sf; }
|
|
||||||
uint8_t getCRPref() const { return _prefs.cr; }
|
|
||||||
float getBWPref() const { return _prefs.bw; }
|
|
||||||
uint8_t getTxPowerPref() const { return _prefs.tx_power_dbm; }
|
|
||||||
|
|
||||||
void begin(FILESYSTEM& fs, BaseSerialInterface& serial, mesh::RNG& trng) {
|
void begin(FILESYSTEM& fs, BaseSerialInterface& serial, mesh::RNG& trng) {
|
||||||
_fs = &fs;
|
_fs = &fs;
|
||||||
_serial = &serial;
|
_serial = &serial;
|
||||||
@@ -440,6 +435,12 @@ public:
|
|||||||
|
|
||||||
loadContacts();
|
loadContacts();
|
||||||
_public = addChannel(PUBLIC_GROUP_PSK); // pre-configure Andy's public channel
|
_public = addChannel(PUBLIC_GROUP_PSK); // pre-configure Andy's public channel
|
||||||
|
|
||||||
|
_phy->setFrequency(_prefs.freq);
|
||||||
|
_phy->setSpreadingFactor(_prefs.sf);
|
||||||
|
_phy->setBandwidth(_prefs.bw);
|
||||||
|
_phy->setCodingRate(_prefs.cr);
|
||||||
|
_phy->setOutputPower(_prefs.tx_power_dbm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void savePrefs() {
|
void savePrefs() {
|
||||||
@@ -644,7 +645,14 @@ public:
|
|||||||
_prefs.freq = (float)freq / 1000.0;
|
_prefs.freq = (float)freq / 1000.0;
|
||||||
_prefs.bw = (float)bw / 1000.0;
|
_prefs.bw = (float)bw / 1000.0;
|
||||||
savePrefs();
|
savePrefs();
|
||||||
writeOKFrame(); // reboot now required!
|
|
||||||
|
_phy->setFrequency(_prefs.freq);
|
||||||
|
_phy->setSpreadingFactor(_prefs.sf);
|
||||||
|
_phy->setBandwidth(_prefs.bw);
|
||||||
|
_phy->setCodingRate(_prefs.cr);
|
||||||
|
MESH_DEBUG_PRINTLN("OK: CMD_SET_RADIO_PARAMS: f=%d, bw=%d, sf=%d, cr=%d", freq, bw, (uint32_t)sf, (uint32_t)cr);
|
||||||
|
|
||||||
|
writeOKFrame();
|
||||||
} else {
|
} else {
|
||||||
MESH_DEBUG_PRINTLN("Error: CMD_SET_RADIO_PARAMS: f=%d, bw=%d, sf=%d, cr=%d", freq, bw, (uint32_t)sf, (uint32_t)cr);
|
MESH_DEBUG_PRINTLN("Error: CMD_SET_RADIO_PARAMS: f=%d, bw=%d, sf=%d, cr=%d", freq, bw, (uint32_t)sf, (uint32_t)cr);
|
||||||
writeErrFrame();
|
writeErrFrame();
|
||||||
@@ -655,7 +663,8 @@ public:
|
|||||||
} else {
|
} else {
|
||||||
_prefs.tx_power_dbm = cmd_frame[1];
|
_prefs.tx_power_dbm = cmd_frame[1];
|
||||||
savePrefs();
|
savePrefs();
|
||||||
writeOKFrame(); // reboot now required!
|
_phy->setOutputPower(_prefs.tx_power_dbm);
|
||||||
|
writeOKFrame();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
writeErrFrame();
|
writeErrFrame();
|
||||||
@@ -718,7 +727,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU
|
|||||||
#endif
|
#endif
|
||||||
StdRNG fast_rng;
|
StdRNG fast_rng;
|
||||||
SimpleMeshTables tables;
|
SimpleMeshTables tables;
|
||||||
MyMesh the_mesh(*new WRAPPER_CLASS(radio, board), fast_rng, *new VolatileRTCClock(), tables);
|
MyMesh the_mesh(radio, *new WRAPPER_CLASS(radio, board), fast_rng, *new VolatileRTCClock(), tables);
|
||||||
|
|
||||||
void halt() {
|
void halt() {
|
||||||
while (1) ;
|
while (1) ;
|
||||||
@@ -779,22 +788,6 @@ void setup() {
|
|||||||
#else
|
#else
|
||||||
#error "need to define filesystem"
|
#error "need to define filesystem"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (LORA_FREQ != the_mesh.getFreqPref()) {
|
|
||||||
radio.setFrequency(the_mesh.getFreqPref());
|
|
||||||
}
|
|
||||||
if (LORA_SF != the_mesh.getSFPref()) {
|
|
||||||
radio.setSpreadingFactor(the_mesh.getSFPref());
|
|
||||||
}
|
|
||||||
if (LORA_BW != the_mesh.getBWPref()) {
|
|
||||||
radio.setBandwidth(the_mesh.getBWPref());
|
|
||||||
}
|
|
||||||
if (LORA_CR != the_mesh.getCRPref()) {
|
|
||||||
radio.setCodingRate(the_mesh.getCRPref());
|
|
||||||
}
|
|
||||||
if (LORA_TX_POWER != the_mesh.getTxPowerPref()) {
|
|
||||||
radio.setOutputPower(the_mesh.getTxPowerPref());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|||||||
Reference in New Issue
Block a user