Improved Serial Output
This commit is contained in:
parent
21bf17d0a7
commit
193dfda32a
|
@ -2,7 +2,7 @@
|
||||||
// CONFIGURATION:
|
// CONFIGURATION:
|
||||||
#define REGION RegionCode_EU865 // define your region here. For US, RegionCode_US, CN RegionCode_Cn etc.
|
#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"
|
char MESHTASTIC_NAME[12] = {"Default"}; // Channel Name, but without "-Xy" suffix , e.g. use "Test" instead of "Test-A"
|
||||||
#define MESHTASTIC_SPEED 2 // 0 = short range, 1 = medium range, 2 = long range, 3 = very long range
|
#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 TX_MAX_POWER 14 // max output power in dB, keep in mind the maximums set by law and the hardware
|
||||||
// :CONFIGURATION
|
// :CONFIGURATION
|
||||||
|
|
||||||
|
@ -32,9 +32,6 @@ typedef enum _RegionCode {
|
||||||
#define MESHTASTIC_PSK { 0x10, 0xd4, 0xf1, 0xbb, 0x3a, 0x20, 0x29, 0x07, 0x59, 0xf0, 0xbc, 0xff, 0xab, 0xcf, 0x4e, 0x69, 0xbf }
|
#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 }
|
#define PSK_NOENCRYPTION { 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||||
|
|
||||||
// sleep times @ speed 0 1 2 3
|
|
||||||
uint32_t sleepTime[] = { 77, 20, 1512, 2499 };
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t to, from, id;
|
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
|
uint8_t flags; // The bottom three bits of flags are used to store hop_limit, bit 4 is the WANT_ACK flag
|
||||||
|
@ -79,3 +76,6 @@ const RegionInfo regions[] = {
|
||||||
// freq. (921.9f is for download, others are for uplink)
|
// freq. (921.9f is for download, others are for uplink)
|
||||||
RDEF(TW, 923.0f, 0.2f, 10, 0) // TW channel settings (AS2 bandplan 923-925MHz)
|
RDEF(TW, 923.0f, 0.2f, 10, 0) // TW channel settings (AS2 bandplan 923-925MHz)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Bandwidths and CodeRate. Arrays are specific to the Radio.c of the CubeCells
|
||||||
|
const uint32_t TheBandwidths[] = { 125E3, 250E3, 500E3, 62500, 41670, 31250, 20830, 15630, 10420, 7810 };
|
|
@ -14,8 +14,7 @@ static ChannelSettings ChanSet;
|
||||||
static RadioEvents_t RadioEvents;
|
static RadioEvents_t RadioEvents;
|
||||||
static TimerEvent_t CheckRadio;
|
static TimerEvent_t CheckRadio;
|
||||||
static uint32_t lastreceivedID = 0;
|
static uint32_t lastreceivedID = 0;
|
||||||
//static uint32_t lpTime;
|
static uint32_t sleepTime;
|
||||||
static uint32_t dutyTime;
|
|
||||||
static bool noTimer;
|
static bool noTimer;
|
||||||
static uint32_t startTime = 0;
|
static uint32_t startTime = 0;
|
||||||
|
|
||||||
|
@ -90,37 +89,33 @@ void setup() {
|
||||||
ChanSet.bandwidth = 0; // 125 kHz
|
ChanSet.bandwidth = 0; // 125 kHz
|
||||||
ChanSet.coding_rate = 1; // = 4/5
|
ChanSet.coding_rate = 1; // = 4/5
|
||||||
ChanSet.spread_factor = 7;
|
ChanSet.spread_factor = 7;
|
||||||
dutyTime = 10.24; // 10 symbols
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1: { // medium range
|
case 1: { // medium range
|
||||||
ChanSet.bandwidth = 2; // 500 kHz
|
ChanSet.bandwidth = 2; // 500 kHz
|
||||||
ChanSet.coding_rate = 1; // = 4/5
|
ChanSet.coding_rate = 1; // = 4/5
|
||||||
ChanSet.spread_factor = 7;
|
ChanSet.spread_factor = 7;
|
||||||
dutyTime = 2.56;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2: { // long range
|
case 2: { // long range
|
||||||
ChanSet.bandwidth = 5; // 31.25 kHz
|
ChanSet.bandwidth = 5; // 31.25 kHz
|
||||||
ChanSet.coding_rate = 4; // = 4/8
|
ChanSet.coding_rate = 4; // = 4/8
|
||||||
ChanSet.spread_factor = 9;
|
ChanSet.spread_factor = 9;
|
||||||
dutyTime = 163.84;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 3: { // very long range
|
case 3: { // very long range
|
||||||
ChanSet.bandwidth = 0; // 125 kHz
|
ChanSet.bandwidth = 0; // 125 kHz
|
||||||
ChanSet.coding_rate = 4; // = 4/8
|
ChanSet.coding_rate = 4; // = 4/8
|
||||||
ChanSet.spread_factor = 12;
|
ChanSet.spread_factor = 12;
|
||||||
dutyTime = 327.68;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:{ // default setting is very long range
|
default:{ // default setting is very long range
|
||||||
ChanSet.bandwidth = 0; // 125 kHz
|
ChanSet.bandwidth = 0; // 125 kHz
|
||||||
ChanSet.coding_rate = 4; // = 4/8
|
ChanSet.coding_rate = 4; // = 4/8
|
||||||
ChanSet.spread_factor = 12;
|
ChanSet.spread_factor = 12;
|
||||||
dutyTime = 327.68;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sleepTime = floor( 10 * ((1<< ChanSet.spread_factor)*1000 +32) / TheBandwidths[ChanSet.bandwidth] + 0.5 );
|
||||||
ConfigureRadio( ChanSet );
|
ConfigureRadio( ChanSet );
|
||||||
#ifndef SILENT
|
#ifndef SILENT
|
||||||
MSG("..done! Switch to Receive Mode.\n");
|
MSG("..done! Switch to Receive Mode.\n");
|
||||||
|
@ -132,7 +127,10 @@ void setup() {
|
||||||
Radio.StartCad( 4 ); // length in symbols
|
Radio.StartCad( 4 ); // length in symbols
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCheckRadio(void){ noTimer=false; }
|
void onCheckRadio(void)
|
||||||
|
{
|
||||||
|
noTimer=false;
|
||||||
|
}
|
||||||
|
|
||||||
// Cycle starts @ 0 symbols. LoRA: CAD for 4 symbols, then (implicitly) Standby MCU: sleep
|
// Cycle starts @ 0 symbols. LoRA: CAD for 4 symbols, then (implicitly) Standby MCU: sleep
|
||||||
// After 10 LoRa symbols, wake up MCU and check for IRQs from LoRa (including CADdone)
|
// After 10 LoRa symbols, wake up MCU and check for IRQs from LoRa (including CADdone)
|
||||||
|
@ -143,7 +141,7 @@ void onCheckRadio(void){ noTimer=false; }
|
||||||
void loop( )
|
void loop( )
|
||||||
{
|
{
|
||||||
noTimer = true;
|
noTimer = true;
|
||||||
TimerSetValue( &CheckRadio, dutyTime ); // MCU sleeps 10 LoRa symbols
|
TimerSetValue( &CheckRadio, sleepTime ); // MCU sleeps 10 LoRa symbols
|
||||||
TimerStart( &CheckRadio ); // onCheckRadio() will set noTimer to false
|
TimerStart( &CheckRadio ); // onCheckRadio() will set noTimer to false
|
||||||
while (noTimer) lowPowerHandler( );
|
while (noTimer) lowPowerHandler( );
|
||||||
|
|
||||||
|
@ -154,11 +152,11 @@ void loop( )
|
||||||
|
|
||||||
void onCadDone( bool ChannelActive ){
|
void onCadDone( bool ChannelActive ){
|
||||||
// Rx Time = 500 * symbol time should be longer than receive time for max. packet length
|
// Rx Time = 500 * symbol time should be longer than receive time for max. packet length
|
||||||
(ChannelActive) ? Radio.Rx( dutyTime * 50 ) : Radio.Standby();
|
(ChannelActive) ? Radio.Rx( sleepTime * 50 ) : Radio.Sleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onRxTimeout( void ){
|
void onRxTimeout( void ){
|
||||||
Radio.Standby();
|
Radio.Sleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onTxDone( void )
|
void onTxDone( void )
|
||||||
|
@ -175,8 +173,7 @@ MSG(".done (%ims)! Switch to Receive Mode.\n", millis() - startTime );
|
||||||
display.drawString(42,53,str);
|
display.drawString(42,53,str);
|
||||||
display.display();
|
display.display();
|
||||||
#endif
|
#endif
|
||||||
//Radio.Rx( 0 ); // switch to receive mode
|
Radio.Sleep();
|
||||||
Radio.Standby();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onTxTimeout( void )
|
void onTxTimeout( void )
|
||||||
|
@ -193,13 +190,12 @@ void onTxTimeout( void )
|
||||||
display.drawString(42,53,str);
|
display.drawString(42,53,str);
|
||||||
display.display();
|
display.display();
|
||||||
#endif
|
#endif
|
||||||
Radio.Standby();
|
Radio.Sleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
|
void onRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
|
||||||
{
|
{
|
||||||
// if ( !(Radio.GetStatus() == RF_RX_RUNNING) ) Radio.Sleep( );
|
Radio.Sleep();
|
||||||
Radio.Sleep();
|
|
||||||
if ( size > MAX_PAYLOAD_LENGTH ) size = MAX_PAYLOAD_LENGTH;
|
if ( size > MAX_PAYLOAD_LENGTH ) size = MAX_PAYLOAD_LENGTH;
|
||||||
if ( !(size > sizeof(PacketHeader)) ) {
|
if ( !(size > sizeof(PacketHeader)) ) {
|
||||||
#ifndef SILENT
|
#ifndef SILENT
|
||||||
|
@ -279,7 +275,6 @@ void onRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
|
||||||
display.drawString(0,53,str);
|
display.drawString(0,53,str);
|
||||||
display.display();
|
display.display();
|
||||||
#endif
|
#endif
|
||||||
Radio.Standby();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,14 +292,13 @@ unsigned long hash(char *str)
|
||||||
void ConfigureRadio( ChannelSettings ChanSet )
|
void ConfigureRadio( ChannelSettings ChanSet )
|
||||||
{
|
{
|
||||||
uint32_t freq = (regions[REGION].freq + regions[REGION].spacing * ChanSet.channel_num)*1E6;
|
uint32_t freq = (regions[REGION].freq + regions[REGION].spacing * ChanSet.channel_num)*1E6;
|
||||||
|
|
||||||
#ifndef SILENT
|
#ifndef SILENT
|
||||||
MSG("\nRegion is: %s", regions[REGION].name);
|
MSG("\nRegion is: %s", regions[REGION].name);
|
||||||
MSG(" TX power: %i\n", ChanSet.tx_power);
|
MSG(" TX power: %i\n", ChanSet.tx_power);
|
||||||
MSG("Setting frequency to %i Hz (meshtastic channel %i) .. \n",freq,ChanSet.channel_num );
|
MSG("Setting frequency to %i Hz (meshtastic channel %i) .. \n",freq,ChanSet.channel_num );
|
||||||
MSG("Channel name is: %s .. \n", ChanSet.name );
|
MSG("Channel name is: '%s' .. \n", ChanSet.name );
|
||||||
MSG("Setting bandwidth to index %i ..\n",ChanSet.bandwidth);
|
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 CodeRate to index %i (4/%i).. \n", ChanSet.coding_rate, ChanSet.coding_rate + 4 );
|
||||||
MSG("Setting SpreadingFactor to %i ..\n",ChanSet.spread_factor);
|
MSG("Setting SpreadingFactor to %i ..\n",ChanSet.spread_factor);
|
||||||
#endif
|
#endif
|
||||||
Radio.SetChannel( freq );
|
Radio.SetChannel( freq );
|
||||||
|
|
Loading…
Reference in New Issue