Skip to content

Commit

Permalink
Update Region.c
Browse files Browse the repository at this point in the history
  • Loading branch information
alistairjordan committed Jan 5, 2024
1 parent 437062c commit 05658ce
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 18 deletions.
4 changes: 4 additions & 0 deletions sysdrv/tools/board/lorawan-bridge/LoraMac/LoRaMac.c
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,7 @@ bool LoRaMacIsBusy( void )

if( LoRaMacRadioEvents.Events.RxProcessPending == 1 )
{
printf("Rx Process Pending: LoraMac Busy.\n");
return true;
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 =
{
Expand Down
35 changes: 23 additions & 12 deletions sysdrv/tools/board/lorawan-bridge/LoraMac/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -434,23 +442,26 @@ 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;
}

uint8_t channel = 0;

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 )
{
Expand Down Expand Up @@ -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( );
Expand All @@ -490,7 +501,7 @@ static void UplinkProcess( void )
CRITICAL_SECTION_END( );
if( isPending == 1 )
{
PrepareTxFrame( );
PrepareTxFrame( size, buffer );
}
}

Expand Down
17 changes: 14 additions & 3 deletions sysdrv/tools/board/lorawan-bridge/LoraMac/region/Region.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
*/
#include "LoRaMac.h"
#include "Region.h"
#include <stdio.h>


// Setup regions
//#ifdef REGION_AS923
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions sysdrv/tools/board/lorawan-bridge/LoraMac/rtc-board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 5 additions & 1 deletion sysdrv/tools/board/lorawan-bridge/LoraMac/sx1276.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*
* \author Wael Guibene ( Semtech )
*/
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "utilities.h"
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Binary file modified sysdrv/tools/board/lorawan-bridge/rest_server
Binary file not shown.

0 comments on commit 05658ce

Please sign in to comment.