Skip to content

Commit

Permalink
Using sleep mode in GPS enable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anol Paisal committed Jul 13, 2021
1 parent 29c56bd commit e422a66
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/apps/LoRaMac/common/LmHandler/LmHandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
10 changes: 8 additions & 2 deletions src/apps/LoRaMac/periodic-uplink-lpp/SKiM980A/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*!
*
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -495,7 +501,7 @@ static void PrepareTxFrame( void )
// vdd = BoardGetBatteryVoltage( );
GpsGetLatestGpsPositionDouble((double*) &lt, (double*) &ln);
m = (float) GpsGetLatestGpsAltitude();
CayenneLppAddDigitalInput( channel++, AppLedStateOn );
// CayenneLppAddDigitalInput( channel++, AppLedStateOn );
CayenneLppAddAnalogInput( channel++, BoardGetBatteryLevel( ) * 100 / 254 );
// CayenneLppAddAnalogInput( channel++, potiPercentage );
// CayenneLppAddAnalogInput( channel++, vdd );
Expand Down
16 changes: 14 additions & 2 deletions src/boards/SKiM980A/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -241,6 +245,8 @@ void BoardInitMcu( void )
#if ( USE_GPS == 0 )
AdcInit( &Adc, POTI );
#else
// Init GPS
GpsStart( );
AdcInit( &Adc, NC ); // VREF
#endif

Expand Down Expand Up @@ -271,6 +277,12 @@ void BoardDeInitMcu( void )
{
Gpio_t ioPin;

#if ( USE_GPS == 0 )

#else
// DeInit GPS
GpsStop( );
#endif
AdcDeInit( &Adc );

SpiDeInit( &SX1272.Spi );
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 11 additions & 4 deletions src/boards/SKiM980A/display-board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions src/boards/SKiM980A/gps-board.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void GpsMcuInit( void )

void GpsMcuStart( void )
{
if(!GpsPowerEnInverted) {
// if( GpsPowerEnInverted == true )
// {
GpioWrite( &GpsPowerEn, 0 ); // power up the GPS
Expand All @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/display/GUI/ImageData.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
6 changes: 3 additions & 3 deletions src/mac/region/RegionAS923.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
Expand Down Expand Up @@ -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;

Expand Down
18 changes: 0 additions & 18 deletions src/mac/region/RegionAS923.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e422a66

Please sign in to comment.