From 3b1e44a281fc4fb695a02acca19a372b16bb1934 Mon Sep 17 00:00:00 2001 From: Anol Paisal Date: Tue, 29 Mar 2022 17:27:45 +0700 Subject: [PATCH] Add arc time counter sampling periodically 1 second with red LED blink, and send data every 5 minute. --- .../SKiM980A/main.c | 40 +++++++++++-------- .../periodic-uplink-lpp/NucleoL152/main.c | 14 ++++++- src/boards/NucleoL152/CMakeLists.txt | 2 +- src/boards/SKiM980A/board.c | 2 +- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/apps/LoRaMac/periodic-uplink-lpp-counter/SKiM980A/main.c b/src/apps/LoRaMac/periodic-uplink-lpp-counter/SKiM980A/main.c index 362d33b40..9e053a58f 100644 --- a/src/apps/LoRaMac/periodic-uplink-lpp-counter/SKiM980A/main.c +++ b/src/apps/LoRaMac/periodic-uplink-lpp-counter/SKiM980A/main.c @@ -316,7 +316,7 @@ int main( void ) TimerSetValue( &Led4Timer, 25 ); TimerInit( &Led2Timer, OnLed2TimerEvent ); - TimerSetValue( &Led2Timer, 500 ); + TimerSetValue( &Led2Timer, 1000 ); TimerStart(&Led2Timer); TimerInit( &LedBeaconTimer, OnLedBeaconTimerEvent ); @@ -379,9 +379,9 @@ int main( void ) BoardLowPowerHandler( ); } - - + CRITICAL_SECTION_END( ); + } } @@ -535,7 +535,7 @@ static void PrepareTxFrame( void ) // AppData.BufferSize = CayenneLppGetSize( ); /* Test uplink WKUP and IO2 */ - + uplink_buffer[0U] = in_cnt >> 24U; uplink_buffer[1U] = in_cnt >> 16U; uplink_buffer[2U] = in_cnt >> 8U; @@ -560,7 +560,7 @@ static void PrepareTxFrame( void ) { NvmmWrite(uplink_buffer, APP_SIZE, 0x0FF8); } - + in_out_cnt = 0; } } @@ -646,6 +646,7 @@ static void OnLed4TimerEvent( void* context ) * Function executed on Led 2 Timeout event */ bool IsArc = false; + static void OnLed2TimerEvent( void* context ) { TimerStop( &Led2Timer ); @@ -654,18 +655,23 @@ static void OnLed2TimerEvent( void* context ) uint8_t potiLevel = BoardGetPotiLevel(); - if(potiLevel < 50 && !IsArc) + if(potiLevel < 75) { IsArc = true; OnIO2Event(NULL); printf("Arc lvl: %d\n", potiLevel); - } else if (potiLevel > 50 && IsArc) + + //TODO: TOGGLE LED BLINK + GpioToggle(&Io1); + + } else if (potiLevel > 75 && IsArc) { IsArc = false; printf("Arc lvl: %d\n", potiLevel); + //TODO: LED OFF + GpioWrite( &Io1, 0 ); } - - + TimerStart( &Led2Timer ); } @@ -698,22 +704,22 @@ void OnWKUPEvent(void *context) CRITICAL_SECTION_BEGIN( ); - TimerStop( &TxTimer ); + // TimerStop( &TxTimer ); IsStopMode = 1U; while (--timeout > 0x0); in_cnt++; - IsTxFramePending = 1; + // IsTxFramePending = 1; CRITICAL_SECTION_END( ) ; printf("In : %ld\n", in_cnt); // Schedule next transmission - TimerSetValue( &TxTimer, TxPeriodicity ); - TimerStart( &TxTimer ); + // TimerSetValue( &TxTimer, TxPeriodicity ); + // TimerStart( &TxTimer ); } /*! @@ -733,7 +739,7 @@ void OnIO2Event(void *context) CRITICAL_SECTION_BEGIN( ); - TimerStop( &TxTimer ); + // TimerStop( &TxTimer ); IsStopMode = 2U; // while (--timeout > 0); @@ -741,13 +747,13 @@ void OnIO2Event(void *context) in_out_cnt++; // read/write input/output - IsTxFramePending = 1; + // IsTxFramePending = 1; CRITICAL_SECTION_END( ) ; printf("In Out: %ld\n", in_out_cnt); // Schedule next transmission - TimerSetValue( &TxTimer, TxPeriodicity ); - TimerStart( &TxTimer ); + // TimerSetValue( &TxTimer, TxPeriodicity ); + // TimerStart( &TxTimer ); } \ No newline at end of file diff --git a/src/apps/LoRaMac/periodic-uplink-lpp/NucleoL152/main.c b/src/apps/LoRaMac/periodic-uplink-lpp/NucleoL152/main.c index 5002cb51b..48461c5bf 100644 --- a/src/apps/LoRaMac/periodic-uplink-lpp/NucleoL152/main.c +++ b/src/apps/LoRaMac/periodic-uplink-lpp/NucleoL152/main.c @@ -450,14 +450,26 @@ static void PrepareTxFrame( void ) uint8_t channel = 0; AppData.Port = LORAWAN_APP_PORT; - +#if 0 CayenneLppReset( ); CayenneLppAddDigitalInput( channel++, AppLedStateOn ); CayenneLppAddAnalogInput( channel++, BoardGetBatteryLevel( ) * 100 / 254 ); CayenneLppCopy( AppData.Buffer ); AppData.BufferSize = CayenneLppGetSize( ); +#else + AppData.Buffer[0] = 0x0; + AppData.Buffer[1] = 0x0; + AppData.Buffer[2] = 0x0; + AppData.Buffer[3] = 0x01; + AppData.Buffer[4] = 0x0; + AppData.Buffer[5] = 0x0; + AppData.Buffer[6] = 0x0; + AppData.Buffer[7] = 0x01; + AppData.Buffer[8] = BoardGetBatteryLevel( ) * 100 / 254; + AppData.BufferSize = 9; +#endif if( LmHandlerSend( &AppData, LmHandlerParams.IsTxConfirmed ) == LORAMAC_HANDLER_SUCCESS ) { // Switch LED 1 ON diff --git a/src/boards/NucleoL152/CMakeLists.txt b/src/boards/NucleoL152/CMakeLists.txt index 43f5880d7..c015f06e7 100644 --- a/src/boards/NucleoL152/CMakeLists.txt +++ b/src/boards/NucleoL152/CMakeLists.txt @@ -53,7 +53,7 @@ list(APPEND ${PROJECT_NAME}_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_rtc.c" "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_rtc_ex.c" "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_spi.c" - "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_spi_ex.c" + #"${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_spi_ex.c" "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_uart.c" ) diff --git a/src/boards/SKiM980A/board.c b/src/boards/SKiM980A/board.c index 4ebd42542..e296b04fa 100644 --- a/src/boards/SKiM980A/board.c +++ b/src/boards/SKiM980A/board.c @@ -267,7 +267,7 @@ void BoardGetUniqueId( uint8_t *id ) /*! * Potentiometer max and min levels definition */ -#define POTI_MAX_LEVEL 900 +#define POTI_MAX_LEVEL 3000 #define POTI_MIN_LEVEL 10 uint8_t BoardGetPotiLevel( void )