|
|
|
@ -48,9 +48,9 @@ |
|
|
|
|
|
|
|
#include <helpers/BaseChatMesh.h> |
|
|
|
|
|
|
|
#define SEND_TIMEOUT_BASE_MILLIS 300 |
|
|
|
#define SEND_TIMEOUT_BASE_MILLIS 500 |
|
|
|
#define FLOOD_SEND_TIMEOUT_FACTOR 16.0f |
|
|
|
#define DIRECT_SEND_PERHOP_FACTOR 5.0f |
|
|
|
#define DIRECT_SEND_PERHOP_FACTOR 6.0f |
|
|
|
#define DIRECT_SEND_PERHOP_EXTRA_MILLIS 250 |
|
|
|
|
|
|
|
#define PUBLIC_GROUP_PSK "izOH6cXN6mrJ5e26oRXNcg==" |
|
|
|
@ -100,6 +100,7 @@ static uint32_t _atoi(const char* sp) { |
|
|
|
#define CMD_SYNC_NEXT_MESSAGE 10 |
|
|
|
#define CMD_SET_RADIO_PARAMS 11 |
|
|
|
#define CMD_SET_RADIO_TX_POWER 12 |
|
|
|
#define CMD_RESET_PATH 13 |
|
|
|
|
|
|
|
#define RESP_CODE_OK 0 |
|
|
|
#define RESP_CODE_ERR 1 |
|
|
|
@ -137,6 +138,7 @@ struct NodePrefs { // persisted to file |
|
|
|
|
|
|
|
class MyMesh : public BaseChatMesh { |
|
|
|
FILESYSTEM* _fs; |
|
|
|
RADIO_CLASS* _phy; |
|
|
|
NodePrefs _prefs; |
|
|
|
uint32_t expected_ack_crc; // TODO: keep table of expected ACKs
|
|
|
|
mesh::GroupChannel* _public; |
|
|
|
@ -389,8 +391,8 @@ protected: |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
MyMesh(RadioLibWrapper& radio, mesh::RNG& rng, mesh::RTCClock& rtc, SimpleMeshTables& tables) |
|
|
|
: BaseChatMesh(radio, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables), _serial(NULL) |
|
|
|
MyMesh(RADIO_CLASS& phy, RadioLibWrapper& rw, mesh::RNG& rng, mesh::RTCClock& rtc, SimpleMeshTables& tables) |
|
|
|
: BaseChatMesh(rw, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables), _serial(NULL), _phy(&phy) |
|
|
|
{ |
|
|
|
_iter_started = false; |
|
|
|
offline_queue_len = 0; |
|
|
|
@ -406,12 +408,6 @@ public: |
|
|
|
_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) { |
|
|
|
_fs = &fs; |
|
|
|
_serial = &serial; |
|
|
|
@ -439,6 +435,12 @@ public: |
|
|
|
|
|
|
|
loadContacts(); |
|
|
|
_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() { |
|
|
|
@ -590,6 +592,17 @@ public: |
|
|
|
} else { |
|
|
|
writeErrFrame(); |
|
|
|
} |
|
|
|
} else if (cmd_frame[0] == CMD_RESET_PATH && len >= 1+32) { |
|
|
|
uint8_t* pub_key = &cmd_frame[1]; |
|
|
|
ContactInfo* recipient = lookupContactByPubKey(pub_key, PUB_KEY_SIZE); |
|
|
|
if (recipient) { |
|
|
|
recipient->out_path_len = -1; |
|
|
|
//recipient->lastmod = ?? shouldn't be needed, app already has this version of contact
|
|
|
|
saveContacts(); |
|
|
|
writeOKFrame(); |
|
|
|
} else { |
|
|
|
writeErrFrame(); // unknown contact
|
|
|
|
} |
|
|
|
} else if (cmd_frame[0] == CMD_ADD_UPDATE_CONTACT && len >= 1+32+2+1) { |
|
|
|
uint8_t* pub_key = &cmd_frame[1]; |
|
|
|
ContactInfo* recipient = lookupContactByPubKey(pub_key, PUB_KEY_SIZE); |
|
|
|
@ -632,7 +645,14 @@ public: |
|
|
|
_prefs.freq = (float)freq / 1000.0; |
|
|
|
_prefs.bw = (float)bw / 1000.0; |
|
|
|
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 { |
|
|
|
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(); |
|
|
|
@ -643,7 +663,8 @@ public: |
|
|
|
} else { |
|
|
|
_prefs.tx_power_dbm = cmd_frame[1]; |
|
|
|
savePrefs(); |
|
|
|
writeOKFrame(); // reboot now required!
|
|
|
|
_phy->setOutputPower(_prefs.tx_power_dbm); |
|
|
|
writeOKFrame(); |
|
|
|
} |
|
|
|
} else { |
|
|
|
writeErrFrame(); |
|
|
|
@ -706,7 +727,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU |
|
|
|
#endif |
|
|
|
StdRNG fast_rng; |
|
|
|
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() { |
|
|
|
while (1) ; |
|
|
|
@ -767,22 +788,6 @@ void setup() { |
|
|
|
#else |
|
|
|
#error "need to define filesystem" |
|
|
|
#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() { |
|
|
|
|