From 52eaea7aa31dd3fc03cd45684b3bfb7ea0b0608c Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Fri, 5 Aug 2022 22:41:12 +0100 Subject: [PATCH 01/95] don't make otaa configurable at runtime revert back to making it a compile time config Update main.c --- src/apps/LoRaMac/common/LmHandler/LmHandler.c | 40 +++++++++---------- src/apps/LoRaMac/common/LmHandler/LmHandler.h | 5 --- src/apps/LoRaMac/common/LmHandlerMsgDisplay.c | 2 + .../periodic-uplink-lpp/B-L072Z-LRWAN1/main.c | 1 - 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/apps/LoRaMac/common/LmHandler/LmHandler.c b/src/apps/LoRaMac/common/LmHandler/LmHandler.c index 026aa98fb..a33598155 100644 --- a/src/apps/LoRaMac/common/LmHandler/LmHandler.c +++ b/src/apps/LoRaMac/common/LmHandler/LmHandler.c @@ -41,9 +41,9 @@ #include "LoRaMacTest.h" -CommissioningParams_t CommissioningParams = +static CommissioningParams_t CommissioningParams = { - .IsOtaaActivation = false, + .IsOtaaActivation = OVER_THE_AIR_ACTIVATION, .DevEui = { 0 }, // Automatically filed from secure-element .JoinEui = { 0 }, // Automatically filed from secure-element .SePin = { 0 }, // Automatically filed from secure-element @@ -303,31 +303,27 @@ LmHandlerErrorStatus_t LmHandlerInit( LmHandlerCallbacks_t *handlerCallbacks, LoRaMacMibGetRequestConfirm( &mibReq ); memcpy1( CommissioningParams.SePin, mibReq.Param.SePin, 4 ); - CommissioningParams.IsOtaaActivation = LmHandlerParams->is_over_the_air_activation; - - - if( LmHandlerParams->is_over_the_air_activation == false ) - { - // Tell the MAC layer which network server version are we connecting too. - mibReq.Type = MIB_ABP_LORAWAN_VERSION; - mibReq.Param.AbpLrWanVersion.Value = ABP_ACTIVATION_LRWAN_VERSION; - LoRaMacMibSetRequestConfirm( &mibReq ); +#if( OVER_THE_AIR_ACTIVATION == 0 ) + // Tell the MAC layer which network server version are we connecting too. + mibReq.Type = MIB_ABP_LORAWAN_VERSION; + mibReq.Param.AbpLrWanVersion.Value = ABP_ACTIVATION_LRWAN_VERSION; + LoRaMacMibSetRequestConfirm( &mibReq ); - mibReq.Type = MIB_NET_ID; - mibReq.Param.NetID = LORAWAN_NETWORK_ID; - LoRaMacMibSetRequestConfirm( &mibReq ); + mibReq.Type = MIB_NET_ID; + mibReq.Param.NetID = LORAWAN_NETWORK_ID; + LoRaMacMibSetRequestConfirm( &mibReq ); #if( STATIC_DEVICE_ADDRESS != 1 ) - // Random seed initialization - srand1( LmHandlerCallbacks->GetRandomSeed( ) ); - // Choose a random device address - CommissioningParams.DevAddr = randr( 0, 0x01FFFFFF ); + // Random seed initialization + srand1( LmHandlerCallbacks->GetRandomSeed( ) ); + // Choose a random device address + CommissioningParams.DevAddr = randr( 0, 0x01FFFFFF ); #endif - mibReq.Type = MIB_DEV_ADDR; - mibReq.Param.DevAddr = CommissioningParams.DevAddr; - LoRaMacMibSetRequestConfirm( &mibReq ); - } + mibReq.Type = MIB_DEV_ADDR; + mibReq.Param.DevAddr = CommissioningParams.DevAddr; + LoRaMacMibSetRequestConfirm( &mibReq ); +#endif // #if( OVER_THE_AIR_ACTIVATION == 0 ) } mibReq.Type = MIB_PUBLIC_NETWORK; mibReq.Param.EnablePublicNetwork = LmHandlerParams->PublicNetworkEnable; diff --git a/src/apps/LoRaMac/common/LmHandler/LmHandler.h b/src/apps/LoRaMac/common/LmHandler/LmHandler.h index 5a7c2aa1e..5d4b83f01 100644 --- a/src/apps/LoRaMac/common/LmHandler/LmHandler.h +++ b/src/apps/LoRaMac/common/LmHandler/LmHandler.h @@ -106,11 +106,6 @@ typedef struct LmHandlerParams_s * Application data buffer pointer */ uint8_t *DataBuffer; - /** - * Select whether to use OTAA or ABP - * - */ - bool is_over_the_air_activation; }LmHandlerParams_t; typedef struct LmHandlerCallbacks_s diff --git a/src/apps/LoRaMac/common/LmHandlerMsgDisplay.c b/src/apps/LoRaMac/common/LmHandlerMsgDisplay.c index 2bbcf83e1..0d21090c2 100644 --- a/src/apps/LoRaMac/common/LmHandlerMsgDisplay.c +++ b/src/apps/LoRaMac/common/LmHandlerMsgDisplay.c @@ -254,6 +254,7 @@ void DisplayJoinRequestUpdate( LmHandlerJoinParams_t *params ) printf( "DATA RATE : DR_%d\n\n", params->Datarate ); } } +#if ( OVER_THE_AIR_ACTIVATION == 0 ) else { printf( "###### =========== JOINED ============ ######\n" ); @@ -261,6 +262,7 @@ void DisplayJoinRequestUpdate( LmHandlerJoinParams_t *params ) printf( "DevAddr : %08lX\n", params->CommissioningParams->DevAddr ); printf( "\n\n" ); } +#endif } void DisplayTxUpdate( LmHandlerTxParams_t *params ) diff --git a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c index 9ee080a85..ba71d996a 100644 --- a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c +++ b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c @@ -115,7 +115,6 @@ static LmHandlerParams_t LmHandlerParams = .DutyCycleEnabled = LORAWAN_DUTYCYCLE_ON, .DataBufferMaxSize = LORAWAN_APP_DATA_BUFFER_MAX_SIZE, .DataBuffer = AppDataBuffer, - .is_over_the_air_activation = false, }; static LmhpComplianceParams_t LmhpComplianceParams = From 05f08f0ead04e3ac5a81455185efee5fed800a87 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Fri, 5 Aug 2022 22:45:19 +0100 Subject: [PATCH 02/95] use ABP, not OTAA --- src/apps/LoRaMac/common/Commissioning.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/apps/LoRaMac/common/Commissioning.h b/src/apps/LoRaMac/common/Commissioning.h index afec24711..ee4018ead 100644 --- a/src/apps/LoRaMac/common/Commissioning.h +++ b/src/apps/LoRaMac/common/Commissioning.h @@ -40,6 +40,7 @@ * When set to 1 the application uses the Over-the-Air activation procedure * When set to 0 the application uses the Personalization activation procedure */ +#define OVER_THE_AIR_ACTIVATION 0 /*! * When using ABP activation the MAC layer must know in advance to which server From d0cca79f1351336d15a442c4eabf516b5c48233f Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Fri, 5 Aug 2022 22:47:46 +0100 Subject: [PATCH 03/95] revert unneeded change in cmakelists --- src/system/CMakeLists.txt | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt index e93ba59ba..161676cb7 100644 --- a/src/system/CMakeLists.txt +++ b/src/system/CMakeLists.txt @@ -23,17 +23,7 @@ cmake_minimum_required(VERSION 3.6) #--------------------------------------------------------------------------------------- file(GLOB ${PROJECT_NAME}_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/adc.c" - "${CMAKE_CURRENT_SOURCE_DIR}/delay.c" - "${CMAKE_CURRENT_SOURCE_DIR}/fifo.c" - "${CMAKE_CURRENT_SOURCE_DIR}/gpio.c" - "${CMAKE_CURRENT_SOURCE_DIR}/i2c.c" - "${CMAKE_CURRENT_SOURCE_DIR}/nvmm.c" - "${CMAKE_CURRENT_SOURCE_DIR}/systime.c" - "${CMAKE_CURRENT_SOURCE_DIR}/timer.c" - "${CMAKE_CURRENT_SOURCE_DIR}/uart.c" - - # Crypto + "${CMAKE_CURRENT_SOURCE_DIR}/*.c" "${CMAKE_CURRENT_SOURCE_DIR}/crypto/*.c" ) From e50d90070a134e5ef56cd04b9e1f44fc17afc581 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Fri, 5 Aug 2022 22:55:47 +0100 Subject: [PATCH 04/95] Revert unnecessary changes in NvmDataMgmt.c Update NvmDataMgmt.c CONTEXT_MANAGEMENT_ENABLED macro added back to using CONTEXT_MANAGEMENT_ENABLED define old format Update NvmDataMgmt.c move back LoRaMacMibGetRequestConfirm() check comment change delete redundant PRINT_TIME() and PRINT() macro use old stdio import formatting only --- src/apps/LoRaMac/common/NvmDataMgmt.c | 200 ++++++++++++-------------- 1 file changed, 90 insertions(+), 110 deletions(-) diff --git a/src/apps/LoRaMac/common/NvmDataMgmt.c b/src/apps/LoRaMac/common/NvmDataMgmt.c index 259583e31..a2e69346b 100644 --- a/src/apps/LoRaMac/common/NvmDataMgmt.c +++ b/src/apps/LoRaMac/common/NvmDataMgmt.c @@ -31,12 +31,12 @@ * \author Johannes Bruder ( STACKFORCE ) */ +#include #include "nvmm.h" #include "NvmDataMgmt.h" #include "LoRaWAN_config_switcher.h" #include "secure-element.h" #include "print_utils.h" -#include "stdio.h" #include "LmHandlerMsgDisplay.h" #include "eeprom_settings_manager.h" @@ -44,138 +44,118 @@ * Enables/Disables the context storage management storage. * Must be enabled for LoRaWAN 1.0.4 or later. */ -bool context_management_enabled = true; - -#define PRINT_TIME() \ - do \ - { \ - SysTime_t time = SysTimeGet(); \ - printf("%ld.%03d: ", time.Seconds - UNIX_GPS_EPOCH_OFFSET, time.SubSeconds); \ - } while (0) - -#define PRINT(...) \ - do \ - { \ - PRINT_TIME(); \ - printf("[DBG ] "); \ - printf(__VA_ARGS__); \ - } while (0) +#ifndef CONTEXT_MANAGEMENT_ENABLED +#define CONTEXT_MANAGEMENT_ENABLED 1 +#endif static uint16_t NvmNotifyFlags = 0; -void NvmDataMgmtEvent(uint16_t notifyFlags) +void NvmDataMgmtEvent( uint16_t notifyFlags ) { NvmNotifyFlags = notifyFlags; } -uint16_t NvmDataMgmtStore(void) +uint16_t NvmDataMgmtStore( void ) { - if (context_management_enabled == true) +#if( CONTEXT_MANAGEMENT_ENABLED == 1 ) + MibRequestConfirm_t mibReq; + mibReq.Type = MIB_NVM_CTXS; + LoRaMacMibGetRequestConfirm( &mibReq ); + LoRaMacNvmData_t* nvm = mibReq.Param.Contexts; + + // Input checks + if( NvmNotifyFlags == LORAMAC_NVM_NOTIFY_FLAG_NONE ) { + // There was no update. + return 0; + } + if( LoRaMacStop( ) != LORAMAC_STATUS_OK ) + { + return 0; + } - // Input checks - if (NvmNotifyFlags == LORAMAC_NVM_NOTIFY_FLAG_NONE) - { - // There was no update. - return 0; - } - - if (LoRaMacStop() != LORAMAC_STATUS_OK) - { - return 0; - } - - // Store frame count here - - MibRequestConfirm_t mibReq; - mibReq.Type = MIB_NVM_CTXS; - LoRaMacMibGetRequestConfirm(&mibReq); - LoRaMacNvmData_t *nvm = mibReq.Param.Contexts; + // Store frame count here - // read nvm fcount for the registered device - network_keys_t current_keys; - registered_devices_t registered_device = get_current_network(); + // read nvm fcount for the registered device + network_keys_t current_keys; + registered_devices_t registered_device = get_current_network(); - read_current_keys(¤t_keys, registered_device); + read_current_keys(¤t_keys, registered_device); - /* update current mac state to be saved */ - current_keys.frame_count = nvm->Crypto.FCntList.FCntUp; - current_keys.ReceiveDelay1 = nvm->MacGroup2.MacParams.ReceiveDelay1; - current_keys.ReceiveDelay2 = nvm->MacGroup2.MacParams.ReceiveDelay2; + /* update current mac state to be saved */ + current_keys.frame_count = nvm->Crypto.FCntList.FCntUp; + current_keys.ReceiveDelay1 = nvm->MacGroup2.MacParams.ReceiveDelay1; + current_keys.ReceiveDelay2 = nvm->MacGroup2.MacParams.ReceiveDelay2; - uint16_t bytes_written = save_lorawan_keys_to_eeprom_with_CRC(¤t_keys, registered_device); + uint16_t bytes_written = save_lorawan_keys_to_eeprom_with_CRC(¤t_keys, registered_device); - printf("FNwkSIntKey_SNwkSIntKey_NwkSEncKey:"); - PrintHexBuffer(nvm->SecureElement.KeyList[S_NWK_S_INT_KEY].KeyValue, 16); - printf("\n"); + printf("FNwkSIntKey_SNwkSIntKey_NwkSEncKey:"); + PrintHexBuffer(nvm->SecureElement.KeyList[S_NWK_S_INT_KEY].KeyValue, 16); + printf("\n"); - printf("AppSKey:"); - PrintHexBuffer(nvm->SecureElement.KeyList[APP_S_KEY].KeyValue, 16); - printf("\n"); + printf("AppSKey:"); + PrintHexBuffer(nvm->SecureElement.KeyList[APP_S_KEY].KeyValue, 16); + printf("\n"); - printf("DevAddr:"); - PrintHexBuffer((uint8_t *)&nvm->MacGroup2.DevAddr, 4); - printf("\n"); + printf("DevAddr:"); + PrintHexBuffer((uint8_t *)&nvm->MacGroup2.DevAddr, 4); + printf("\n"); - // Reset notification flags - NvmNotifyFlags = LORAMAC_NVM_NOTIFY_FLAG_NONE; + // Reset notification flags + NvmNotifyFlags = LORAMAC_NVM_NOTIFY_FLAG_NONE; - // Resume LoRaMac - LoRaMacStart(); + // Resume LoRaMac + LoRaMacStart( ); - return bytes_written; - } - else - { - return 0; - } + return bytes_written; +#else + return 0; +#endif } -uint16_t NvmDataMgmtRestore(void) +uint16_t NvmDataMgmtRestore( void ) { - if (context_management_enabled == true) - { - MibRequestConfirm_t mibReq; - mibReq.Type = MIB_NVM_CTXS; - LoRaMacMibGetRequestConfirm(&mibReq); - LoRaMacNvmData_t *nvm = mibReq.Param.Contexts; - - // Read from eeprom the region/networks fcount - - // read nvm fcount for the registered device - registered_devices_t registered_device = get_current_network(); - print_registered_device(registered_device); - network_keys_t current_keys; - - uint16_t bytes_read = read_current_keys(¤t_keys, registered_device); - - /** - * Increment the Fcount in EEPROM and locally to be absolutely sure that every - * transmission increments the fcount. There could be instances when tx is done, - * but incrementation of fcount in EEPROM does not happen due to brownout. - * So to be absolutely sure, increment fcount in EEPROM during the initialisation - * phase that always happens after boot. - * - */ - current_keys.frame_count += 1; - save_lorawan_keys_to_eeprom_with_CRC(¤t_keys, registered_device); - - /* Now update the mac state. We set the frame count, dev_addr, rx1 delay and rx2 delay - * and FNwkSIntKey,SNwkSIntKey, NwkSEncKey, AppSKey. The rest we leave as default for - * this region. - */ - nvm->Crypto.FCntList.FCntUp = current_keys.frame_count; - nvm->MacGroup2.DevAddr = current_keys.DevAddr; - nvm->MacGroup2.MacParams.ReceiveDelay1 = current_keys.ReceiveDelay1; - nvm->MacGroup2.MacParams.ReceiveDelay2 = current_keys.ReceiveDelay2; - SecureElementSetKey(F_NWK_S_INT_KEY, current_keys.FNwkSIntKey_SNwkSIntKey_NwkSEncKey); - SecureElementSetKey(S_NWK_S_INT_KEY, current_keys.FNwkSIntKey_SNwkSIntKey_NwkSEncKey); - SecureElementSetKey(NWK_S_ENC_KEY, current_keys.FNwkSIntKey_SNwkSIntKey_NwkSEncKey); - SecureElementSetKey(APP_S_KEY, current_keys.AppSKey); - - return bytes_read; - } +#if( CONTEXT_MANAGEMENT_ENABLED == 1 ) + MibRequestConfirm_t mibReq; + mibReq.Type = MIB_NVM_CTXS; + LoRaMacMibGetRequestConfirm( &mibReq ); + LoRaMacNvmData_t *nvm = mibReq.Param.Contexts; + + // Read from eeprom the region/networks fcount + + // read nvm fcount for the registered device + registered_devices_t registered_device = get_current_network(); + print_registered_device(registered_device); + network_keys_t current_keys; + + uint16_t bytes_read = read_current_keys(¤t_keys, registered_device); + + /** + * Increment the Fcount in EEPROM and locally to be absolutely sure that every + * transmission increments the fcount. There could be instances when tx is done, + * but incrementation of fcount in EEPROM does not happen due to brownout. + * So to be absolutely sure, increment fcount in EEPROM during the initialisation + * phase that always happens after boot. + */ + current_keys.frame_count += 1; + save_lorawan_keys_to_eeprom_with_CRC(¤t_keys, registered_device); + + /* Now update the mac state. We set the frame count, dev_addr, rx1 delay and rx2 delay + * and FNwkSIntKey,SNwkSIntKey, NwkSEncKey, AppSKey. The rest we leave as default for + * this region. + */ + nvm->Crypto.FCntList.FCntUp = current_keys.frame_count; + nvm->MacGroup2.DevAddr = current_keys.DevAddr; + nvm->MacGroup2.MacParams.ReceiveDelay1 = current_keys.ReceiveDelay1; + nvm->MacGroup2.MacParams.ReceiveDelay2 = current_keys.ReceiveDelay2; + SecureElementSetKey(F_NWK_S_INT_KEY, current_keys.FNwkSIntKey_SNwkSIntKey_NwkSEncKey); + SecureElementSetKey(S_NWK_S_INT_KEY, current_keys.FNwkSIntKey_SNwkSIntKey_NwkSEncKey); + SecureElementSetKey(NWK_S_ENC_KEY, current_keys.FNwkSIntKey_SNwkSIntKey_NwkSEncKey); + SecureElementSetKey(APP_S_KEY, current_keys.AppSKey); + + return bytes_read; +#else return 0; +#endif } - From 0ffcb679b9c89ebb5a870b375ed7d8cf7ab0f1fd Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Fri, 5 Aug 2022 23:36:11 +0100 Subject: [PATCH 05/95] revert unnessary import --- src/apps/LoRaMac/common/NvmDataMgmt.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/apps/LoRaMac/common/NvmDataMgmt.h b/src/apps/LoRaMac/common/NvmDataMgmt.h index 15fa87e50..f50df3836 100644 --- a/src/apps/LoRaMac/common/NvmDataMgmt.h +++ b/src/apps/LoRaMac/common/NvmDataMgmt.h @@ -37,8 +37,6 @@ #ifndef __NVMDATAMGMT_H__ #define __NVMDATAMGMT_H__ -#include "LoRaWAN_config_switcher.h" - /*! * \brief NVM Management event. * From 365b4564df60d1a3620a92cbfce5ea299b61fd85 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Fri, 5 Aug 2022 23:37:06 +0100 Subject: [PATCH 06/95] delete mocking/CMakeLists.txt --- mocking/CMakeLists.txt | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 mocking/CMakeLists.txt diff --git a/mocking/CMakeLists.txt b/mocking/CMakeLists.txt deleted file mode 100644 index 10563b431..000000000 --- a/mocking/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.7) - -project(cpputest_example_pythagorean) - - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) - From eaf359774a3f22062cea62cdca2862c71f2c2893 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Fri, 5 Aug 2022 23:47:19 +0100 Subject: [PATCH 07/95] Indentation for cmake file Update toolchain-arm-none-eabi.cmake --- cmake/toolchain-arm-none-eabi.cmake | 119 ++++++++++++++-------------- 1 file changed, 58 insertions(+), 61 deletions(-) diff --git a/cmake/toolchain-arm-none-eabi.cmake b/cmake/toolchain-arm-none-eabi.cmake index 2b80b52f0..9f1ed08c3 100644 --- a/cmake/toolchain-arm-none-eabi.cmake +++ b/cmake/toolchain-arm-none-eabi.cmake @@ -20,75 +20,72 @@ ## if(NOT UNIT_TESTING) + # Append current directory to CMAKE_MODULE_PATH for making device specific cmake modules visible + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) + # Target definition + set(CMAKE_SYSTEM_NAME Generic) + set(CMAKE_SYSTEM_PROCESSOR ARM) -# Append current directory to CMAKE_MODULE_PATH for making device specific cmake modules visible -list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) - -# Target definition -set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_PROCESSOR ARM) + #--------------------------------------------------------------------------------------- + # Set toolchain paths + #--------------------------------------------------------------------------------------- + set(TOOLCHAIN arm-none-eabi) + if(NOT DEFINED TOOLCHAIN_PREFIX) + if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux) + set(TOOLCHAIN_PREFIX "/usr") + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) + set(TOOLCHAIN_PREFIX "/usr/local") + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) + message(STATUS "Please specify the TOOLCHAIN_PREFIX !\n For example: -DTOOLCHAIN_PREFIX=\"C:/Program Files/GNU Tools ARM Embedded\" ") + else() + set(TOOLCHAIN_PREFIX "/usr") + message(STATUS "No TOOLCHAIN_PREFIX specified, using default: " ${TOOLCHAIN_PREFIX}) + endif() + endif() + set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/bin) + set(TOOLCHAIN_INC_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/include) + set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/lib) -#--------------------------------------------------------------------------------------- -# Set toolchain paths -#--------------------------------------------------------------------------------------- -set(TOOLCHAIN arm-none-eabi) -if(NOT DEFINED TOOLCHAIN_PREFIX) - if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux) - set(TOOLCHAIN_PREFIX "/usr") - elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) - set(TOOLCHAIN_PREFIX "/usr/local") - elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) - message(STATUS "Please specify the TOOLCHAIN_PREFIX !\n For example: -DTOOLCHAIN_PREFIX=\"C:/Program Files/GNU Tools ARM Embedded\" ") + # Set system depended extensions + if(WIN32) + set(TOOLCHAIN_EXT ".exe" ) else() - set(TOOLCHAIN_PREFIX "/usr") - message(STATUS "No TOOLCHAIN_PREFIX specified, using default: " ${TOOLCHAIN_PREFIX}) + set(TOOLCHAIN_EXT "" ) endif() -endif() -set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/bin) -set(TOOLCHAIN_INC_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/include) -set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/lib) -# Set system depended extensions -if(WIN32) - set(TOOLCHAIN_EXT ".exe" ) -else() - set(TOOLCHAIN_EXT "" ) -endif() + # Perform compiler test with static library + set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) -# Perform compiler test with static library -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + #--------------------------------------------------------------------------------------- + # Preset some general GCC Options + #--------------------------------------------------------------------------------------- -#--------------------------------------------------------------------------------------- -# Preset some general GCC Options -#--------------------------------------------------------------------------------------- + # Options for DEBUG build + # -Og enables optimizations that do not interfere with debugging + # -g produce debugging information in the operating system’s native format + set(CMAKE_C_FLAGS_DEBUG "-Og -g -DDEBUG" CACHE INTERNAL "C Compiler options for debug build type") + set(CMAKE_CXX_FLAGS_DEBUG "-Og -g -DDEBUG" CACHE INTERNAL "C++ Compiler options for debug build type") + set(CMAKE_ASM_FLAGS_DEBUG "-g" CACHE INTERNAL "ASM Compiler options for debug build type") + set(CMAKE_EXE_LINKER_FLAGS_DEBUG "" CACHE INTERNAL "Linker options for debug build type") -# Options for DEBUG build -# -Og enables optimizations that do not interfere with debugging -# -g produce debugging information in the operating system’s native format -set(CMAKE_C_FLAGS_DEBUG "-Og -g -DDEBUG" CACHE INTERNAL "C Compiler options for debug build type") -set(CMAKE_CXX_FLAGS_DEBUG "-Og -g -DDEBUG" CACHE INTERNAL "C++ Compiler options for debug build type") -set(CMAKE_ASM_FLAGS_DEBUG "-g" CACHE INTERNAL "ASM Compiler options for debug build type") -set(CMAKE_EXE_LINKER_FLAGS_DEBUG "" CACHE INTERNAL "Linker options for debug build type") + # Options for RELEASE build + # -Os Optimize for size. -Os enables all -O2 optimizations + set(CMAKE_C_FLAGS_RELEASE "-Os" CACHE INTERNAL "C Compiler options for release build type") + set(CMAKE_CXX_FLAGS_RELEASE "-Os" CACHE INTERNAL "C++ Compiler options for release build type") + set(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "ASM Compiler options for release build type") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE INTERNAL "Linker options for release build type") -# Options for RELEASE build -# -Os Optimize for size. -Os enables all -O2 optimizations -set(CMAKE_C_FLAGS_RELEASE "-Os" CACHE INTERNAL "C Compiler options for release build type") -set(CMAKE_CXX_FLAGS_RELEASE "-Os" CACHE INTERNAL "C++ Compiler options for release build type") -set(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "ASM Compiler options for release build type") -set(CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE INTERNAL "Linker options for release build type") + #--------------------------------------------------------------------------------------- + # Set compilers + #--------------------------------------------------------------------------------------- + set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "C Compiler") + set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-g++${TOOLCHAIN_EXT} CACHE INTERNAL "C++ Compiler") + set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "ASM Compiler") -#--------------------------------------------------------------------------------------- -# Set compilers -#--------------------------------------------------------------------------------------- -set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "C Compiler") -set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-g++${TOOLCHAIN_EXT} CACHE INTERNAL "C++ Compiler") -set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "ASM Compiler") - -set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/${${TOOLCHAIN}} ${CMAKE_PREFIX_PATH}) -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) - -endif() \ No newline at end of file + set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/${${TOOLCHAIN}} ${CMAKE_PREFIX_PATH}) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) +endif() From 4f2971490224d38ac91d92287b9c9733f043c715 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Fri, 5 Aug 2022 23:47:58 +0100 Subject: [PATCH 08/95] Delete ideal_launch.json --- ideal_launch.json | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 ideal_launch.json diff --git a/ideal_launch.json b/ideal_launch.json deleted file mode 100644 index 0e1362f91..000000000 --- a/ideal_launch.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Debug-LoRaMac-periodic-uplink-lpp", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceRoot}/build/src/apps/LoRaMac/LoRaMac-periodic-uplink-lpp", - "args": [], - "stopAtEntry": true, - "cwd": "${workspaceRoot}", - "environment": [], - "externalConsole": false, - "serverLaunchTimeout": 20000, - "debugServerArgs": "-f interface/stlink-v2.cfg -f target/stm32l0_dual_bank.cfg", - "filterStderr": true, - "filterStdout": false, - "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", - "setupCommands": [ - { "text": "cd ${workspaceRoot}/build" }, - { "text": "file src/apps/LoRaMac/LoRaMac-periodic-uplink-lpp", "description": "load file", "ignoreFailures": false}, - { "text": "target extended-remote localhost:3333", "description": "connect to target", "ignoreFailures": false }, - { "text": "monitor reset halt", "description": "perform a reset and halt the target", "ignoreFailures": false }, - { "text": "load", "description": "flash target", "ignoreFailures": false }, - { "text": "monitor reset init", "description": "perform a reset and init the target", "ignoreFailures": false }, - { "text": "set output-radix 16", "description": "set the default numeric base to 16", "ignoreFailures": false } - ], - "logging": { - "moduleLoad": true, - "trace": true, - "engineLogging": true, - "programOutput": true, - "exceptions": true - }, - "MIMode": "gdb", - "miDebuggerPath": "/usr/bin/gdb-multiarch", - "debugServerPath": "/usr/bin/openocd" - } - ] -} - From d287ddaeaa152f09f5e5cf84f88c5d3e5405bc79 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Fri, 5 Aug 2022 23:53:19 +0100 Subject: [PATCH 09/95] revert back adc-board.c changes It makes no difference - adc temperature sensing is not working. --- src/boards/B-L072Z-LRWAN1/adc-board.c | 106 ++++++++++++++------------ 1 file changed, 57 insertions(+), 49 deletions(-) diff --git a/src/boards/B-L072Z-LRWAN1/adc-board.c b/src/boards/B-L072Z-LRWAN1/adc-board.c index 766743462..1c2888dcc 100644 --- a/src/boards/B-L072Z-LRWAN1/adc-board.c +++ b/src/boards/B-L072Z-LRWAN1/adc-board.c @@ -27,8 +27,6 @@ #include "adc-board.h" ADC_HandleTypeDef AdcHandle; -static bool AdcInitialized = false; - void AdcMcuInit( Adc_t *obj, PinNames adcInput ) { @@ -47,74 +45,84 @@ void AdcMcuInit( Adc_t *obj, PinNames adcInput ) void AdcMcuConfig( void ) { // Configure ADC + AdcHandle.Init.OversamplingMode = DISABLE; + AdcHandle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV1; + AdcHandle.Init.Resolution = ADC_RESOLUTION_12B; + AdcHandle.Init.SamplingTime = ADC_SAMPLETIME_160CYCLES_5; + AdcHandle.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD; + AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; + AdcHandle.Init.ContinuousConvMode = DISABLE; + AdcHandle.Init.DiscontinuousConvMode = DISABLE; + AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; + AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T6_TRGO; + AdcHandle.Init.DMAContinuousRequests = DISABLE; + AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; + AdcHandle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; + AdcHandle.Init.LowPowerAutoWait = DISABLE; + AdcHandle.Init.LowPowerFrequencyMode = DISABLE; // To be enabled only if ADC clock < 2.8 MHz + AdcHandle.Init.LowPowerAutoPowerOff = DISABLE; + HAL_ADC_Init( &AdcHandle ); + + // Calibration + HAL_ADCEx_Calibration_Start( &AdcHandle, ADC_SINGLE_ENDED ); - if (AdcInitialized == false) - { - AdcInitialized = true; - - AdcHandle.Instance = ADC1; - - AdcHandle.Init.OversamplingMode = DISABLE; - - AdcHandle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; - AdcHandle.Init.Resolution = ADC_RESOLUTION_12B; - AdcHandle.Init.SamplingTime = ADC_SAMPLETIME_160CYCLES_5; - AdcHandle.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD; - AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; - AdcHandle.Init.ContinuousConvMode = DISABLE; - AdcHandle.Init.DiscontinuousConvMode = DISABLE; - AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; - AdcHandle.Init.DMAContinuousRequests = DISABLE; - AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; - AdcHandle.Init.LowPowerAutoPowerOff = DISABLE; - AdcHandle.Init.LowPowerAutoWait = DISABLE; - AdcHandle.Init.LowPowerFrequencyMode = ENABLE; - - __HAL_RCC_ADC1_CLK_ENABLE(); - - HAL_ADC_Init(&AdcHandle); - } } uint16_t AdcMcuReadChannel( Adc_t *obj, uint32_t channel ) { ADC_ChannelConfTypeDef adcConf = { 0 }; uint16_t adcData = 0; + uint32_t tickStart = 0; + bool isAdcReady = true; - if (AdcInitialized == true) + // Enable HSI + __HAL_RCC_HSI_ENABLE( ); + + // Wait till HSI is ready + while( __HAL_RCC_GET_FLAG( RCC_FLAG_HSIRDY ) == RESET ) { - /* wait the the Vrefint used by adc is set */ - while (__HAL_PWR_GET_FLAG(PWR_FLAG_VREFINTRDY) == RESET) - { - }; + } - __HAL_RCC_ADC1_CLK_ENABLE(); + __HAL_RCC_ADC1_CLK_ENABLE( ); - /* Calibrate ADC if any calibraiton hardware. Must be called before HAL_ADC_Start() */ - HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED); + adcConf.Channel = channel; + adcConf.Rank = ADC_RANK_CHANNEL_NUMBER; + HAL_ADC_ConfigChannel( &AdcHandle, &adcConf ); - /* Deselects all channels*/ - adcConf.Channel = ADC_CHANNEL_MASK; - adcConf.Rank = ADC_RANK_NONE; - HAL_ADC_ConfigChannel( &AdcHandle, &adcConf ); + // Enable ADC1 + __HAL_ADC_ENABLE( &AdcHandle ); - /* configure adc channel */ - adcConf.Channel = channel; - adcConf.Rank = ADC_RANK_CHANNEL_NUMBER; - HAL_ADC_ConfigChannel( &AdcHandle, &adcConf ); + // Wait for ADC to effectively be enabled + tickStart = HAL_GetTick( ); + while( __HAL_ADC_GET_FLAG( &AdcHandle, ADC_FLAG_RDY ) == RESET ) + { + if( ( HAL_GetTick( ) - tickStart ) > ADC_ENABLE_TIMEOUT ) + { + isAdcReady = false; + break; + } + } - /* Start the conversion process */ + if( isAdcReady != false ) + { + // Start ADC Software Conversion HAL_ADC_Start( &AdcHandle ); - /* Wait for the end of conversion */ HAL_ADC_PollForConversion( &AdcHandle, HAL_MAX_DELAY ); - /* Get the converted value of regular channel */ adcData = HAL_ADC_GetValue( &AdcHandle ); + } - HAL_ADC_Stop( &AdcHandle ); + __HAL_ADC_DISABLE( &AdcHandle ); - __HAL_RCC_ADC1_CLK_DISABLE(); + if( ( adcConf.Channel == ADC_CHANNEL_TEMPSENSOR ) || ( adcConf.Channel == ADC_CHANNEL_VREFINT ) ) + { + HAL_ADC_DeInit( &AdcHandle ); } + __HAL_RCC_ADC1_CLK_DISABLE( ); + + // Disable HSI + __HAL_RCC_HSI_DISABLE( ); + return adcData; } From b0a2903acf0486d86f8cf1f688f89a35e9630551 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Fri, 5 Aug 2022 23:56:35 +0100 Subject: [PATCH 10/95] Delete config.c Update CMakeLists.txt --- src/peripherals/config.c | 11 ----------- tests/CMakeLists.txt | 1 - 2 files changed, 12 deletions(-) delete mode 100644 src/peripherals/config.c diff --git a/src/peripherals/config.c b/src/peripherals/config.c deleted file mode 100644 index 361502462..000000000 --- a/src/peripherals/config.c +++ /dev/null @@ -1,11 +0,0 @@ -/** - * @file config.c - * @author Medad Newman (medad@medadnewman.co.uk) - * @brief - * @version 0.1 - * @date 2021-08-13 - * - * @copyright Copyright (c) 2021 - * - */ -#include "config.h" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 505a847da..f93e7a899 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -106,7 +106,6 @@ set(MOCKS # Put in compile files(all logic so no hardware connection) set(FILES_UNDER_TEST - ${PROJECT_SOURCE_DIR}/src/peripherals/config.c ${PROJECT_SOURCE_DIR}/src/peripherals/geofence.c ${PROJECT_SOURCE_DIR}/src/peripherals/playback.c ${PROJECT_SOURCE_DIR}/src/peripherals/bsp.c From 1cc22c6277e4ebffde7fa7985b70703aa86aefa1 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 00:06:11 +0100 Subject: [PATCH 11/95] put back warning macro --- src/apps/LoRaMac/common/LmHandler/LmHandler.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/apps/LoRaMac/common/LmHandler/LmHandler.c b/src/apps/LoRaMac/common/LmHandler/LmHandler.c index a33598155..c38455487 100644 --- a/src/apps/LoRaMac/common/LmHandler/LmHandler.c +++ b/src/apps/LoRaMac/common/LmHandler/LmHandler.c @@ -37,7 +37,13 @@ #include "LmhpRemoteMcastSetup.h" #include "LmhpFragmentation.h" +#ifndef ACTIVE_REGION +#warning "No active region defined, LORAMAC_REGION_EU868 will be used as default." + +#define ACTIVE_REGION LORAMAC_REGION_EU868 + +#endif #include "LoRaMacTest.h" From 217c122ed788334f4f5ad7c8f403e17dfaf42698 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 00:33:30 +0100 Subject: [PATCH 12/95] significant simplifications and formatting of main.c Update main.c Update main.c space after control Update main.c Update main.c Update main.c Update main.c remove seperate function for init_loramac() Update main.c simplify formatting simplify to using a single timer delete all code guarded by #ifdef UNITTESTING_LORA Its not effective Update main.c Don't use break Update main.c Update main.c simplifications Update main.c Update main.c Update main.c refactoring function names for credential switch region in right place revert formatting changes in board.c revert formatting changes in main.c Update main.c Update main.c Update main.c Update main.c Update main.c Update main.c Update main.c Update main.c Update main.c Update main.c Update main.c Update main.c revert spaces formatting change Update main.c Update main.c Update main.c Update main.c Update main.c Update main.c Update main.c Update main.c Update main.c spaces move to better place Update main.c Update main.c put in function declaration for setup_next_tx_alarm() Update main.c Update main.c --- .../periodic-uplink-lpp/B-L072Z-LRWAN1/main.c | 332 +++++++----------- src/boards/B-L072Z-LRWAN1/board.c | 7 +- src/peripherals/config.h | 4 +- src/peripherals/geofence.c | 6 - src/peripherals/geofence.h | 4 - tests/mocks/main.h | 4 - 6 files changed, 135 insertions(+), 222 deletions(-) diff --git a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c index ba71d996a..2976a1056 100644 --- a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c +++ b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c @@ -34,21 +34,11 @@ #include "print_utils.h" #include "NvmDataMgmt.h" #include "RegionAS923.h" - #include "callbacks.h" #include "message_sender.h" #include "eeprom_settings_manager.h" #include "nvmm.h" -/*! - * - */ -typedef enum -{ - LORAMAC_HANDLER_TX_ON_TIMER, - LORAMAC_HANDLER_TX_ON_EVENT, -} LmHandlerTxEvents_t; - /*! * User application data */ @@ -58,71 +48,63 @@ static uint8_t AppDataBuffer[LORAWAN_APP_DATA_BUFFER_MAX_SIZE]; * User application data structure */ static LmHandlerAppData_t AppData = - { - .Buffer = AppDataBuffer, - .BufferSize = 0, - .Port = 0}; +{ + .Buffer = AppDataBuffer, + .BufferSize = 0, + .Port = 0 +}; /*! * Timer to handle the application data transmission duty cycle */ static TimerEvent_t TxTimer; -typedef enum -{ - geofence_reinit_pending, - no_issue_carry_on, -} loop_status_t; - -static void OnMacProcessNotify(void); -static void StartTxProcess(LmHandlerTxEvents_t txEvent); -static void UplinkProcess(void); -static void init_loramac(picotracker_lorawan_settings_t settings); +static void OnMacProcessNotify( void ); +static void timer_init( void ); +static void UplinkProcess( void ); +static void transmit_n_times_on_this_credential( void ); +static void setup_next_tx_alarm( uint32_t interval ); /*! * Function executed on TxTimer event */ -static void OnTxTimerEvent(void *context); - -loop_status_t run_loop_once(void); -void run_main_loop(void); -void do_n_transmissions(uint32_t n_transmissions_todo); +static void OnTxTimerEvent( void* context ); static LmHandlerCallbacks_t LmHandlerCallbacks = - { - .GetBatteryLevel = BoardGetBatteryLevel, - .GetTemperature = NULL, - .GetRandomSeed = BoardGetRandomSeed, - .OnMacProcess = OnMacProcessNotify, - .OnNvmDataChange = OnNvmDataChange, - .OnNetworkParametersChange = OnNetworkParametersChange, - .OnMacMcpsRequest = OnMacMcpsRequest, - .OnMacMlmeRequest = OnMacMlmeRequest, - .OnJoinRequest = OnJoinRequest, - .OnTxData = OnTxData, - .OnRxData = OnRxData, - .OnClassChange = OnClassChange, - .OnBeaconStatusChange = OnBeaconStatusChange, - .OnSysTimeUpdate = OnSysTimeUpdate, +{ + .GetBatteryLevel = BoardGetBatteryLevel, + .GetTemperature = NULL, + .GetRandomSeed = BoardGetRandomSeed, + .OnMacProcess = OnMacProcessNotify, + .OnNvmDataChange = OnNvmDataChange, + .OnNetworkParametersChange = OnNetworkParametersChange, + .OnMacMcpsRequest = OnMacMcpsRequest, + .OnMacMlmeRequest = OnMacMlmeRequest, + .OnJoinRequest = OnJoinRequest, + .OnTxData = OnTxData, + .OnRxData = OnRxData, + .OnClassChange= OnClassChange, + .OnBeaconStatusChange = OnBeaconStatusChange, + .OnSysTimeUpdate = OnSysTimeUpdate, }; static LmHandlerParams_t LmHandlerParams = - { - .Region = ACTIVE_REGION, - .AdrEnable = LORAWAN_ADR_STATE, - .TxDatarate = LORAWAN_DEFAULT_DATARATE, - .PublicNetworkEnable = LORAWAN_PUBLIC_NETWORK, - .DutyCycleEnabled = LORAWAN_DUTYCYCLE_ON, - .DataBufferMaxSize = LORAWAN_APP_DATA_BUFFER_MAX_SIZE, - .DataBuffer = AppDataBuffer, +{ + .Region = ACTIVE_REGION, + .AdrEnable = LORAWAN_ADR_STATE, + .TxDatarate = LORAWAN_DEFAULT_DATARATE, + .PublicNetworkEnable = LORAWAN_PUBLIC_NETWORK, + .DutyCycleEnabled = LORAWAN_DUTYCYCLE_ON, + .DataBufferMaxSize = LORAWAN_APP_DATA_BUFFER_MAX_SIZE, + .DataBuffer = AppDataBuffer }; static LmhpComplianceParams_t LmhpComplianceParams = - { - .AdrEnabled = LORAWAN_ADR_STATE, - .DutyCycleEnabled = LORAWAN_DUTYCYCLE_ON, - .StopPeripherals = NULL, - .StartPeripherals = NULL, +{ + .AdrEnabled = LORAWAN_ADR_STATE, + .DutyCycleEnabled = LORAWAN_DUTYCYCLE_ON, + .StopPeripherals = NULL, + .StartPeripherals = NULL, }; /*! @@ -131,6 +113,7 @@ static LmhpComplianceParams_t LmhpComplianceParams = * \warning If variable is equal to 0 then the MCU can be set in low power mode */ static volatile uint8_t IsMacProcessPending = 0; + static volatile uint8_t IsTxFramePending = 0; /*! @@ -138,217 +121,166 @@ static volatile uint8_t IsTxFramePending = 0; */ extern Uart_t Uart1; -#ifdef UNITTESTING_LORA -extern TimerTime_t current_time; -#endif -uint32_t tx_count = 0; -uint32_t n_tx_per_network = 1; +uint32_t tx_count_on_this_credential = 0; /*! * Main application entry point. */ -#ifndef UNITTESTING_LORA -int main(void) -#else -int run_app(void) -#endif +int main( void ) { -#if (USE_WATCHDOG) - IWDG_Init(); +#if( USE_WATCHDOG ) + IWDG_Init( ); #endif - setup_board(); + setup_board( ); #if PRINT_EEPROM_DEBUG - printf("Dumping EEPROM:\n"); - EEPROM_Dump(); - printf("\n"); + printf( "Dumping EEPROM:\n" ); + EEPROM_Dump( ); + printf( "\n" ); #endif - run_main_loop(); -} + /* Initialise timer */ + timer_init( ); -void run_main_loop() -{ - /* Start up periodic timer for sending uplinks */ - StartTxProcess(LORAMAC_HANDLER_TX_ON_TIMER); + /* Transmit immediately (10 milliseconds later) */ + setup_next_tx_alarm( 10 ); - while (1) + while( 1 ) { - do_n_transmissions(N_TRANMISSIONS_PER_NETWORK + 1); // do 2 transmissions on the same network + switch_to_next_registered_credentials( ); // Switch to the next set of + // credentials + transmit_n_times_on_this_credential( ); // do 2 transmissions on the + // same credential } } -void do_n_transmissions(uint32_t n_transmissions_todo) +static void transmit_n_times_on_this_credential( void ) { - n_tx_per_network = n_transmissions_todo; - - switch_to_next_registered_credentials(); // Credentials have been set. So now tell it that next time credentials are called for, use the next set. - - print_current_region(); - picotracker_lorawan_settings_t settings = get_lorawan_setting(get_current_loramac_region()); + print_current_region( ); - init_loramac(settings); + /* Configure the subband settings for AS923 BEFORE initing it. Only needed + * to be done for AS923 - does not do anything for other regions */ + as923_subbands_t current_subband = get_as923_subband( ); + set_as923_region_specific_frequencies( current_subband ); - LmHandlerJoin(); - - IWDG_reset(); + /* Set region and datarate */ + LoRaMacRegion_t current_loramac_region = get_current_loramac_region( ); + picotracker_lorawan_settings_t settings = get_lorawan_setting( current_loramac_region ); + LmHandlerParams.Region = current_loramac_region; + LmHandlerParams.TxDatarate = settings.datarate; - tx_count = 0; - while (1) + if ( LmHandlerInit( &LmHandlerCallbacks, &LmHandlerParams ) != LORAMAC_HANDLER_SUCCESS ) { - run_loop_once(); - - if (tx_count > n_transmissions_todo) + printf( "LoRaMac wasn't properly initialized\n" ); + // Fatal error, endless loop. + while ( 1 ) { - break; } } -} -loop_status_t run_loop_once() -{ -#ifdef UNITTESTING_LORA - current_time += 1; /* simulate 1 millisecond per loop */ + // Set system maximum tolerated rx error in milliseconds + LmHandlerSetSystemMaxRxError( 500 ); - TimerIrqHandler(); -#endif + // The LoRa-Alliance Compliance protocol package should always be + // initialized and activated. + LmHandlerPackageRegister( PACKAGE_ID_COMPLIANCE, &LmhpComplianceParams ); - // Process characters sent over the command line interface - CliProcess(&Uart1); + LmHandlerJoin( ); - // Processes the LoRaMac events - LmHandlerProcess(); + IWDG_reset( ); - // Process application uplinks management - UplinkProcess(); + tx_count_on_this_credential = 0; // reset tx count for this network back to 0. - CRITICAL_SECTION_BEGIN(); - if (IsMacProcessPending == 1) - { - // Clear flag and prevent MCU to go into low power modes. - IsMacProcessPending = 0; - } - else + while( tx_count_on_this_credential <= N_TRANMISSIONS_PER_CREDENTIAL ) { - // The MCU wakes up through events - BoardLowPowerHandler(); - } - CRITICAL_SECTION_END(); + // Process characters sent over the command line interface + CliProcess( &Uart1 ); - return no_issue_carry_on; -} - -static void init_loramac(picotracker_lorawan_settings_t settings) -{ - - /* Set region and datarate */ + // Processes the LoRaMac events + LmHandlerProcess( ); - /* Configure the subband settings for AS923 BEFORE initing it */ - set_as923_region_specific_frequencies(get_as923_subband()); + // Process application uplinks management + UplinkProcess( ); - LmHandlerParams.Region = get_current_loramac_region(); - LmHandlerParams.TxDatarate = settings.datarate; - - if (LmHandlerInit(&LmHandlerCallbacks, &LmHandlerParams) != LORAMAC_HANDLER_SUCCESS) - { - printf("LoRaMac wasn't properly initialized\n"); - // Fatal error, endless loop. - while (1) + CRITICAL_SECTION_BEGIN( ); + if( IsMacProcessPending == 1 ) + { + // Clear flag and prevent MCU to go into low power modes. + IsMacProcessPending = 0; + } + else { + // The MCU wakes up through events + BoardLowPowerHandler( ); } + CRITICAL_SECTION_END( ); } - - // Set system maximum tolerated rx error in milliseconds - LmHandlerSetSystemMaxRxError(500); - - // The LoRa-Alliance Compliance protocol package should always be - // initialized and activated. - LmHandlerPackageRegister(PACKAGE_ID_COMPLIANCE, &LmhpComplianceParams); } -static void OnMacProcessNotify(void) +static void OnMacProcessNotify( void ) { IsMacProcessPending = 1; } -void setup_next_tx_alarm(uint32_t interval) -{ - IWDG_reset(); - TimerStop(&TxTimer); /* Stop tx timer. Requirement before starting it back up again */ - TimerSetValue(&TxTimer, interval); - TimerStart(&TxTimer); /* Restart tx interval timer */ -} - /*! * Prepares the payload of the frame and transmits it. */ -static void PrepareTxFrame(void) +static void PrepareTxFrame( void ) { - IWDG_reset(); + IWDG_reset( ); - if (LmHandlerIsBusy() == true) + if( LmHandlerIsBusy( ) == true ) { return; } - tx_count++; - - if (tx_count < n_tx_per_network) - { - sensor_read_and_send(&AppData, LmHandlerParams.Region); - setup_next_tx_alarm(read_tx_interval_in_eeprom(TX_INTERVAL_EEPROM_ADDRESS, TX_INTERVAL_GPS_FIX_OK)); - } - else - { - setup_next_tx_alarm(10); - } + tx_count_on_this_credential ++; + sensor_read_and_send( &AppData, LmHandlerParams.Region ); + uint32_t interval = read_tx_interval_in_eeprom( TX_INTERVAL_EEPROM_ADDRESS, + TX_INTERVAL_GPS_FIX_OK ); + setup_next_tx_alarm( interval ); } -static void StartTxProcess(LmHandlerTxEvents_t txEvent) -{ - switch (txEvent) - { - default: - // Intentional fall through - case LORAMAC_HANDLER_TX_ON_TIMER: - { - // Schedule 1st packet transmission - TimerInit(&TxTimer, OnTxTimerEvent); - TimerStop(&TxTimer); - IsTxFramePending = 1; - } - break; - case LORAMAC_HANDLER_TX_ON_EVENT: - { - } - break; - } -} - -static void UplinkProcess(void) +static void UplinkProcess( void ) { uint8_t isPending = 0; - CRITICAL_SECTION_BEGIN(); + CRITICAL_SECTION_BEGIN( ); isPending = IsTxFramePending; IsTxFramePending = 0; - CRITICAL_SECTION_END(); - if (isPending == 1) + CRITICAL_SECTION_END( ); + if( isPending == 1 ) { - IWDG_reset(); - PrepareTxFrame(); - IWDG_reset(); + IWDG_reset( ); + PrepareTxFrame( ); + IWDG_reset( ); } } /*! * Function executed on TxTimer event */ -static void OnTxTimerEvent(void *context) +static void OnTxTimerEvent( void* context ) { - IWDG_reset(); - TimerStop(&TxTimer); + IWDG_reset( ); + TimerStop( &TxTimer ); // stop the timer now - it will be restarted after a + // tranmission has been completed. IsTxFramePending = 1; } + +static void setup_next_tx_alarm( uint32_t interval ) +{ + IWDG_reset( ); + TimerStop( &TxTimer ); /* Stop tx timer. Requirement before starting it back + up again */ + TimerSetValue( &TxTimer, interval ); + TimerStart( &TxTimer ); /* Restart tx interval timer */ +} + +static void timer_init( ) +{ + TimerInit( &TxTimer, OnTxTimerEvent ); + TimerStop( &TxTimer ); +} diff --git a/src/boards/B-L072Z-LRWAN1/board.c b/src/boards/B-L072Z-LRWAN1/board.c index 8d40ada91..8a1ac6c76 100644 --- a/src/boards/B-L072Z-LRWAN1/board.c +++ b/src/boards/B-L072Z-LRWAN1/board.c @@ -166,8 +166,6 @@ void BoardInitMcu( void ) if( McuInitialized == false ) { HAL_Init( ); - - // LEDs GpioInit( &Led1, LED_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); @@ -230,7 +228,6 @@ void BoardInitMcu( void ) } } - void BoardResetMcu( void ) { CRITICAL_SECTION_BEGIN( ); @@ -267,7 +264,7 @@ uint16_t BoardBatteryMeasureVoltage( void ) return 0; } -uint32_t BoardGetBatteryVoltage(void) +uint32_t BoardGetBatteryVoltage( void ) { uint16_t nVrefIntLevel = AdcReadChannel(&Adc, ADC_CHANNEL_VREFINT); return __LL_ADC_CALC_VREFANALOG_VOLTAGE(nVrefIntLevel, LL_ADC_RESOLUTION_12B); @@ -285,8 +282,6 @@ int32_t HW_GetTemperatureLevel_int(void) return __LL_ADC_CALC_TEMPERATURE(Vdd_mV, temp_sensor_adc_value, LL_ADC_RESOLUTION_12B); } - - uint8_t BoardGetBatteryLevel( void ) { return 0; diff --git a/src/peripherals/config.h b/src/peripherals/config.h index d1a587a0d..f8cee4d53 100644 --- a/src/peripherals/config.h +++ b/src/peripherals/config.h @@ -111,10 +111,10 @@ extern "C" #define N_POSITIONS_TO_PRINTOUT 30 /** - * @brief Number of transmissions to do per network + * @brief Number of transmissions to do per credential * */ -#define N_TRANMISSIONS_PER_NETWORK 2 +#define N_TRANMISSIONS_PER_CREDENTIAL 2 /** * @brief Define how quickly to return to searching for a GPS fix after transmitting diff --git a/src/peripherals/geofence.c b/src/peripherals/geofence.c index c18a07398..b5c4f5d51 100644 --- a/src/peripherals/geofence.c +++ b/src/peripherals/geofence.c @@ -828,12 +828,6 @@ Polygon_t get_polygon(float latitude, float longitude); /* Functions definitions go here, organised into sections */ -#ifdef UNITTESTING_LORA -uint32_t get_n_polygons() -{ - return (uint32_t)n_polygons; -} -#endif // Strategy: check if GPS coordinate is in any of the polygons. If so, look up what transmit frequency it uses. diff --git a/src/peripherals/geofence.h b/src/peripherals/geofence.h index 95d24fad0..b0367d006 100644 --- a/src/peripherals/geofence.h +++ b/src/peripherals/geofence.h @@ -69,10 +69,6 @@ extern "C" void set_current_loramac_region(LoRaMacRegion_t region); tx_permission_t get_current_tx_permission(void); -#ifdef UNITTESTING_LORA - uint32_t get_n_polygons(); -#endif - #endif #ifdef __cplusplus } diff --git a/tests/mocks/main.h b/tests/mocks/main.h index 52c0c1cba..acefd24b9 100644 --- a/tests/mocks/main.h +++ b/tests/mocks/main.h @@ -20,11 +20,7 @@ extern "C" #include "LmHandler.h" -#ifdef UNITTESTING_LORA - int run_app(void); - void do_n_transmissions(uint32_t n_transmissions_todo); -#endif #ifdef __cplusplus } From 7b35e1eb9c9203e0f62f97354a89c2b161d3f915 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 17:43:57 +0100 Subject: [PATCH 13/95] delete mocking cmake --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 37b944c41..f02280a5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,6 @@ if(UNIT_TESTING) picotracker_lora_tests EXCLUDE "build/_deps*" "/usr/include/c++/*" # Patterns to exclude (can be relative ) - add_subdirectory(mocking) add_subdirectory(tests) else() message(STATUS ">>> Compiling for target") From ae7804f4bb25a5ac924b25024f8b066979731ea4 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 17:45:30 +0100 Subject: [PATCH 14/95] delete references to context_management_enabled variable --- tests/LoRaWAN_config_switcher_ut.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/tests/LoRaWAN_config_switcher_ut.cpp b/tests/LoRaWAN_config_switcher_ut.cpp index 8da36c2e5..b933c8729 100644 --- a/tests/LoRaWAN_config_switcher_ut.cpp +++ b/tests/LoRaWAN_config_switcher_ut.cpp @@ -9,8 +9,6 @@ extern "C" #include "stdint.h" -extern bool context_management_enabled; - void run_stout_test(void); TEST_GROUP(config_switcher_tests){ @@ -33,19 +31,15 @@ TEST(config_switcher_tests, test_eu868_4_tx) setting = get_lorawan_setting(target_region); CHECK_EQUAL(expected_dr, setting.datarate); - CHECK_EQUAL(true, context_management_enabled); setting = get_lorawan_setting(target_region); CHECK_EQUAL(expected_dr, setting.datarate); - CHECK_EQUAL(true, context_management_enabled); setting = get_lorawan_setting(target_region); CHECK_EQUAL(expected_dr, setting.datarate); - CHECK_EQUAL(true, context_management_enabled); setting = get_lorawan_setting(target_region); CHECK_EQUAL(expected_dr, setting.datarate); - CHECK_EQUAL(true, context_management_enabled); } TEST(config_switcher_tests, test_us915_4_tx) @@ -57,19 +51,15 @@ TEST(config_switcher_tests, test_us915_4_tx) setting = get_lorawan_setting(target_region); CHECK_EQUAL(expected_dr, setting.datarate); - CHECK_EQUAL(true, context_management_enabled); setting = get_lorawan_setting(target_region); CHECK_EQUAL(expected_dr, setting.datarate); - CHECK_EQUAL(true, context_management_enabled); setting = get_lorawan_setting(target_region); CHECK_EQUAL(expected_dr, setting.datarate); - CHECK_EQUAL(true, context_management_enabled); setting = get_lorawan_setting(target_region); CHECK_EQUAL(expected_dr, setting.datarate); - CHECK_EQUAL(true, context_management_enabled); } TEST(config_switcher_tests, test_as923_4_tx) @@ -81,17 +71,13 @@ TEST(config_switcher_tests, test_as923_4_tx) setting = get_lorawan_setting(target_region); CHECK_EQUAL(expected_dr, setting.datarate); - CHECK_EQUAL(true, context_management_enabled); setting = get_lorawan_setting(target_region); CHECK_EQUAL(expected_dr, setting.datarate); - CHECK_EQUAL(true, context_management_enabled); setting = get_lorawan_setting(target_region); CHECK_EQUAL(expected_dr, setting.datarate); - CHECK_EQUAL(true, context_management_enabled); setting = get_lorawan_setting(target_region); CHECK_EQUAL(expected_dr, setting.datarate); - CHECK_EQUAL(true, context_management_enabled); } From aef758576781dc0ee599dbdee5b4b8edaf033832 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 17:45:53 +0100 Subject: [PATCH 15/95] don't build target main.c for unittests Then you have 2 main() functions otherwise --- tests/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f93e7a899..90c12e206 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -115,7 +115,6 @@ set(FILES_UNDER_TEST ${PROJECT_SOURCE_DIR}/src/peripherals/LoRaWAN_config_switcher.c ${PROJECT_SOURCE_DIR}/src/peripherals/linear_congruential_generator.c ${PROJECT_SOURCE_DIR}/src/peripherals/eeprom_settings_manager.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandlerMsgDisplay.c ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/LmHandler.c ${PROJECT_SOURCE_DIR}/src/system/delay.c From 3f2d7c0e00c31d70a14b2366c6c577db4b0cdf4d Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 17:48:17 +0100 Subject: [PATCH 16/95] delete ref to do_n_transmissions() in uniitest Its a static, internal function --- tests/message_sender_ut.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/message_sender_ut.cpp b/tests/message_sender_ut.cpp index 81427df3e..15ab1b238 100644 --- a/tests/message_sender_ut.cpp +++ b/tests/message_sender_ut.cpp @@ -44,7 +44,6 @@ void setup_test() { mock().expectNCalls(12, "get_latest_gps_info").andReturnValue(&gps_info_mock_message); BSP_sensor_Init(); - do_n_transmissions(2); } /** * @brief Test if it transmits when loramac region correctly set From 0530315519b064efa6b61b79ab48db4e5a16484a Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 17:50:22 +0100 Subject: [PATCH 17/95] put back check for n polygons --- src/peripherals/geofence.c | 6 ++++++ src/peripherals/geofence.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/peripherals/geofence.c b/src/peripherals/geofence.c index b5c4f5d51..c18a07398 100644 --- a/src/peripherals/geofence.c +++ b/src/peripherals/geofence.c @@ -828,6 +828,12 @@ Polygon_t get_polygon(float latitude, float longitude); /* Functions definitions go here, organised into sections */ +#ifdef UNITTESTING_LORA +uint32_t get_n_polygons() +{ + return (uint32_t)n_polygons; +} +#endif // Strategy: check if GPS coordinate is in any of the polygons. If so, look up what transmit frequency it uses. diff --git a/src/peripherals/geofence.h b/src/peripherals/geofence.h index b0367d006..95d24fad0 100644 --- a/src/peripherals/geofence.h +++ b/src/peripherals/geofence.h @@ -69,6 +69,10 @@ extern "C" void set_current_loramac_region(LoRaMacRegion_t region); tx_permission_t get_current_tx_permission(void); +#ifdef UNITTESTING_LORA + uint32_t get_n_polygons(); +#endif + #endif #ifdef __cplusplus } From c407b891fdaa1ea8dd13dc7a8a15284f9b4cc1ec Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 19:01:59 +0100 Subject: [PATCH 18/95] remove mock imports from where its not needed --- tests/bsp_mock.cpp | 1 - tests/eeprom-board-mock.cpp | 1 - tests/timer-mock.cpp | 1 - 3 files changed, 3 deletions(-) diff --git a/tests/bsp_mock.cpp b/tests/bsp_mock.cpp index 0e07a0079..2ba583745 100644 --- a/tests/bsp_mock.cpp +++ b/tests/bsp_mock.cpp @@ -1,4 +1,3 @@ -#include "CppUTestExt/MockSupport.h" extern "C" { diff --git a/tests/eeprom-board-mock.cpp b/tests/eeprom-board-mock.cpp index 6a4f6ef2a..806071830 100644 --- a/tests/eeprom-board-mock.cpp +++ b/tests/eeprom-board-mock.cpp @@ -23,7 +23,6 @@ * Modified by Medad Newman for unittesting */ -#include "CppUTestExt/MockSupport.h" extern "C" { diff --git a/tests/timer-mock.cpp b/tests/timer-mock.cpp index 2ac1a4cda..25e306c78 100644 --- a/tests/timer-mock.cpp +++ b/tests/timer-mock.cpp @@ -26,7 +26,6 @@ * to timers. It calls the call back of each timer when it expires. */ -#include "CppUTestExt/MockSupport.h" #include /*! From 90aa7c5c3258964f60e2c6eb30d25f6ed1ccc5a0 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 19:02:19 +0100 Subject: [PATCH 19/95] integration test executable --- tests/CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 90c12e206..8eb249410 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -187,3 +187,12 @@ target_link_options(picotracker_lora_tests PRIVATE -m32) # Add tests add_test(picotracker_lora_tests picotracker_lora_tests -p) # Pass option to run CppUTests all on different threads + + + +set(INTEGRATION_TEST_SOURCE_FILES + ${MOCKS} + ${FILES_UNDER_TEST} +) +add_executable(picotracker_lora_integration_tests ${INTEGRATION_TEST_SOURCE_FILES}) + From 0cd7c92d5eff8f94c540d4a4525737c0712ba3e3 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 19:06:28 +0100 Subject: [PATCH 20/95] get rid of mocks from gps --- tests/gps_mock_utils.cpp | 3 --- tests/ublox-mock.cpp | 5 ++--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/gps_mock_utils.cpp b/tests/gps_mock_utils.cpp index dcafc6966..d4a4abf75 100644 --- a/tests/gps_mock_utils.cpp +++ b/tests/gps_mock_utils.cpp @@ -9,9 +9,6 @@ * */ -#include "CppUTest/TestHarness.h" -#include "CppUTestExt/MockSupport.h" - extern "C" { #include "ublox.h" diff --git a/tests/ublox-mock.cpp b/tests/ublox-mock.cpp index 88fa44e67..2fffe4c6c 100644 --- a/tests/ublox-mock.cpp +++ b/tests/ublox-mock.cpp @@ -1,4 +1,3 @@ -#include "CppUTestExt/MockSupport.h" extern "C" { @@ -29,8 +28,8 @@ uint16_t get_load_solar_voltage() gps_info_t get_latest_gps_info() { - auto returnValue = mock().actualCall(__func__).returnPointerValue(); - return *(gps_info_t *)(returnValue); + gps_info_t gps_info; + return gps_info; } gps_status_t get_latest_gps_status(void) From 93f7bc3d7448f9b76ae54de5c2d293d18cc227f9 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 19:07:03 +0100 Subject: [PATCH 21/95] just builds --- tests/CMakeLists.txt | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8eb249410..31b1d5a9b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -94,7 +94,6 @@ set(MOCKS systime-mock.cpp ublox-mock.cpp nvm_images.cpp - gps_mock_utils.cpp delay-board-mock.c gpio_mock.c ) @@ -119,6 +118,7 @@ set(FILES_UNDER_TEST ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/LmHandler.c ${PROJECT_SOURCE_DIR}/src/system/delay.c ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/callbacks.c + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c @@ -175,20 +175,6 @@ set(SOURCE_FILES ${FILES_UNDER_TEST} ) -add_executable(picotracker_lora_tests ${SOURCE_FILES}) -target_compile_options(picotracker_lora_tests PRIVATE -fshort-enums) -# target_compile_options(picotracker_lora_tests PRIVATE -Wall -Wextra -Wpedantic) -target_link_libraries(picotracker_lora_tests PRIVATE CppUTest CppUTestExt) - - -# only build 32-bit binaries -target_compile_options(picotracker_lora_tests PRIVATE -m32) -target_link_options(picotracker_lora_tests PRIVATE -m32) - -# Add tests -add_test(picotracker_lora_tests picotracker_lora_tests -p) # Pass option to run CppUTests all on different threads - - set(INTEGRATION_TEST_SOURCE_FILES ${MOCKS} @@ -196,3 +182,7 @@ set(INTEGRATION_TEST_SOURCE_FILES ) add_executable(picotracker_lora_integration_tests ${INTEGRATION_TEST_SOURCE_FILES}) +# only build 32-bit binaries +target_compile_options(picotracker_lora_integration_tests PRIVATE -m32) +target_link_options(picotracker_lora_integration_tests PRIVATE -m32) + From 286177a6afa14a70dc94fac9b064f1f79a1b4a5c Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 19:14:18 +0100 Subject: [PATCH 22/95] add back in our way of incrementing time. --- src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c index 2976a1056..9e35018f5 100644 --- a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c +++ b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c @@ -121,6 +121,9 @@ static volatile uint8_t IsTxFramePending = 0; */ extern Uart_t Uart1; +#ifdef UNITTESTING_LORA +extern TimerTime_t current_time; +#endif uint32_t tx_count_on_this_credential = 0; @@ -195,6 +198,10 @@ static void transmit_n_times_on_this_credential( void ) while( tx_count_on_this_credential <= N_TRANMISSIONS_PER_CREDENTIAL ) { +#ifdef UNITTESTING_LORA + current_time += 1; /* simulate 1 millisecond per loop */ + TimerIrqHandler(); +#endif // Process characters sent over the command line interface CliProcess( &Uart1 ); From 9e4a299586948e828bafd54ca6b8707a835c9bd0 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 19:18:29 +0100 Subject: [PATCH 23/95] [bugfix] Fix correct count of txs on credential --- src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c index 9e35018f5..4bdd71e36 100644 --- a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c +++ b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c @@ -196,7 +196,7 @@ static void transmit_n_times_on_this_credential( void ) tx_count_on_this_credential = 0; // reset tx count for this network back to 0. - while( tx_count_on_this_credential <= N_TRANMISSIONS_PER_CREDENTIAL ) + while( tx_count_on_this_credential < N_TRANMISSIONS_PER_CREDENTIAL ) { #ifdef UNITTESTING_LORA current_time += 1; /* simulate 1 millisecond per loop */ From c068fa75be1a1c3f015c5ce5eefa82bed7b1d180 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 19:18:29 +0100 Subject: [PATCH 24/95] [bugfix] Fix correct count of txs on credential --- src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c index 2976a1056..5e7e67b4b 100644 --- a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c +++ b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c @@ -193,7 +193,7 @@ static void transmit_n_times_on_this_credential( void ) tx_count_on_this_credential = 0; // reset tx count for this network back to 0. - while( tx_count_on_this_credential <= N_TRANMISSIONS_PER_CREDENTIAL ) + while( tx_count_on_this_credential < N_TRANMISSIONS_PER_CREDENTIAL ) { // Process characters sent over the command line interface CliProcess( &Uart1 ); From 5c3154140ce9e0fe2af493bab1ea16923dfc9d99 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 22:08:09 +0100 Subject: [PATCH 25/95] return dummy gps info Update ublox-mock.cpp --- tests/ublox-mock.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/ublox-mock.cpp b/tests/ublox-mock.cpp index 2fffe4c6c..0ebb0bdf3 100644 --- a/tests/ublox-mock.cpp +++ b/tests/ublox-mock.cpp @@ -4,6 +4,10 @@ extern "C" #include "ublox.h" } +gps_info_t dummy_gps_info = { + .GPS_UBX_latitude_Float = 1.290270, + .GPS_UBX_longitude_Float = 103.851959 +}; gps_status_t get_location_fix(uint32_t timeout) @@ -28,8 +32,7 @@ uint16_t get_load_solar_voltage() gps_info_t get_latest_gps_info() { - gps_info_t gps_info; - return gps_info; + return dummy_gps_info; } gps_status_t get_latest_gps_status(void) From 8061bd3a1088c0bccd3e960488a9b8f7bca1724d Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 22:45:16 +0100 Subject: [PATCH 26/95] need max of 20 timers Update timer-mock.cpp --- tests/timer-mock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/timer-mock.cpp b/tests/timer-mock.cpp index 25e306c78..583b3e174 100644 --- a/tests/timer-mock.cpp +++ b/tests/timer-mock.cpp @@ -54,7 +54,7 @@ extern "C" */ TimerTime_t current_time = 0; -TimerEvent_t *list_of_timer_event_pointers[100000]; /* There won't be more than 100 timers in the project */ +TimerEvent_t *list_of_timer_event_pointers[10]; /* There won't be more than 10 timers in the project */ int number_of_timers = 0; void TimerInit(TimerEvent_t *obj, void (*callback)(void *context)) From ba832189bf19f830508e70549595e60a0f62f387 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 23:21:06 +0100 Subject: [PATCH 27/95] use more of the original timer implementation --- tests/timer-mock.cpp | 311 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 262 insertions(+), 49 deletions(-) diff --git a/tests/timer-mock.cpp b/tests/timer-mock.cpp index 583b3e174..74493c58f 100644 --- a/tests/timer-mock.cpp +++ b/tests/timer-mock.cpp @@ -19,14 +19,11 @@ * \author Miguel Luis ( Semtech ) * * \author Gregory Cristian ( Semtech ) - * - * \author Modified for mocking by Medad Newman - * - * This file implements a mock of the timer.c file, using a c++ list to hold all pointers - * to timers. It calls the call back of each timer when it expires. */ - -#include +#include "utilities.h" +#include "board.h" +#include "rtc-board.h" +#include "timer.h" /*! * Safely execute call back @@ -45,17 +42,49 @@ } \ } while (0); -extern "C" -{ -#include "timer.h" -} +TimerTime_t current_time = 0; + /*! * Timers list head pointer */ -TimerTime_t current_time = 0; +static TimerEvent_t *TimerListHead = NULL; -TimerEvent_t *list_of_timer_event_pointers[10]; /* There won't be more than 10 timers in the project */ -int number_of_timers = 0; +/*! + * \brief Adds or replace the head timer of the list. + * + * \remark The list is automatically sorted. The list head always contains the + * next timer to expire. + * + * \param [IN] obj Timer object to be become the new head + * \param [IN] remainingTime Remaining time of the previous head to be replaced + */ +static void TimerInsertNewHeadTimer(TimerEvent_t *obj); + +/*! + * \brief Adds a timer to the list. + * + * \remark The list is automatically sorted. The list head always contains the + * next timer to expire. + * + * \param [IN] obj Timer object to be added to the list + * \param [IN] remainingTime Remaining time of the running head after which the object may be added + */ +static void TimerInsertTimer(TimerEvent_t *obj); + +/*! + * \brief Sets a timeout with the duration "timestamp" + * + * \param [IN] timestamp Delay duration + */ +static void TimerSetTimeout(TimerEvent_t *obj); + +/*! + * \brief Check if the Object to be added is not already in the list + * + * \param [IN] timestamp Delay duration + * \retval true (the object is already in the list) or false + */ +static bool TimerExists(TimerEvent_t *obj); void TimerInit(TimerEvent_t *obj, void (*callback)(void *context)) { @@ -66,76 +95,249 @@ void TimerInit(TimerEvent_t *obj, void (*callback)(void *context)) obj->Callback = callback; obj->Context = NULL; obj->Next = NULL; +} - list_of_timer_event_pointers[number_of_timers] = obj; - number_of_timers++; +void TimerSetContext(TimerEvent_t *obj, void *context) +{ + obj->Context = context; } void TimerStart(TimerEvent_t *obj) { + uint32_t elapsedTime = 0; + + CRITICAL_SECTION_BEGIN(); + + if ((obj == NULL) || (TimerExists(obj) == true)) + { + CRITICAL_SECTION_END(); + return; + } + obj->Timestamp = obj->ReloadValue; obj->IsStarted = true; obj->IsNext2Expire = false; + + if (TimerListHead == NULL) + { + // Inserts a timer at time now + obj->Timestamp + TimerInsertNewHeadTimer(obj); + } + else + { + elapsedTime = current_time; + obj->Timestamp += elapsedTime; + + if (obj->Timestamp < TimerListHead->Timestamp) + { + TimerInsertNewHeadTimer(obj); + } + else + { + TimerInsertTimer(obj); + } + } + CRITICAL_SECTION_END(); } -void TimerIrqHandler(void) +static void TimerInsertTimer(TimerEvent_t *obj) { - /** - * @brief Check through countdown timers, and decrement them if they are active. - * If hits zero, set them inactive(IsStarted = false), and set IsNext2Expire - * - * @param list_of_timer_event_pointers - */ - for (int i = 0; i < number_of_timers; ++i) + TimerEvent_t *cur = TimerListHead; + TimerEvent_t *next = TimerListHead->Next; + + while (cur->Next != NULL) { - TimerEvent_t *timer_event = list_of_timer_event_pointers[i]; - // printf("Timestamp[ms]: %d\n", timer_event->Timestamp); + if (obj->Timestamp > next->Timestamp) + { + cur = next; + next = next->Next; + } + else + { + cur->Next = obj; + obj->Next = next; + return; + } + } + cur->Next = obj; + obj->Next = NULL; +} + +static void TimerInsertNewHeadTimer(TimerEvent_t *obj) +{ + TimerEvent_t *cur = TimerListHead; + + if (cur != NULL) + { + cur->IsNext2Expire = false; + } + + obj->Next = cur; + TimerListHead = obj; + TimerSetTimeout(TimerListHead); +} + +bool TimerIsStarted(TimerEvent_t *obj) +{ + return obj->IsStarted; +} - if (timer_event->IsStarted) +void TimerIrqHandler(void) +{ + TimerEvent_t *cur; + TimerEvent_t *next; + + uint32_t deltaContext = 1; + + // Update timeStamp based upon new Time Reference + // because delta context should never exceed 2^32 + if (TimerListHead != NULL) + { + for (cur = TimerListHead; cur->Next != NULL; cur = cur->Next) { - timer_event->Timestamp--; + next = cur->Next; + if (next->Timestamp > deltaContext) + { + next->Timestamp -= deltaContext; + } + else + { + next->Timestamp = 0; + } + } + } + + // Execute immediately the alarm callback + if (TimerListHead != NULL) + { + cur = TimerListHead; + TimerListHead = TimerListHead->Next; + cur->IsStarted = false; + ExecuteCallBack(cur->Callback, cur->Context); + } - if (timer_event->Timestamp == 0) + // Remove all the expired object from the list + while ((TimerListHead != NULL) && (TimerListHead->Timestamp < current_time)) + { + cur = TimerListHead; + TimerListHead = TimerListHead->Next; + cur->IsStarted = false; + ExecuteCallBack(cur->Callback, cur->Context); + } + + // Start the next TimerListHead if it exists AND NOT running + if ((TimerListHead != NULL) && (TimerListHead->IsNext2Expire == false)) + { + TimerSetTimeout(TimerListHead); + } +} + +void TimerStop(TimerEvent_t *obj) +{ + CRITICAL_SECTION_BEGIN(); + + TimerEvent_t *prev = TimerListHead; + TimerEvent_t *cur = TimerListHead; + + // List is empty or the obj to stop does not exist + if ((TimerListHead == NULL) || (obj == NULL)) + { + CRITICAL_SECTION_END(); + return; + } + + obj->IsStarted = false; + + if (TimerListHead == obj) // Stop the Head + { + if (TimerListHead->IsNext2Expire == true) // The head is already running + { + TimerListHead->IsNext2Expire = false; + if (TimerListHead->Next != NULL) + { + TimerListHead = TimerListHead->Next; + TimerSetTimeout(TimerListHead); + } + else + { + TimerListHead = NULL; + } + } + else // Stop the head before it is started + { + if (TimerListHead->Next != NULL) + { + TimerListHead = TimerListHead->Next; + } + else { - timer_event->IsNext2Expire = true; - timer_event->IsStarted = false; + TimerListHead = NULL; } } } + else // Stop an object within the list + { + while (cur != NULL) + { + if (cur == obj) + { + if (cur->Next != NULL) + { + cur = cur->Next; + prev->Next = cur; + } + else + { + cur = NULL; + prev->Next = cur; + } + break; + } + else + { + prev = cur; + cur = cur->Next; + } + } + } + CRITICAL_SECTION_END(); +} - // printf("\n"); +static bool TimerExists(TimerEvent_t *obj) +{ + TimerEvent_t *cur = TimerListHead; - /** - * Now here, execute the call back of first expiring timer - * Leave the execution of the next expiring timer to the next time - * TimerIrqHandler() is called, to allow stuff to update on the main - * main loop. - * - */ - for (int i = 0; i < number_of_timers; ++i) + while (cur != NULL) { - TimerEvent_t *timer_event = list_of_timer_event_pointers[i]; - if (timer_event->IsNext2Expire == true) + if (cur == obj) { - ExecuteCallBack(timer_event->Callback, timer_event->Context); - timer_event->IsNext2Expire = false; - return; + return true; } + cur = cur->Next; } + return false; } -void TimerStop(TimerEvent_t *obj) +void TimerReset(TimerEvent_t *obj) { - obj->IsStarted = false; + TimerStop(obj); + TimerStart(obj); } void TimerSetValue(TimerEvent_t *obj, uint32_t value) { + uint32_t minValue = 3; + uint32_t ticks = value; TimerStop(obj); - obj->Timestamp = value; - obj->ReloadValue = value; + if (ticks < minValue) + { + ticks = minValue; + } + + obj->Timestamp = ticks; + obj->ReloadValue = ticks; } TimerTime_t TimerGetCurrentTime(void) @@ -145,5 +347,16 @@ TimerTime_t TimerGetCurrentTime(void) TimerTime_t TimerGetElapsedTime(TimerTime_t past) { + if (past == 0) + { + return 0; + } + // Intentional wrap around. Works Ok if tick duration below 1ms return current_time - past; } + +static void TimerSetTimeout(TimerEvent_t *obj) +{ + int32_t minTicks = 3; + obj->IsNext2Expire = true; +} From 1bd4c76a5b15dad33ef55a8b0a3216267f0668fa Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 23:38:10 +0100 Subject: [PATCH 28/95] put back all rtc stuff --- tests/timer-mock.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/tests/timer-mock.cpp b/tests/timer-mock.cpp index 74493c58f..b6113df19 100644 --- a/tests/timer-mock.cpp +++ b/tests/timer-mock.cpp @@ -42,8 +42,6 @@ } \ } while (0); -TimerTime_t current_time = 0; - /*! * Timers list head pointer */ @@ -120,12 +118,13 @@ void TimerStart(TimerEvent_t *obj) if (TimerListHead == NULL) { + RtcSetTimerContext(); // Inserts a timer at time now + obj->Timestamp TimerInsertNewHeadTimer(obj); } else { - elapsedTime = current_time; + elapsedTime = RtcGetTimerElapsedTime(); obj->Timestamp += elapsedTime; if (obj->Timestamp < TimerListHead->Timestamp) @@ -187,7 +186,9 @@ void TimerIrqHandler(void) TimerEvent_t *cur; TimerEvent_t *next; - uint32_t deltaContext = 1; + uint32_t old = RtcGetTimerContext(); + uint32_t now = RtcSetTimerContext(); + uint32_t deltaContext = now - old; // intentional wrap around // Update timeStamp based upon new Time Reference // because delta context should never exceed 2^32 @@ -217,7 +218,7 @@ void TimerIrqHandler(void) } // Remove all the expired object from the list - while ((TimerListHead != NULL) && (TimerListHead->Timestamp < current_time)) + while ((TimerListHead != NULL) && (TimerListHead->Timestamp < RtcGetTimerElapsedTime())) { cur = TimerListHead; TimerListHead = TimerListHead->Next; @@ -260,6 +261,7 @@ void TimerStop(TimerEvent_t *obj) } else { + RtcStopAlarm(); TimerListHead = NULL; } } @@ -326,11 +328,13 @@ void TimerReset(TimerEvent_t *obj) void TimerSetValue(TimerEvent_t *obj, uint32_t value) { - uint32_t minValue = 3; - uint32_t ticks = value; + uint32_t minValue = 0; + uint32_t ticks = RtcMs2Tick(value); TimerStop(obj); + minValue = RtcGetMinimumTimeout(); + if (ticks < minValue) { ticks = minValue; @@ -342,7 +346,8 @@ void TimerSetValue(TimerEvent_t *obj, uint32_t value) TimerTime_t TimerGetCurrentTime(void) { - return current_time; + uint32_t now = RtcGetTimerValue(); + return RtcTick2Ms(now); } TimerTime_t TimerGetElapsedTime(TimerTime_t past) @@ -351,12 +356,15 @@ TimerTime_t TimerGetElapsedTime(TimerTime_t past) { return 0; } + uint32_t nowInTicks = RtcGetTimerValue(); + uint32_t pastInTicks = RtcMs2Tick(past); + // Intentional wrap around. Works Ok if tick duration below 1ms - return current_time - past; + return RtcTick2Ms(nowInTicks - pastInTicks); } static void TimerSetTimeout(TimerEvent_t *obj) { - int32_t minTicks = 3; + int32_t minTicks = RtcGetMinimumTimeout(); obj->IsNext2Expire = true; } From 3df1300823baef5a1a0057f647ddcebb3791861a Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 23:38:20 +0100 Subject: [PATCH 29/95] put in rtc mock --- tests/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 31b1d5a9b..de5061f20 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -96,6 +96,7 @@ set(MOCKS nvm_images.cpp delay-board-mock.c gpio_mock.c + rtc-board-mock.c ) From 7412202cbd67e5b9c63de434d1c6031693b3dcde Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 23:38:34 +0100 Subject: [PATCH 30/95] current time in rtc board mock --- tests/rtc-board-mock.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/rtc-board-mock.c b/tests/rtc-board-mock.c index d8dcfd565..b9bb77763 100644 --- a/tests/rtc-board-mock.c +++ b/tests/rtc-board-mock.c @@ -80,6 +80,9 @@ */ #define DIVC(X, N) (((X) + (N)-1) / (N)) +TimerTime_t current_time = 0; + + /*! * RTC timer context */ From f819ea2759556b5278bcc192c740cff41385c46e Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 23:57:56 +0100 Subject: [PATCH 31/95] start and stop alarms --- .../periodic-uplink-lpp/B-L072Z-LRWAN1/main.c | 14 ++ tests/rtc-board-mock.c | 197 ++---------------- 2 files changed, 32 insertions(+), 179 deletions(-) diff --git a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c index 4bdd71e36..e9c960cb2 100644 --- a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c +++ b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c @@ -159,6 +159,12 @@ int main( void ) } } + +extern bool currently_alarm_ringing; +extern uint32_t countdown; +extern bool alarm_stopped; + + static void transmit_n_times_on_this_credential( void ) { print_current_region( ); @@ -200,6 +206,14 @@ static void transmit_n_times_on_this_credential( void ) { #ifdef UNITTESTING_LORA current_time += 1; /* simulate 1 millisecond per loop */ + if (countdown > 0 && !alarm_stopped) + { + countdown--; + } + if (countdown == 0) + { + currently_alarm_ringing = true; + } TimerIrqHandler(); #endif // Process characters sent over the command line interface diff --git a/tests/rtc-board-mock.c b/tests/rtc-board-mock.c index b9bb77763..d8606bb50 100644 --- a/tests/rtc-board-mock.c +++ b/tests/rtc-board-mock.c @@ -82,9 +82,8 @@ TimerTime_t current_time = 0; - /*! - * RTC timer context + * RTC timer context */ typedef struct { @@ -118,6 +117,10 @@ static const uint8_t DaysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 */ static const uint8_t DaysInMonthLeapYear[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +bool currently_alarm_ringing = false; +uint32_t countdown = 0; +bool alarm_stopped = true; + /*! * \brief RTC Handle */ @@ -159,6 +162,11 @@ static uint64_t RtcGetCalendarValue(RTC_DateTypeDef *date, RTC_TimeTypeDef *time void RtcInit(void) { + if (RtcInitialized == false) + { + RtcSetTimerContext(); + RtcInitialized = true; + } } /*! @@ -202,6 +210,7 @@ uint32_t RtcGetMinimumTimeout(void) */ uint32_t RtcMs2Tick(uint32_t milliseconds) { + milliseconds = milliseconds * 37000 / 32768; return (uint32_t)((((uint64_t)milliseconds) * CONV_DENOM) / CONV_NUMER); } @@ -216,7 +225,9 @@ uint32_t RtcTick2Ms(uint32_t tick) uint32_t seconds = tick >> N_PREDIV_S; tick = tick & PREDIV_S; - return ((seconds * 1000) + ((tick * 1000) >> N_PREDIV_S)); + + uint32_t unscaled_ms = ((seconds * 1000) + ((tick * 1000) >> N_PREDIV_S)); + return unscaled_ms * 32768 / 37000; } /*! @@ -253,108 +264,15 @@ void RtcSetAlarm(uint32_t timeout) void RtcStopAlarm(void) { + alarm_stopped = true; } void RtcStartAlarm(uint32_t timeout) { - uint16_t rtcAlarmSubSeconds = 0; - uint16_t rtcAlarmSeconds = 0; - uint16_t rtcAlarmMinutes = 0; - uint16_t rtcAlarmHours = 0; - uint16_t rtcAlarmDays = 0; - RTC_TimeTypeDef time = RtcTimerContext.CalendarTime; - RTC_DateTypeDef date = RtcTimerContext.CalendarDate; RtcStopAlarm(); - /*reverse counter */ - rtcAlarmSubSeconds = PREDIV_S - time.SubSeconds; - rtcAlarmSubSeconds += (timeout & PREDIV_S); - // convert timeout to seconds - timeout >>= N_PREDIV_S; - - // Convert microsecs to RTC format and add to 'Now' - rtcAlarmDays = date.Date; - while (timeout >= TM_SECONDS_IN_1DAY) - { - timeout -= TM_SECONDS_IN_1DAY; - rtcAlarmDays++; - } - - // Calc hours - rtcAlarmHours = time.Hours; - while (timeout >= TM_SECONDS_IN_1HOUR) - { - timeout -= TM_SECONDS_IN_1HOUR; - rtcAlarmHours++; - } - - // Calc minutes - rtcAlarmMinutes = time.Minutes; - while (timeout >= TM_SECONDS_IN_1MINUTE) - { - timeout -= TM_SECONDS_IN_1MINUTE; - rtcAlarmMinutes++; - } - - // Calc seconds - rtcAlarmSeconds = time.Seconds + timeout; - - //***** Correct for modulo******** - while (rtcAlarmSubSeconds >= (PREDIV_S + 1)) - { - rtcAlarmSubSeconds -= (PREDIV_S + 1); - rtcAlarmSeconds++; - } - - while (rtcAlarmSeconds >= TM_SECONDS_IN_1MINUTE) - { - rtcAlarmSeconds -= TM_SECONDS_IN_1MINUTE; - rtcAlarmMinutes++; - } - - while (rtcAlarmMinutes >= TM_MINUTES_IN_1HOUR) - { - rtcAlarmMinutes -= TM_MINUTES_IN_1HOUR; - rtcAlarmHours++; - } - - while (rtcAlarmHours >= TM_HOURS_IN_1DAY) - { - rtcAlarmHours -= TM_HOURS_IN_1DAY; - rtcAlarmDays++; - } - - if (date.Year % 4 == 0) - { - if (rtcAlarmDays > DaysInMonthLeapYear[date.Month - 1]) - { - rtcAlarmDays = rtcAlarmDays % DaysInMonthLeapYear[date.Month - 1]; - } - } - else - { - if (rtcAlarmDays > DaysInMonth[date.Month - 1]) - { - rtcAlarmDays = rtcAlarmDays % DaysInMonth[date.Month - 1]; - } - } - - /* Set RTC_AlarmStructure with calculated values*/ - RtcAlarm.AlarmTime.SubSeconds = PREDIV_S - rtcAlarmSubSeconds; - RtcAlarm.AlarmSubSecondMask = ALARM_SUBSECOND_MASK; - RtcAlarm.AlarmTime.Seconds = rtcAlarmSeconds; - RtcAlarm.AlarmTime.Minutes = rtcAlarmMinutes; - RtcAlarm.AlarmTime.Hours = rtcAlarmHours; - RtcAlarm.AlarmDateWeekDay = (uint8_t)rtcAlarmDays; - RtcAlarm.AlarmTime.TimeFormat = time.TimeFormat; - RtcAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; - RtcAlarm.AlarmMask = RTC_ALARMMASK_NONE; - RtcAlarm.Alarm = RTC_ALARM_A; - RtcAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; - RtcAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET; - - // Set RTC_Alarm + alarm_stopped = false; } uint32_t RtcGetTimerValue(void) @@ -377,14 +295,6 @@ uint32_t RtcGetTimerElapsedTime(void) return ((uint32_t)(calendarValue - RtcTimerContext.Time)); } -void RtcSetMcuWakeUpTime(void) -{ - RTC_TimeTypeDef time; - RTC_DateTypeDef date; - - uint32_t now, hit; - int16_t mcuWakeUpTime; -} int16_t RtcGetMcuWakeUpTime(void) { @@ -393,35 +303,12 @@ int16_t RtcGetMcuWakeUpTime(void) static uint64_t RtcGetCalendarValue(RTC_DateTypeDef *date, RTC_TimeTypeDef *time) { - uint64_t calendarValue = 0; - - return (calendarValue); + return current_time; } -extern TimerTime_t current_time; - uint32_t RtcGetCalendarTime(uint16_t *milliseconds) { - RTC_TimeTypeDef time; - RTC_DateTypeDef date; - uint32_t ticks; - - uint64_t calendarValue = RtcGetCalendarValue(&date, &time); - - uint32_t seconds = (uint32_t)(calendarValue >> N_PREDIV_S); - - ticks = (uint32_t)calendarValue & PREDIV_S; - - *milliseconds = current_time; - - return seconds; -} - -/*! - * \brief RTC IRQ Handler of the RTC Alarm - */ -void RTC_IRQHandler(void) -{ + return current_time; } /*! @@ -433,51 +320,3 @@ void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) { TimerIrqHandler(); } - -void RtcBkupWrite(uint32_t data0, uint32_t data1) -{ -} - -void RtcBkupRead(uint32_t *data0, uint32_t *data1) -{ -} - -void RtcProcess(void) -{ - // Not used on this platform. -} - -TimerTime_t RtcTempCompensation(TimerTime_t period, float temperature) -{ - float k = RTC_TEMP_COEFFICIENT; - float kDev = RTC_TEMP_DEV_COEFFICIENT; - float t = RTC_TEMP_TURNOVER; - float tDev = RTC_TEMP_DEV_TURNOVER; - float interim = 0.0f; - float ppm = 0.0f; - - if (k < 0.0f) - { - ppm = (k - kDev); - } - else - { - ppm = (k + kDev); - } - interim = (temperature - (t - tDev)); - ppm *= interim * interim; - - // Calculate the drift in time - interim = ((float)period * ppm) / 1000000.0f; - // Calculate the resulting time period - interim += period; - interim = floor(interim); - - if (interim < 0.0f) - { - interim = (float)period; - } - - // Calculate the resulting period - return (TimerTime_t)interim; -} From de7d97583a0fb8b450d94d0e79e0a6a386a9db79 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 6 Aug 2022 23:58:15 +0100 Subject: [PATCH 32/95] Update rtc-board-mock.c --- tests/rtc-board-mock.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/tests/rtc-board-mock.c b/tests/rtc-board-mock.c index d8606bb50..64a4e4b07 100644 --- a/tests/rtc-board-mock.c +++ b/tests/rtc-board-mock.c @@ -230,24 +230,6 @@ uint32_t RtcTick2Ms(uint32_t tick) return unscaled_ms * 32768 / 37000; } -/*! - * \brief a delay of delay ms by polling RTC - * - * \param[IN] delay in ms - */ -void RtcDelayMs(uint32_t delay) -{ - uint64_t delayTicks = 0; - uint64_t refTicks = RtcGetTimerValue(); - - delayTicks = RtcMs2Tick(delay); - - // Wait delay ms - while (((RtcGetTimerValue() - refTicks)) < delayTicks) - { - __NOP(); - } -} /*! * \brief Sets the alarm From 63a62d20ec316899357ee246989e0e68d48f66f6 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sun, 7 Aug 2022 00:00:00 +0100 Subject: [PATCH 33/95] redundant code --- tests/rtc-board-mock.c | 27 --------------------------- tests/timer-mock.cpp | 8 ++++---- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/tests/rtc-board-mock.c b/tests/rtc-board-mock.c index 64a4e4b07..ed1c1c6d0 100644 --- a/tests/rtc-board-mock.c +++ b/tests/rtc-board-mock.c @@ -202,33 +202,6 @@ uint32_t RtcGetMinimumTimeout(void) return (MIN_ALARM_DELAY); } -/*! - * \brief converts time in ms to time in ticks - * - * \param[IN] milliseconds Time in milliseconds - * \retval returns time in timer ticks - */ -uint32_t RtcMs2Tick(uint32_t milliseconds) -{ - milliseconds = milliseconds * 37000 / 32768; - return (uint32_t)((((uint64_t)milliseconds) * CONV_DENOM) / CONV_NUMER); -} - -/*! - * \brief converts time in ticks to time in ms - * - * \param[IN] time in timer ticks - * \retval returns time in milliseconds - */ -uint32_t RtcTick2Ms(uint32_t tick) -{ - uint32_t seconds = tick >> N_PREDIV_S; - - tick = tick & PREDIV_S; - - uint32_t unscaled_ms = ((seconds * 1000) + ((tick * 1000) >> N_PREDIV_S)); - return unscaled_ms * 32768 / 37000; -} /*! diff --git a/tests/timer-mock.cpp b/tests/timer-mock.cpp index b6113df19..363701681 100644 --- a/tests/timer-mock.cpp +++ b/tests/timer-mock.cpp @@ -329,7 +329,7 @@ void TimerReset(TimerEvent_t *obj) void TimerSetValue(TimerEvent_t *obj, uint32_t value) { uint32_t minValue = 0; - uint32_t ticks = RtcMs2Tick(value); + uint32_t ticks = value; TimerStop(obj); @@ -347,7 +347,7 @@ void TimerSetValue(TimerEvent_t *obj, uint32_t value) TimerTime_t TimerGetCurrentTime(void) { uint32_t now = RtcGetTimerValue(); - return RtcTick2Ms(now); + return now; } TimerTime_t TimerGetElapsedTime(TimerTime_t past) @@ -357,10 +357,10 @@ TimerTime_t TimerGetElapsedTime(TimerTime_t past) return 0; } uint32_t nowInTicks = RtcGetTimerValue(); - uint32_t pastInTicks = RtcMs2Tick(past); + uint32_t pastInTicks = past; // Intentional wrap around. Works Ok if tick duration below 1ms - return RtcTick2Ms(nowInTicks - pastInTicks); + return nowInTicks - pastInTicks; } static void TimerSetTimeout(TimerEvent_t *obj) From 0aef33da4fd5d435b2aa01eaa85db93ef50fed1f Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 18:18:10 +0100 Subject: [PATCH 34/95] Update timer-mock.cpp --- tests/timer-mock.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/timer-mock.cpp b/tests/timer-mock.cpp index 363701681..655aaf0d1 100644 --- a/tests/timer-mock.cpp +++ b/tests/timer-mock.cpp @@ -329,7 +329,7 @@ void TimerReset(TimerEvent_t *obj) void TimerSetValue(TimerEvent_t *obj, uint32_t value) { uint32_t minValue = 0; - uint32_t ticks = value; + uint32_t ticks = RtcMs2Tick(value); TimerStop(obj); @@ -347,7 +347,7 @@ void TimerSetValue(TimerEvent_t *obj, uint32_t value) TimerTime_t TimerGetCurrentTime(void) { uint32_t now = RtcGetTimerValue(); - return now; + return RtcTick2Ms(now); } TimerTime_t TimerGetElapsedTime(TimerTime_t past) @@ -357,14 +357,31 @@ TimerTime_t TimerGetElapsedTime(TimerTime_t past) return 0; } uint32_t nowInTicks = RtcGetTimerValue(); - uint32_t pastInTicks = past; + uint32_t pastInTicks = RtcMs2Tick(past); // Intentional wrap around. Works Ok if tick duration below 1ms - return nowInTicks - pastInTicks; + return RtcTick2Ms(nowInTicks - pastInTicks); } static void TimerSetTimeout(TimerEvent_t *obj) { int32_t minTicks = RtcGetMinimumTimeout(); obj->IsNext2Expire = true; + + // In case deadline too soon + if (obj->Timestamp < (RtcGetTimerElapsedTime() + minTicks)) + { + obj->Timestamp = RtcGetTimerElapsedTime() + minTicks; + } + RtcSetAlarm(obj->Timestamp); +} + +TimerTime_t TimerTempCompensation(TimerTime_t period, float temperature) +{ + return RtcTempCompensation(period, temperature); +} + +void TimerProcess(void) +{ + RtcProcess(); } From 96aedde2f3b8ebbffc116b64e44c5b15e2b49ac8 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 18:25:14 +0100 Subject: [PATCH 35/95] use original timer --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index de5061f20..c541c9c2c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -87,7 +87,6 @@ set(MOCKS cli-mock.c board-mock.c sx1276-mock.c - timer-mock.cpp bsp_mock.cpp eeprom-board-mock.cpp # loramac-mock.cpp @@ -118,6 +117,7 @@ set(FILES_UNDER_TEST ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandlerMsgDisplay.c ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/LmHandler.c ${PROJECT_SOURCE_DIR}/src/system/delay.c + ${PROJECT_SOURCE_DIR}/src/system/timer.c ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/callbacks.c ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c From 57345c0448e7a788ab0fa0df1ea5012ffa6d1ab0 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 18:27:20 +0100 Subject: [PATCH 36/95] put in rtc converstion --- tests/rtc-board-mock.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/rtc-board-mock.c b/tests/rtc-board-mock.c index ed1c1c6d0..46adc6a3f 100644 --- a/tests/rtc-board-mock.c +++ b/tests/rtc-board-mock.c @@ -202,7 +202,27 @@ uint32_t RtcGetMinimumTimeout(void) return (MIN_ALARM_DELAY); } +/*! + * \brief converts time in ms to time in ticks + * + * \param[IN] milliseconds Time in milliseconds + * \retval returns time in timer ticks + */ +uint32_t RtcMs2Tick(uint32_t milliseconds) +{ + return milliseconds; +} +/*! + * \brief converts time in ticks to time in ms + * + * \param[IN] time in timer ticks + * \retval returns time in milliseconds + */ +uint32_t RtcTick2Ms(uint32_t tick) +{ + return tick; +} /*! * \brief Sets the alarm From 6dd99e585ae1edd2723ff2e06aa3ff8c22d105eb Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 18:27:29 +0100 Subject: [PATCH 37/95] Delete timer-mock.cpp --- tests/timer-mock.cpp | 387 ------------------------------------------- 1 file changed, 387 deletions(-) delete mode 100644 tests/timer-mock.cpp diff --git a/tests/timer-mock.cpp b/tests/timer-mock.cpp deleted file mode 100644 index 655aaf0d1..000000000 --- a/tests/timer-mock.cpp +++ /dev/null @@ -1,387 +0,0 @@ -/*! - * \file timer.c - * - * \brief Timer objects and scheduling management implementation - * - * \copyright Revised BSD License, see section \ref LICENSE. - * - * \code - * ______ _ - * / _____) _ | | - * ( (____ _____ ____ _| |_ _____ ____| |__ - * \____ \| ___ | (_ _) ___ |/ ___) _ \ - * _____) ) ____| | | || |_| ____( (___| | | | - * (______/|_____)_|_|_| \__)_____)\____)_| |_| - * (C)2013-2017 Semtech - * - * \endcode - * - * \author Miguel Luis ( Semtech ) - * - * \author Gregory Cristian ( Semtech ) - */ -#include "utilities.h" -#include "board.h" -#include "rtc-board.h" -#include "timer.h" - -/*! - * Safely execute call back - */ -#define ExecuteCallBack(_callback_, context) \ - do \ - { \ - if (_callback_ == NULL) \ - { \ - while (1) \ - ; \ - } \ - else \ - { \ - _callback_(context); \ - } \ - } while (0); - -/*! - * Timers list head pointer - */ -static TimerEvent_t *TimerListHead = NULL; - -/*! - * \brief Adds or replace the head timer of the list. - * - * \remark The list is automatically sorted. The list head always contains the - * next timer to expire. - * - * \param [IN] obj Timer object to be become the new head - * \param [IN] remainingTime Remaining time of the previous head to be replaced - */ -static void TimerInsertNewHeadTimer(TimerEvent_t *obj); - -/*! - * \brief Adds a timer to the list. - * - * \remark The list is automatically sorted. The list head always contains the - * next timer to expire. - * - * \param [IN] obj Timer object to be added to the list - * \param [IN] remainingTime Remaining time of the running head after which the object may be added - */ -static void TimerInsertTimer(TimerEvent_t *obj); - -/*! - * \brief Sets a timeout with the duration "timestamp" - * - * \param [IN] timestamp Delay duration - */ -static void TimerSetTimeout(TimerEvent_t *obj); - -/*! - * \brief Check if the Object to be added is not already in the list - * - * \param [IN] timestamp Delay duration - * \retval true (the object is already in the list) or false - */ -static bool TimerExists(TimerEvent_t *obj); - -void TimerInit(TimerEvent_t *obj, void (*callback)(void *context)) -{ - obj->Timestamp = 0; - obj->ReloadValue = 0; - obj->IsStarted = false; - obj->IsNext2Expire = false; - obj->Callback = callback; - obj->Context = NULL; - obj->Next = NULL; -} - -void TimerSetContext(TimerEvent_t *obj, void *context) -{ - obj->Context = context; -} - -void TimerStart(TimerEvent_t *obj) -{ - uint32_t elapsedTime = 0; - - CRITICAL_SECTION_BEGIN(); - - if ((obj == NULL) || (TimerExists(obj) == true)) - { - CRITICAL_SECTION_END(); - return; - } - - obj->Timestamp = obj->ReloadValue; - obj->IsStarted = true; - obj->IsNext2Expire = false; - - if (TimerListHead == NULL) - { - RtcSetTimerContext(); - // Inserts a timer at time now + obj->Timestamp - TimerInsertNewHeadTimer(obj); - } - else - { - elapsedTime = RtcGetTimerElapsedTime(); - obj->Timestamp += elapsedTime; - - if (obj->Timestamp < TimerListHead->Timestamp) - { - TimerInsertNewHeadTimer(obj); - } - else - { - TimerInsertTimer(obj); - } - } - CRITICAL_SECTION_END(); -} - -static void TimerInsertTimer(TimerEvent_t *obj) -{ - TimerEvent_t *cur = TimerListHead; - TimerEvent_t *next = TimerListHead->Next; - - while (cur->Next != NULL) - { - if (obj->Timestamp > next->Timestamp) - { - cur = next; - next = next->Next; - } - else - { - cur->Next = obj; - obj->Next = next; - return; - } - } - cur->Next = obj; - obj->Next = NULL; -} - -static void TimerInsertNewHeadTimer(TimerEvent_t *obj) -{ - TimerEvent_t *cur = TimerListHead; - - if (cur != NULL) - { - cur->IsNext2Expire = false; - } - - obj->Next = cur; - TimerListHead = obj; - TimerSetTimeout(TimerListHead); -} - -bool TimerIsStarted(TimerEvent_t *obj) -{ - return obj->IsStarted; -} - -void TimerIrqHandler(void) -{ - TimerEvent_t *cur; - TimerEvent_t *next; - - uint32_t old = RtcGetTimerContext(); - uint32_t now = RtcSetTimerContext(); - uint32_t deltaContext = now - old; // intentional wrap around - - // Update timeStamp based upon new Time Reference - // because delta context should never exceed 2^32 - if (TimerListHead != NULL) - { - for (cur = TimerListHead; cur->Next != NULL; cur = cur->Next) - { - next = cur->Next; - if (next->Timestamp > deltaContext) - { - next->Timestamp -= deltaContext; - } - else - { - next->Timestamp = 0; - } - } - } - - // Execute immediately the alarm callback - if (TimerListHead != NULL) - { - cur = TimerListHead; - TimerListHead = TimerListHead->Next; - cur->IsStarted = false; - ExecuteCallBack(cur->Callback, cur->Context); - } - - // Remove all the expired object from the list - while ((TimerListHead != NULL) && (TimerListHead->Timestamp < RtcGetTimerElapsedTime())) - { - cur = TimerListHead; - TimerListHead = TimerListHead->Next; - cur->IsStarted = false; - ExecuteCallBack(cur->Callback, cur->Context); - } - - // Start the next TimerListHead if it exists AND NOT running - if ((TimerListHead != NULL) && (TimerListHead->IsNext2Expire == false)) - { - TimerSetTimeout(TimerListHead); - } -} - -void TimerStop(TimerEvent_t *obj) -{ - CRITICAL_SECTION_BEGIN(); - - TimerEvent_t *prev = TimerListHead; - TimerEvent_t *cur = TimerListHead; - - // List is empty or the obj to stop does not exist - if ((TimerListHead == NULL) || (obj == NULL)) - { - CRITICAL_SECTION_END(); - return; - } - - obj->IsStarted = false; - - if (TimerListHead == obj) // Stop the Head - { - if (TimerListHead->IsNext2Expire == true) // The head is already running - { - TimerListHead->IsNext2Expire = false; - if (TimerListHead->Next != NULL) - { - TimerListHead = TimerListHead->Next; - TimerSetTimeout(TimerListHead); - } - else - { - RtcStopAlarm(); - TimerListHead = NULL; - } - } - else // Stop the head before it is started - { - if (TimerListHead->Next != NULL) - { - TimerListHead = TimerListHead->Next; - } - else - { - TimerListHead = NULL; - } - } - } - else // Stop an object within the list - { - while (cur != NULL) - { - if (cur == obj) - { - if (cur->Next != NULL) - { - cur = cur->Next; - prev->Next = cur; - } - else - { - cur = NULL; - prev->Next = cur; - } - break; - } - else - { - prev = cur; - cur = cur->Next; - } - } - } - CRITICAL_SECTION_END(); -} - -static bool TimerExists(TimerEvent_t *obj) -{ - TimerEvent_t *cur = TimerListHead; - - while (cur != NULL) - { - if (cur == obj) - { - return true; - } - cur = cur->Next; - } - return false; -} - -void TimerReset(TimerEvent_t *obj) -{ - TimerStop(obj); - TimerStart(obj); -} - -void TimerSetValue(TimerEvent_t *obj, uint32_t value) -{ - uint32_t minValue = 0; - uint32_t ticks = RtcMs2Tick(value); - - TimerStop(obj); - - minValue = RtcGetMinimumTimeout(); - - if (ticks < minValue) - { - ticks = minValue; - } - - obj->Timestamp = ticks; - obj->ReloadValue = ticks; -} - -TimerTime_t TimerGetCurrentTime(void) -{ - uint32_t now = RtcGetTimerValue(); - return RtcTick2Ms(now); -} - -TimerTime_t TimerGetElapsedTime(TimerTime_t past) -{ - if (past == 0) - { - return 0; - } - uint32_t nowInTicks = RtcGetTimerValue(); - uint32_t pastInTicks = RtcMs2Tick(past); - - // Intentional wrap around. Works Ok if tick duration below 1ms - return RtcTick2Ms(nowInTicks - pastInTicks); -} - -static void TimerSetTimeout(TimerEvent_t *obj) -{ - int32_t minTicks = RtcGetMinimumTimeout(); - obj->IsNext2Expire = true; - - // In case deadline too soon - if (obj->Timestamp < (RtcGetTimerElapsedTime() + minTicks)) - { - obj->Timestamp = RtcGetTimerElapsedTime() + minTicks; - } - RtcSetAlarm(obj->Timestamp); -} - -TimerTime_t TimerTempCompensation(TimerTime_t period, float temperature) -{ - return RtcTempCompensation(period, temperature); -} - -void TimerProcess(void) -{ - RtcProcess(); -} From 256a7870d2f8374dba1bd5f18a834788f1fde6f2 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 18:29:24 +0100 Subject: [PATCH 38/95] RtcProcess and RtcTempCompensation --- tests/rtc-board-mock.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/rtc-board-mock.c b/tests/rtc-board-mock.c index 46adc6a3f..2fb00aa0d 100644 --- a/tests/rtc-board-mock.c +++ b/tests/rtc-board-mock.c @@ -295,3 +295,13 @@ void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) { TimerIrqHandler(); } +void RtcProcess(void) +{ + // Not used on this platform. +} + +TimerTime_t RtcTempCompensation(TimerTime_t period, float temperature) +{ + + return (TimerTime_t)1; +} From 80a838ec78594733cc2867c1739714c454282b19 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 18:44:04 +0100 Subject: [PATCH 39/95] Update main.c --- src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c index e9c960cb2..dc4aab4e0 100644 --- a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c +++ b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c @@ -38,6 +38,8 @@ #include "message_sender.h" #include "eeprom_settings_manager.h" #include "nvmm.h" +#include "stm32l0xx.h" + /*! * User application data @@ -213,8 +215,9 @@ static void transmit_n_times_on_this_credential( void ) if (countdown == 0) { currently_alarm_ringing = true; + RTC_HandleTypeDef dummy; + HAL_RTC_AlarmAEventCallback(&dummy); } - TimerIrqHandler(); #endif // Process characters sent over the command line interface CliProcess( &Uart1 ); From 1697ccdf108090f39696a59178f57dba41e3aa5c Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 18:45:07 +0100 Subject: [PATCH 40/95] delete redundant stuff --- tests/rtc-board-mock.c | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/tests/rtc-board-mock.c b/tests/rtc-board-mock.c index 2fb00aa0d..c8505f70b 100644 --- a/tests/rtc-board-mock.c +++ b/tests/rtc-board-mock.c @@ -97,26 +97,6 @@ typedef struct */ static bool RtcInitialized = false; -/*! - * \brief Indicates if the RTC Wake Up Time is calibrated or not - */ -static bool McuWakeUpTimeInitialized = false; - -/*! - * \brief Compensates MCU wakeup time - */ -static int16_t McuWakeUpTimeCal = 0; - -/*! - * Number of days in each month on a normal year - */ -static const uint8_t DaysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - -/*! - * Number of days in each month on a leap year - */ -static const uint8_t DaysInMonthLeapYear[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - bool currently_alarm_ringing = false; uint32_t countdown = 0; bool alarm_stopped = true; @@ -270,12 +250,6 @@ uint32_t RtcGetTimerElapsedTime(void) return ((uint32_t)(calendarValue - RtcTimerContext.Time)); } - -int16_t RtcGetMcuWakeUpTime(void) -{ - return McuWakeUpTimeCal; -} - static uint64_t RtcGetCalendarValue(RTC_DateTypeDef *date, RTC_TimeTypeDef *time) { return current_time; From 724d302da6a26169ed6a34af156da656e3ecf8dc Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 18:46:32 +0100 Subject: [PATCH 41/95] Update rtc-board-mock.c --- tests/rtc-board-mock.c | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/tests/rtc-board-mock.c b/tests/rtc-board-mock.c index c8505f70b..2a3ffe1f5 100644 --- a/tests/rtc-board-mock.c +++ b/tests/rtc-board-mock.c @@ -38,47 +38,7 @@ // MCU Wake Up Time #define MIN_ALARM_DELAY 3 // in ticks -// sub-second number of bits -#define N_PREDIV_S 10 -// Synchronous prediv -#define PREDIV_S ((1 << N_PREDIV_S) - 1) - -// Asynchronous prediv -#define PREDIV_A (1 << (15 - N_PREDIV_S)) - 1 - -// Sub-second mask definition -#define ALARM_SUBSECOND_MASK (N_PREDIV_S << RTC_ALRMASSR_MASKSS_Pos) - -// RTC Time base in us -#define USEC_NUMBER 1000000 -#define MSEC_NUMBER (USEC_NUMBER / 1000) - -#define COMMON_FACTOR 3 -#define CONV_NUMER (MSEC_NUMBER >> COMMON_FACTOR) -#define CONV_DENOM (1 << (N_PREDIV_S - COMMON_FACTOR)) - -/*! - * \brief Days, Hours, Minutes and seconds - */ -#define DAYS_IN_LEAP_YEAR ((uint32_t)366U) -#define DAYS_IN_YEAR ((uint32_t)365U) -#define SECONDS_IN_1DAY ((uint32_t)86400U) -#define SECONDS_IN_1HOUR ((uint32_t)3600U) -#define SECONDS_IN_1MINUTE ((uint32_t)60U) -#define MINUTES_IN_1HOUR ((uint32_t)60U) -#define HOURS_IN_1DAY ((uint32_t)24U) - -/*! - * \brief Correction factors - */ -#define DAYS_IN_MONTH_CORRECTION_NORM ((uint32_t)0x99AAA0) -#define DAYS_IN_MONTH_CORRECTION_LEAP ((uint32_t)0x445550) - -/*! - * \brief Calculates ceiling( X / N ) - */ -#define DIVC(X, N) (((X) + (N)-1) / (N)) TimerTime_t current_time = 0; From 41036b90898d7cd333a564fecb21e4f31571e906 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 18:46:49 +0100 Subject: [PATCH 42/95] Update rtc-board-mock.c --- tests/rtc-board-mock.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/tests/rtc-board-mock.c b/tests/rtc-board-mock.c index 2a3ffe1f5..d8acbe0a0 100644 --- a/tests/rtc-board-mock.c +++ b/tests/rtc-board-mock.c @@ -61,24 +61,6 @@ bool currently_alarm_ringing = false; uint32_t countdown = 0; bool alarm_stopped = true; -/*! - * \brief RTC Handle - */ -static RTC_HandleTypeDef RtcHandle = - { - .Instance = NULL, - .Init = - { - .HourFormat = 0, - .AsynchPrediv = 0, - .SynchPrediv = 0, - .OutPut = 0, - .OutPutRemap = 0, - .OutPutPolarity = 0, - .OutPutType = 0}, - .Lock = HAL_UNLOCKED, - .State = HAL_RTC_STATE_RESET}; - /*! * \brief RTC Alarm */ From 30843407b4be146b1f92694aa8e335d7ed4e9fa3 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 18:50:05 +0100 Subject: [PATCH 43/95] Update rtc-board-mock.c --- tests/rtc-board-mock.c | 41 ++++------------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/tests/rtc-board-mock.c b/tests/rtc-board-mock.c index d8acbe0a0..101f79695 100644 --- a/tests/rtc-board-mock.c +++ b/tests/rtc-board-mock.c @@ -38,8 +38,6 @@ // MCU Wake Up Time #define MIN_ALARM_DELAY 3 // in ticks - - TimerTime_t current_time = 0; /*! @@ -47,9 +45,7 @@ TimerTime_t current_time = 0; */ typedef struct { - uint32_t Time; // Reference time - RTC_TimeTypeDef CalendarTime; // Reference time in calendar format - RTC_DateTypeDef CalendarDate; // Reference date in calendar format + uint32_t Time; // Reference time } RtcTimerContext_t; /*! @@ -73,15 +69,6 @@ static RTC_AlarmTypeDef RtcAlarm; */ static RtcTimerContext_t RtcTimerContext; -/*! - * \brief Get the current time from calendar in ticks - * - * \param [IN] date Pointer to RTC_DateStruct - * \param [IN] time Pointer to RTC_TimeStruct - * \retval calendarValue Time in ticks - */ -static uint64_t RtcGetCalendarValue(RTC_DateTypeDef *date, RTC_TimeTypeDef *time); - void RtcInit(void) { if (RtcInitialized == false) @@ -99,7 +86,7 @@ void RtcInit(void) */ uint32_t RtcSetTimerContext(void) { - RtcTimerContext.Time = (uint32_t)RtcGetCalendarValue(&RtcTimerContext.CalendarDate, &RtcTimerContext.CalendarTime); + RtcTimerContext.Time = current_time; return (uint32_t)RtcTimerContext.Time; } @@ -173,33 +160,13 @@ void RtcStartAlarm(uint32_t timeout) } uint32_t RtcGetTimerValue(void) -{ - RTC_TimeTypeDef time; - RTC_DateTypeDef date; - - uint32_t calendarValue = (uint32_t)RtcGetCalendarValue(&date, &time); - - return (calendarValue); -} - -uint32_t RtcGetTimerElapsedTime(void) -{ - RTC_TimeTypeDef time; - RTC_DateTypeDef date; - - uint32_t calendarValue = (uint32_t)RtcGetCalendarValue(&date, &time); - - return ((uint32_t)(calendarValue - RtcTimerContext.Time)); -} - -static uint64_t RtcGetCalendarValue(RTC_DateTypeDef *date, RTC_TimeTypeDef *time) { return current_time; } -uint32_t RtcGetCalendarTime(uint16_t *milliseconds) +uint32_t RtcGetTimerElapsedTime(void) { - return current_time; + return ((uint32_t)(current_time - RtcTimerContext.Time)); } /*! From ed3c07a4eb3bdd6338c86de621d1b798b3956a1c Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 18:56:26 +0100 Subject: [PATCH 44/95] Update main.c --- src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c index dc4aab4e0..7ac4bb9a1 100644 --- a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c +++ b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c @@ -218,6 +218,8 @@ static void transmit_n_times_on_this_credential( void ) RTC_HandleTypeDef dummy; HAL_RTC_AlarmAEventCallback(&dummy); } + + printf("current time: %d ms, countdown: %d ms, alarm_stopped: %d\n", current_time, countdown, alarm_stopped); #endif // Process characters sent over the command line interface CliProcess( &Uart1 ); From 7c27d771425dffadfd49cdef920ba1b8b4b34404 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 18:56:33 +0100 Subject: [PATCH 45/95] Update rtc-board-mock.c --- tests/rtc-board-mock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/rtc-board-mock.c b/tests/rtc-board-mock.c index 101f79695..f75caaa23 100644 --- a/tests/rtc-board-mock.c +++ b/tests/rtc-board-mock.c @@ -155,6 +155,7 @@ void RtcStartAlarm(uint32_t timeout) { RtcStopAlarm(); + countdown = timeout; alarm_stopped = false; } From e1f9fa461c9e90d8fd8fe90a0ad3118b0259e848 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 19:21:16 +0100 Subject: [PATCH 46/95] simplify --- src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c | 2 -- tests/rtc-board-mock.c | 1 - 2 files changed, 3 deletions(-) diff --git a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c index 7ac4bb9a1..f63f4fcf9 100644 --- a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c +++ b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c @@ -162,7 +162,6 @@ int main( void ) } -extern bool currently_alarm_ringing; extern uint32_t countdown; extern bool alarm_stopped; @@ -214,7 +213,6 @@ static void transmit_n_times_on_this_credential( void ) } if (countdown == 0) { - currently_alarm_ringing = true; RTC_HandleTypeDef dummy; HAL_RTC_AlarmAEventCallback(&dummy); } diff --git a/tests/rtc-board-mock.c b/tests/rtc-board-mock.c index f75caaa23..dabee9793 100644 --- a/tests/rtc-board-mock.c +++ b/tests/rtc-board-mock.c @@ -53,7 +53,6 @@ typedef struct */ static bool RtcInitialized = false; -bool currently_alarm_ringing = false; uint32_t countdown = 0; bool alarm_stopped = true; From a78b6c0f0671bf999d75ceb0e3835066c7d7037d Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 21:14:42 +0100 Subject: [PATCH 47/95] setup alarm in right place --- src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c index f63f4fcf9..c8ba761c5 100644 --- a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c +++ b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c @@ -149,9 +149,6 @@ int main( void ) /* Initialise timer */ timer_init( ); - /* Transmit immediately (10 milliseconds later) */ - setup_next_tx_alarm( 10 ); - while( 1 ) { switch_to_next_registered_credentials( ); // Switch to the next set of @@ -168,6 +165,9 @@ extern bool alarm_stopped; static void transmit_n_times_on_this_credential( void ) { + /* Transmit immediately (10 milliseconds later) */ + setup_next_tx_alarm( 10 ); + print_current_region( ); /* Configure the subband settings for AS923 BEFORE initing it. Only needed From 2b8fdfc1c1eea386256cbbfcb214daef2fb18db9 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 21:39:26 +0100 Subject: [PATCH 48/95] bump tx count only after the final rx has been received. --- src/apps/LoRaMac/common/callbacks.c | 3 +++ src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/apps/LoRaMac/common/callbacks.c b/src/apps/LoRaMac/common/callbacks.c index 8ff6e7b8a..5ad26e5f5 100644 --- a/src/apps/LoRaMac/common/callbacks.c +++ b/src/apps/LoRaMac/common/callbacks.c @@ -31,6 +31,7 @@ typedef struct } uplink_key_setter_message_t; uplink_key_setter_message_t uplink_key_setter_message; +extern uint32_t tx_count_on_this_credential; void OnNvmDataChange(LmHandlerNvmContextStates_t state, uint16_t size) { @@ -46,6 +47,8 @@ void OnNvmDataChange(LmHandlerNvmContextStates_t state, uint16_t size) */ if (state == LORAMAC_HANDLER_NVM_STORE) { + tx_count_on_this_credential++; + #if GPS_ENABLED setup_GPS(); #endif diff --git a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c index c8ba761c5..89b292f75 100644 --- a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c +++ b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c @@ -260,7 +260,6 @@ static void PrepareTxFrame( void ) return; } - tx_count_on_this_credential ++; sensor_read_and_send( &AppData, LmHandlerParams.Region ); uint32_t interval = read_tx_interval_in_eeprom( TX_INTERVAL_EEPROM_ADDRESS, TX_INTERVAL_GPS_FIX_OK ); From c38236bb8f80aaaea7b1e8c2fb0e2e82ae719575 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 21:43:36 +0100 Subject: [PATCH 49/95] Delete main.h --- tests/mocks/main.h | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 tests/mocks/main.h diff --git a/tests/mocks/main.h b/tests/mocks/main.h deleted file mode 100644 index acefd24b9..000000000 --- a/tests/mocks/main.h +++ /dev/null @@ -1,29 +0,0 @@ -/** - * @file main.h - * @author Medad Newman (medad@medadnewman.co.uk) - * @brief - * @version 0.1 - * @date 2021-08-11 - * - * @copyright Copyright (c) 2021 - * - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __MAIN_H_1 -#define __MAIN_H_1 - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include "LmHandler.h" - - - -#ifdef __cplusplus -} -#endif - -#endif /* __MAIN_H_1 */ From 2d49f21bb5150a53ebc769ad097e424a4e8c4e07 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 21:49:18 +0100 Subject: [PATCH 50/95] Update config.h --- src/peripherals/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/peripherals/config.h b/src/peripherals/config.h index f8cee4d53..94554963f 100644 --- a/src/peripherals/config.h +++ b/src/peripherals/config.h @@ -120,7 +120,7 @@ extern "C" * @brief Define how quickly to return to searching for a GPS fix after transmitting * */ -#define TX_INTERVAL_GPS_FIX_OK 2800 /* When fix was aquired, then sleep for this period (in milliseconds) before searching again */ +#define TX_INTERVAL_GPS_FIX_OK 10000 /* When fix was aquired, then sleep for this period (in milliseconds) before searching again */ /** * @brief Lorawan defaults, normally will not be changed From 787530921a442d87e97ae0c452714f1cb87ab42d Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 21:56:43 +0100 Subject: [PATCH 51/95] move rtc tick simulation off to separate files --- .../periodic-uplink-lpp/B-L072Z-LRWAN1/main.c | 26 +++---------- tests/CMakeLists.txt | 1 + tests/mocks/rtc_mock.c | 39 +++++++++++++++++++ tests/mocks/rtc_mock.h | 12 ++++++ 4 files changed, 57 insertions(+), 21 deletions(-) create mode 100644 tests/mocks/rtc_mock.c create mode 100644 tests/mocks/rtc_mock.h diff --git a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c index 89b292f75..1a4edf6df 100644 --- a/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c +++ b/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c @@ -38,8 +38,10 @@ #include "message_sender.h" #include "eeprom_settings_manager.h" #include "nvmm.h" -#include "stm32l0xx.h" +#ifdef UNITTESTING_LORA +#include "rtc_mock.h" +#endif /*! * User application data @@ -123,10 +125,6 @@ static volatile uint8_t IsTxFramePending = 0; */ extern Uart_t Uart1; -#ifdef UNITTESTING_LORA -extern TimerTime_t current_time; -#endif - uint32_t tx_count_on_this_credential = 0; /*! @@ -159,10 +157,6 @@ int main( void ) } -extern uint32_t countdown; -extern bool alarm_stopped; - - static void transmit_n_times_on_this_credential( void ) { /* Transmit immediately (10 milliseconds later) */ @@ -206,18 +200,8 @@ static void transmit_n_times_on_this_credential( void ) while( tx_count_on_this_credential < N_TRANMISSIONS_PER_CREDENTIAL ) { #ifdef UNITTESTING_LORA - current_time += 1; /* simulate 1 millisecond per loop */ - if (countdown > 0 && !alarm_stopped) - { - countdown--; - } - if (countdown == 0) - { - RTC_HandleTypeDef dummy; - HAL_RTC_AlarmAEventCallback(&dummy); - } - - printf("current time: %d ms, countdown: %d ms, alarm_stopped: %d\n", current_time, countdown, alarm_stopped); + /* simulate 1 millisecond per loop */ + bump_rtc_tick( ); #endif // Process characters sent over the command line interface CliProcess( &Uart1 ); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c541c9c2c..e9a5a1eed 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -96,6 +96,7 @@ set(MOCKS delay-board-mock.c gpio_mock.c rtc-board-mock.c + mocks/rtc_mock.c ) diff --git a/tests/mocks/rtc_mock.c b/tests/mocks/rtc_mock.c new file mode 100644 index 000000000..799c3abfb --- /dev/null +++ b/tests/mocks/rtc_mock.c @@ -0,0 +1,39 @@ +/** + * @file rtc_mock.cpp + * @author Medad Newman (medad@medadnewman.co.uk) + * @brief + * @version 0.1 + * @date 2022-08-08 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "rtc_mock.h" +#include "stdint.h" +#include "stdbool.h" +#include "stm32l0xx.h" +#include "rtc-board.h" + + +extern uint32_t countdown; +extern bool alarm_stopped; +extern TimerTime_t current_time; + + +void bump_rtc_tick() +{ + current_time += 1; /* simulate 1 millisecond per loop */ + if (countdown > 0 && !alarm_stopped) + { + countdown--; + } + + // printf("current time: %d ms, countdown: %d ms, alarm_stopped: %d\n", current_time, countdown, alarm_stopped); + + if (countdown == 0) + { + RTC_HandleTypeDef dummy; + HAL_RTC_AlarmAEventCallback(&dummy); + } +} diff --git a/tests/mocks/rtc_mock.h b/tests/mocks/rtc_mock.h new file mode 100644 index 000000000..0e301cf2f --- /dev/null +++ b/tests/mocks/rtc_mock.h @@ -0,0 +1,12 @@ +/** + * @file rtc_mock.hpp + * @author Medad Newman (medad@medadnewman.co.uk) + * @brief + * @version 0.1 + * @date 2022-08-08 + * + * @copyright Copyright (c) 2022 + * + */ + +void bump_rtc_tick(); From 55c1d173e23c332363d501d60b9ef9f2ae546e27 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 8 Aug 2022 21:57:37 +0100 Subject: [PATCH 52/95] Printout that lorawan stack initialised for wrong region --- src/apps/LoRaMac/common/message_sender.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/apps/LoRaMac/common/message_sender.c b/src/apps/LoRaMac/common/message_sender.c index 0811b77c6..1c505e9e1 100644 --- a/src/apps/LoRaMac/common/message_sender.c +++ b/src/apps/LoRaMac/common/message_sender.c @@ -15,6 +15,7 @@ #include "print_utils.h" #include "callbacks.h" #include "iwdg.h" +#include "stdio.h" bool can_tx(LoRaMacRegion_t current_stack_region); @@ -49,6 +50,10 @@ bool sensor_read_and_send(LmHandlerAppData_t *AppData, LoRaMacRegion_t current_s ret = true; } + else + { + printf("Lorawan stack initialised for wrong region."); + } return ret; } From 52232abc64b39d8742b2262c9867f90af1986361 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 01:55:55 +0100 Subject: [PATCH 53/95] include grpc --- tests/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e9a5a1eed..0e48c0f29 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -182,9 +182,19 @@ set(INTEGRATION_TEST_SOURCE_FILES ${MOCKS} ${FILES_UNDER_TEST} ) + +FetchContent_Declare( + gRPC + GIT_REPOSITORY https://github.com/grpc/grpc + GIT_TAG v1.49.1 + ) +set(FETCHCONTENT_QUIET OFF) +FetchContent_MakeAvailable(gRPC) + add_executable(picotracker_lora_integration_tests ${INTEGRATION_TEST_SOURCE_FILES}) # only build 32-bit binaries target_compile_options(picotracker_lora_integration_tests PRIVATE -m32) target_link_options(picotracker_lora_integration_tests PRIVATE -m32) +target_link_libraries(picotracker_lora_integration_tests grpc++) From 6d45a20e39b75d1d322a7c4df0c71c210800ad5f Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 01:56:09 +0100 Subject: [PATCH 54/95] add greeter client --- tests/greeter_client.cc | 108 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 tests/greeter_client.cc diff --git a/tests/greeter_client.cc b/tests/greeter_client.cc new file mode 100644 index 000000000..6b9c12d50 --- /dev/null +++ b/tests/greeter_client.cc @@ -0,0 +1,108 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include + +#ifdef BAZEL_BUILD +#include "examples/protos/helloworld.grpc.pb.h" +#else +#include "helloworld.grpc.pb.h" +#endif + +using grpc::Channel; +using grpc::ClientContext; +using grpc::Status; +using helloworld::Greeter; +using helloworld::HelloReply; +using helloworld::HelloRequest; + +class GreeterClient { + public: + GreeterClient(std::shared_ptr channel) + : stub_(Greeter::NewStub(channel)) {} + + // Assembles the client's payload, sends it and presents the response back + // from the server. + std::string SayHello(const std::string& user) { + // Data we are sending to the server. + HelloRequest request; + request.set_name(user); + + // Container for the data we expect from the server. + HelloReply reply; + + // Context for the client. It could be used to convey extra information to + // the server and/or tweak certain RPC behaviors. + ClientContext context; + + // The actual RPC. + Status status = stub_->SayHello(&context, request, &reply); + + // Act upon its status. + if (status.ok()) { + return reply.message(); + } else { + std::cout << status.error_code() << ": " << status.error_message() + << std::endl; + return "RPC failed"; + } + } + + private: + std::unique_ptr stub_; +}; + +int main(int argc, char** argv) { + // Instantiate the client. It requires a channel, out of which the actual RPCs + // are created. This channel models a connection to an endpoint specified by + // the argument "--target=" which is the only expected argument. + // We indicate that the channel isn't authenticated (use of + // InsecureChannelCredentials()). + std::string target_str; + std::string arg_str("--target"); + if (argc > 1) { + std::string arg_val = argv[1]; + size_t start_pos = arg_val.find(arg_str); + if (start_pos != std::string::npos) { + start_pos += arg_str.size(); + if (arg_val[start_pos] == '=') { + target_str = arg_val.substr(start_pos + 1); + } else { + std::cout << "The only correct argument syntax is --target=" + << std::endl; + return 0; + } + } else { + std::cout << "The only acceptable argument is --target=" << std::endl; + return 0; + } + } else { + target_str = "localhost:50051"; + } + GreeterClient greeter( + grpc::CreateChannel(target_str, grpc::InsecureChannelCredentials())); + std::string user("world"); + std::string reply = greeter.SayHello(user); + std::cout << "Greeter received: " << reply << std::endl; + + return 0; +} From 1f18f40bd2f52e3ebf98f4d34541cc766ab6bfd9 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 02:42:03 +0100 Subject: [PATCH 55/95] first stab at using protobuf --- tests/CMakeLists.txt | 44 +++++++++++---- tests/common.cmake | 125 +++++++++++++++++++++++++++++++++++++++++ tests/helloworld.proto | 38 +++++++++++++ 3 files changed, 196 insertions(+), 11 deletions(-) create mode 100644 tests/common.cmake create mode 100644 tests/helloworld.proto diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0e48c0f29..b036606f9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -119,10 +119,7 @@ set(FILES_UNDER_TEST ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/LmHandler.c ${PROJECT_SOURCE_DIR}/src/system/delay.c ${PROJECT_SOURCE_DIR}/src/system/timer.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/callbacks.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c - - + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/callbacks.c # Compile region files ${PROJECT_SOURCE_DIR}/src/mac/region/RegionAU915.c @@ -168,6 +165,7 @@ set(FILES_UNDER_TEST ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/message_sender.c ${PROJECT_SOURCE_DIR}/src/system/nvmm.c + greeter_client.cc ) @@ -183,13 +181,37 @@ set(INTEGRATION_TEST_SOURCE_FILES ${FILES_UNDER_TEST} ) -FetchContent_Declare( - gRPC - GIT_REPOSITORY https://github.com/grpc/grpc - GIT_TAG v1.49.1 - ) -set(FETCHCONTENT_QUIET OFF) -FetchContent_MakeAvailable(gRPC) + +SET(THIRD_PARTY_PATH ${CMAKE_CURRENT_BINARY_DIR}) +# SET(GRPC_FETCHCONTENT ON) +include(common.cmake) + +# Proto output dir +set(PB_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generator) +file(MAKE_DIRECTORY ${PB_OUTPUT}) + +# Proto file +get_filename_component(hw_proto "helloworld.proto" ABSOLUTE) +get_filename_component(hw_proto_path "${hw_proto}" PATH) + +# Generated sources +set(hw_proto_srcs "${PB_OUTPUT}/helloworld.pb.cc") +set(hw_proto_hdrs "${PB_OUTPUT}/helloworld.pb.h") +set(hw_grpc_srcs "${PB_OUTPUT}/helloworld.grpc.pb.cc") +set(hw_grpc_hdrs "${PB_OUTPUT}/helloworld.grpc.pb.h") + +add_custom_command( + OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}" + COMMAND ${_PROTOBUF_PROTOC} + ARGS --grpc_out "${PB_OUTPUT}" + --cpp_out "${PB_OUTPUT}" + -I "${hw_proto_path}" + --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" + "${hw_proto}" + DEPENDS "${hw_proto}") + +# Include generated *.pb.h files +include_directories("${PB_OUTPUT}") add_executable(picotracker_lora_integration_tests ${INTEGRATION_TEST_SOURCE_FILES}) diff --git a/tests/common.cmake b/tests/common.cmake new file mode 100644 index 000000000..1326a5be3 --- /dev/null +++ b/tests/common.cmake @@ -0,0 +1,125 @@ +# Copyright 2018 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# cmake build file for C++ route_guide example. +# Assumes protobuf and gRPC have been installed using cmake. +# See cmake_externalproject/CMakeLists.txt for all-in-one cmake build +# that automatically builds all the dependencies before building route_guide. + +cmake_minimum_required(VERSION 3.5.1) + +if (NOT DEFINED CMAKE_CXX_STANDARD) + set (CMAKE_CXX_STANDARD 14) +endif() + +if(MSVC) + add_definitions(-D_WIN32_WINNT=0x600) +endif() + +find_package(Threads REQUIRED) + +if(GRPC_AS_SUBMODULE) + # One way to build a projects that uses gRPC is to just include the + # entire gRPC project tree via "add_subdirectory". + # This approach is very simple to use, but the are some potential + # disadvantages: + # * it includes gRPC's CMakeLists.txt directly into your build script + # without and that can make gRPC's internal setting interfere with your + # own build. + # * depending on what's installed on your system, the contents of submodules + # in gRPC's third_party/* might need to be available (and there might be + # additional prerequisites required to build them). Consider using + # the gRPC_*_PROVIDER options to fine-tune the expected behavior. + # + # A more robust approach to add dependency on gRPC is using + # cmake's ExternalProject_Add (see cmake_externalproject/CMakeLists.txt). + + # Include the gRPC's cmake build (normally grpc source code would live + # in a git submodule called "third_party/grpc", but this example lives in + # the same repository as gRPC sources, so we just look a few directories up) + add_subdirectory(../../.. ${CMAKE_CURRENT_BINARY_DIR}/grpc EXCLUDE_FROM_ALL) + message(STATUS "Using gRPC via add_subdirectory.") + + # After using add_subdirectory, we can now use the grpc targets directly from + # this build. + set(_PROTOBUF_LIBPROTOBUF libprotobuf) + set(_REFLECTION grpc++_reflection) + if(CMAKE_CROSSCOMPILING) + find_program(_PROTOBUF_PROTOC protoc) + else() + set(_PROTOBUF_PROTOC $) + endif() + set(_GRPC_GRPCPP grpc++) + if(CMAKE_CROSSCOMPILING) + find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) + else() + set(_GRPC_CPP_PLUGIN_EXECUTABLE $) + endif() +elseif(GRPC_FETCHCONTENT) + # Another way is to use CMake's FetchContent module to clone gRPC at + # configure time. This makes gRPC's source code available to your project, + # similar to a git submodule. + message(STATUS "Using gRPC via add_subdirectory (FetchContent).") + include(FetchContent) + FetchContent_Declare( + grpc + GIT_REPOSITORY https://github.com/grpc/grpc.git + # when using gRPC, you will actually set this to an existing tag, such as + # v1.25.0, v1.26.0 etc.. + # For the purpose of testing, we override the tag used to the commit + # that's currently under test. + GIT_TAG vGRPC_TAG_VERSION_OF_YOUR_CHOICE) + FetchContent_MakeAvailable(grpc) + + # Since FetchContent uses add_subdirectory under the hood, we can use + # the grpc targets directly from this build. + set(_PROTOBUF_LIBPROTOBUF libprotobuf) + set(_REFLECTION grpc++_reflection) + set(_PROTOBUF_PROTOC $) + set(_GRPC_GRPCPP grpc++) + if(CMAKE_CROSSCOMPILING) + find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) + else() + set(_GRPC_CPP_PLUGIN_EXECUTABLE $) + endif() +else() + # This branch assumes that gRPC and all its dependencies are already installed + # on this system, so they can be located by find_package(). + + # Find Protobuf installation + # Looks for protobuf-config.cmake file installed by Protobuf's cmake installation. + set(protobuf_MODULE_COMPATIBLE TRUE) + find_package(Protobuf CONFIG REQUIRED) + message(STATUS "Using protobuf ${Protobuf_VERSION}") + + set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf) + set(_REFLECTION gRPC::grpc++_reflection) + if(CMAKE_CROSSCOMPILING) + find_program(_PROTOBUF_PROTOC protoc) + else() + set(_PROTOBUF_PROTOC $) + endif() + + # Find gRPC installation + # Looks for gRPCConfig.cmake file installed by gRPC's cmake installation. + find_package(gRPC CONFIG REQUIRED) + message(STATUS "Using gRPC ${gRPC_VERSION}") + + set(_GRPC_GRPCPP gRPC::grpc++) + if(CMAKE_CROSSCOMPILING) + find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) + else() + set(_GRPC_CPP_PLUGIN_EXECUTABLE $) + endif() +endif() diff --git a/tests/helloworld.proto b/tests/helloworld.proto new file mode 100644 index 000000000..be878ce25 --- /dev/null +++ b/tests/helloworld.proto @@ -0,0 +1,38 @@ +// Copyright 2015 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.helloworld"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; + +package helloworld; + +// The greeting service definition. +service Greeter { + // Sends a greeting + rpc SayHello (HelloRequest) returns (HelloReply) {} +} + +// The request message containing the user's name. +message HelloRequest { + string name = 1; +} + +// The response message containing the greetings +message HelloReply { + string message = 1; +} From b210b5284f81e84255624457245241472ef18cc9 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 02:49:14 +0100 Subject: [PATCH 56/95] clone specific version --- tests/common.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/common.cmake b/tests/common.cmake index 1326a5be3..19669b355 100644 --- a/tests/common.cmake +++ b/tests/common.cmake @@ -72,6 +72,7 @@ elseif(GRPC_FETCHCONTENT) # similar to a git submodule. message(STATUS "Using gRPC via add_subdirectory (FetchContent).") include(FetchContent) + set(FETCHCONTENT_QUIET OFF) FetchContent_Declare( grpc GIT_REPOSITORY https://github.com/grpc/grpc.git @@ -79,7 +80,7 @@ elseif(GRPC_FETCHCONTENT) # v1.25.0, v1.26.0 etc.. # For the purpose of testing, we override the tag used to the commit # that's currently under test. - GIT_TAG vGRPC_TAG_VERSION_OF_YOUR_CHOICE) + GIT_TAG v1.49.1) FetchContent_MakeAvailable(grpc) # Since FetchContent uses add_subdirectory under the hood, we can use From 5d918ee9fcbf3e82a677d229306509674e7d5f50 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 02:52:57 +0100 Subject: [PATCH 57/95] use fetchcontent --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b036606f9..d4f1326e6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -183,7 +183,7 @@ set(INTEGRATION_TEST_SOURCE_FILES SET(THIRD_PARTY_PATH ${CMAKE_CURRENT_BINARY_DIR}) -# SET(GRPC_FETCHCONTENT ON) +option(GRPC_FETCHCONTENT "submodule" ON) include(common.cmake) # Proto output dir From 6ac467666a76ec9fd95fffeeecb6fd3069123ebf Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 03:18:19 +0100 Subject: [PATCH 58/95] use src dir --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d4f1326e6..e0b7b5ed0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -187,7 +187,7 @@ option(GRPC_FETCHCONTENT "submodule" ON) include(common.cmake) # Proto output dir -set(PB_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generator) +set(PB_OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/generator) file(MAKE_DIRECTORY ${PB_OUTPUT}) # Proto file From 30944a1184085df7b83353a2e293a5104dd5dcdc Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 03:18:27 +0100 Subject: [PATCH 59/95] status messages --- tests/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e0b7b5ed0..c0a34149a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -200,6 +200,9 @@ set(hw_proto_hdrs "${PB_OUTPUT}/helloworld.pb.h") set(hw_grpc_srcs "${PB_OUTPUT}/helloworld.grpc.pb.cc") set(hw_grpc_hdrs "${PB_OUTPUT}/helloworld.grpc.pb.h") +message(STATUS filepath ${PB_OUTPUT}) +message(STATUS command ${_PROTOBUF_PROTOC}) + add_custom_command( OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}" COMMAND ${_PROTOBUF_PROTOC} @@ -213,6 +216,8 @@ add_custom_command( # Include generated *.pb.h files include_directories("${PB_OUTPUT}") +message(STATUS "Just ran custom command") + add_executable(picotracker_lora_integration_tests ${INTEGRATION_TEST_SOURCE_FILES}) # only build 32-bit binaries From 4134f59967bbd33fe38bb2ab384d762b9d5878d9 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 03:33:14 +0100 Subject: [PATCH 60/95] hack it with fixed cache values --- tests/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c0a34149a..81bc78793 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -203,13 +203,16 @@ set(hw_grpc_hdrs "${PB_OUTPUT}/helloworld.grpc.pb.h") message(STATUS filepath ${PB_OUTPUT}) message(STATUS command ${_PROTOBUF_PROTOC}) +set(helloworld_PROTOBUF_PROTOC_EXECUTABLE "/usr/local/bin/protoc" CACHE STRING "Protoc binary on host") +set(helloworld_GRPC_CPP_PLUGIN_EXECUTABLE "/usr/local/bin/grpc_cpp_plugin" CACHE STRING "gRPC CPP plugin binary on host") + add_custom_command( OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}" - COMMAND ${_PROTOBUF_PROTOC} + COMMAND ${helloworld_PROTOBUF_PROTOC_EXECUTABLE} ARGS --grpc_out "${PB_OUTPUT}" --cpp_out "${PB_OUTPUT}" -I "${hw_proto_path}" - --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" + --plugin=protoc-gen-grpc="${helloworld_GRPC_CPP_PLUGIN_EXECUTABLE}" "${hw_proto}" DEPENDS "${hw_proto}") From b54171d84aec8489a988efe10d12647a67083669 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 11:37:54 +0100 Subject: [PATCH 61/95] shallow clone --- tests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 81bc78793..da50b2c1b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -224,7 +224,7 @@ message(STATUS "Just ran custom command") add_executable(picotracker_lora_integration_tests ${INTEGRATION_TEST_SOURCE_FILES}) # only build 32-bit binaries -target_compile_options(picotracker_lora_integration_tests PRIVATE -m32) -target_link_options(picotracker_lora_integration_tests PRIVATE -m32) +#target_compile_options(picotracker_lora_integration_tests PRIVATE -m32) +#target_link_options(picotracker_lora_integration_tests PRIVATE -m32) target_link_libraries(picotracker_lora_integration_tests grpc++) From 4d4a8420189a57b1355b6bdf8b37f623aea49810 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 11:38:05 +0100 Subject: [PATCH 62/95] Revert "shallow clone" This reverts commit b54171d84aec8489a988efe10d12647a67083669. --- tests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index da50b2c1b..81bc78793 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -224,7 +224,7 @@ message(STATUS "Just ran custom command") add_executable(picotracker_lora_integration_tests ${INTEGRATION_TEST_SOURCE_FILES}) # only build 32-bit binaries -#target_compile_options(picotracker_lora_integration_tests PRIVATE -m32) -#target_link_options(picotracker_lora_integration_tests PRIVATE -m32) +target_compile_options(picotracker_lora_integration_tests PRIVATE -m32) +target_link_options(picotracker_lora_integration_tests PRIVATE -m32) target_link_libraries(picotracker_lora_integration_tests grpc++) From c595f1a423f53e309c20fc12a6675d208d6dda0c Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 11:38:16 +0100 Subject: [PATCH 63/95] shallow clone --- tests/common.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/common.cmake b/tests/common.cmake index 19669b355..dca433f7a 100644 --- a/tests/common.cmake +++ b/tests/common.cmake @@ -80,7 +80,12 @@ elseif(GRPC_FETCHCONTENT) # v1.25.0, v1.26.0 etc.. # For the purpose of testing, we override the tag used to the commit # that's currently under test. - GIT_TAG v1.49.1) + GIT_TAG v1.49.1 + + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE + + ) FetchContent_MakeAvailable(grpc) # Since FetchContent uses add_subdirectory under the hood, we can use From e6f8d92508d643c6b85d0e3dbff6f82137dcae79 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 11:38:24 +0100 Subject: [PATCH 64/95] build 64 bit This reverts commit 4d4a8420189a57b1355b6bdf8b37f623aea49810. --- tests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 81bc78793..da50b2c1b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -224,7 +224,7 @@ message(STATUS "Just ran custom command") add_executable(picotracker_lora_integration_tests ${INTEGRATION_TEST_SOURCE_FILES}) # only build 32-bit binaries -target_compile_options(picotracker_lora_integration_tests PRIVATE -m32) -target_link_options(picotracker_lora_integration_tests PRIVATE -m32) +#target_compile_options(picotracker_lora_integration_tests PRIVATE -m32) +#target_link_options(picotracker_lora_integration_tests PRIVATE -m32) target_link_libraries(picotracker_lora_integration_tests grpc++) From 30aa33024e27559e1503125eb7ff6ed129aa661a Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 12:24:06 +0100 Subject: [PATCH 65/95] use correct paths --- tests/CMakeLists.txt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index da50b2c1b..b7796a180 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -165,7 +165,6 @@ set(FILES_UNDER_TEST ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/message_sender.c ${PROJECT_SOURCE_DIR}/src/system/nvmm.c - greeter_client.cc ) @@ -221,8 +220,26 @@ include_directories("${PB_OUTPUT}") message(STATUS "Just ran custom command") + +set(INTEGRATION_TEST_SOURCE_FILES + ${MOCKS} + ${FILES_UNDER_TEST} + ${hw_grpc_srcs} + ${hw_grpc_hdrs} + ${hw_proto_srcs} + ${hw_proto_hdrs} + greeter_client.cc + +) + add_executable(picotracker_lora_integration_tests ${INTEGRATION_TEST_SOURCE_FILES}) +target_link_libraries(picotracker_lora_integration_tests + ${_REFLECTION} + ${_GRPC_GRPCPP} + ${_PROTOBUF_LIBPROTOBUF}) + + # only build 32-bit binaries #target_compile_options(picotracker_lora_integration_tests PRIVATE -m32) #target_link_options(picotracker_lora_integration_tests PRIVATE -m32) From f03fa0a9a3691a76c4c1db889a6e1ff23f147716 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 12:26:54 +0100 Subject: [PATCH 66/95] delete duplicate --- tests/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b7796a180..90dc8d3be 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -175,10 +175,6 @@ set(SOURCE_FILES ) -set(INTEGRATION_TEST_SOURCE_FILES - ${MOCKS} - ${FILES_UNDER_TEST} -) SET(THIRD_PARTY_PATH ${CMAKE_CURRENT_BINARY_DIR}) From 14d2020ce7c2d7768656b171c58276c21cf9f045 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 12:28:40 +0100 Subject: [PATCH 67/95] Update .gitignore --- .gitignore | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4a29d3aad..6764095e0 100644 --- a/.gitignore +++ b/.gitignore @@ -113,7 +113,10 @@ ipch/ *.dbg* *.scvd -.vscode/.cortex-debug.registers.state.json -:50003 -:50006 -.vscode/.cortex-debug.peripherals.state.json +.vscode/.cortex-debug.registers.state.json +:50003 +:50006 +.vscode/.cortex-debug.peripherals.state.json + +# Generated files +tests/generator From 9b63bf89019987912004113833debd73b78d7013 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 12:29:00 +0100 Subject: [PATCH 68/95] temp disable usage of main.c --- src/apps/LoRaMac/common/callbacks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/LoRaMac/common/callbacks.c b/src/apps/LoRaMac/common/callbacks.c index 5ad26e5f5..fb7afef95 100644 --- a/src/apps/LoRaMac/common/callbacks.c +++ b/src/apps/LoRaMac/common/callbacks.c @@ -31,7 +31,7 @@ typedef struct } uplink_key_setter_message_t; uplink_key_setter_message_t uplink_key_setter_message; -extern uint32_t tx_count_on_this_credential; +// extern uint32_t tx_count_on_this_credential; void OnNvmDataChange(LmHandlerNvmContextStates_t state, uint16_t size) { @@ -47,7 +47,7 @@ void OnNvmDataChange(LmHandlerNvmContextStates_t state, uint16_t size) */ if (state == LORAMAC_HANDLER_NVM_STORE) { - tx_count_on_this_credential++; + // tx_count_on_this_credential++; #if GPS_ENABLED setup_GPS(); From 3779853c6c53a45a0068a77f7064f82440a81e76 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 12:46:36 +0100 Subject: [PATCH 69/95] get rid of cpputest --- tests/CMakeLists.txt | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 90dc8d3be..6fef7dfa4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,22 +1,6 @@ cmake_minimum_required(VERSION 3.7) -# Get the test framework Cpputest -include(FetchContent) -FetchContent_Declare( - cpputest - GIT_REPOSITORY https://github.com/cpputest/cpputest.git - GIT_TAG v4.0 -) -# Set this to ON if you want to have the CppUTests in your project as well. -set(TESTS OFF CACHE BOOL "Switch off CppUTest Test build") - - -set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} -m32") -set(CPPUTEST_LD_FLAGS "${CPPUTEST_LD_FLAGS} -m32") - -FetchContent_MakeAvailable(cpputest) - add_definitions( -DREGION_EU868 -DREGION_US915 From e0f5a2764f0e8e147c55d2ad5923ee3f9bf28141 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 12:59:07 +0100 Subject: [PATCH 70/95] parallel build --- CMakePresets.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index c9e420402..9f3c5a71e 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -61,17 +61,25 @@ } ], "buildPresets": [ + { + "name": "parallel_build", + "description": "Build will all cores", + "displayName": "parallel_build", + "jobs": 0 + }, { "name": "unittest_build", "description": "Build the unittest", "displayName": "unittest_build", - "configurePreset": "unittesting_configs" + "configurePreset": "unittesting_configs", + "inherits": "parallel_build" }, { "name": "target_build", "description": "Build for the STM32l0 target", "displayName": "target_build", - "configurePreset": "on_target_configs" + "configurePreset": "on_target_configs", + "inherits": "parallel_build" } ], "testPresets": [ From dd7eb366f893082c6b8949c78f8c6f30a070e0a3 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 13:29:32 +0100 Subject: [PATCH 71/95] use pre-installed protobuf based on https://rolandsdev.blog/posts/cross-compile-grpc-for-arm-with-docker/#write-a-little-hello-app --- .github/workflows/cpputest.yml | 7 +- tests/CMakeLists.txt | 269 +++++------------------- tests/{helloworld.proto => hello.proto} | 0 3 files changed, 56 insertions(+), 220 deletions(-) rename tests/{helloworld.proto => hello.proto} (100%) diff --git a/.github/workflows/cpputest.yml b/.github/workflows/cpputest.yml index 7e05da850..d3d12763f 100644 --- a/.github/workflows/cpputest.yml +++ b/.github/workflows/cpputest.yml @@ -11,7 +11,9 @@ env: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 + container: + image: pllee4/ubuntu-ci:20.04-gRPC steps: - uses: actions/checkout@v2 @@ -23,6 +25,3 @@ jobs: - name: Build run: cmake --build --preset=unittest_build - - - name: Test - run: ctest --preset=unittest --rerun-failed --output-on-failure diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6fef7dfa4..6eea9f055 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,227 +1,64 @@ -cmake_minimum_required(VERSION 3.7) +# src/CMakeLists.txt +cmake_minimum_required(VERSION 3.5.1) +# For Protobuf's cmake warnings +if(POLICY CMP0077) + cmake_policy(SET CMP0077 NEW) +endif() -add_definitions( - -DREGION_EU868 - -DREGION_US915 - -DREGION_AU915 - -DREGION_CN470 - -DREGION_AS923 - -DREGION_KR920 - -DREGION_IN865 - -DREGION_RU864 - -DSOFT_SE -DSTM32L072xx -DUSE_HAL_DRIVER -DUNITTESTING_LORA) +project(hello C CXX) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +find_package(Threads REQUIRED) -add_definitions( - -DREGION_AS923_DEFAULT_CHANNEL_PLAN=CHANNEL_PLAN_GROUP_AS923_1 +# Find Protobuf installation +# Looks for protobuf-config.cmake file installed by Protobuf's cmake installation. +set(protobuf_MODULE_COMPATIBLE TRUE) +find_package(Protobuf CONFIG REQUIRED) +message(STATUS "Using protobuf ${Protobuf_VERSION}") -) +set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf) +set(_REFLECTION gRPC::grpc++_reflection) +find_program(_PROTOBUF_PROTOC protoc) +# Find gRPC installation +# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation. +find_package(gRPC CONFIG REQUIRED) +message(STATUS "Using gRPC ${gRPC_VERSION}") -include_directories(${CPPUTEST_SRC_DIR}) -include_directories(${CPPUTESTEXT_SRC_DIR}) +set(_GRPC_GRPCPP gRPC::grpc++) +find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) -# Test includes -include_directories(${PROJECT_SOURCE_DIR}/mocking) -include_directories(${PROJECT_SOURCE_DIR}/tests/mocks/) - - -# Loramac original header files -include_directories(${PROJECT_SOURCE_DIR}/src/peripherals/) -include_directories(${PROJECT_SOURCE_DIR}/src/mac/) -include_directories(${PROJECT_SOURCE_DIR}/src/mac/region/) -include_directories(${PROJECT_SOURCE_DIR}/src/system/) -include_directories(${PROJECT_SOURCE_DIR}/src/boards/) -include_directories(${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/) -include_directories(${PROJECT_SOURCE_DIR}/src/peripherals/soft-se/) -include_directories(${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/) -include_directories(${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/packages/) -include_directories(${PROJECT_SOURCE_DIR}/src/radio/) -include_directories(${PROJECT_SOURCE_DIR}/src/boards/B-L072Z-LRWAN1/) -include_directories(${PROJECT_SOURCE_DIR}/src/boards/B-L072Z-LRWAN1/cmsis/) -include_directories(${PROJECT_SOURCE_DIR}/src/boards/mcu/stm32/STM32L0xx_HAL_Driver/Inc/) -include_directories(${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/) -include_directories(${PROJECT_SOURCE_DIR}/src/radio/sx1276/) - - - - -# Unittests -set(UNIT_TESTS - main.cpp - geofence_ut.cpp - playback_ut.cpp - lorawan_credentials_ut.cpp - NvmDataMgmt_ut.cpp - app_ut.cpp - bsp_ut.cpp - print_utils_ut.cpp - soft_se_ut.cpp - LoRaWAN_config_switcher_ut.cpp - uplink_commands_ut.cpp - message_sender_ut.cpp - position_time_encoder_ut.cpp - test_eeprom_settings_manager.cpp -) - -# Mocks -set(MOCKS - sx1276-board-mock.c - cli-mock.c - board-mock.c - sx1276-mock.c - bsp_mock.cpp - eeprom-board-mock.cpp - # loramac-mock.cpp - systime-mock.cpp - ublox-mock.cpp - nvm_images.cpp - delay-board-mock.c - gpio_mock.c - rtc-board-mock.c - mocks/rtc_mock.c -) - - - -# CLI sources - - -# Put in compile files(all logic so no hardware connection) -set(FILES_UNDER_TEST - ${PROJECT_SOURCE_DIR}/src/peripherals/geofence.c - ${PROJECT_SOURCE_DIR}/src/peripherals/playback.c - ${PROJECT_SOURCE_DIR}/src/peripherals/bsp.c - ${PROJECT_SOURCE_DIR}/src/peripherals/struct.c - ${PROJECT_SOURCE_DIR}/src/peripherals/print_utils.c - ${PROJECT_SOURCE_DIR}/src/peripherals/position_time_encoder.c - ${PROJECT_SOURCE_DIR}/src/peripherals/LoRaWAN_config_switcher.c - ${PROJECT_SOURCE_DIR}/src/peripherals/linear_congruential_generator.c - ${PROJECT_SOURCE_DIR}/src/peripherals/eeprom_settings_manager.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandlerMsgDisplay.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/LmHandler.c - ${PROJECT_SOURCE_DIR}/src/system/delay.c - ${PROJECT_SOURCE_DIR}/src/system/timer.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/callbacks.c - - # Compile region files - ${PROJECT_SOURCE_DIR}/src/mac/region/RegionAU915.c - ${PROJECT_SOURCE_DIR}/src/mac/region/RegionUS915.c - ${PROJECT_SOURCE_DIR}/src/mac/region/RegionAS923.c - ${PROJECT_SOURCE_DIR}/src/mac/region/RegionCN470.c - ${PROJECT_SOURCE_DIR}/src/mac/region/RegionEU868.c - ${PROJECT_SOURCE_DIR}/src/mac/region/RegionIN865.c - ${PROJECT_SOURCE_DIR}/src/mac/region/RegionKR920.c - ${PROJECT_SOURCE_DIR}/src/mac/region/RegionRU864.c - ${PROJECT_SOURCE_DIR}/src/mac/region/RegionBaseUS.c - ${PROJECT_SOURCE_DIR}/src/mac/region/RegionCommon.c - ${PROJECT_SOURCE_DIR}/src/mac/region/Region.c - - - ${PROJECT_SOURCE_DIR}/src/mac/LoRaMac.c - ${PROJECT_SOURCE_DIR}/src/mac/LoRaMacAdr.c - ${PROJECT_SOURCE_DIR}/src/mac/LoRaMacClassB.c - ${PROJECT_SOURCE_DIR}/src/mac/LoRaMacCommands.c - ${PROJECT_SOURCE_DIR}/src/mac/LoRaMacConfirmQueue.c - ${PROJECT_SOURCE_DIR}/src/mac/LoRaMacCrypto.c - ${PROJECT_SOURCE_DIR}/src/mac/LoRaMacParser.c - ${PROJECT_SOURCE_DIR}/src/mac/LoRaMacSerializer.c - - ${PROJECT_SOURCE_DIR}/src/peripherals/soft-se/soft-se.c - ${PROJECT_SOURCE_DIR}/src/peripherals/soft-se/cmac.c - ${PROJECT_SOURCE_DIR}/src/peripherals/soft-se/aes.c - ${PROJECT_SOURCE_DIR}/src/peripherals/soft-se/soft-se-hal.c - - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/CayenneLpp.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandlerMsgDisplay.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/NvmDataMgmt.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/LmHandler.c - - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/packages/FragDecoder.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/packages/LmhpClockSync.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/packages/LmhpCompliance.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/packages/LmhpFragmentation.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/packages/LmhpRemoteMcastSetup.c - - ${PROJECT_SOURCE_DIR}/src/boards/mcu/utilities.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/NvmDataMgmt.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/message_sender.c - - ${PROJECT_SOURCE_DIR}/src/system/nvmm.c - -) - -set(SOURCE_FILES - ${UNIT_TESTS} - ${MOCKS} - ${FILES_UNDER_TEST} -) - - - - -SET(THIRD_PARTY_PATH ${CMAKE_CURRENT_BINARY_DIR}) -option(GRPC_FETCHCONTENT "submodule" ON) -include(common.cmake) - -# Proto output dir -set(PB_OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/generator) -file(MAKE_DIRECTORY ${PB_OUTPUT}) - -# Proto file -get_filename_component(hw_proto "helloworld.proto" ABSOLUTE) -get_filename_component(hw_proto_path "${hw_proto}" PATH) +# Protos +get_filename_component(h_proto "hello.proto" ABSOLUTE) +get_filename_component(h_proto_path "${h_proto}" PATH) # Generated sources -set(hw_proto_srcs "${PB_OUTPUT}/helloworld.pb.cc") -set(hw_proto_hdrs "${PB_OUTPUT}/helloworld.pb.h") -set(hw_grpc_srcs "${PB_OUTPUT}/helloworld.grpc.pb.cc") -set(hw_grpc_hdrs "${PB_OUTPUT}/helloworld.grpc.pb.h") - -message(STATUS filepath ${PB_OUTPUT}) -message(STATUS command ${_PROTOBUF_PROTOC}) - -set(helloworld_PROTOBUF_PROTOC_EXECUTABLE "/usr/local/bin/protoc" CACHE STRING "Protoc binary on host") -set(helloworld_GRPC_CPP_PLUGIN_EXECUTABLE "/usr/local/bin/grpc_cpp_plugin" CACHE STRING "gRPC CPP plugin binary on host") - +set(h_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/hello.pb.cc") +set(h_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/hello.pb.h") +set(h_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/hello.grpc.pb.cc") +set(h_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/hello.grpc.pb.h") add_custom_command( - OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}" - COMMAND ${helloworld_PROTOBUF_PROTOC_EXECUTABLE} - ARGS --grpc_out "${PB_OUTPUT}" - --cpp_out "${PB_OUTPUT}" - -I "${hw_proto_path}" - --plugin=protoc-gen-grpc="${helloworld_GRPC_CPP_PLUGIN_EXECUTABLE}" - "${hw_proto}" - DEPENDS "${hw_proto}") - -# Include generated *.pb.h files -include_directories("${PB_OUTPUT}") - -message(STATUS "Just ran custom command") - - -set(INTEGRATION_TEST_SOURCE_FILES - ${MOCKS} - ${FILES_UNDER_TEST} - ${hw_grpc_srcs} - ${hw_grpc_hdrs} - ${hw_proto_srcs} - ${hw_proto_hdrs} - greeter_client.cc - -) - -add_executable(picotracker_lora_integration_tests ${INTEGRATION_TEST_SOURCE_FILES}) - -target_link_libraries(picotracker_lora_integration_tests - ${_REFLECTION} - ${_GRPC_GRPCPP} - ${_PROTOBUF_LIBPROTOBUF}) - - -# only build 32-bit binaries -#target_compile_options(picotracker_lora_integration_tests PRIVATE -m32) -#target_link_options(picotracker_lora_integration_tests PRIVATE -m32) -target_link_libraries(picotracker_lora_integration_tests grpc++) - + OUTPUT "${h_proto_srcs}" "${h_proto_hdrs}" "${h_grpc_srcs}" "${h_grpc_hdrs}" + COMMAND ${_PROTOBUF_PROTOC} + ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" + --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" + -I "${h_proto_path}" + --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" + "${h_proto}" + DEPENDS "${h_proto}") + +# Generated sources headers +include_directories("${CMAKE_CURRENT_BINARY_DIR}") + +# Targets (the binaries) +foreach(_target + greeter_client) + add_executable(${_target} "${_target}.cc" + ${h_proto_srcs} + ${h_grpc_srcs}) + target_link_libraries(${_target} + ${_REFLECTION} + ${_GRPC_GRPCPP} + ${_PROTOBUF_LIBPROTOBUF}) +endforeach() diff --git a/tests/helloworld.proto b/tests/hello.proto similarity index 100% rename from tests/helloworld.proto rename to tests/hello.proto From 48396daa9ecb5f6559521bd05fc9698cdfe87710 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 13:34:47 +0100 Subject: [PATCH 72/95] Update cpputest.yml --- .github/workflows/cpputest.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/cpputest.yml b/.github/workflows/cpputest.yml index d3d12763f..e27d9226a 100644 --- a/.github/workflows/cpputest.yml +++ b/.github/workflows/cpputest.yml @@ -12,13 +12,11 @@ env: jobs: build: runs-on: ubuntu-20.04 - container: + container: image: pllee4/ubuntu-ci:20.04-gRPC steps: - uses: actions/checkout@v2 - - name: dependencies install - run: sudo apt-get install lcov gcovr gcc-multilib g++-multilib - name: Configure CMake run: cmake --preset unittesting_configs From 0369dd399f10eb7faa656362f4e4b2f9eac5a6d0 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 13:45:58 +0100 Subject: [PATCH 73/95] Update cpputest.yml --- .github/workflows/cpputest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpputest.yml b/.github/workflows/cpputest.yml index e27d9226a..f4090e599 100644 --- a/.github/workflows/cpputest.yml +++ b/.github/workflows/cpputest.yml @@ -13,7 +13,7 @@ jobs: build: runs-on: ubuntu-20.04 container: - image: pllee4/ubuntu-ci:20.04-gRPC + image: grpctesting/cxx_jessie_x64 steps: - uses: actions/checkout@v2 From 3b04da0b0c90e25ae7e2e32e52b6802177edd0c4 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 13:48:25 +0100 Subject: [PATCH 74/95] Update cpputest.yml --- .github/workflows/cpputest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpputest.yml b/.github/workflows/cpputest.yml index f4090e599..acad72361 100644 --- a/.github/workflows/cpputest.yml +++ b/.github/workflows/cpputest.yml @@ -13,7 +13,7 @@ jobs: build: runs-on: ubuntu-20.04 container: - image: grpctesting/cxx_jessie_x64 + image: grpctesting/cxx_alpine_x64 steps: - uses: actions/checkout@v2 From a676fa50c66360b71c220252c3be47259acd2ce8 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 19:08:42 +0100 Subject: [PATCH 75/95] Revert "Update cpputest.yml" This reverts commit 3b04da0b0c90e25ae7e2e32e52b6802177edd0c4. --- .github/workflows/cpputest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpputest.yml b/.github/workflows/cpputest.yml index acad72361..f4090e599 100644 --- a/.github/workflows/cpputest.yml +++ b/.github/workflows/cpputest.yml @@ -13,7 +13,7 @@ jobs: build: runs-on: ubuntu-20.04 container: - image: grpctesting/cxx_alpine_x64 + image: grpctesting/cxx_jessie_x64 steps: - uses: actions/checkout@v2 From 21f768c8a1f7b651967ed6b433fd5ecf477ebd2b Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 19:08:48 +0100 Subject: [PATCH 76/95] Revert "Update cpputest.yml" This reverts commit 0369dd399f10eb7faa656362f4e4b2f9eac5a6d0. --- .github/workflows/cpputest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpputest.yml b/.github/workflows/cpputest.yml index f4090e599..e27d9226a 100644 --- a/.github/workflows/cpputest.yml +++ b/.github/workflows/cpputest.yml @@ -13,7 +13,7 @@ jobs: build: runs-on: ubuntu-20.04 container: - image: grpctesting/cxx_jessie_x64 + image: pllee4/ubuntu-ci:20.04-gRPC steps: - uses: actions/checkout@v2 From 9413b4ac133eb75289a5d47c61863e678252ed0f Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 19:08:52 +0100 Subject: [PATCH 77/95] Revert "Update cpputest.yml" This reverts commit 48396daa9ecb5f6559521bd05fc9698cdfe87710. --- .github/workflows/cpputest.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cpputest.yml b/.github/workflows/cpputest.yml index e27d9226a..d3d12763f 100644 --- a/.github/workflows/cpputest.yml +++ b/.github/workflows/cpputest.yml @@ -12,11 +12,13 @@ env: jobs: build: runs-on: ubuntu-20.04 - container: + container: image: pllee4/ubuntu-ci:20.04-gRPC steps: - uses: actions/checkout@v2 + - name: dependencies install + run: sudo apt-get install lcov gcovr gcc-multilib g++-multilib - name: Configure CMake run: cmake --preset unittesting_configs From a11cd6eafa81d7f277352a744076373c8880bdc5 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 19:10:26 +0100 Subject: [PATCH 78/95] use correct path --- tests/greeter_client.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/greeter_client.cc b/tests/greeter_client.cc index 6b9c12d50..29ede7a42 100644 --- a/tests/greeter_client.cc +++ b/tests/greeter_client.cc @@ -25,7 +25,7 @@ #ifdef BAZEL_BUILD #include "examples/protos/helloworld.grpc.pb.h" #else -#include "helloworld.grpc.pb.h" +#include "hello.grpc.pb.h" #endif using grpc::Channel; From 27c63bde2711919c14dddeaac4a1285dafcf95a3 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 21:16:25 +0100 Subject: [PATCH 79/95] move code into ublox-mock --- tests/greeter_client.cc | 108 ---------------------------------------- tests/ublox-mock.cpp | 95 +++++++++++++++++++++++++++++++++-- 2 files changed, 92 insertions(+), 111 deletions(-) delete mode 100644 tests/greeter_client.cc diff --git a/tests/greeter_client.cc b/tests/greeter_client.cc deleted file mode 100644 index 29ede7a42..000000000 --- a/tests/greeter_client.cc +++ /dev/null @@ -1,108 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include - -#include - -#ifdef BAZEL_BUILD -#include "examples/protos/helloworld.grpc.pb.h" -#else -#include "hello.grpc.pb.h" -#endif - -using grpc::Channel; -using grpc::ClientContext; -using grpc::Status; -using helloworld::Greeter; -using helloworld::HelloReply; -using helloworld::HelloRequest; - -class GreeterClient { - public: - GreeterClient(std::shared_ptr channel) - : stub_(Greeter::NewStub(channel)) {} - - // Assembles the client's payload, sends it and presents the response back - // from the server. - std::string SayHello(const std::string& user) { - // Data we are sending to the server. - HelloRequest request; - request.set_name(user); - - // Container for the data we expect from the server. - HelloReply reply; - - // Context for the client. It could be used to convey extra information to - // the server and/or tweak certain RPC behaviors. - ClientContext context; - - // The actual RPC. - Status status = stub_->SayHello(&context, request, &reply); - - // Act upon its status. - if (status.ok()) { - return reply.message(); - } else { - std::cout << status.error_code() << ": " << status.error_message() - << std::endl; - return "RPC failed"; - } - } - - private: - std::unique_ptr stub_; -}; - -int main(int argc, char** argv) { - // Instantiate the client. It requires a channel, out of which the actual RPCs - // are created. This channel models a connection to an endpoint specified by - // the argument "--target=" which is the only expected argument. - // We indicate that the channel isn't authenticated (use of - // InsecureChannelCredentials()). - std::string target_str; - std::string arg_str("--target"); - if (argc > 1) { - std::string arg_val = argv[1]; - size_t start_pos = arg_val.find(arg_str); - if (start_pos != std::string::npos) { - start_pos += arg_str.size(); - if (arg_val[start_pos] == '=') { - target_str = arg_val.substr(start_pos + 1); - } else { - std::cout << "The only correct argument syntax is --target=" - << std::endl; - return 0; - } - } else { - std::cout << "The only acceptable argument is --target=" << std::endl; - return 0; - } - } else { - target_str = "localhost:50051"; - } - GreeterClient greeter( - grpc::CreateChannel(target_str, grpc::InsecureChannelCredentials())); - std::string user("world"); - std::string reply = greeter.SayHello(user); - std::cout << "Greeter received: " << reply << std::endl; - - return 0; -} diff --git a/tests/ublox-mock.cpp b/tests/ublox-mock.cpp index 0ebb0bdf3..ba24adc0a 100644 --- a/tests/ublox-mock.cpp +++ b/tests/ublox-mock.cpp @@ -4,11 +4,87 @@ extern "C" #include "ublox.h" } -gps_info_t dummy_gps_info = { - .GPS_UBX_latitude_Float = 1.290270, - .GPS_UBX_longitude_Float = 103.851959 +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include + +#ifdef BAZEL_BUILD +#include "examples/protos/helloworld.grpc.pb.h" +#else +#include "hello.grpc.pb.h" +#endif + +using grpc::Channel; +using grpc::ClientContext; +using grpc::Status; +using helloworld::Greeter; +using helloworld::HelloReply; +using helloworld::HelloRequest; + +class GreeterClient +{ +public: + GreeterClient(std::shared_ptr channel) + : stub_(Greeter::NewStub(channel)) {} + + // Assembles the client's payload, sends it and presents the response back + // from the server. + std::string SayHello(const std::string &user) + { + // Data we are sending to the server. + HelloRequest request; + request.set_name(user); + + // Container for the data we expect from the server. + HelloReply reply; + + // Context for the client. It could be used to convey extra information to + // the server and/or tweak certain RPC behaviors. + ClientContext context; + + // The actual RPC. + Status status = stub_->SayHello(&context, request, &reply); + + // Act upon its status. + if (status.ok()) + { + return reply.message(); + } + else + { + std::cout << status.error_code() << ": " << status.error_message() + << std::endl; + return "RPC failed"; + } + } + +private: + std::unique_ptr stub_; }; +gps_info_t dummy_gps_info = { + .GPS_UBX_latitude_Float = 1.290270, + .GPS_UBX_longitude_Float = 103.851959}; gps_status_t get_location_fix(uint32_t timeout) { @@ -32,6 +108,19 @@ uint16_t get_load_solar_voltage() gps_info_t get_latest_gps_info() { + + // Instantiate the client. It requires a channel, out of which the actual RPCs + // are created. This channel models a connection to an endpoint specified by + // the argument "--target=" which is the only expected argument. + // We indicate that the channel isn't authenticated (use of + // InsecureChannelCredentials()). + std::string target_str = "localhost:50051"; + GreeterClient greeter( + grpc::CreateChannel(target_str, grpc::InsecureChannelCredentials())); + std::string user("world"); + std::string reply = greeter.SayHello(user); + std::cout << "Greeter received: " << reply << std::endl; + return dummy_gps_info; } From c71aa2cdab1b7f786a7a96f5f21aa5effa1b91ef Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 21:19:40 +0100 Subject: [PATCH 80/95] put in project files --- tests/CMakeLists.txt | 143 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6eea9f055..6770e68e9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,6 +9,149 @@ endif() project(hello C CXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + +add_definitions( + -DREGION_EU868 + -DREGION_US915 + -DREGION_AU915 + -DREGION_CN470 + -DREGION_AS923 + -DREGION_KR920 + -DREGION_IN865 + -DREGION_RU864 + -DSOFT_SE -DSTM32L072xx -DUSE_HAL_DRIVER -DUNITTESTING_LORA) + + +add_definitions( + -DREGION_AS923_DEFAULT_CHANNEL_PLAN=CHANNEL_PLAN_GROUP_AS923_1 + +) + + +# Test includes +include_directories(${PROJECT_SOURCE_DIR}/mocking) +include_directories(${PROJECT_SOURCE_DIR}/tests/mocks/) + + +# Loramac original header files +include_directories(${PROJECT_SOURCE_DIR}/src/peripherals/) +include_directories(${PROJECT_SOURCE_DIR}/src/mac/) +include_directories(${PROJECT_SOURCE_DIR}/src/mac/region/) +include_directories(${PROJECT_SOURCE_DIR}/src/system/) +include_directories(${PROJECT_SOURCE_DIR}/src/boards/) +include_directories(${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/) +include_directories(${PROJECT_SOURCE_DIR}/src/peripherals/soft-se/) +include_directories(${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/) +include_directories(${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/packages/) +include_directories(${PROJECT_SOURCE_DIR}/src/radio/) +include_directories(${PROJECT_SOURCE_DIR}/src/boards/B-L072Z-LRWAN1/) +include_directories(${PROJECT_SOURCE_DIR}/src/boards/B-L072Z-LRWAN1/cmsis/) +include_directories(${PROJECT_SOURCE_DIR}/src/boards/mcu/stm32/STM32L0xx_HAL_Driver/Inc/) +include_directories(${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/) +include_directories(${PROJECT_SOURCE_DIR}/src/radio/sx1276/) + + + + +# Unittests +set(UNIT_TESTS + main.cpp + geofence_ut.cpp + playback_ut.cpp + lorawan_credentials_ut.cpp + NvmDataMgmt_ut.cpp + app_ut.cpp + bsp_ut.cpp + print_utils_ut.cpp + soft_se_ut.cpp + LoRaWAN_config_switcher_ut.cpp + uplink_commands_ut.cpp + message_sender_ut.cpp + position_time_encoder_ut.cpp + test_eeprom_settings_manager.cpp +) + +# Mocks +set(MOCKS + sx1276-board-mock.c + cli-mock.c + board-mock.c + sx1276-mock.c + bsp_mock.cpp + eeprom-board-mock.cpp + # loramac-mock.cpp + systime-mock.cpp + ublox-mock.cpp + nvm_images.cpp + delay-board-mock.c + gpio_mock.c + rtc-board-mock.c + mocks/rtc_mock.c +) + +# Put in compile files(all logic so no hardware connection) +set(FILES_UNDER_TEST + ${PROJECT_SOURCE_DIR}/src/peripherals/geofence.c + ${PROJECT_SOURCE_DIR}/src/peripherals/playback.c + ${PROJECT_SOURCE_DIR}/src/peripherals/bsp.c + ${PROJECT_SOURCE_DIR}/src/peripherals/struct.c + ${PROJECT_SOURCE_DIR}/src/peripherals/print_utils.c + ${PROJECT_SOURCE_DIR}/src/peripherals/position_time_encoder.c + ${PROJECT_SOURCE_DIR}/src/peripherals/LoRaWAN_config_switcher.c + ${PROJECT_SOURCE_DIR}/src/peripherals/linear_congruential_generator.c + ${PROJECT_SOURCE_DIR}/src/peripherals/eeprom_settings_manager.c + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandlerMsgDisplay.c + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/LmHandler.c + ${PROJECT_SOURCE_DIR}/src/system/delay.c + ${PROJECT_SOURCE_DIR}/src/system/timer.c + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/callbacks.c + + # Compile region files + ${PROJECT_SOURCE_DIR}/src/mac/region/RegionAU915.c + ${PROJECT_SOURCE_DIR}/src/mac/region/RegionUS915.c + ${PROJECT_SOURCE_DIR}/src/mac/region/RegionAS923.c + ${PROJECT_SOURCE_DIR}/src/mac/region/RegionCN470.c + ${PROJECT_SOURCE_DIR}/src/mac/region/RegionEU868.c + ${PROJECT_SOURCE_DIR}/src/mac/region/RegionIN865.c + ${PROJECT_SOURCE_DIR}/src/mac/region/RegionKR920.c + ${PROJECT_SOURCE_DIR}/src/mac/region/RegionRU864.c + ${PROJECT_SOURCE_DIR}/src/mac/region/RegionBaseUS.c + ${PROJECT_SOURCE_DIR}/src/mac/region/RegionCommon.c + ${PROJECT_SOURCE_DIR}/src/mac/region/Region.c + + + ${PROJECT_SOURCE_DIR}/src/mac/LoRaMac.c + ${PROJECT_SOURCE_DIR}/src/mac/LoRaMacAdr.c + ${PROJECT_SOURCE_DIR}/src/mac/LoRaMacClassB.c + ${PROJECT_SOURCE_DIR}/src/mac/LoRaMacCommands.c + ${PROJECT_SOURCE_DIR}/src/mac/LoRaMacConfirmQueue.c + ${PROJECT_SOURCE_DIR}/src/mac/LoRaMacCrypto.c + ${PROJECT_SOURCE_DIR}/src/mac/LoRaMacParser.c + ${PROJECT_SOURCE_DIR}/src/mac/LoRaMacSerializer.c + + ${PROJECT_SOURCE_DIR}/src/peripherals/soft-se/soft-se.c + ${PROJECT_SOURCE_DIR}/src/peripherals/soft-se/cmac.c + ${PROJECT_SOURCE_DIR}/src/peripherals/soft-se/aes.c + ${PROJECT_SOURCE_DIR}/src/peripherals/soft-se/soft-se-hal.c + + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/CayenneLpp.c + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandlerMsgDisplay.c + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/NvmDataMgmt.c + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/LmHandler.c + + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/packages/FragDecoder.c + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/packages/LmhpClockSync.c + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/packages/LmhpCompliance.c + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/packages/LmhpFragmentation.c + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/LmHandler/packages/LmhpRemoteMcastSetup.c + + ${PROJECT_SOURCE_DIR}/src/boards/mcu/utilities.c + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/NvmDataMgmt.c + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/message_sender.c + + ${PROJECT_SOURCE_DIR}/src/system/nvmm.c +) + find_package(Threads REQUIRED) # Find Protobuf installation From 2c52cf82999b4ec6056d9d8222ee9fece5925974 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 21:23:38 +0100 Subject: [PATCH 81/95] Delete common.cmake --- tests/common.cmake | 131 --------------------------------------------- 1 file changed, 131 deletions(-) delete mode 100644 tests/common.cmake diff --git a/tests/common.cmake b/tests/common.cmake deleted file mode 100644 index dca433f7a..000000000 --- a/tests/common.cmake +++ /dev/null @@ -1,131 +0,0 @@ -# Copyright 2018 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# cmake build file for C++ route_guide example. -# Assumes protobuf and gRPC have been installed using cmake. -# See cmake_externalproject/CMakeLists.txt for all-in-one cmake build -# that automatically builds all the dependencies before building route_guide. - -cmake_minimum_required(VERSION 3.5.1) - -if (NOT DEFINED CMAKE_CXX_STANDARD) - set (CMAKE_CXX_STANDARD 14) -endif() - -if(MSVC) - add_definitions(-D_WIN32_WINNT=0x600) -endif() - -find_package(Threads REQUIRED) - -if(GRPC_AS_SUBMODULE) - # One way to build a projects that uses gRPC is to just include the - # entire gRPC project tree via "add_subdirectory". - # This approach is very simple to use, but the are some potential - # disadvantages: - # * it includes gRPC's CMakeLists.txt directly into your build script - # without and that can make gRPC's internal setting interfere with your - # own build. - # * depending on what's installed on your system, the contents of submodules - # in gRPC's third_party/* might need to be available (and there might be - # additional prerequisites required to build them). Consider using - # the gRPC_*_PROVIDER options to fine-tune the expected behavior. - # - # A more robust approach to add dependency on gRPC is using - # cmake's ExternalProject_Add (see cmake_externalproject/CMakeLists.txt). - - # Include the gRPC's cmake build (normally grpc source code would live - # in a git submodule called "third_party/grpc", but this example lives in - # the same repository as gRPC sources, so we just look a few directories up) - add_subdirectory(../../.. ${CMAKE_CURRENT_BINARY_DIR}/grpc EXCLUDE_FROM_ALL) - message(STATUS "Using gRPC via add_subdirectory.") - - # After using add_subdirectory, we can now use the grpc targets directly from - # this build. - set(_PROTOBUF_LIBPROTOBUF libprotobuf) - set(_REFLECTION grpc++_reflection) - if(CMAKE_CROSSCOMPILING) - find_program(_PROTOBUF_PROTOC protoc) - else() - set(_PROTOBUF_PROTOC $) - endif() - set(_GRPC_GRPCPP grpc++) - if(CMAKE_CROSSCOMPILING) - find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) - else() - set(_GRPC_CPP_PLUGIN_EXECUTABLE $) - endif() -elseif(GRPC_FETCHCONTENT) - # Another way is to use CMake's FetchContent module to clone gRPC at - # configure time. This makes gRPC's source code available to your project, - # similar to a git submodule. - message(STATUS "Using gRPC via add_subdirectory (FetchContent).") - include(FetchContent) - set(FETCHCONTENT_QUIET OFF) - FetchContent_Declare( - grpc - GIT_REPOSITORY https://github.com/grpc/grpc.git - # when using gRPC, you will actually set this to an existing tag, such as - # v1.25.0, v1.26.0 etc.. - # For the purpose of testing, we override the tag used to the commit - # that's currently under test. - GIT_TAG v1.49.1 - - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE - - ) - FetchContent_MakeAvailable(grpc) - - # Since FetchContent uses add_subdirectory under the hood, we can use - # the grpc targets directly from this build. - set(_PROTOBUF_LIBPROTOBUF libprotobuf) - set(_REFLECTION grpc++_reflection) - set(_PROTOBUF_PROTOC $) - set(_GRPC_GRPCPP grpc++) - if(CMAKE_CROSSCOMPILING) - find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) - else() - set(_GRPC_CPP_PLUGIN_EXECUTABLE $) - endif() -else() - # This branch assumes that gRPC and all its dependencies are already installed - # on this system, so they can be located by find_package(). - - # Find Protobuf installation - # Looks for protobuf-config.cmake file installed by Protobuf's cmake installation. - set(protobuf_MODULE_COMPATIBLE TRUE) - find_package(Protobuf CONFIG REQUIRED) - message(STATUS "Using protobuf ${Protobuf_VERSION}") - - set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf) - set(_REFLECTION gRPC::grpc++_reflection) - if(CMAKE_CROSSCOMPILING) - find_program(_PROTOBUF_PROTOC protoc) - else() - set(_PROTOBUF_PROTOC $) - endif() - - # Find gRPC installation - # Looks for gRPCConfig.cmake file installed by gRPC's cmake installation. - find_package(gRPC CONFIG REQUIRED) - message(STATUS "Using gRPC ${gRPC_VERSION}") - - set(_GRPC_GRPCPP gRPC::grpc++) - if(CMAKE_CROSSCOMPILING) - find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) - else() - set(_GRPC_CPP_PLUGIN_EXECUTABLE $) - endif() -endif() From 56711a517a3929639c738172292353d289840965 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 21:26:56 +0100 Subject: [PATCH 82/95] single target --- tests/CMakeLists.txt | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6770e68e9..83b5896fb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,12 +1,7 @@ # src/CMakeLists.txt cmake_minimum_required(VERSION 3.5.1) -# For Protobuf's cmake warnings -if(POLICY CMP0077) - cmake_policy(SET CMP0077 NEW) -endif() -project(hello C CXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") @@ -194,14 +189,19 @@ add_custom_command( # Generated sources headers include_directories("${CMAKE_CURRENT_BINARY_DIR}") -# Targets (the binaries) -foreach(_target - greeter_client) - add_executable(${_target} "${_target}.cc" - ${h_proto_srcs} - ${h_grpc_srcs}) - target_link_libraries(${_target} - ${_REFLECTION} - ${_GRPC_GRPCPP} - ${_PROTOBUF_LIBPROTOBUF}) -endforeach() + +set(INTEGRATION_TEST_SOURCE_FILES + ${MOCKS} + ${FILES_UNDER_TEST} + ${hw_grpc_srcs} + ${hw_proto_srcs} + ${h_proto_hdrs} + ${h_grpc_hdrs} +) + +add_executable(picotracker_lora_integration_tests ${INTEGRATION_TEST_SOURCE_FILES}) + +target_link_libraries(picotracker_lora_integration_tests + ${_REFLECTION} + ${_GRPC_GRPCPP} + ${_PROTOBUF_LIBPROTOBUF}) From b055eba1f2dd90d178ed63689cd412883e8be97a Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 21:27:24 +0100 Subject: [PATCH 83/95] Revert "temp disable usage of main.c" This reverts commit 9b63bf89019987912004113833debd73b78d7013. --- src/apps/LoRaMac/common/callbacks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/LoRaMac/common/callbacks.c b/src/apps/LoRaMac/common/callbacks.c index fb7afef95..5ad26e5f5 100644 --- a/src/apps/LoRaMac/common/callbacks.c +++ b/src/apps/LoRaMac/common/callbacks.c @@ -31,7 +31,7 @@ typedef struct } uplink_key_setter_message_t; uplink_key_setter_message_t uplink_key_setter_message; -// extern uint32_t tx_count_on_this_credential; +extern uint32_t tx_count_on_this_credential; void OnNvmDataChange(LmHandlerNvmContextStates_t state, uint16_t size) { @@ -47,7 +47,7 @@ void OnNvmDataChange(LmHandlerNvmContextStates_t state, uint16_t size) */ if (state == LORAMAC_HANDLER_NVM_STORE) { - // tx_count_on_this_credential++; + tx_count_on_this_credential++; #if GPS_ENABLED setup_GPS(); From 286addf96bb563a17b490ed2474e2e96ac03b4e5 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 21:58:01 +0100 Subject: [PATCH 84/95] Revert "move code into ublox-mock" This reverts commit 27c63bde2711919c14dddeaac4a1285dafcf95a3. --- tests/greeter_client.cc | 108 ++++++++++++++++++++++++++++++++++++++++ tests/ublox-mock.cpp | 95 ++--------------------------------- 2 files changed, 111 insertions(+), 92 deletions(-) create mode 100644 tests/greeter_client.cc diff --git a/tests/greeter_client.cc b/tests/greeter_client.cc new file mode 100644 index 000000000..29ede7a42 --- /dev/null +++ b/tests/greeter_client.cc @@ -0,0 +1,108 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include + +#ifdef BAZEL_BUILD +#include "examples/protos/helloworld.grpc.pb.h" +#else +#include "hello.grpc.pb.h" +#endif + +using grpc::Channel; +using grpc::ClientContext; +using grpc::Status; +using helloworld::Greeter; +using helloworld::HelloReply; +using helloworld::HelloRequest; + +class GreeterClient { + public: + GreeterClient(std::shared_ptr channel) + : stub_(Greeter::NewStub(channel)) {} + + // Assembles the client's payload, sends it and presents the response back + // from the server. + std::string SayHello(const std::string& user) { + // Data we are sending to the server. + HelloRequest request; + request.set_name(user); + + // Container for the data we expect from the server. + HelloReply reply; + + // Context for the client. It could be used to convey extra information to + // the server and/or tweak certain RPC behaviors. + ClientContext context; + + // The actual RPC. + Status status = stub_->SayHello(&context, request, &reply); + + // Act upon its status. + if (status.ok()) { + return reply.message(); + } else { + std::cout << status.error_code() << ": " << status.error_message() + << std::endl; + return "RPC failed"; + } + } + + private: + std::unique_ptr stub_; +}; + +int main(int argc, char** argv) { + // Instantiate the client. It requires a channel, out of which the actual RPCs + // are created. This channel models a connection to an endpoint specified by + // the argument "--target=" which is the only expected argument. + // We indicate that the channel isn't authenticated (use of + // InsecureChannelCredentials()). + std::string target_str; + std::string arg_str("--target"); + if (argc > 1) { + std::string arg_val = argv[1]; + size_t start_pos = arg_val.find(arg_str); + if (start_pos != std::string::npos) { + start_pos += arg_str.size(); + if (arg_val[start_pos] == '=') { + target_str = arg_val.substr(start_pos + 1); + } else { + std::cout << "The only correct argument syntax is --target=" + << std::endl; + return 0; + } + } else { + std::cout << "The only acceptable argument is --target=" << std::endl; + return 0; + } + } else { + target_str = "localhost:50051"; + } + GreeterClient greeter( + grpc::CreateChannel(target_str, grpc::InsecureChannelCredentials())); + std::string user("world"); + std::string reply = greeter.SayHello(user); + std::cout << "Greeter received: " << reply << std::endl; + + return 0; +} diff --git a/tests/ublox-mock.cpp b/tests/ublox-mock.cpp index ba24adc0a..0ebb0bdf3 100644 --- a/tests/ublox-mock.cpp +++ b/tests/ublox-mock.cpp @@ -4,87 +4,11 @@ extern "C" #include "ublox.h" } -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include - -#include - -#ifdef BAZEL_BUILD -#include "examples/protos/helloworld.grpc.pb.h" -#else -#include "hello.grpc.pb.h" -#endif - -using grpc::Channel; -using grpc::ClientContext; -using grpc::Status; -using helloworld::Greeter; -using helloworld::HelloReply; -using helloworld::HelloRequest; - -class GreeterClient -{ -public: - GreeterClient(std::shared_ptr channel) - : stub_(Greeter::NewStub(channel)) {} - - // Assembles the client's payload, sends it and presents the response back - // from the server. - std::string SayHello(const std::string &user) - { - // Data we are sending to the server. - HelloRequest request; - request.set_name(user); - - // Container for the data we expect from the server. - HelloReply reply; - - // Context for the client. It could be used to convey extra information to - // the server and/or tweak certain RPC behaviors. - ClientContext context; - - // The actual RPC. - Status status = stub_->SayHello(&context, request, &reply); - - // Act upon its status. - if (status.ok()) - { - return reply.message(); - } - else - { - std::cout << status.error_code() << ": " << status.error_message() - << std::endl; - return "RPC failed"; - } - } - -private: - std::unique_ptr stub_; -}; - gps_info_t dummy_gps_info = { .GPS_UBX_latitude_Float = 1.290270, - .GPS_UBX_longitude_Float = 103.851959}; + .GPS_UBX_longitude_Float = 103.851959 +}; + gps_status_t get_location_fix(uint32_t timeout) { @@ -108,19 +32,6 @@ uint16_t get_load_solar_voltage() gps_info_t get_latest_gps_info() { - - // Instantiate the client. It requires a channel, out of which the actual RPCs - // are created. This channel models a connection to an endpoint specified by - // the argument "--target=" which is the only expected argument. - // We indicate that the channel isn't authenticated (use of - // InsecureChannelCredentials()). - std::string target_str = "localhost:50051"; - GreeterClient greeter( - grpc::CreateChannel(target_str, grpc::InsecureChannelCredentials())); - std::string user("world"); - std::string reply = greeter.SayHello(user); - std::cout << "Greeter received: " << reply << std::endl; - return dummy_gps_info; } From 644ded5c6508752b2103508d21efaee31380e4f6 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 21:58:28 +0100 Subject: [PATCH 85/95] include main --- tests/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 83b5896fb..1184ecc8b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -100,6 +100,7 @@ set(FILES_UNDER_TEST ${PROJECT_SOURCE_DIR}/src/system/delay.c ${PROJECT_SOURCE_DIR}/src/system/timer.c ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/callbacks.c + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c # Compile region files ${PROJECT_SOURCE_DIR}/src/mac/region/RegionAU915.c From 04250780b26170e88a4fa7c9258e11af4a8674dc Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 22:00:07 +0100 Subject: [PATCH 86/95] greeter client is main --- tests/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1184ecc8b..01f74b834 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -100,7 +100,7 @@ set(FILES_UNDER_TEST ${PROJECT_SOURCE_DIR}/src/system/delay.c ${PROJECT_SOURCE_DIR}/src/system/timer.c ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/callbacks.c - ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c + # ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c # Compile region files ${PROJECT_SOURCE_DIR}/src/mac/region/RegionAU915.c @@ -146,6 +146,7 @@ set(FILES_UNDER_TEST ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/message_sender.c ${PROJECT_SOURCE_DIR}/src/system/nvmm.c + greeter_client.cc ) find_package(Threads REQUIRED) From c964cf1ee7eb36ba954f2726d96616507e66be78 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 22:00:10 +0100 Subject: [PATCH 87/95] Revert "single target" This reverts commit 56711a517a3929639c738172292353d289840965. --- tests/CMakeLists.txt | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 01f74b834..ba94e52a8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,12 @@ # src/CMakeLists.txt cmake_minimum_required(VERSION 3.5.1) +# For Protobuf's cmake warnings +if(POLICY CMP0077) + cmake_policy(SET CMP0077 NEW) +endif() +project(hello C CXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") @@ -191,19 +196,14 @@ add_custom_command( # Generated sources headers include_directories("${CMAKE_CURRENT_BINARY_DIR}") - -set(INTEGRATION_TEST_SOURCE_FILES - ${MOCKS} - ${FILES_UNDER_TEST} - ${hw_grpc_srcs} - ${hw_proto_srcs} - ${h_proto_hdrs} - ${h_grpc_hdrs} -) - -add_executable(picotracker_lora_integration_tests ${INTEGRATION_TEST_SOURCE_FILES}) - -target_link_libraries(picotracker_lora_integration_tests - ${_REFLECTION} - ${_GRPC_GRPCPP} - ${_PROTOBUF_LIBPROTOBUF}) +# Targets (the binaries) +foreach(_target + greeter_client) + add_executable(${_target} "${_target}.cc" + ${h_proto_srcs} + ${h_grpc_srcs}) + target_link_libraries(${_target} + ${_REFLECTION} + ${_GRPC_GRPCPP} + ${_PROTOBUF_LIBPROTOBUF}) +endforeach() From 6d518638d061b50b988b6d48f5eca61daa73a8ca Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 22:10:47 +0100 Subject: [PATCH 88/95] make greeter client accessible from outside --- tests/greeter_client.cc | 76 +++++++++++++--------------------------- tests/greeter_client.hpp | 21 +++++++++++ 2 files changed, 46 insertions(+), 51 deletions(-) create mode 100644 tests/greeter_client.hpp diff --git a/tests/greeter_client.cc b/tests/greeter_client.cc index 29ede7a42..2af96b115 100644 --- a/tests/greeter_client.cc +++ b/tests/greeter_client.cc @@ -21,6 +21,7 @@ #include #include +#include "greeter_client.hpp" #ifdef BAZEL_BUILD #include "examples/protos/helloworld.grpc.pb.h" @@ -35,14 +36,8 @@ using helloworld::Greeter; using helloworld::HelloReply; using helloworld::HelloRequest; -class GreeterClient { - public: - GreeterClient(std::shared_ptr channel) - : stub_(Greeter::NewStub(channel)) {} - - // Assembles the client's payload, sends it and presents the response back - // from the server. - std::string SayHello(const std::string& user) { +std::string GreeterClient::SayHello(const std::string &user) +{ // Data we are sending to the server. HelloRequest request; request.set_name(user); @@ -58,51 +53,30 @@ class GreeterClient { Status status = stub_->SayHello(&context, request, &reply); // Act upon its status. - if (status.ok()) { - return reply.message(); - } else { - std::cout << status.error_code() << ": " << status.error_message() - << std::endl; - return "RPC failed"; + if (status.ok()) + { + return reply.message(); } - } - - private: - std::unique_ptr stub_; -}; - -int main(int argc, char** argv) { - // Instantiate the client. It requires a channel, out of which the actual RPCs - // are created. This channel models a connection to an endpoint specified by - // the argument "--target=" which is the only expected argument. - // We indicate that the channel isn't authenticated (use of - // InsecureChannelCredentials()). - std::string target_str; - std::string arg_str("--target"); - if (argc > 1) { - std::string arg_val = argv[1]; - size_t start_pos = arg_val.find(arg_str); - if (start_pos != std::string::npos) { - start_pos += arg_str.size(); - if (arg_val[start_pos] == '=') { - target_str = arg_val.substr(start_pos + 1); - } else { - std::cout << "The only correct argument syntax is --target=" + else + { + std::cout << status.error_code() << ": " << status.error_message() << std::endl; - return 0; - } - } else { - std::cout << "The only acceptable argument is --target=" << std::endl; - return 0; + return "RPC failed"; } - } else { - target_str = "localhost:50051"; - } - GreeterClient greeter( - grpc::CreateChannel(target_str, grpc::InsecureChannelCredentials())); - std::string user("world"); - std::string reply = greeter.SayHello(user); - std::cout << "Greeter received: " << reply << std::endl; +} + +void GreeterClient::connect() +{ + // Instantiate the client. It requires a channel, out of which the actual RPCs + // are created. This channel models a connection to an endpoint specified by + // the argument "--target=" which is the only expected argument. + // We indicate that the channel isn't authenticated (use of + // InsecureChannelCredentials()). + std::string target_str = "localhost:50051"; - return 0; + GreeterClient greeter( + grpc::CreateChannel(target_str, grpc::InsecureChannelCredentials())); + std::string user("world"); + std::string reply = greeter.SayHello(user); + std::cout << "Greeter received: " << reply << std::endl; } diff --git a/tests/greeter_client.hpp b/tests/greeter_client.hpp new file mode 100644 index 000000000..2a554bfc9 --- /dev/null +++ b/tests/greeter_client.hpp @@ -0,0 +1,21 @@ +#include +#include +#include + +#include "hello.grpc.pb.h" + +class GreeterClient +{ +public: + GreeterClient(std::shared_ptr channel) + : stub_(helloworld::Greeter::NewStub(channel)) {} + + // Assembles the client's payload, sends it and presents the response back + // from the server. + std::string SayHello(const std::string &user); + + void connect(); + +private: + std::unique_ptr stub_; +}; \ No newline at end of file From fc5d18ca71ef774f8d75595ccd737963972ef31d Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 22:11:02 +0100 Subject: [PATCH 89/95] include mocks and files from project --- tests/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ba94e52a8..9fbe69e65 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -200,6 +200,8 @@ include_directories("${CMAKE_CURRENT_BINARY_DIR}") foreach(_target greeter_client) add_executable(${_target} "${_target}.cc" + ${FILES_UNDER_TEST} + ${MOCKS} ${h_proto_srcs} ${h_grpc_srcs}) target_link_libraries(${_target} From 10397e5e1a31d652d57e03afc38b7638297368a1 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 22:11:17 +0100 Subject: [PATCH 90/95] no local project --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9fbe69e65..dac71d5e0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,7 +6,7 @@ if(POLICY CMP0077) cmake_policy(SET CMP0077 NEW) endif() -project(hello C CXX) +# project(hello C CXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") From 75a8a6f3850a4c55755e49c18f5ec48aef1c21e8 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 22:19:22 +0100 Subject: [PATCH 91/95] include main --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dac71d5e0..26b902867 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -105,7 +105,7 @@ set(FILES_UNDER_TEST ${PROJECT_SOURCE_DIR}/src/system/delay.c ${PROJECT_SOURCE_DIR}/src/system/timer.c ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/common/callbacks.c - # ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c + ${PROJECT_SOURCE_DIR}/src/apps/LoRaMac/periodic-uplink-lpp/B-L072Z-LRWAN1/main.c # Compile region files ${PROJECT_SOURCE_DIR}/src/mac/region/RegionAU915.c From 6da86796a5ab75dd729bb29f11938c997a22a52c Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 22:19:30 +0100 Subject: [PATCH 92/95] use greeter client --- tests/ublox-mock.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/ublox-mock.cpp b/tests/ublox-mock.cpp index 0ebb0bdf3..4c78d6e3f 100644 --- a/tests/ublox-mock.cpp +++ b/tests/ublox-mock.cpp @@ -4,6 +4,10 @@ extern "C" #include "ublox.h" } +#include "greeter_client.hpp" + +GreeterClient client; + gps_info_t dummy_gps_info = { .GPS_UBX_latitude_Float = 1.290270, .GPS_UBX_longitude_Float = 103.851959 @@ -32,6 +36,7 @@ uint16_t get_load_solar_voltage() gps_info_t get_latest_gps_info() { + client.connect(); return dummy_gps_info; } From d4782d91bc3e730208432d7ad65e323fd3671f1a Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 24 Sep 2022 22:22:54 +0100 Subject: [PATCH 93/95] use client --- tests/greeter_client.cc | 16 ---------------- tests/greeter_client.hpp | 2 -- tests/ublox-mock.cpp | 16 ++++++++++++++-- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/tests/greeter_client.cc b/tests/greeter_client.cc index 2af96b115..75a9372e9 100644 --- a/tests/greeter_client.cc +++ b/tests/greeter_client.cc @@ -64,19 +64,3 @@ std::string GreeterClient::SayHello(const std::string &user) return "RPC failed"; } } - -void GreeterClient::connect() -{ - // Instantiate the client. It requires a channel, out of which the actual RPCs - // are created. This channel models a connection to an endpoint specified by - // the argument "--target=" which is the only expected argument. - // We indicate that the channel isn't authenticated (use of - // InsecureChannelCredentials()). - std::string target_str = "localhost:50051"; - - GreeterClient greeter( - grpc::CreateChannel(target_str, grpc::InsecureChannelCredentials())); - std::string user("world"); - std::string reply = greeter.SayHello(user); - std::cout << "Greeter received: " << reply << std::endl; -} diff --git a/tests/greeter_client.hpp b/tests/greeter_client.hpp index 2a554bfc9..d6dc43ca4 100644 --- a/tests/greeter_client.hpp +++ b/tests/greeter_client.hpp @@ -14,8 +14,6 @@ class GreeterClient // from the server. std::string SayHello(const std::string &user); - void connect(); - private: std::unique_ptr stub_; }; \ No newline at end of file diff --git a/tests/ublox-mock.cpp b/tests/ublox-mock.cpp index 4c78d6e3f..1b0ffd012 100644 --- a/tests/ublox-mock.cpp +++ b/tests/ublox-mock.cpp @@ -6,7 +6,7 @@ extern "C" #include "greeter_client.hpp" -GreeterClient client; +#include gps_info_t dummy_gps_info = { .GPS_UBX_latitude_Float = 1.290270, @@ -36,7 +36,19 @@ uint16_t get_load_solar_voltage() gps_info_t get_latest_gps_info() { - client.connect(); + // Instantiate the client. It requires a channel, out of which the actual RPCs + // are created. This channel models a connection to an endpoint specified by + // the argument "--target=" which is the only expected argument. + // We indicate that the channel isn't authenticated (use of + // InsecureChannelCredentials()). + std::string target_str = "localhost:50051"; + + GreeterClient greeter( + grpc::CreateChannel(target_str, grpc::InsecureChannelCredentials())); + std::string user("world"); + std::string reply = greeter.SayHello(user); + std::cout << "Greeter received: " << reply << std::endl; + return dummy_gps_info; } From 79dd08ff68daf770841d7bf0f11abd31740a80f4 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 29 Oct 2022 21:52:12 +0100 Subject: [PATCH 94/95] add in what was left last[May not work] --- tests/greeter_client.cc | 36 ------------------------------------ tests/greeter_client.hpp | 39 ++++++++++++++++++++++++++++++++++----- tests/ublox-mock.cpp | 6 ++---- 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/tests/greeter_client.cc b/tests/greeter_client.cc index 75a9372e9..a7664a4ce 100644 --- a/tests/greeter_client.cc +++ b/tests/greeter_client.cc @@ -28,39 +28,3 @@ #else #include "hello.grpc.pb.h" #endif - -using grpc::Channel; -using grpc::ClientContext; -using grpc::Status; -using helloworld::Greeter; -using helloworld::HelloReply; -using helloworld::HelloRequest; - -std::string GreeterClient::SayHello(const std::string &user) -{ - // Data we are sending to the server. - HelloRequest request; - request.set_name(user); - - // Container for the data we expect from the server. - HelloReply reply; - - // Context for the client. It could be used to convey extra information to - // the server and/or tweak certain RPC behaviors. - ClientContext context; - - // The actual RPC. - Status status = stub_->SayHello(&context, request, &reply); - - // Act upon its status. - if (status.ok()) - { - return reply.message(); - } - else - { - std::cout << status.error_code() << ": " << status.error_message() - << std::endl; - return "RPC failed"; - } -} diff --git a/tests/greeter_client.hpp b/tests/greeter_client.hpp index d6dc43ca4..fee974c2c 100644 --- a/tests/greeter_client.hpp +++ b/tests/greeter_client.hpp @@ -4,16 +4,45 @@ #include "hello.grpc.pb.h" +using grpc::Channel; +using grpc::ClientContext; +using grpc::Status; +using helloworld::Greeter; +using helloworld::HelloReply; +using helloworld::HelloRequest; + class GreeterClient { public: - GreeterClient(std::shared_ptr channel) - : stub_(helloworld::Greeter::NewStub(channel)) {} - + GreeterClient(std::shared_ptr channel) + : stub_(Greeter::NewStub(channel)) {} // Assembles the client's payload, sends it and presents the response back // from the server. - std::string SayHello(const std::string &user); + std::string SayHello(const std::string &user) + { + // Data we are sending to the server. + HelloRequest request; + request.set_name(user); + // Container for the data we expect from the server. + HelloReply reply; + // Context for the client. It could be used to convey extra information to + // the server and/or tweak certain RPC behaviors. + ClientContext context; + // The actual RPC. + Status status = stub_->SayHello(&context, request, &reply); + // Act upon its status. + if (status.ok()) + { + return reply.message(); + } + else + { + std::cout << status.error_code() << ": " << status.error_message() + << std::endl; + return "RPC failed"; + } + } private: - std::unique_ptr stub_; + std::unique_ptr stub_; }; \ No newline at end of file diff --git a/tests/ublox-mock.cpp b/tests/ublox-mock.cpp index 1b0ffd012..e2a8e8bfb 100644 --- a/tests/ublox-mock.cpp +++ b/tests/ublox-mock.cpp @@ -10,16 +10,14 @@ extern "C" gps_info_t dummy_gps_info = { .GPS_UBX_latitude_Float = 1.290270, - .GPS_UBX_longitude_Float = 103.851959 -}; - + .GPS_UBX_longitude_Float = 103.851959}; gps_status_t get_location_fix(uint32_t timeout) { return GPS_SUCCESS; } -/* +/* * sets up gps by putting in airbourne mode, setting to use GPS satellites only, turning off NMEA * Needs TO BE REFACTORED TO TIME OUT OR EXIT IF NO MESSAGED IS ReCEIVED BACK! */ From 5c0b9f5f2857cf44e98cf2825a285512cb1fa00c Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Mon, 31 Oct 2022 20:21:19 +0000 Subject: [PATCH 95/95] Revert "add in what was left last[May not work]" This reverts commit 79dd08ff68daf770841d7bf0f11abd31740a80f4. --- tests/greeter_client.cc | 36 ++++++++++++++++++++++++++++++++++++ tests/greeter_client.hpp | 39 +++++---------------------------------- tests/ublox-mock.cpp | 6 ++++-- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/tests/greeter_client.cc b/tests/greeter_client.cc index a7664a4ce..75a9372e9 100644 --- a/tests/greeter_client.cc +++ b/tests/greeter_client.cc @@ -28,3 +28,39 @@ #else #include "hello.grpc.pb.h" #endif + +using grpc::Channel; +using grpc::ClientContext; +using grpc::Status; +using helloworld::Greeter; +using helloworld::HelloReply; +using helloworld::HelloRequest; + +std::string GreeterClient::SayHello(const std::string &user) +{ + // Data we are sending to the server. + HelloRequest request; + request.set_name(user); + + // Container for the data we expect from the server. + HelloReply reply; + + // Context for the client. It could be used to convey extra information to + // the server and/or tweak certain RPC behaviors. + ClientContext context; + + // The actual RPC. + Status status = stub_->SayHello(&context, request, &reply); + + // Act upon its status. + if (status.ok()) + { + return reply.message(); + } + else + { + std::cout << status.error_code() << ": " << status.error_message() + << std::endl; + return "RPC failed"; + } +} diff --git a/tests/greeter_client.hpp b/tests/greeter_client.hpp index fee974c2c..d6dc43ca4 100644 --- a/tests/greeter_client.hpp +++ b/tests/greeter_client.hpp @@ -4,45 +4,16 @@ #include "hello.grpc.pb.h" -using grpc::Channel; -using grpc::ClientContext; -using grpc::Status; -using helloworld::Greeter; -using helloworld::HelloReply; -using helloworld::HelloRequest; - class GreeterClient { public: - GreeterClient(std::shared_ptr channel) - : stub_(Greeter::NewStub(channel)) {} + GreeterClient(std::shared_ptr channel) + : stub_(helloworld::Greeter::NewStub(channel)) {} + // Assembles the client's payload, sends it and presents the response back // from the server. - std::string SayHello(const std::string &user) - { - // Data we are sending to the server. - HelloRequest request; - request.set_name(user); - // Container for the data we expect from the server. - HelloReply reply; - // Context for the client. It could be used to convey extra information to - // the server and/or tweak certain RPC behaviors. - ClientContext context; - // The actual RPC. - Status status = stub_->SayHello(&context, request, &reply); - // Act upon its status. - if (status.ok()) - { - return reply.message(); - } - else - { - std::cout << status.error_code() << ": " << status.error_message() - << std::endl; - return "RPC failed"; - } - } + std::string SayHello(const std::string &user); private: - std::unique_ptr stub_; + std::unique_ptr stub_; }; \ No newline at end of file diff --git a/tests/ublox-mock.cpp b/tests/ublox-mock.cpp index e2a8e8bfb..1b0ffd012 100644 --- a/tests/ublox-mock.cpp +++ b/tests/ublox-mock.cpp @@ -10,14 +10,16 @@ extern "C" gps_info_t dummy_gps_info = { .GPS_UBX_latitude_Float = 1.290270, - .GPS_UBX_longitude_Float = 103.851959}; + .GPS_UBX_longitude_Float = 103.851959 +}; + gps_status_t get_location_fix(uint32_t timeout) { return GPS_SUCCESS; } -/* +/* * sets up gps by putting in airbourne mode, setting to use GPS satellites only, turning off NMEA * Needs TO BE REFACTORED TO TIME OUT OR EXIT IF NO MESSAGED IS ReCEIVED BACK! */