Use CAD cycle, better deep sleep
This commit is contained in:
58
src/config.h
58
src/config.h
@ -1,11 +1,22 @@
|
||||
#include "mesh.pb.h"
|
||||
// CONFIGURATION:
|
||||
#define REGION RegionCode_EU865 // define your region here. For US, RegionCode_US, CN RegionCode_Cn etc.
|
||||
char MESHTASTIC_NAME[12] = {"Default"}; // Channel Name, but without "-Xy" suffix , e.g. use "Test" instead of "Test-A"
|
||||
#define MESHTASTIC_SPEED 3 // 0 = short range, 1 = medium range, 2 = long range, 3 = very long range
|
||||
#define TX_MAX_POWER 14 // max output power in dB, keep in mind the maximums set by law and the hardware
|
||||
#define REGION RegionCode_EU865 // define your region here. For US, RegionCode_US, CN RegionCode_Cn etc.
|
||||
#define TX_MAX_POWER 14 // max output power in dB, keep in mind the maximums set by law and the hardware
|
||||
char MeshtasticLink[] = "https://www.meshtastic.org/c/#GAMiENTxuzogKQdZ8Lz_q89Oab8qB0RlZmF1bHQ=" ;
|
||||
// :CONFIGURATION
|
||||
|
||||
/* RegionCodes:
|
||||
|
||||
RegionCode_Unset
|
||||
RegionCode_US
|
||||
RegionCode_EU433
|
||||
RegionCode_EU865
|
||||
RegionCode_CN
|
||||
RegionCode_JP
|
||||
RegionCode_ANZ
|
||||
RegionCode_KR
|
||||
RegionCode_TW
|
||||
*/
|
||||
|
||||
#define RGB_GREEN 0x000300 // receive mode --- not longer used
|
||||
#define RGB_RED 0x030000 // send mode
|
||||
|
||||
@ -14,39 +25,26 @@ char MESHTASTIC_NAME[12] = {"Default"}; // Channel Name, but without "-Xy" su
|
||||
#define RX_TIMEOUT_VALUE 1000
|
||||
#define MAX_PAYLOAD_LENGTH 0xFF // max payload (see \cores\asr650x\device\asr6501_lrwan\radio.c --> MaxPayloadLength)
|
||||
|
||||
/* possible RegionCodes, from mesh.pb.h:
|
||||
typedef enum _RegionCode {
|
||||
RegionCode_Unset = 0,
|
||||
RegionCode_US = 1,
|
||||
RegionCode_EU433 = 2,
|
||||
RegionCode_EU865 = 3,
|
||||
RegionCode_CN = 4,
|
||||
RegionCode_JP = 5,
|
||||
RegionCode_ANZ = 6,
|
||||
RegionCode_KR = 7,
|
||||
RegionCode_TW = 8
|
||||
} RegionCode;
|
||||
*/
|
||||
|
||||
// the PSK is not used for encryption/decryption, you can leave it as it is
|
||||
#define MESHTASTIC_PSK { 0x10, 0xd4, 0xf1, 0xbb, 0x3a, 0x20, 0x29, 0x07, 0x59, 0xf0, 0xbc, 0xff, 0xab, 0xcf, 0x4e, 0x69, 0xbf }
|
||||
#define PSK_NOENCRYPTION { 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||
#include "mesh.pb.h"
|
||||
#include "mesh-pb-constants.h"
|
||||
|
||||
typedef struct {
|
||||
uint32_t to, from, id;
|
||||
uint8_t flags; // The bottom three bits of flags are used to store hop_limit, bit 4 is the WANT_ACK flag
|
||||
} PacketHeader;
|
||||
|
||||
#define MSG(...) Serial.printf(__VA_ARGS__)
|
||||
//#define DUTY(symbTime) ( (uint32_t)( symbTime * LORA_PREAMBLE_LENGTH / 2 ) )
|
||||
#define MSG(...) Serial.printf(__VA_ARGS__)
|
||||
#define LINE( count, c) { for (uint8_t i=0; i<count; i++ ) { Serial.print(c); } Serial.println(); }
|
||||
|
||||
void onTxDone( void );
|
||||
void onCadDone( bool ChannelActive );
|
||||
void onRxTimeout( void );
|
||||
void onTxTimeout( void );
|
||||
void onRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
|
||||
void onCheckRadio( void );
|
||||
void ConfigureRadio( ChannelSettings ChanSet );
|
||||
void setRxCycle(void);
|
||||
unsigned long hash(char *str);
|
||||
|
||||
void MCU_deepsleep( void );
|
||||
unsigned long hash( char *str );
|
||||
|
||||
// from Meshtastic project: MeshRadio.h , RadioInterface.cpp
|
||||
#define RDEF(name, freq, spacing, num_ch, power_limit) \
|
||||
@ -75,5 +73,7 @@ const RegionInfo regions[] = {
|
||||
RDEF(TW, 923.0f, 0.2f, 10, 0) // TW channel settings (AS2 bandplan 923-925MHz)
|
||||
};
|
||||
|
||||
// Bandwidths. Array is specific to the Radio.c of the CubeCells
|
||||
const uint32_t TheBandwidths[] = { 125E3, 250E3, 500E3, 62500, 41670, 31250, 20830, 15630, 10420, 7810 };
|
||||
// Bandwidths array is specific to the Radio.c of the CubeCell boards
|
||||
const uint32_t TheBandwidths[] = { 125E3, 250E3, 500E3, 62500, 41670, 31250, 20830, 15630, 10420, 7810 };
|
||||
|
||||
|
||||
|
144
src/main.cpp
144
src/main.cpp
@ -1,5 +1,7 @@
|
||||
#include <Arduino.h>
|
||||
#include "config.h"
|
||||
#include <Base64.h>
|
||||
#include "cyPm.c"
|
||||
|
||||
// CONFIGURATION:
|
||||
// Change RegionCode, Frequency, Speed in config.h !
|
||||
@ -9,16 +11,14 @@
|
||||
// OLED supported for cubecell_board_Plus (HTCC-AB02) and cubecell_gps (HTCC-AB02S)
|
||||
// :CONFIGURATION
|
||||
|
||||
static MeshPacket thePacket;
|
||||
static ChannelSettings ChanSet;
|
||||
static RadioEvents_t RadioEvents;
|
||||
static uint32_t lastreceivedID = 0;
|
||||
static uint32_t startTime = 0;
|
||||
static uint32_t symbolTime;
|
||||
static uint32_t sleepTime;
|
||||
static uint32_t rxTime;
|
||||
static bool flag_No_Cycle = false;
|
||||
|
||||
static MeshPacket thePacket;
|
||||
static ChannelSettings ChanSet;
|
||||
static RadioEvents_t RadioEvents;
|
||||
static TimerEvent_t CheckRadio;
|
||||
static uint32_t lastreceivedID = 0;
|
||||
static uint32_t symbolTime;
|
||||
static uint32_t sendTime;
|
||||
extern uint32_t systime; // global system time count --> millis()
|
||||
|
||||
#ifndef NOBLINK
|
||||
#include "CubeCell_NeoPixel.h"
|
||||
@ -38,6 +38,7 @@ char str[32];
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
TimerInit( &CheckRadio, onCheckRadio );
|
||||
#ifndef NO_OLED
|
||||
pinMode(Vext,OUTPUT);
|
||||
digitalWrite(Vext,LOW);
|
||||
@ -60,17 +61,24 @@ void setup() {
|
||||
#endif
|
||||
#ifndef SILENT
|
||||
Serial.begin(115200);
|
||||
MSG("\n***********************************************************\nSetting up Radio:\n");
|
||||
MSG("\n");
|
||||
LINE(60, "*");
|
||||
MSG("Setting up Radio:\n");
|
||||
#endif
|
||||
RadioEvents.TxDone = onTxDone;
|
||||
RadioEvents.TxTimeout = onTxTimeout;
|
||||
RadioEvents.RxDone = onRxDone;
|
||||
RadioEvents.RxTimeout = onRxTimeout;
|
||||
RadioEvents.CadDone = onCadDone;
|
||||
Radio.Init( &RadioEvents );
|
||||
memcpy(ChanSet.name, MESHTASTIC_NAME, 12);
|
||||
ChanSet.channel_num = hash( MESHTASTIC_NAME ) % regions[REGION].numChannels; // see config.h
|
||||
Radio.Sleep();
|
||||
// import Channel Settings from Meshtastic Link (channel name, modem config):
|
||||
char decoded[Base64.decodedLength(&MeshtasticLink[30], sizeof(MeshtasticLink)-30)];
|
||||
Base64.decode(decoded, &MeshtasticLink[30], sizeof(MeshtasticLink)-30);
|
||||
pb_decode_from_bytes((uint8_t *)&decoded[0], sizeof(decoded), ChannelSettings_fields, &ChanSet);
|
||||
// done, populate remaining settings according to channel name and provided modem config
|
||||
ChanSet.channel_num = hash( ChanSet.name ) % regions[REGION].numChannels; // see config.h
|
||||
ChanSet.tx_power = (regions[REGION].powerLimit == 0) ? TX_MAX_POWER : MIN(regions[REGION].powerLimit, TX_MAX_POWER) ;
|
||||
//ChanSet.psk = MESHTASTIC_PSK;
|
||||
ChanSet.psk = PSK_NOENCRYPTION;
|
||||
/* FYI:
|
||||
"bandwidth":
|
||||
[0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: 62.5kHz, 4: 41.67kHz, 5: 31.25kHz, 6: 20.83kHz, 7: 15.63kHz, 8: 10.42kHz, 9: 7.81kHz]
|
||||
@ -82,64 +90,79 @@ void setup() {
|
||||
"coding rate":
|
||||
[1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
|
||||
*/
|
||||
switch ( MESHTASTIC_SPEED ){
|
||||
switch ( (uint8_t)ChanSet.modem_config ){
|
||||
case 0: { // short range
|
||||
ChanSet.bandwidth = 0; // 125 kHz
|
||||
ChanSet.coding_rate = 1; // = 4/5
|
||||
ChanSet.spread_factor = 7;
|
||||
symbolTime = 1024; // in micro seconds!
|
||||
break;
|
||||
}
|
||||
case 1: { // medium range
|
||||
ChanSet.bandwidth = 2; // 500 kHz
|
||||
ChanSet.coding_rate = 1; // = 4/5
|
||||
ChanSet.spread_factor = 7;
|
||||
symbolTime = 256;
|
||||
break;
|
||||
}
|
||||
case 2: { // long range
|
||||
ChanSet.bandwidth = 5; // 31.25 kHz
|
||||
ChanSet.coding_rate = 4; // = 4/8
|
||||
ChanSet.spread_factor = 9;
|
||||
symbolTime = 16384;
|
||||
break;
|
||||
}
|
||||
case 3: { // very long range
|
||||
ChanSet.bandwidth = 0; // 125 kHz
|
||||
ChanSet.coding_rate = 4; // = 4/8
|
||||
ChanSet.spread_factor = 12;
|
||||
symbolTime = 32768;
|
||||
break;
|
||||
}
|
||||
default:{ // default setting is very long range
|
||||
ChanSet.bandwidth = 0; // 125 kHz
|
||||
ChanSet.coding_rate = 4; // = 4/8
|
||||
ChanSet.spread_factor = 12;
|
||||
symbolTime = 32768;
|
||||
}
|
||||
}
|
||||
symbolTime = ((1<< ChanSet.spread_factor)*1000 +32) *1000 / TheBandwidths[ChanSet.bandwidth]; // in micro seconds!
|
||||
ConfigureRadio( ChanSet );
|
||||
#ifndef SILENT
|
||||
MSG("\n..done! Switch to Receive Mode.\n***********************************************************\n");
|
||||
MSG("\n..done!\n");
|
||||
LINE(60,"*");
|
||||
#endif
|
||||
#ifndef NO_OLED
|
||||
display.drawString(0,32, "Receive Mode..");
|
||||
display.display();
|
||||
#endif
|
||||
setRxCycle();
|
||||
TimerSetValue( &CheckRadio, symbolTime / 100 ); // MCU sleeps 10 LoRa symbols (in milli seconds)
|
||||
TimerStart( &CheckRadio ); // onCheckRadio() will break deep sleep mode
|
||||
Radio.StartCad( 3 ); // length in symbols
|
||||
}
|
||||
|
||||
void onCheckRadio(void)
|
||||
{
|
||||
TimerReset(&CheckRadio);
|
||||
}
|
||||
|
||||
// Cycle starts @ 0 symbols. LoRA: CAD for x symbols, then (implicitly) Standby MCU: sleep
|
||||
// After 10 LoRa symbols, wake up MCU and check for IRQs from LoRa (including CADdone)
|
||||
// If channel activiy detected, switch to RX mode for 500 symbols, to capture very long packages.
|
||||
// If the package is shorter, the onRXDone handler will put the LoRa to sleep, so no excess power consumption
|
||||
// Radio.Send() is non-blocking, so if a TX is running we cannot immediatly start a new CAD. We wait (sleep) until LoRa is idle.
|
||||
|
||||
void loop( )
|
||||
{
|
||||
while ( !(Radio.GetStatus() == RF_IDLE) ) {
|
||||
for (uint8_t i = 0; i<6; i++) lowPowerHandler();
|
||||
Radio.IrqProcess();
|
||||
}
|
||||
setRxCycle();
|
||||
|
||||
MCU_deepsleep( );
|
||||
Radio.IrqProcess(); // handle events from LoRa, if CAD, set SX1262 to receive (onCadDone)
|
||||
if ( Radio.GetStatus() == RF_IDLE ) Radio.StartCad( 3 ); // (in symbols)
|
||||
|
||||
}
|
||||
|
||||
void setRxCycle(void){
|
||||
(flag_No_Cycle) ? Radio.Rx( 0 ) : Radio.SetRxDutyCycle( rxTime, sleepTime );
|
||||
void onCadDone( bool ChannelActive ){
|
||||
// Rx Time = 500 * symbol time (in ms) should be longer than receive time for max. packet length
|
||||
(ChannelActive) ? Radio.Rx( symbolTime >> 1 ) : Radio.Sleep();
|
||||
}
|
||||
|
||||
void onRxTimeout( void ){
|
||||
Radio.Sleep();
|
||||
}
|
||||
|
||||
void onTxDone( void )
|
||||
@ -149,14 +172,14 @@ void onTxDone( void )
|
||||
LED.show( );
|
||||
#endif
|
||||
#ifndef SILENT
|
||||
MSG(".done (%ims)! Switch to Receive Mode.\n", millis() - startTime );
|
||||
MSG(".done (%ims)! Switch to Receive Mode.\n", millis() - sendTime );
|
||||
#endif
|
||||
#ifndef NO_OLED
|
||||
sprintf(str,"..done. RX Mode..");
|
||||
display.drawString(42,53,str);
|
||||
display.display();
|
||||
sprintf(str,"..done. RX Mode..");
|
||||
display.drawString(42,53,str);
|
||||
display.display();
|
||||
#endif
|
||||
Radio.Standby();
|
||||
Radio.Sleep();
|
||||
}
|
||||
|
||||
void onTxTimeout( void )
|
||||
@ -173,11 +196,12 @@ void onTxTimeout( void )
|
||||
display.drawString(42,53,str);
|
||||
display.display();
|
||||
#endif
|
||||
Radio.Standby();
|
||||
Radio.Sleep();
|
||||
}
|
||||
|
||||
void onRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
|
||||
{
|
||||
Radio.Sleep();
|
||||
if ( size > MAX_PAYLOAD_LENGTH ) size = MAX_PAYLOAD_LENGTH;
|
||||
if ( !(size > sizeof(PacketHeader)) ) {
|
||||
#ifndef SILENT
|
||||
@ -189,7 +213,7 @@ void onRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
|
||||
LED.show();
|
||||
#endif
|
||||
Radio.Send( payload, size );
|
||||
Radio.Standby();
|
||||
Radio.Rx( 0 );
|
||||
return;
|
||||
}
|
||||
PacketHeader * h = (PacketHeader *)payload;
|
||||
@ -243,8 +267,8 @@ void onRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
|
||||
LED.show();
|
||||
#endif
|
||||
#ifndef SILENT
|
||||
MSG("Sending packet.. (Size: %i)..", size);
|
||||
startTime = millis();
|
||||
MSG("Sending packet..");
|
||||
sendTime = millis();
|
||||
#endif
|
||||
Radio.Send( payload, size );
|
||||
}
|
||||
@ -277,36 +301,30 @@ void ConfigureRadio( ChannelSettings ChanSet )
|
||||
#ifndef SILENT
|
||||
MSG("\nRegion is: %s", regions[REGION].name);
|
||||
MSG(" TX power: %i\n", ChanSet.tx_power);
|
||||
MSG("Channel name is: '%s' .. \n", ChanSet.name );
|
||||
MSG("Setting frequency to %i Hz (meshtastic channel %i) .. \n",freq,ChanSet.channel_num );
|
||||
MSG("Channel name is: %s .. \n", ChanSet.name );
|
||||
MSG("Setting bandwidth to index %i (%ikHz)..\n", ChanSet.bandwidth, TheBandwidths[ChanSet.bandwidth]);
|
||||
MSG("Setting CodeRate to index %i .. \n", ChanSet.coding_rate);
|
||||
MSG("Setting bandwidth to index %i (%ikHz)..\n", ChanSet.bandwidth, TheBandwidths[ChanSet.bandwidth] );
|
||||
MSG("Setting CodeRate to index %i (4/%i).. \n", ChanSet.coding_rate, ChanSet.coding_rate + 4 );
|
||||
MSG("Setting SpreadingFactor to %i ..\n",ChanSet.spread_factor);
|
||||
MSG("Symboltime is %i micro s ..\n", symbolTime );
|
||||
#endif
|
||||
Radio.SetChannel( freq );
|
||||
Radio.SetTxConfig( MODEM_LORA, ChanSet.tx_power ,0 , ChanSet.bandwidth, ChanSet.spread_factor, ChanSet.coding_rate,
|
||||
LORA_PREAMBLE_LENGTH, false, true, false, 0, false, 20000 );
|
||||
Radio.SetRxConfig( MODEM_LORA, ChanSet.bandwidth, ChanSet.spread_factor, ChanSet.coding_rate, 0, LORA_PREAMBLE_LENGTH,
|
||||
LORA_SYMBOL_TIMEOUT, false , 0, true, false, 0, false, true );
|
||||
|
||||
// SET UP RX_DUTY_CYCLE:
|
||||
#define RXSYMBOLS 8 // Minimum count of symbols to reliably detect a LoRa preamble in rx mode. Should not be lower than 6.
|
||||
if ( (LORA_PREAMBLE_LENGTH + 4.5) < (2 * RXSYMBOLS + 1 ) ) // 4.5 symbols are added to the user set preamble by the Sx1262
|
||||
{
|
||||
#ifndef SILENT
|
||||
MSG("Short Preamble, will not use RxDutyCycle!\n");
|
||||
#endif
|
||||
flag_No_Cycle = true;
|
||||
return;
|
||||
}
|
||||
uint32_t preambTime = symbolTime * (LORA_PREAMBLE_LENGTH + 4.5); // micro secs.
|
||||
rxTime = 2 * RXSYMBOLS * symbolTime;
|
||||
sleepTime = preambTime - rxTime - 1000; // SX1262 needs 500 micro sec for each sleep/wake transition
|
||||
if (preambTime < (2* rxTime + sleepTime) ) flag_No_Cycle = true;
|
||||
#ifndef SILENT
|
||||
MSG("Will use RxDutyCycle: %s\n", (flag_No_Cycle) ? "YES" : "NO" );
|
||||
MSG("RX time: %u micro s sleep time: %u micro s\n", rxTime, sleepTime);
|
||||
#endif
|
||||
rxTime = (rxTime * 125) >> 3; // * 15.768 micro s (125/8 is 15.768)
|
||||
sleepTime = (sleepTime * 125) >> 3;
|
||||
}
|
||||
|
||||
void MCU_deepsleep(void)
|
||||
{
|
||||
#ifndef SILENT
|
||||
UART_1_Sleep;
|
||||
#endif
|
||||
pinMode(P4_1, ANALOG); // SPI0 MISO
|
||||
CySysPmDeepSleep(); // deep sleep mode
|
||||
systime = (uint32_t)TimerGetCurrentTime();
|
||||
pinMode(P4_1, INPUT);
|
||||
#ifndef SILENT
|
||||
UART_1_Wakeup;
|
||||
#endif
|
||||
}
|
||||
|
76
src/mesh-pb-constants.cpp
Normal file
76
src/mesh-pb-constants.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
#include "mesh-pb-constants.h"
|
||||
/*#include "FS.h"
|
||||
#include "configuration.h"
|
||||
#include <Arduino.h>*/
|
||||
#include <assert.h>
|
||||
#include <pb_decode.h>
|
||||
#include <pb_encode.h>
|
||||
|
||||
#ifdef ARDUINO_ARCH_NRF52
|
||||
#include "Adafruit_LittleFS.h"
|
||||
using namespace Adafruit_LittleFS_Namespace; // To get File type
|
||||
#endif
|
||||
|
||||
/// helper function for encoding a record as a protobuf, any failures to encode are fatal and we will panic
|
||||
/// returns the encoded packet size
|
||||
size_t pb_encode_to_bytes(uint8_t *destbuf, size_t destbufsize, const pb_msgdesc_t *fields, const void *src_struct)
|
||||
{
|
||||
|
||||
pb_ostream_t stream = pb_ostream_from_buffer(destbuf, destbufsize);
|
||||
if (!pb_encode(&stream, fields, src_struct)) {
|
||||
//MSG("Error: can't encode protobuf %s\n", PB_GET_ERROR(&stream));
|
||||
assert(0); // FIXME - panic
|
||||
} else {
|
||||
return stream.bytes_written;
|
||||
}
|
||||
}
|
||||
|
||||
/// helper function for decoding a record as a protobuf, we will return false if the decoding failed
|
||||
bool pb_decode_from_bytes(const uint8_t *srcbuf, size_t srcbufsize, const pb_msgdesc_t *fields, void *dest_struct)
|
||||
{
|
||||
pb_istream_t stream = pb_istream_from_buffer(srcbuf, srcbufsize);
|
||||
if (!pb_decode(&stream, fields, dest_struct)) {
|
||||
//DEBUG_MSG("Error: can't decode protobuf %s, pb_msgdesc 0x%p\n", PB_GET_ERROR(&stream), fields);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/*
|
||||
/// Read from an Arduino File
|
||||
bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count)
|
||||
{
|
||||
bool status = false;
|
||||
File *file = (File *)stream->state;
|
||||
|
||||
if (buf == NULL) {
|
||||
while (count-- && file->read() != EOF)
|
||||
;
|
||||
return count == 0;
|
||||
}
|
||||
|
||||
status = (file->read(buf, count) == (int)count);
|
||||
|
||||
if (file->available() == 0)
|
||||
stream->bytes_left = 0;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/// Write to an arduino file
|
||||
bool writecb(pb_ostream_t *stream, const uint8_t *buf, size_t count)
|
||||
{
|
||||
File *file = (File *)stream->state;
|
||||
// DEBUG_MSG("writing %d bytes to protobuf file\n", count);
|
||||
return file->write(buf, count) == count;
|
||||
}
|
||||
|
||||
bool is_in_helper(uint32_t n, const uint32_t *array, pb_size_t count)
|
||||
{
|
||||
for (pb_size_t i = 0; i < count; i++)
|
||||
if (array[i] == n)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
39
src/mesh-pb-constants.h
Normal file
39
src/mesh-pb-constants.h
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "mesh.pb.h"
|
||||
|
||||
// this file defines constants which come from mesh.options
|
||||
|
||||
// Tricky macro to let you find the sizeof a type member
|
||||
#define member_size(type, member) sizeof(((type *)0)->member)
|
||||
|
||||
/// max number of packets which can be waiting for delivery to android - note, this value comes from mesh.options protobuf
|
||||
// FIXME - max_count is actually 32 but we save/load this as one long string of preencoded MeshPacket bytes - not a big array in RAM
|
||||
// #define MAX_RX_TOPHONE (member_size(DeviceState, receive_queue) / member_size(DeviceState, receive_queue[0]))
|
||||
#define MAX_RX_TOPHONE 32
|
||||
|
||||
/// max number of nodes allowed in the mesh
|
||||
#define MAX_NUM_NODES (member_size(DeviceState, node_db) / member_size(DeviceState, node_db[0]))
|
||||
|
||||
/// helper function for encoding a record as a protobuf, any failures to encode are fatal and we will panic
|
||||
/// returns the encoded packet size
|
||||
size_t pb_encode_to_bytes(uint8_t *destbuf, size_t destbufsize, const pb_msgdesc_t *fields, const void *src_struct);
|
||||
|
||||
/// helper function for decoding a record as a protobuf, we will return false if the decoding failed
|
||||
bool pb_decode_from_bytes(const uint8_t *srcbuf, size_t srcbufsize, const pb_msgdesc_t *fields, void *dest_struct);
|
||||
|
||||
/// Read from an Arduino File
|
||||
bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count);
|
||||
|
||||
/// Write to an arduino file
|
||||
bool writecb(pb_ostream_t *stream, const uint8_t *buf, size_t count);
|
||||
|
||||
/** is_in_repeated is a macro/function that returns true if a specified word appears in a repeated protobuf array.
|
||||
* It relies on the following naming conventions from nanopb:
|
||||
*
|
||||
* pb_size_t ignore_incoming_count;
|
||||
* uint32_t ignore_incoming[3];
|
||||
*/
|
||||
bool is_in_helper(uint32_t n, const uint32_t *array, pb_size_t count);
|
||||
|
||||
#define is_in_repeated(name, n) is_in_helper(n, name, name##_count)
|
64
src/mesh.pb.c
Normal file
64
src/mesh.pb.c
Normal file
@ -0,0 +1,64 @@
|
||||
/* Automatically generated nanopb constant definitions */
|
||||
/* Generated by nanopb-0.4.1 */
|
||||
|
||||
#include "mesh.pb.h"
|
||||
#if PB_PROTO_HEADER_VERSION != 40
|
||||
#error Regenerate this file with the current version of nanopb generator.
|
||||
#endif
|
||||
|
||||
PB_BIND(Position, Position, AUTO)
|
||||
|
||||
|
||||
PB_BIND(Data, Data, AUTO)
|
||||
|
||||
|
||||
PB_BIND(User, User, AUTO)
|
||||
|
||||
|
||||
PB_BIND(RouteDiscovery, RouteDiscovery, AUTO)
|
||||
|
||||
|
||||
PB_BIND(SubPacket, SubPacket, 2)
|
||||
|
||||
|
||||
PB_BIND(MeshPacket, MeshPacket, 2)
|
||||
|
||||
|
||||
PB_BIND(ChannelSettings, ChannelSettings, AUTO)
|
||||
|
||||
|
||||
PB_BIND(RadioConfig, RadioConfig, 2)
|
||||
|
||||
|
||||
PB_BIND(RadioConfig_UserPreferences, RadioConfig_UserPreferences, 2)
|
||||
|
||||
|
||||
PB_BIND(NodeInfo, NodeInfo, AUTO)
|
||||
|
||||
|
||||
PB_BIND(MyNodeInfo, MyNodeInfo, AUTO)
|
||||
|
||||
|
||||
PB_BIND(DeviceState, DeviceState, 2)
|
||||
|
||||
|
||||
PB_BIND(DebugString, DebugString, 2)
|
||||
|
||||
|
||||
PB_BIND(FromRadio, FromRadio, 2)
|
||||
|
||||
|
||||
PB_BIND(ToRadio, ToRadio, 2)
|
||||
|
||||
|
||||
PB_BIND(ManufacturingData, ManufacturingData, AUTO)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -37,6 +37,19 @@ typedef enum _RegionCode {
|
||||
RegionCode_TW = 8
|
||||
} RegionCode;
|
||||
|
||||
typedef enum _GpsOperation {
|
||||
GpsOperation_GpsOpUnset = 0,
|
||||
GpsOperation_GpsOpMobile = 2,
|
||||
GpsOperation_GpsOpTimeOnly = 3,
|
||||
GpsOperation_GpsOpDisabled = 4
|
||||
} GpsOperation;
|
||||
|
||||
typedef enum _LocationSharing {
|
||||
LocationSharing_LocUnset = 0,
|
||||
LocationSharing_LocEnabled = 1,
|
||||
LocationSharing_LocDisabled = 2
|
||||
} LocationSharing;
|
||||
|
||||
typedef enum _Data_Type {
|
||||
Data_Type_OPAQUE = 0,
|
||||
Data_Type_CLEAR_TEXT = 1,
|
||||
@ -121,6 +134,12 @@ typedef struct _RadioConfig_UserPreferences {
|
||||
char wifi_password[64];
|
||||
bool wifi_ap_mode;
|
||||
RegionCode region;
|
||||
LocationSharing location_share;
|
||||
GpsOperation gps_operation;
|
||||
uint32_t gps_update_interval;
|
||||
uint32_t gps_attempt_time;
|
||||
bool is_router;
|
||||
bool is_low_power;
|
||||
bool factory_reset;
|
||||
pb_size_t ignore_incoming_count;
|
||||
uint32_t ignore_incoming[3];
|
||||
@ -248,6 +267,14 @@ typedef struct _ToRadio {
|
||||
#define _RegionCode_MAX RegionCode_TW
|
||||
#define _RegionCode_ARRAYSIZE ((RegionCode)(RegionCode_TW+1))
|
||||
|
||||
#define _GpsOperation_MIN GpsOperation_GpsOpUnset
|
||||
#define _GpsOperation_MAX GpsOperation_GpsOpDisabled
|
||||
#define _GpsOperation_ARRAYSIZE ((GpsOperation)(GpsOperation_GpsOpDisabled+1))
|
||||
|
||||
#define _LocationSharing_MIN LocationSharing_LocUnset
|
||||
#define _LocationSharing_MAX LocationSharing_LocDisabled
|
||||
#define _LocationSharing_ARRAYSIZE ((LocationSharing)(LocationSharing_LocDisabled+1))
|
||||
|
||||
#define _Data_Type_MIN Data_Type_OPAQUE
|
||||
#define _Data_Type_MAX Data_Type_CLEAR_READACK
|
||||
#define _Data_Type_ARRAYSIZE ((Data_Type)(Data_Type_CLEAR_READACK+1))
|
||||
@ -266,7 +293,7 @@ typedef struct _ToRadio {
|
||||
#define MeshPacket_init_default {0, 0, 0, {SubPacket_init_default}, 0, 0, 0, 0, 0}
|
||||
#define ChannelSettings_init_default {0, _ChannelSettings_ModemConfig_MIN, {0, {0}}, "", 0, 0, 0, 0}
|
||||
#define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default, false, ChannelSettings_init_default}
|
||||
#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, 0, 0, {0, 0, 0}}
|
||||
#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, {0, 0, 0}}
|
||||
#define NodeInfo_init_default {0, false, User_init_default, false, Position_init_default, 0, 0}
|
||||
#define MyNodeInfo_init_default {0, 0, 0, "", "", "", 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
#define DeviceState_init_default {false, RadioConfig_init_default, false, MyNodeInfo_init_default, false, User_init_default, 0, {NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default}, 0, {MeshPacket_init_default}, false, MeshPacket_init_default, 0, 0, 0}
|
||||
@ -282,7 +309,7 @@ typedef struct _ToRadio {
|
||||
#define MeshPacket_init_zero {0, 0, 0, {SubPacket_init_zero}, 0, 0, 0, 0, 0}
|
||||
#define ChannelSettings_init_zero {0, _ChannelSettings_ModemConfig_MIN, {0, {0}}, "", 0, 0, 0, 0}
|
||||
#define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero, false, ChannelSettings_init_zero}
|
||||
#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, 0, 0, {0, 0, 0}}
|
||||
#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, {0, 0, 0}}
|
||||
#define NodeInfo_init_zero {0, false, User_init_zero, false, Position_init_zero, 0, 0}
|
||||
#define MyNodeInfo_init_zero {0, 0, 0, "", "", "", 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
#define DeviceState_init_zero {false, RadioConfig_init_zero, false, MyNodeInfo_init_zero, false, User_init_zero, 0, {NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero}, 0, {MeshPacket_init_zero}, false, MeshPacket_init_zero, 0, 0, 0}
|
||||
@ -341,7 +368,13 @@ typedef struct _ToRadio {
|
||||
#define RadioConfig_UserPreferences_wifi_password_tag 13
|
||||
#define RadioConfig_UserPreferences_wifi_ap_mode_tag 14
|
||||
#define RadioConfig_UserPreferences_region_tag 15
|
||||
#define RadioConfig_UserPreferences_is_router_tag 37
|
||||
#define RadioConfig_UserPreferences_is_low_power_tag 38
|
||||
#define RadioConfig_UserPreferences_factory_reset_tag 100
|
||||
#define RadioConfig_UserPreferences_location_share_tag 32
|
||||
#define RadioConfig_UserPreferences_gps_operation_tag 33
|
||||
#define RadioConfig_UserPreferences_gps_update_interval_tag 34
|
||||
#define RadioConfig_UserPreferences_gps_attempt_time_tag 36
|
||||
#define RadioConfig_UserPreferences_ignore_incoming_tag 103
|
||||
#define RouteDiscovery_route_tag 2
|
||||
#define User_id_tag 1
|
||||
@ -498,6 +531,12 @@ X(a, STATIC, SINGULAR, STRING, wifi_ssid, 12) \
|
||||
X(a, STATIC, SINGULAR, STRING, wifi_password, 13) \
|
||||
X(a, STATIC, SINGULAR, BOOL, wifi_ap_mode, 14) \
|
||||
X(a, STATIC, SINGULAR, UENUM, region, 15) \
|
||||
X(a, STATIC, SINGULAR, UENUM, location_share, 32) \
|
||||
X(a, STATIC, SINGULAR, UENUM, gps_operation, 33) \
|
||||
X(a, STATIC, SINGULAR, UINT32, gps_update_interval, 34) \
|
||||
X(a, STATIC, SINGULAR, UINT32, gps_attempt_time, 36) \
|
||||
X(a, STATIC, SINGULAR, BOOL, is_router, 37) \
|
||||
X(a, STATIC, SINGULAR, BOOL, is_low_power, 38) \
|
||||
X(a, STATIC, SINGULAR, BOOL, factory_reset, 100) \
|
||||
X(a, STATIC, REPEATED, UINT32, ignore_incoming, 103)
|
||||
#define RadioConfig_UserPreferences_CALLBACK NULL
|
||||
@ -635,11 +674,11 @@ extern const pb_msgdesc_t ManufacturingData_msg;
|
||||
#define SubPacket_size 274
|
||||
#define MeshPacket_size 313
|
||||
#define ChannelSettings_size 84
|
||||
#define RadioConfig_size 282
|
||||
#define RadioConfig_UserPreferences_size 193
|
||||
#define RadioConfig_size 308
|
||||
#define RadioConfig_UserPreferences_size 219
|
||||
#define NodeInfo_size 132
|
||||
#define MyNodeInfo_size 110
|
||||
#define DeviceState_size 5434
|
||||
#define DeviceState_size 5460
|
||||
#define DebugString_size 258
|
||||
#define FromRadio_size 322
|
||||
#define ToRadio_size 316
|
||||
@ -649,4 +688,4 @@ extern const pb_msgdesc_t ManufacturingData_msg;
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user