From e422a66651b405fc5e0d6545b9263f6ec5235362 Mon Sep 17 00:00:00 2001 From: Anol Paisal Date: Tue, 13 Jul 2021 19:30:52 +0700 Subject: [PATCH] Using sleep mode in GPS enable. --- src/apps/LoRaMac/common/LmHandler/LmHandler.c | 6 +++--- .../periodic-uplink-lpp/SKiM980A/main.c | 10 ++++++++-- src/boards/SKiM980A/board.c | 16 ++++++++++++++-- src/boards/SKiM980A/display-board.c | 15 +++++++++++---- src/boards/SKiM980A/gps-board.c | 11 +++++++++-- src/display/GUI/ImageData.c | 2 +- src/mac/region/RegionAS923.c | 6 +++--- src/mac/region/RegionAS923.h | 18 ------------------ 8 files changed, 49 insertions(+), 35 deletions(-) diff --git a/src/apps/LoRaMac/common/LmHandler/LmHandler.c b/src/apps/LoRaMac/common/LmHandler/LmHandler.c index 91ca41f91..a1075b7c4 100644 --- a/src/apps/LoRaMac/common/LmHandler/LmHandler.c +++ b/src/apps/LoRaMac/common/LmHandler/LmHandler.c @@ -248,14 +248,14 @@ LmHandlerErrorStatus_t LmHandlerInit( LmHandlerCallbacks_t *handlerCallbacks, IsClassBSwitchPending = false; IsUplinkTxPending = false; + // Restore data if required + nbNvmData = NvmDataMgmtRestore( ); + if( LoRaMacInitialization( &LoRaMacPrimitives, &LoRaMacCallbacks, LmHandlerParams->Region ) != LORAMAC_STATUS_OK ) { return LORAMAC_HANDLER_ERROR; } - // Restore data if required - nbNvmData = NvmDataMgmtRestore( ); - // Try to restore from NVM and query the mac if possible. if( nbNvmData > 0 ) { diff --git a/src/apps/LoRaMac/periodic-uplink-lpp/SKiM980A/main.c b/src/apps/LoRaMac/periodic-uplink-lpp/SKiM980A/main.c index 06a391e99..3be6aa57f 100644 --- a/src/apps/LoRaMac/periodic-uplink-lpp/SKiM980A/main.c +++ b/src/apps/LoRaMac/periodic-uplink-lpp/SKiM980A/main.c @@ -97,7 +97,7 @@ * LoRaWAN application port * @remark The allowed port range is from 1 up to 223. Other values are reserved. */ -#define LORAWAN_APP_PORT 3 +#define LORAWAN_APP_PORT 2 /*! * @@ -406,6 +406,12 @@ static void OnRxData( LmHandlerAppData_t* appData, LmHandlerRxParams_t* params ) #endif } break; + case 3: + OnTxPeriodicityChanged(APP_TX_DUTYCYCLE * appData->Buffer[0] & 0xFF); + break; + case 99: + BoardResetMcu(); + break; default: break; } @@ -495,7 +501,7 @@ static void PrepareTxFrame( void ) // vdd = BoardGetBatteryVoltage( ); GpsGetLatestGpsPositionDouble((double*) <, (double*) &ln); m = (float) GpsGetLatestGpsAltitude(); - CayenneLppAddDigitalInput( channel++, AppLedStateOn ); + // CayenneLppAddDigitalInput( channel++, AppLedStateOn ); CayenneLppAddAnalogInput( channel++, BoardGetBatteryLevel( ) * 100 / 254 ); // CayenneLppAddAnalogInput( channel++, potiPercentage ); // CayenneLppAddAnalogInput( channel++, vdd ); diff --git a/src/boards/SKiM980A/board.c b/src/boards/SKiM980A/board.c index ba5f0b7c4..fa0a87862 100644 --- a/src/boards/SKiM980A/board.c +++ b/src/boards/SKiM980A/board.c @@ -223,14 +223,18 @@ void BoardInitMcu( void ) GpioWrite( &Led3, 0 ); GpioWrite( &Led4, 0 ); #else - // Init GPS + // Init GPS GpsInit( ); #endif BoardUnusedIoInit( ); if( GetBoardPowerSource( ) == BATTERY_POWER ) { +#if ( USE_GPS == 0) // Disables OFF mode - Enables lowest power mode (STOP) LpmSetOffMode( LPM_APPLI_ID, LPM_DISABLE ); +#else + LpmSetStopMode( LPM_APPLI_ID, LPM_DISABLE ); +#endif } } else @@ -241,6 +245,8 @@ void BoardInitMcu( void ) #if ( USE_GPS == 0 ) AdcInit( &Adc, POTI ); #else + // Init GPS + GpsStart( ); AdcInit( &Adc, NC ); // VREF #endif @@ -271,6 +277,12 @@ void BoardDeInitMcu( void ) { Gpio_t ioPin; +#if ( USE_GPS == 0 ) + +#else + // DeInit GPS + GpsStop( ); +#endif AdcDeInit( &Adc ); SpiDeInit( &SX1272.Spi ); @@ -357,7 +369,7 @@ void BoardDisplayShow( void ) sprintf(buf, "LT:%d.%d LN:%d.%d", (int) (sPaint_gps.lat / 100000), (int)(sPaint_gps.lat % 100000), \ (int)(sPaint_gps.lon / 100000), (int)(sPaint_gps.lon % 100000)); Paint_DrawString_EN(5, 1, buf, &Font8, BLACK, WHITE); - sprintf(buf, "AT:%d F:%d", sPaint_gps.alt, sPaint_gps.fix); + sprintf(buf, "AT:%d FX:%d BT:%3d%%", sPaint_gps.alt, sPaint_gps.fix, BoardGetBatteryLevel( ) * 100 / 254); Paint_DrawString_EN(5, 1 + Font8.Height, buf, &Font8, BLACK, WHITE); sprintf(buf, "UL->PW:%d CL:%c | DR:%d", (16 - sPaint_lora.pwr), sPaint_lora.class, sPaint_lora.dr); diff --git a/src/boards/SKiM980A/display-board.c b/src/boards/SKiM980A/display-board.c index 8d57ecbc9..6b8db5a5c 100644 --- a/src/boards/SKiM980A/display-board.c +++ b/src/boards/SKiM980A/display-board.c @@ -20,6 +20,7 @@ #include "rtc-board.h" #include "display-board.h" #include "string.h" +#include "gps.h" static Gpio_t OledNrst; static Gpio_t OledKey1; @@ -58,20 +59,26 @@ void DisplayMcuOnKey1Signal( void* context ) { // Wake up if(wkup == 0) { - LpmSetOffMode( LPM_DISPLAY_ID , LPM_ENABLE ); + TimerStop(&DisplayTimer); + DisplayOff(); + GpsStop(); + + LpmSetStopMode( LPM_DISPLAY_ID , LPM_DISABLE ); wkup = 1; - TimerStop(&DisplayTimer); /*Suspend Tick increment to prevent wakeup by Systick interrupt. Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base)*/ // HAL_SuspendTick(); // LpmEnterStopMode(); } else { - LpmSetOffMode( LPM_DISPLAY_ID , LPM_DISABLE ); - wkup = 0; /* Resume Tick interrupt if disabled prior to SLEEP mode entry */ // HAL_ResumeTick(); + wkup = 0; + LpmSetStopMode( LPM_DISPLAY_ID , LPM_ENABLE ); + + GpsStart(); + DisplayInitReg(); DisplayOn(); TimerStart(&DisplayTimer); diff --git a/src/boards/SKiM980A/gps-board.c b/src/boards/SKiM980A/gps-board.c index 0c161bbb6..b74b32236 100644 --- a/src/boards/SKiM980A/gps-board.c +++ b/src/boards/SKiM980A/gps-board.c @@ -108,6 +108,7 @@ void GpsMcuInit( void ) void GpsMcuStart( void ) { + if(!GpsPowerEnInverted) { // if( GpsPowerEnInverted == true ) // { GpioWrite( &GpsPowerEn, 0 ); // power up the GPS @@ -117,21 +118,27 @@ void GpsMcuStart( void ) // { GpioWrite( &GpsPowerEn, 1 ); // power up the GPS // } + + } + UartInit( &Uart1, UART_1, GPS_UART_TX, GPS_UART_RX ); UartConfig( &Uart1, RX_ONLY, 9600, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY, NO_FLOW_CTRL ); + GpsPowerEnInverted = true; } void GpsMcuStop( void ) { // if( GpsPowerEnInverted == true ) // { - GpioWrite( &GpsPowerEn, 1 ); // power down the GPS + // GpioWrite( &GpsPowerEn, 1 ); // power down the GPS RtcDelayMs(100); // } // else // { - GpioWrite( &GpsPowerEn, 0 ); // power down the GPS + // GpioWrite( &GpsPowerEn, 0 ); // power down the GPS + // } + UartDeInit( &Uart1 ); } void GpsMcuProcess( void ) diff --git a/src/display/GUI/ImageData.c b/src/display/GUI/ImageData.c index 6f950d622..0a9532434 100644 --- a/src/display/GUI/ImageData.c +++ b/src/display/GUI/ImageData.c @@ -38,7 +38,7 @@ const unsigned char Msg816[16] = //message 0x1F,0xF8,0x10,0x08,0x18,0x18,0x14,0x28,0x13,0xC8,0x10,0x08,0x10,0x08,0x1F,0xF8 }; -const unsigned char Bat816[16] = //batery +const unsigned char Bat816[16] = //battery { 0x0F,0xFE,0x30,0x02,0x26,0xDA,0x26,0xDA,0x26,0xDA,0x26,0xDA,0x30,0x02,0x0F,0xFE }; diff --git a/src/mac/region/RegionAS923.c b/src/mac/region/RegionAS923.c index 02fd311f9..bcbb9169b 100644 --- a/src/mac/region/RegionAS923.c +++ b/src/mac/region/RegionAS923.c @@ -152,6 +152,8 @@ #undef AS923_DEFAULT_MAX_EIRP #define AS923_DEFAULT_MAX_EIRP 20.0f +#undef AS923_DEFAULT_ANTENNA_GAIN +#define AS923_DEFAULT_ANTENNA_GAIN 0.0f #endif /* @@ -964,9 +966,7 @@ LoRaMacStatus_t RegionAS923NextChannel( NextChanParams_t* nextChanParams, uint8_ if( status == LORAMAC_STATUS_OK ) { -#if ( REGION_AS923_DEFAULT_CHANNEL_PLAN == CHANNEL_PLAN_GROUP_AS923_1_JP || \ - REGION_AS923_DEFAULT_CHANNEL_PLAN == CHANNEL_PLAN_GROUP_AS923_1_TH || \ - REGION_AS923_DEFAULT_CHANNEL_PLAN == CHANNEL_PLAN_GROUP_AS923_2_TH) +#if ( REGION_AS923_DEFAULT_CHANNEL_PLAN == CHANNEL_PLAN_GROUP_AS923_1_JP ) // Executes the LBT algorithm when operating in Japan or Thailand uint8_t channelNext = 0; diff --git a/src/mac/region/RegionAS923.h b/src/mac/region/RegionAS923.h index 90104652d..b3ba03643 100644 --- a/src/mac/region/RegionAS923.h +++ b/src/mac/region/RegionAS923.h @@ -47,24 +47,6 @@ extern "C" #include "region/Region.h" -/*! - * Channel plan group AS923-1 - * AS923_FREQ_OFFSET = 0 - */ -#define CHANNEL_PLAN_GROUP_AS923_1 1 - -/*! - * Channel plan group AS923-2 - * AS923_FREQ_OFFSET = -1.8MHz - */ -#define CHANNEL_PLAN_GROUP_AS923_2 2 - -/*! - * Channel plan group AS923-3 - * AS923_FREQ_OFFSET = -6.6MHz - */ -#define CHANNEL_PLAN_GROUP_AS923_3 3 - /*! * Channel plan group AS923-1 * AS923_FREQ_OFFSET = 0