@@ -27,12 +27,11 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jae
2727#include "LoRaMac.h"
2828#include "region/Region.h"
2929#include "LoRaMacCrypto.h"
30-
30+ #include "lora_app.h"
3131#include "LoRaMacTest.h"
3232#include "log.h"
3333#include "lora_config.h"
3434#include "tremo_gpio.h"
35-
3635#include "tremo_iwdg.h"
3736bool jr_flag = 0 ;
3837uint8_t jr_nb = 0 ;
@@ -46,6 +45,8 @@ extern uint8_t symbtime1_value;
4645extern uint8_t flag1 ;
4746extern uint8_t symbtime2_value ;
4847extern uint8_t flag2 ;
48+ extern bool down_check ;
49+ extern bool mac_response_flag ;
4950extern bool debug_flags ;
5051extern bool rejoin_status ;
5152extern bool MAC_COMMAND_ANS_status ;
@@ -849,11 +850,28 @@ static void OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t
849850 // Size of the regular payload is 12. Plus 1 byte MHDR and 4 bytes MIC
850851 applyCFList .Size = size - 17 ;
851852
852- RegionApplyCFList ( LoRaMacRegion , & applyCFList );
853+ #if defined( REGION_US915 ) || defined( REGION_AU915 ) || defined( REGION_CN470 )
854+ if (customize_set8channel_get ()== 0 )
855+ {
856+ RegionApplyCFList ( LoRaMacRegion , & applyCFList );
857+ }
858+ #else
859+ if (customize_freq1_get ()== 0 )
860+ {
861+ RegionApplyCFList ( LoRaMacRegion , & applyCFList );
862+ }
863+ #endif
853864
854865 MlmeConfirm .Status = LORAMAC_EVENT_INFO_STATUS_OK ;
855866 IsLoRaMacNetworkJoined = true;
856- LoRaMacParams .ChannelsDatarate = LoRaMacParamsDefaults .ChannelsDatarate ;
867+ if (AdrCtrlOn == true)
868+ {
869+ LoRaMacParams .ChannelsDatarate = LoRaMacParamsDefaults .ChannelsDatarate ;
870+ }
871+ else
872+ {
873+ LoRaMacParams .ChannelsDatarate = lora_config_tx_datarate_get () ;
874+ }
857875 }
858876 else
859877 {
@@ -943,6 +961,13 @@ static void OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t
943961 {
944962 isMicOk = true;
945963 }
964+ else
965+ {
966+ if (down_check == 1 )
967+ {
968+ DownLinkCounter = 0 ;
969+ }
970+ }
946971 }
947972 else
948973 {
@@ -954,19 +979,28 @@ static void OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t
954979 isMicOk = true;
955980 downLinkCounter = downLinkCounterTmp ;
956981 }
982+ else
983+ {
984+ if (down_check == 1 )
985+ {
986+ DownLinkCounter = 0 ;
987+ }
988+ }
957989 }
958990
959- // Check for a the maximum allowed counter difference
960- getPhy .Attribute = PHY_MAX_FCNT_GAP ;
961- phyParam = RegionGetPhyParam ( LoRaMacRegion , & getPhy );
962- if ( sequenceCounterDiff >= phyParam .Value )
963- {
964- McpsIndication .Status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS ;
965- McpsIndication .DownLinkCounter = downLinkCounter ;
966- PrepareRxDoneAbort ( );
967- address_flags = 1 ;
968- return ;
969- }
991+ if (down_check == 0 )
992+ {
993+ // Check for a the maximum allowed counter difference
994+ getPhy .Attribute = PHY_MAX_FCNT_GAP ;
995+ phyParam = RegionGetPhyParam ( LoRaMacRegion , & getPhy );
996+ if ( sequenceCounterDiff >= phyParam .Value )
997+ {
998+ McpsIndication .Status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS ;
999+ McpsIndication .DownLinkCounter = downLinkCounter ;
1000+ PrepareRxDoneAbort ( );
1001+ return ;
1002+ }
1003+ }
9701004
9711005 if ( isMicOk == true )
9721006 {
@@ -2060,7 +2094,14 @@ static void ProcessMacCommands( uint8_t *payload, uint8_t macIndex, uint8_t comm
20602094 chParam .Rx1Frequency = 0 ;
20612095 chParam .DrRange .Value = payload [macIndex ++ ];
20622096
2063- status = RegionNewChannelReq ( LoRaMacRegion , & newChannelReq );
2097+ if (customize_freq1_get ()== 0 )
2098+ {
2099+ status = RegionNewChannelReq ( LoRaMacRegion , & newChannelReq );
2100+ }
2101+ else
2102+ {
2103+ status = 0x03 ;
2104+ }
20642105
20652106 AddMacCommand ( MOTE_MAC_NEW_CHANNEL_ANS , status , 0 );
20662107 }
@@ -2885,7 +2926,16 @@ LoRaMacStatus_t LoRaMacQueryTxPossible( uint8_t size, LoRaMacTxInfo_t* txInfo )
28852926 // Verify if the fOpts and the payload fit into the maximum payload
28862927 if ( ValidatePayloadLength ( size , datarate , fOptLen ) == false )
28872928 {
2929+ if (mac_response_flag == 1 )
2930+ {
2931+ fOptLen = 0 ;
2932+ MacCommandsBufferIndex = 0 ;
2933+ MacCommandsBufferToRepeatIndex = 0 ;
2934+ }
2935+ else
2936+ {
28882937 return LORAMAC_STATUS_LENGTH_ERROR ;
2938+ }
28892939 }
28902940 return LORAMAC_STATUS_OK ;
28912941}
0 commit comments