diff --git a/sysdrv/tools/board/lorawan-bridge/LoraMac/LoRaMac.c b/sysdrv/tools/board/lorawan-bridge/LoraMac/LoRaMac.c index ac790e1b6f..5e243a56da 100644 --- a/sysdrv/tools/board/lorawan-bridge/LoraMac/LoRaMac.c +++ b/sysdrv/tools/board/lorawan-bridge/LoraMac/LoRaMac.c @@ -1568,6 +1568,7 @@ bool LoRaMacIsBusy( void ) if( LoRaMacRadioEvents.Events.RxProcessPending == 1 ) { + printf("Rx Process Pending: LoraMac Busy.\n"); return true; } @@ -1576,6 +1577,9 @@ bool LoRaMacIsBusy( void ) { return false; } + printf("Unknown Pending: LoraMac Busy.\n"); + printf("MacCtx.MacState == LORAMAC_IDLE: %s\n", MacCtx.MacState == LORAMAC_IDLE ? "True" : "False"); + printf("MacCtx.AllowRequests == LORAMAC_REQUEST_HANDLING_ON: %s\n", MacCtx.AllowRequests == LORAMAC_REQUEST_HANDLING_ON ? "True" : "False"); return true; } diff --git a/sysdrv/tools/board/lorawan-bridge/LoraMac/common/LmHandler/LmHandler.c b/sysdrv/tools/board/lorawan-bridge/LoraMac/common/LmHandler/LmHandler.c index 527b6a5ab0..1437980b14 100644 --- a/sysdrv/tools/board/lorawan-bridge/LoraMac/common/LmHandler/LmHandler.c +++ b/sysdrv/tools/board/lorawan-bridge/LoraMac/common/LmHandler/LmHandler.c @@ -361,11 +361,13 @@ bool LmHandlerIsBusy( void ) { if( LoRaMacIsBusy( ) == true ) { + printf("LoraMacIsBusy!\n"); return true; } if( LmHandlerJoinStatus( ) != LORAMAC_HANDLER_SET ) { // The network isn't yet joined, try again later. + printf("NotJoinedYet!\n"); LmHandlerJoin( ); return true; } @@ -409,12 +411,14 @@ void LmHandlerProcess( void ) // If it is the case exit function earlier if( LmHandlerPackageIsTxPending( ) == true ) { + printf("Package Tx Pending\n"); return; } // If a MAC layer scheduled uplink is still pending try to send it. if( IsUplinkTxPending == true ) { + printf("Uplink Tx Pending\n"); // Send an empty message LmHandlerAppData_t appData = { diff --git a/sysdrv/tools/board/lorawan-bridge/LoraMac/main.c b/sysdrv/tools/board/lorawan-bridge/LoraMac/main.c index 2f28281d08..c0cc585d8b 100644 --- a/sysdrv/tools/board/lorawan-bridge/LoraMac/main.c +++ b/sysdrv/tools/board/lorawan-bridge/LoraMac/main.c @@ -169,9 +169,9 @@ static void OnSysTimeUpdate( bool isSynchronized, int32_t timeCorrection ); #else static void OnSysTimeUpdate( void ); #endif -static void PrepareTxFrame( void ); +static void PrepareTxFrame( uint8_t size, char buffer[] ); static void StartTxProcess( LmHandlerTxEvents_t txEvent ); -static void UplinkProcess( void ); +static void UplinkProcess( uint8_t size, char buffer[] ); static void OnTxPeriodicityChanged( uint32_t periodicity ); static void OnTxFrameCtrlChanged( LmHandlerMsgTypes_t isTxConfirmed ); @@ -296,10 +296,18 @@ int main( void ) // CliProcess( &Uart2 ); // Processes the LoRaMac events - LmHandlerProcess( ); + LmHandlerProcess( ); // Process application uplinks management - UplinkProcess( ); + char payload[] = "Hello world!"; + printf("Sending payload: %s",payload); + UplinkProcess( sizeof(payload), payload ); + LmHandlerProcess( ); + // Array of test data + // int data_remaining = 1 + // while (data_remaining) { + // send_data(data) + // } // CRITICAL_SECTION_BEGIN( ); // if( IsMacProcessPending == 1 ) @@ -434,10 +442,11 @@ static void OnSysTimeUpdate( void ) /*! * Prepares the payload of the frame and transmits it. */ -static void PrepareTxFrame( void ) +static void PrepareTxFrame( uint8_t size, char buffer[] ) { if( LmHandlerIsBusy( ) == true ) { + printf("LmHander busy!\n"); return; } @@ -445,12 +454,14 @@ static void PrepareTxFrame( void ) AppData.Port = LORAWAN_APP_PORT; - CayenneLppReset( ); - CayenneLppAddDigitalInput( channel++, AppLedStateOn ); - CayenneLppAddAnalogInput( channel++, BoardGetBatteryLevel( ) * 100 / 254 ); + // CayenneLppReset( ); + // CayenneLppAddDigitalInput( channel++, AppLedStateOn ); + // CayenneLppAddAnalogInput( channel++, BoardGetBatteryLevel( ) * 100 / 254 ); - CayenneLppCopy( AppData.Buffer ); - AppData.BufferSize = CayenneLppGetSize( ); + // CayenneLppCopy( AppData.Buffer ); + // AppData.BufferSize = CayenneLppGetSize( ); + AppData.BufferSize = size; + AppData.Buffer = buffer; if( LmHandlerSend( &AppData, LmHandlerParams.IsTxConfirmed ) == LORAMAC_HANDLER_SUCCESS ) { @@ -481,7 +492,7 @@ static void StartTxProcess( LmHandlerTxEvents_t txEvent ) } } -static void UplinkProcess( void ) +static void UplinkProcess( uint8_t size, char buffer[] ) { uint8_t isPending = 0; CRITICAL_SECTION_BEGIN( ); @@ -490,7 +501,7 @@ static void UplinkProcess( void ) CRITICAL_SECTION_END( ); if( isPending == 1 ) { - PrepareTxFrame( ); + PrepareTxFrame( size, buffer ); } } diff --git a/sysdrv/tools/board/lorawan-bridge/LoraMac/region/Region.c b/sysdrv/tools/board/lorawan-bridge/LoraMac/region/Region.c index 01024bf12a..fc39b12a7e 100644 --- a/sysdrv/tools/board/lorawan-bridge/LoraMac/region/Region.c +++ b/sysdrv/tools/board/lorawan-bridge/LoraMac/region/Region.c @@ -30,6 +30,8 @@ */ #include "LoRaMac.h" #include "Region.h" +#include + // Setup regions //#ifdef REGION_AS923 @@ -530,67 +532,76 @@ bool RegionIsActive( LoRaMacRegion_t region ) * AS band on 923MHz */ case LORAMAC_REGION_AS923: + printf("AS923 ACTIVE\n"); AS923_IS_ACTIVE( ); break; /*! * Australian band on 915MHz */ case LORAMAC_REGION_AU915: + printf("AU915 ACTIVE\n"); AU915_IS_ACTIVE( ); break; /*! * Chinese band on 470MHz */ case LORAMAC_REGION_CN470: + printf("CN470 ACTIVE\n"); CN470_IS_ACTIVE( ); break; /*! * Chinese band on 779MHz */ case LORAMAC_REGION_CN779: + printf("CN779 ACTIVE\n"); CN779_IS_ACTIVE( ); break; /*! * European band on 433MHz */ case LORAMAC_REGION_EU433: + printf("EU433 ACTIVE\n"); EU433_IS_ACTIVE( ); break; /*! * European band on 868MHz */ case LORAMAC_REGION_EU868: + printf("EU868 ACTIVE\n"); EU868_IS_ACTIVE( ); break; /*! * South korean band on 920MHz */ case LORAMAC_REGION_KR920: + printf("KR920 ACTIVE\n"); KR920_IS_ACTIVE( ); break; /*! * India band on 865MHz */ case LORAMAC_REGION_IN865: + printf("IN865 ACTIVE\n"); IN865_IS_ACTIVE( ); break; /*! * North american band on 915MHz */ case LORAMAC_REGION_US915: + printf("US915 ACTIVE\n"); US915_IS_ACTIVE( ); break; /*! * Russia band on 864MHz */ case LORAMAC_REGION_RU864: + printf("RU864 ACTIVE\n"); RU864_IS_ACTIVE( ); break; - - + default: { - return true; // FIX THIS NOW + return false; } } } diff --git a/sysdrv/tools/board/lorawan-bridge/LoraMac/rtc-board.c b/sysdrv/tools/board/lorawan-bridge/LoraMac/rtc-board.c index df550a2ccc..82cd90aeca 100644 --- a/sysdrv/tools/board/lorawan-bridge/LoraMac/rtc-board.c +++ b/sysdrv/tools/board/lorawan-bridge/LoraMac/rtc-board.c @@ -16,8 +16,8 @@ uint32_t GettimeToTicks(struct timespec *ts) { struct timespec TicksToGettime(uint32_t time) { struct timespec ts; - ts.tv_sec += time / 1000000000; - ts.tv_nsec += time % 1000000000; + ts.tv_sec = time / 1000000000; + ts.tv_nsec = time % 1000000000; return ts; } diff --git a/sysdrv/tools/board/lorawan-bridge/LoraMac/sx1276.c b/sysdrv/tools/board/lorawan-bridge/LoraMac/sx1276.c index a2d0351ee0..bce4353558 100644 --- a/sysdrv/tools/board/lorawan-bridge/LoraMac/sx1276.c +++ b/sysdrv/tools/board/lorawan-bridge/LoraMac/sx1276.c @@ -24,6 +24,7 @@ * * \author Wael Guibene ( Semtech ) */ +#include #include #include #include "utilities.h" @@ -1298,11 +1299,13 @@ void SX1276WriteBuffer( uint32_t addr, uint8_t *buffer, uint8_t size ) //NSS = 0; //GpioWrite( &SX1276.Spi.Nss, 0 ); - SpiInOut( &SX1276.Spi, addr | 0x80 ); for( i = 0; i < size; i++ ) { + printf("Writing data %x\n", buffer[i]); + printf("HERE"); SpiInOut( &SX1276.Spi, buffer[i] ); + printf("HERE"); } //NSS = 1; @@ -1321,6 +1324,7 @@ void SX1276ReadBuffer( uint32_t addr, uint8_t *buffer, uint8_t size ) for( i = 0; i < size; i++ ) { buffer[i] = SpiInOut( &SX1276.Spi, 0 ); + printf("Reading data %x\n",buffer[i]); } //NSS = 1; diff --git a/sysdrv/tools/board/lorawan-bridge/rest_server b/sysdrv/tools/board/lorawan-bridge/rest_server index 8fe2539b5c..3bd15afc90 100755 Binary files a/sysdrv/tools/board/lorawan-bridge/rest_server and b/sysdrv/tools/board/lorawan-bridge/rest_server differ