Skip to content

Commit

Permalink
revert commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sabas1080 committed Feb 15, 2024
1 parent ffeac16 commit 3d93df7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 324 deletions.
125 changes: 0 additions & 125 deletions examples/class_c_otaa_ack/class_c_otaa_ack.ino

This file was deleted.

137 changes: 4 additions & 133 deletions src/arduino-rfm/LoRaMAC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
*****************************************************************************************
*/
void LORA_Cycle(sBuffer *Data_Tx, sBuffer *Data_Rx, RFM_command_t *RFM_Command, sLoRa_Session *Session_Data,
sLoRa_OTAA *OTAA_Data, sLoRa_Message *Message_Rx, sSettings *LoRa_Settings, msg_t *upMsg_Type)
sLoRa_OTAA *OTAA_Data, sLoRa_Message *Message_Rx, sSettings *LoRa_Settings)
{
static const unsigned int Receive_Delay_1 = 1000;
static const unsigned int Receive_Delay_2 = 2000; // Receive_Delay_2 >= Receive_Delay_1 + RX1_Window
Expand Down Expand Up @@ -91,9 +91,9 @@ void LORA_Cycle(sBuffer *Data_Tx, sBuffer *Data_Rx, RFM_command_t *RFM_Command,
digitalWrite(RFM_SWITCH,0); //Rf switch inside RAK module change to Tx
#endif

//Lora send data & ack
if(*upMsg_Type == MSG_UP) LORA_Send_Data(Data_Tx, Session_Data, LoRa_Settings);
else if(*upMsg_Type == MSG_ACK) LORA_Send_ACK(Data_Tx, Session_Data, LoRa_Settings);
//Lora send data
LORA_Send_Data(Data_Tx, Session_Data, LoRa_Settings);



prevTime = millis();
Expand Down Expand Up @@ -146,11 +146,6 @@ void LORA_Cycle(sBuffer *Data_Tx, sBuffer *Data_Rx, RFM_command_t *RFM_Command,
return;
}

//
#ifdef _CLASS_C_
return;
#endif

// Class C open RX2 immediately after first rx window
if(LoRa_Settings->Mote_Class == CLASS_C){
#ifdef US_915
Expand Down Expand Up @@ -336,130 +331,6 @@ void LORA_Send_Data(sBuffer *Data_Tx, sLoRa_Session *Session_Data, sSettings *Lo
}
}

// send uplink message including ACK

void LORA_Send_ACK(sBuffer *Data_Tx, sLoRa_Session *Session_Data, sSettings *LoRa_Settings)
{
Serial.println("LoraMac send ack");
//Define variables
unsigned char i;

//Initialise RFM buffer
unsigned char RFM_Data[MAX_UPLINK_PAYLOAD_SIZE+65];
sBuffer RFM_Package = {&RFM_Data[0], 0x00};

//Initialise Message struct for a transmit message
sLoRa_Message Message;

Message.MAC_Header = 0x00;
Message.Frame_Port = 0x00; //set as MAC command
Message.Frame_Control = 0x00;

//Load device address from session data into the message
Message.DevAddr[0] = Session_Data->DevAddr[0];
Message.DevAddr[1] = Session_Data->DevAddr[1];
Message.DevAddr[2] = Session_Data->DevAddr[2];
Message.DevAddr[3] = Session_Data->DevAddr[3];

//Set up direction
Message.Direction = 0x00;

//Load the frame counter from the session data into the message
Message.Frame_Counter = *Session_Data->Frame_Counter;

//Set confirmation
//Unconfirmed
// if(LoRa_Settings->Confirm == 0x00)
// {
// Message.MAC_Header = Message.MAC_Header | 0x40;
// }
// //Confirmed
// else
// {
// Message.MAC_Header = Message.MAC_Header | 0x80;
// }
Message.MAC_Header = Message.MAC_Header | 0x40;

//Build the Radio Package
//Load mac header
RFM_Package.Data[0] = Message.MAC_Header;

//Load device address
RFM_Package.Data[1] = Message.DevAddr[3];
RFM_Package.Data[2] = Message.DevAddr[2];
RFM_Package.Data[3] = Message.DevAddr[1];
RFM_Package.Data[4] = Message.DevAddr[0];

//Load frame control
RFM_Package.Data[5] = (Message.Frame_Control | 0x20);

//Load frame counter
RFM_Package.Data[6] = (*Session_Data->Frame_Counter & 0x00FF);
RFM_Package.Data[7] = ((*Session_Data->Frame_Counter >> 8) & 0x00FF);

//Set data counter to 8
RFM_Package.Counter = 8;

//If there is data load the Frame_Port field
//Encrypt the data and load the data
if(Data_Tx->Counter > 0x00)
{
//Load Frame port field
//RFM_Data[8] = Message.Frame_Port;
RFM_Package.Data[8] = 0;

//Raise package counter
RFM_Package.Counter++;

//Encrypt the data
Encrypt_Payload(Data_Tx, Session_Data->AppSKey, &Message);

//Load Data
for(i = 0; i < Data_Tx->Counter; i++)
{
RFM_Package.Data[RFM_Package.Counter++] = Data_Tx->Data[i];
}


}

//Calculate MIC
Construct_Data_MIC(&RFM_Package, Session_Data, &Message);

//Load MIC in package
for(i = 0; i < 4; i++)
{
RFM_Package.Data[RFM_Package.Counter++] = Message.MIC[i];
}

//Send Package
RFM_Send_Package(&RFM_Package, LoRa_Settings);

//Raise Frame counter
if(*Session_Data->Frame_Counter != 0xFFFF)
{
//Raise frame counter
*Session_Data->Frame_Counter = *Session_Data->Frame_Counter + 1;
}
else
{
*Session_Data->Frame_Counter = 0x0000;
}

//Change channel for next message if hopping is activated
if(LoRa_Settings->Channel_Hopping == 0x01)
{
if(LoRa_Settings->Channel_Tx < 0x07)
{
LoRa_Settings->Channel_Tx++;
}
else
{
LoRa_Settings->Channel_Tx = 0x00;
}
}
}

/*
*****************************************************************************************
* Description : Function that is used to receive a LoRaWAN message and retrieve the data from the RFM
Expand Down
5 changes: 2 additions & 3 deletions src/arduino-rfm/LoRaMAC.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@
********************************************************************************************
*/

typedef enum {NO_RFM_COMMAND, NEW_RFM_COMMAND, RFM_COMMAND_DONE, JOIN, NEW_ACK_COMMAND} RFM_command_t;
typedef enum {NO_RFM_COMMAND, NEW_RFM_COMMAND, RFM_COMMAND_DONE, JOIN} RFM_command_t;

/*
*****************************************************************************************
* FUNCTION PROTOTYPES
*****************************************************************************************
*/

void LORA_Cycle(sBuffer *Data_Tx, sBuffer *Data_Rx, RFM_command_t *RFM_Command, sLoRa_Session *Session_Data, sLoRa_OTAA *OTAA_Data, sLoRa_Message *Message_Rx, sSettings *LoRa_Settings, msg_t *upMsg_Type);
void LORA_Cycle(sBuffer *Data_Tx, sBuffer *Data_Rx, RFM_command_t *RFM_Command, sLoRa_Session *Session_Data, sLoRa_OTAA *OTAA_Data, sLoRa_Message *Message_Rx, sSettings *LoRa_Settings);
void LORA_Send_Data(sBuffer *Data_Tx, sLoRa_Session *Session_Data, sSettings *LoRa_Settings);
void LORA_Send_ACK(sBuffer *Data_Tx, sLoRa_Session *Session_Data, sSettings *LoRa_Settings);
void LORA_Receive_Data(sBuffer *Data_Rx, sLoRa_Session *Session_Data, sLoRa_OTAA *OTAA_Data, sLoRa_Message *Message, sSettings *LoRa_Settings);
bool LORA_join_Accept(sBuffer *Data_Rx,sLoRa_Session *Session_Data, sLoRa_OTAA *OTAA_Data, sLoRa_Message *Message, sSettings *LoRa_Settings);
void LoRa_Send_JoinReq(sLoRa_OTAA *OTAA_Data, sSettings *LoRa_Settings);
Expand Down
Loading

0 comments on commit 3d93df7

Please sign in to comment.