Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SX1276Lib mbed-src
Revision 0:80ebf9b1dd4f, committed 2016-05-23
- Comitter:
- semsem
- Date:
- Mon May 23 22:28:07 2016 +0000
- Commit message:
- WANOT
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS.cpp Mon May 23 22:28:07 2016 +0000
@@ -0,0 +1,50 @@
+#include "WANOT.h"
+
+/*
+ * Global variables declarations
+ */
+
+
+void GPS_Read(char* StoreRead)
+{
+ debug("GPS Data Query Started...\n\r");
+ int j;
+ int parts;
+ char Parts_TimeBuffer[4];
+
+
+ // struct tm t; // setup time structure reffered to GPS
+
+ Serial SS(NC,PC_11);
+ SS.baud(4800);
+
+ uint8_t Loop_Counter = 0;
+
+ while(Loop_Counter < 3) {
+
+ SS.gets(StoreRead,50);
+
+ debug("New Statement Read\n\r");
+
+ if(StoreRead[0]=='$' && StoreRead[1]=='G' && StoreRead[2]=='P'&& StoreRead[3]=='G'&& StoreRead[4]=='G' && StoreRead[5]=='A') { //GPGGA Message
+
+ debug("GPGGA Statement\n\r");
+ Loop_Counter++; // To make sure it gets GPGGA Statement
+ }
+ }
+
+ debug("GPS Data Fix Finished...\n\r");
+
+ /*Parts of second*/
+ for(j=0; j<3; j++) {
+ //debug("%c",StoreRead[14+j]);//send parts of second
+ Parts_TimeBuffer[j] = StoreRead[14+j];
+ }
+
+ Parts_TimeBuffer[3] = 0;
+
+ parts = atoi(Parts_TimeBuffer); // change to intege for mktime function
+ wait_ms(1000-parts); // to make time reffered to 00.00 of parts
+
+ debug("GPS Synch Finished...\n\r");
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GPS.h Mon May 23 22:28:07 2016 +0000 @@ -0,0 +1,8 @@ +#ifndef _GPS_H_ +#define _GPS_H_ + +#include "WANOT.h" + +void GPS_Read(char* StoreRead); + +#endif //_GPS_H_ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SX1276Lib.lib Mon May 23 22:28:07 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/Semtech/code/SX1276Lib/#3778e6204cc1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SlaveBeacon.cpp Mon May 23 22:28:07 2016 +0000
@@ -0,0 +1,108 @@
+#include "WANOT.h"
+
+/*
+ * Global variables declarations
+ */
+
+extern SuperSlotStates SuperSlotState;
+
+volatile SlaveRegStates SlaveRegState = UnRegistered;
+volatile Slave_Beacon_State Slave_Beacon_States = Beacon_Wait;
+
+extern RadioEvents_t RadioEvents;
+extern SX1276MB1xAS Radio;
+
+extern uint16_t BufferSize;
+extern uint8_t Buffer[];
+
+extern int16_t RssiValue;
+extern int8_t SnrValue;
+
+extern uint32_t LORA_Channels[];
+
+extern uint8_t TDMAChannel;
+
+volatile uint8_t Beacon_New_Rx_Flag = 0;
+volatile uint8_t Beacon_Counter = 0;
+
+void Beacon_OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
+{
+ Radio.Sleep();
+ BufferSize = size;
+ memcpy(Buffer, payload, BufferSize);
+ RssiValue = rssi;
+ SnrValue = snr;
+ debug("Beacon_OnRxDone!!\n\r");
+
+ Beacon_New_Rx_Flag = 0;
+
+ if(Buffer[0] == SETUP_BEACON_SYNCWORD) {
+ TDMAChannel = Buffer[1];
+ debug("Beacon Recieved!!\n\r");
+ Slave_Beacon_States = Beacon_Recieved;
+ } else {
+ debug("Beacon Mismatch\n\r");
+ }
+}
+
+void Beacon_OnRxTimeout(void)
+{
+ Beacon_Counter++;
+ Beacon_New_Rx_Flag = 0;
+ debug("Beacon Not Found!!\n\r");
+}
+
+
+void SetUp_Beacon(void)
+{
+ debug("Beacon SetUP State!!\n\r");
+
+ Beacon_New_Rx_Flag = 0;
+ Beacon_Counter = 0;
+
+ Slave_Beacon_States = Beacon_Wait;
+
+ RadioEvents.RxDone = Beacon_OnRxDone;
+ RadioEvents.RxTimeout = Beacon_OnRxTimeout;
+ Radio.Init(&RadioEvents);
+
+ Radio.SetChannel(SET_UP_FREQUENCY);
+
+ Radio.SetTxConfig(MODEM_LORA, TX_OUTPUT_POWER, 0, SET_UP_LORA_BANDWIDTH,
+ SET_UP_LORA_SPREADING_FACTOR, LORA_CODINGRATE,
+ LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
+ SET_UP_LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP,
+ LORA_IQ_INVERSION_ON, 2000000);
+
+ Radio.SetRxConfig(MODEM_LORA, SET_UP_LORA_BANDWIDTH, SET_UP_LORA_SPREADING_FACTOR,
+ LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
+ LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0,
+ SET_UP_LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP,
+ LORA_IQ_INVERSION_ON, true);
+
+ while((SuperSlotState == SetUp_Beacon_Phase) && (Beacon_Counter != 8) && (Slave_Beacon_States != Beacon_Recieved)) {
+ debug("Waiting for Beacon\n\r");
+ Beacon_New_Rx_Flag = 1;
+ Radio.Rx( RX_TIMEOUT_VALUE );
+ while(Beacon_New_Rx_Flag == 1);
+ }
+
+
+ Radio.SetChannel(LORA_Channels[TDMAChannel]);
+
+ Radio.SetTxConfig(MODEM_LORA, TX_OUTPUT_POWER, 0, SET_UP_LORA_BANDWIDTH,
+ SET_UP_LORA_SPREADING_FACTOR, LORA_CODINGRATE,
+ LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
+ SET_UP_LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP,
+ LORA_IQ_INVERSION_ON, 2000000);
+
+ Radio.SetRxConfig(MODEM_LORA, SET_UP_LORA_BANDWIDTH, SET_UP_LORA_SPREADING_FACTOR,
+ LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
+ LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0,
+ SET_UP_LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP,
+ LORA_IQ_INVERSION_ON, true);
+
+
+ debug("Finished Beacon State\n\r");
+ //RTC Sleep for the rest of setup beacon
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SlaveBeacon.h Mon May 23 22:28:07 2016 +0000
@@ -0,0 +1,20 @@
+#ifndef _SLAVEBEACON_H_
+#define _SLAVEBEACON_H_
+
+#include "WANOT.h"
+
+typedef enum {
+ UnRegistered = 0,
+ Registered
+} SlaveRegStates;
+
+typedef enum {
+ Beacon_Wait = 0,
+ Beacon_Recieved
+
+} Slave_Beacon_State;
+
+void SetUp_Beacon(void);
+
+
+#endif //_SLAVEBEACON_H_
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SlaveData.cpp Mon May 23 22:28:07 2016 +0000
@@ -0,0 +1,14 @@
+#include "WANOT.h"
+
+uint16_t BufferSize = BUFFER_SIZE;
+uint8_t Buffer[BUFFER_SIZE];
+
+int16_t RssiValue = 0.0;
+int8_t SnrValue = 0.0;
+
+uint32_t LORA_Channels[NUMBER_OF_CHANNELS] = {868100000,868300000,868500000,867100000,867300000,867500000,867700000,867900000};
+
+uint8_t SlotNumber = 0;
+uint8_t TDMAChannel = 0;
+
+uint8_t SlaveLocalID = 0;
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SlaveSetUp.cpp Mon May 23 22:28:07 2016 +0000
@@ -0,0 +1,202 @@
+
+#include "WANOT.h"
+
+/*
+ * Global variables declarations
+ */
+
+extern SuperSlotStates SuperSlotState;
+
+extern Slave_Beacon_State Slave_Beacon_States;
+
+volatile SlaveSetUpStates SlaveSetUpState = Rx_Init;
+extern SlaveRegStates SlaveRegState;
+
+volatile msgType messageType = msgRTS;
+volatile msgType messageType2 = msgCTS;
+
+extern RadioEvents_t RadioEvents;
+extern SX1276MB1xAS Radio;
+
+extern uint16_t BufferSize;
+extern uint8_t Buffer[];
+
+extern uint32_t LORA_Channels[NUMBER_OF_CHANNELS];
+
+extern int16_t RssiValue;
+extern int8_t SnrValue;
+
+extern uint8_t TDMAChannel;
+extern uint8_t SlaveLocalID;
+
+void SetUp_OnTxDone(void)
+{
+ Radio.Rx(RX_TIMEOUT_VALUE);
+ debug("SetUp_OnTxDone!!\n\r");
+
+}
+
+void SetUp_OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
+{
+ Radio.Sleep();
+ BufferSize = size;
+ memcpy(Buffer, payload, BufferSize);
+ RssiValue = rssi;
+ SnrValue = snr;
+ debug("SetUp_OnRxDone!!\n\r");
+
+ switch (SlaveSetUpState) {
+ case Wait_for_Beacon:
+ if(Buffer[0] == BEACON_SYNCWORD) {
+ SlaveSetUpState = Phy_CS;
+ debug("Beacon Packet\n\r");
+ } else {
+ SlaveSetUpState = Rx_Init;
+ debug("Beacon Mismatch\n\r");
+
+ }
+ break;
+
+ case Virtual_CS:
+ if ((messageType == Buffer[0]) || (messageType2 == Buffer[0])) {
+ SlaveSetUpState = Channel_Busy;
+ debug("Channel is Busy(CTS/RTS)!!\n\r");
+ } else {
+ SlaveSetUpState = Channel_Busy;
+ debug("Channel is Busy(Invalid Packet)!!\n\r");
+ }
+ break;
+
+ case Wait_for_CTS:
+ messageType = msgCTS;
+ if (messageType == Buffer[0]) {
+ SlaveSetUpState = Send_JoinReq;
+ debug("CTS Packet\n\r");
+ } else {
+ SlaveSetUpState = Rx_Init;
+ debug("CTS Mismatch\n\r");
+ }
+ break;
+
+ case Wait_for_JoinAccept:
+ messageType = msgJoinAccept;
+ if (messageType == Buffer[0]) {
+ SlaveLocalID = Buffer[11];
+ SlaveSetUpState = Send_ACK;
+ debug("JoinAccept Packet\n\r");
+ } else {
+ SlaveSetUpState = Rx_Init;
+ debug("JoinAccept Mismatch\n\r");
+ }
+ break;
+
+ default:
+ debug("Invalid Packet!!");
+ }
+
+
+}
+
+void SetUp_OnTxTimeout(void)
+{
+ SlaveSetUpState = Rx_Init;
+ debug("SetUp_OnTxTimeout!!\n\r");
+
+}
+
+void SetUp_OnRxTimeout(void)
+{
+ switch(SlaveSetUpState) {
+ case Virtual_CS:
+ SlaveSetUpState = Send_RTS;
+ debug("Channel is Free!!\n\r");
+ break;
+ default:
+ SlaveSetUpState = Rx_Init;
+ debug("SetUp_OnRxTimeout!!\n\r");
+ }
+}
+
+void SetUp_OnRxError(void)
+{
+ SlaveSetUpState = Rx_Init;
+
+}
+
+void SlaveSetUp()
+{
+ debug("Slave Set Up Phase Started...\n\r");
+
+ // Initialize Radio driver
+ RadioEvents.TxDone = SetUp_OnTxDone;
+ RadioEvents.RxDone = SetUp_OnRxDone;
+ RadioEvents.RxError = SetUp_OnRxError;
+ RadioEvents.TxTimeout = SetUp_OnTxTimeout;
+ RadioEvents.RxTimeout = SetUp_OnRxTimeout;
+ Radio.Init(&RadioEvents);
+
+ while ((SuperSlotState == SetUp_Phase) && (SlaveRegState == UnRegistered) && (Slave_Beacon_States == Beacon_Recieved)) {
+ switch (SlaveSetUpState) {
+ case Phy_CS:
+ if(Radio.IsChannelFree(MODEM_LORA, SET_UP_FREQUENCY, RSSI_THRESHOLD)) {
+ uint16_t BackOffValue = MIN_BACK_OFF + /*rand()%*/RANDOM_BACK_OFF_WINDOW;
+ SlaveSetUpState = Virtual_CS;
+ Radio.Rx(BackOffValue);
+ } else {
+ SlaveSetUpState = Channel_Busy;
+ }
+ break;
+
+
+ case Virtual_CS:
+ break;
+
+ case Channel_Busy:
+ debug("Channel Busy !!\n\r");
+ wait_ms(MIN_BACK_OFF + RANDOM_BACK_OFF_WINDOW * rand());
+ SlaveSetUpState = Wait_for_Beacon;
+ break;
+
+ case Send_RTS:
+ messageType = msgRTS;
+ Buffer[0] = messageType;
+ Buffer[1] = SnrValue;
+ Radio.Send(Buffer, BUFFER_SIZE_RTS);
+ debug("Case of RTS Sent\n\r");
+ SlaveSetUpState = Wait_for_CTS;
+ break;
+
+ case Send_JoinReq:
+ messageType = msgJoinReq;
+ Buffer[0] = messageType;
+ Radio.Send(Buffer, BUFFER_SIZE_JoinReq);
+ debug("Case of JoinRequest Sent\n\r");
+ SlaveSetUpState = Wait_for_JoinAccept;
+ break;
+
+ case Send_ACK:
+ messageType = msgAck;
+ Buffer[0] = messageType;
+ Radio.Send(Buffer, BUFFER_SIZE_Ack);
+ debug("Registered\n\r");
+ SlaveSetUpState = Rx_Init;
+ SlaveRegState = Registered;
+ debug("Slave Set Up Phase Finished...\n\r");
+ return;
+
+ case Rx_Init:
+ Radio.Rx( RX_TIMEOUT_VALUE );
+ SlaveSetUpState = Wait_for_Beacon;
+ debug("Case of Rx_Init\n\r");
+ break;
+ case Wait_for_Beacon:
+ case Wait_for_CTS:
+ case Wait_for_JoinAccept:
+ break;
+ default:
+ break;
+
+ }
+
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SlaveSetUp.h Mon May 23 22:28:07 2016 +0000
@@ -0,0 +1,30 @@
+#ifndef SLAVESETUP_H_
+#define SLAVESETUP_H_
+
+#include "WANOT.h"
+
+typedef enum {
+ Wait_for_Beacon = 0,
+ Send_RTS,
+ Send_JoinReq,
+ Send_ACK,
+ Wait_for_CTS,
+ Wait_for_JoinAccept,
+ Rx_Init,
+ Phy_CS, //CSMA
+ Virtual_CS,
+ Channel_Busy
+
+} SlaveSetUpStates;
+
+typedef enum {
+ msgRTS = 0x11,
+ msgCTS = 0x12,
+ msgJoinReq = 0x13,
+ msgJoinAccept = 0x14,
+ msgAck = 0x15
+
+} msgType;
+
+void SlaveSetUp();
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SlaveTDMA.cpp Mon May 23 22:28:07 2016 +0000
@@ -0,0 +1,189 @@
+#include "WANOT.h"
+
+/*
+ * Global variables declarations
+ */
+
+extern SuperSlotStates SuperSlotState;
+extern SlaveRegStates SlaveRegState;
+
+extern RadioEvents_t RadioEvents;
+extern SX1276MB1xAS Radio;
+
+extern uint16_t BufferSize;
+extern uint8_t Buffer[];
+
+extern uint32_t LORA_Channels[NUMBER_OF_CHANNELS];
+
+extern int16_t RssiValue;
+extern int8_t SnrValue;
+
+extern uint8_t TDMAChannel;
+extern uint8_t SlaveLocalID;
+
+volatile SlaveTDMAStates SlaveTDMAState = TDMA_Wait_for_Beacon;
+volatile TDMA_msgType TDMA_messageType = TDMA_msgRTS;
+
+
+void TDMA_OnTxDone(void)
+{
+ Radio.Rx(RX_TIMEOUT_VALUE);
+ debug("TDMA_OnTxDone!!\n\r");
+
+}
+
+void TDMA_OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
+{
+ Radio.Sleep();
+ BufferSize = size;
+ memcpy(Buffer, payload, BufferSize);
+ RssiValue = rssi;
+ SnrValue = snr;
+ debug("TDMA_OnRxDone!!\n\r");
+
+ switch (SlaveTDMAState) {
+ case TDMA_Wait_for_Beacon:
+
+ if(Buffer[0] == SETUP_BEACON_SYNCWORD) {
+ debug("Beacon Packet\n\r");
+ if(Buffer[1] == SlaveLocalID)
+ {
+ SlaveTDMAState = TDMA_Send_RTS;
+ debug("Slave Correct Slot \n\r");
+ } else {
+ debug("Slave InCorrect Slot \n\r");
+ //SlaveTDMAState = TDMA_Finished;////////////////////////////////
+ SlaveTDMAState = TDMA_Wait_for_Beacon;
+ }
+ } else {
+ debug("Beacon Mismatch\n\r");
+
+ SlaveTDMAState = TDMA_Finished;
+ }
+ break;
+
+
+ case TDMA_Wait_for_CTS:
+ TDMA_messageType = TDMA_msgCTS;
+ if (TDMA_messageType == Buffer[0]) {
+ debug("CTS Packet\n\r");
+ SlaveTDMAState = TDMA_Send_Data;
+ } else {
+ debug("Wait for CTS failed \n\r");
+
+ SlaveTDMAState = TDMA_Finished;
+ }
+ break;
+
+ case TDMA_Wait_for_Ack:
+ TDMA_messageType = TDMA_msgAck;
+ if (TDMA_messageType == Buffer[0]) {
+ debug("Data Sent and Master Acked \n\r");
+ SlaveTDMAState = TDMA_Wait_for_Beacon;
+
+ SlaveTDMAState = TDMA_Finished;
+ } else {
+ debug("Master Ack Mismatch \n\r");
+
+ SlaveTDMAState = TDMA_Finished;
+ }
+ break;
+
+ default:
+ debug("Invalid Packet!!");
+
+ SlaveTDMAState = TDMA_Finished;
+ }
+
+}
+
+void TDMA_OnTxTimeout(void)
+{
+ debug("TDMA_OnTxTimeout!!\n\r");
+
+ SlaveTDMAState = TDMA_Finished;
+}
+
+void TDMA_OnRxTimeout(void)
+{
+ debug("TDMA_OnRxTimeout!!\n\r");
+
+ SlaveTDMAState = TDMA_Finished;
+}
+
+void TDMA_OnRxError(void)
+{
+ debug("TDMA_OnRxError!!\n\r");
+
+ SlaveTDMAState = TDMA_Finished;
+}
+
+void SlaveTDMA()
+{
+
+ debug("Slave TDMA Started...\n\r");
+
+ SlaveTDMAState = TDMA_Wait_for_Beacon;
+
+ // Initialize Radio driver
+ RadioEvents.TxDone = TDMA_OnTxDone;
+ RadioEvents.RxDone = TDMA_OnRxDone;
+ RadioEvents.RxError = TDMA_OnRxError;
+ RadioEvents.TxTimeout = TDMA_OnTxTimeout;
+ RadioEvents.RxTimeout = TDMA_OnRxTimeout;
+ Radio.Init(&RadioEvents);
+
+ Radio.SetTxConfig(MODEM_LORA, TX_OUTPUT_POWER, 0, SET_UP_LORA_BANDWIDTH,
+ SET_UP_LORA_SPREADING_FACTOR, LORA_CODINGRATE,
+ LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
+ SET_UP_LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP,
+ LORA_IQ_INVERSION_ON, 2000000);
+
+ Radio.SetRxConfig(MODEM_LORA, SET_UP_LORA_BANDWIDTH, SET_UP_LORA_SPREADING_FACTOR,
+ LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
+ LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0,
+ SET_UP_LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP,
+ LORA_IQ_INVERSION_ON, true);
+
+ Radio.SetChannel(LORA_Channels[TDMAChannel]);
+ Radio.Rx(RX_TIMEOUT_VALUE);
+
+
+ while (SuperSlotState == TDMA_Phase) {
+
+ switch (SlaveTDMAState) {
+
+ case TDMA_Send_RTS:
+ TDMA_messageType = TDMA_msgRTS;
+ Buffer[0] = TDMA_messageType;
+ Buffer[1] = SnrValue;
+ Radio.Send(Buffer, BUFFER_SIZE_RTS);
+ debug("Sending RTS\n\r");
+ SlaveTDMAState = TDMA_Wait_for_CTS;
+ break;
+
+ case TDMA_Send_Data:
+ TDMA_messageType = TDMA_msgData;
+ Buffer[0] = TDMA_messageType;
+ Radio.Send(Buffer, BUFFER_SIZE_TDMA_DATA);
+ debug("Sending DATA\n\r");
+ SlaveTDMAState = TDMA_Wait_for_Ack;
+ break;
+
+ case TDMA_Finished:
+ debug("Slave TDMA Slot Finished...\n\r");
+ return;
+
+
+ case TDMA_Wait_for_Beacon:
+ case TDMA_Wait_for_CTS:
+ case TDMA_Wait_for_Ack:
+
+ break;
+ default:
+ break;
+
+ }
+
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SlaveTDMA.h Mon May 23 22:28:07 2016 +0000
@@ -0,0 +1,30 @@
+#ifndef _SLAVETDMA_H_
+#define _SLAVETDMA_H_
+
+#include "WANOT.h"
+
+
+typedef enum {
+ TDMA_Wait_for_Beacon = 0,
+ TDMA_Send_RTS,
+ TDMA_Wait_for_CTS,
+ TDMA_Send_Data,
+ TDMA_Wait_for_Ack,
+ TDMA_Finished
+
+
+} SlaveTDMAStates;
+
+
+typedef enum {
+ TDMA_msgRTS = 0x11,
+ TDMA_msgCTS = 0x12,
+ TDMA_msgData = 0x13,
+ TDMA_msgAck = 0x14
+
+} TDMA_msgType;
+
+void SlaveTDMA();
+
+
+#endif //_SLAVETDMA_H_
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SuperSlot.cpp Mon May 23 22:28:07 2016 +0000
@@ -0,0 +1,41 @@
+#include "WANOT.h"
+
+/*
+ * Global variables declarations
+ */
+
+volatile SuperSlotStates SuperSlotState = SetUp_Beacon_Phase;
+Timeout SwitchState;
+
+void SwitchState_Fn(void)
+{
+ switch(SuperSlotState) {
+ case SetUp_Beacon_Phase:
+ debug("Switching to SetUp Phase State !!\n\r");
+ SuperSlotState = SetUp_Phase;
+ SwitchState.attach(&SwitchState_Fn,SET_UP_INTERVAL);
+ break;
+
+ case SetUp_Phase:
+ debug("Switching to TDMA Phase State !!\n\r");
+ SuperSlotState = TDMA_Phase;
+ SwitchState.attach(&SwitchState_Fn,TDMA_INTERVAL);
+ break;
+
+ case TDMA_Phase:
+ debug("SuperSlot States finished\n\r\n\r\n\r");
+ debug("Switching to SetUp Beacon State !! \n\r");
+ SuperSlotState = SetUp_Beacon_Phase;
+ SwitchState.attach(&SwitchState_Fn, BEACON_SET_UP_INTERVAL);
+ break;
+
+ }
+}
+
+void SuperSlotInit ()
+{
+
+ debug("Switching to SetUp Beacon State !! \n\r");
+ SuperSlotState = SetUp_Beacon_Phase;
+ SwitchState.attach(&SwitchState_Fn, BEACON_SET_UP_INTERVAL);
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SuperSlot.h Mon May 23 22:28:07 2016 +0000
@@ -0,0 +1,15 @@
+#ifndef _MASTERSUPERSLOT_H_
+#define _MASTERSUPERSLOT_H_
+
+#include "WANOT.h"
+
+typedef enum {
+ SetUp_Beacon_Phase = 0,
+ SetUp_Phase,
+ TDMA_Phase
+
+} SuperSlotStates;
+
+void SuperSlotInit (void);
+
+#endif //_MASTERSUPERSLOT_H_
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WANOT.h Mon May 23 22:28:07 2016 +0000 @@ -0,0 +1,74 @@ +#include "mbed.h" +#include "sx1276-hal.h" +#include "debug.h" +#include "radio.h" +#include "Serial.h" +#include "Timeout.h" + +#include "SuperSlot.h" + +#include "SlaveSetUp.h" +#include "SlaveBeacon.h" +#include "SlaveTDMA.h" + +#include"GPS.h" + +/* + * LoRa Default Params + */ + +#define TX_OUTPUT_POWER 10 // 14 dBm + +#define LORA_CODINGRATE 1 // [1: 4/5] +#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx +#define LORA_SYMBOL_TIMEOUT 5 // Symbols +#define LORA_FIX_LENGTH_PAYLOAD_ON false +#define LORA_FHSS_ENABLED false +#define LORA_NB_SYMB_HOP 4 +#define LORA_IQ_INVERSION_ON false + +#define NUMBER_OF_CHANNELS 8 +#define RSSI_THRESHOLD -90 + +/* + * Set Up Phase Params + */ + +#define SET_UP_LORA_SPREADING_FACTOR 7 // [SF7..SF12] +#define SET_UP_LORA_CRC_ENABLED false +#define SET_UP_LORA_BANDWIDTH 0 // [0: 125 kHz, +#define SET_UP_FREQUENCY LORA_Channels[0] +#define MIN_BACK_OFF 1000 //uS +#define RANDOM_BACK_OFF_WINDOW 10000 //uS +#define BEACON_TIMEOUT_VALUE 100000 // in us +#define TDMA_TIME_OUT_VALUE 100000 + + +/* + * Buffer Sizes + */ + +#define RX_TIMEOUT_VALUE 100000 // in us +#define BUFFER_SIZE 70 // Define the payload size here +#define BUFFER_SIZE_RTS 2 +#define BUFFER_SIZE_CTS 2 +#define BUFFER_SIZE_JoinReq 6 +#define BUFFER_SIZE_JoinAccept 14 +#define BUFFER_SIZE_Ack 2 +#define BUFFER_SIZE_Beacon 1 +#define BUFFER_SIZE_TDMA_DATA 50 + +/* + * Beacons Synch Words + */ + +#define SETUP_BEACON_SYNCWORD 0x74 +#define BEACON_SYNCWORD 0x74 + +/* + * SuperSlot Phases Intervals + */ + + #define BEACON_SET_UP_INTERVAL 1.2 + #define SET_UP_INTERVAL 19.8 + #define TDMA_INTERVAL 39 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon May 23 22:28:07 2016 +0000
@@ -0,0 +1,51 @@
+#include"WANOT.h"
+
+/*
+ * Global variables declarations
+ */
+
+/*!
+ * Radio events function pointer
+ */
+RadioEvents_t RadioEvents;
+
+/*
+ * Global variables declarations
+ */
+SX1276MB1xAS Radio(NULL);
+
+extern SuperSlotStates SuperSlotState;
+
+
+int main()
+{
+
+ // verify the connection with the board
+ while (Radio.Read(REG_VERSION) == 0x00) {
+ debug("Radio could not be detected!\n\r\r", NULL);
+ wait(1);
+ }
+ debug("WANOT Slave Started...\n\r");
+
+ char StoreRead[50];
+ GPS_Read(StoreRead);
+
+ SuperSlotInit();
+
+ while(1) {
+ switch(SuperSlotState) {
+ case SetUp_Beacon_Phase:
+ SetUp_Beacon();
+ break;
+
+ case SetUp_Phase:
+ SlaveSetUp();
+ break;
+
+ case TDMA_Phase:
+ SlaveTDMA();
+ break;
+ }
+ }
+
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-src.lib Mon May 23 22:28:07 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-src/#a11c0372f0ba