Master Implementation of WANOT

Dependencies:   SX1276Lib mbed

Files at this revision

API Documentation at this revision

Comitter:
semsem
Date:
Mon May 23 22:25:40 2016 +0000
Commit message:
V0.2

Changed in this revision

GPS.cpp Show annotated file Show diff for this revision Revisions of this file
GPS.h Show annotated file Show diff for this revision Revisions of this file
MasterBeacon.cpp Show annotated file Show diff for this revision Revisions of this file
MasterBeacon.h Show annotated file Show diff for this revision Revisions of this file
MasterData.cpp Show annotated file Show diff for this revision Revisions of this file
MasterSetUp.cpp Show annotated file Show diff for this revision Revisions of this file
MasterSetUp.h Show annotated file Show diff for this revision Revisions of this file
MasterTDMA.cpp Show annotated file Show diff for this revision Revisions of this file
MasterTDMA.h Show annotated file Show diff for this revision Revisions of this file
SX1276Lib.lib Show annotated file Show diff for this revision Revisions of this file
SuperSlot.cpp Show annotated file Show diff for this revision Revisions of this file
SuperSlot.h Show annotated file Show diff for this revision Revisions of this file
WANOT.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 8b449140caa2 GPS.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS.cpp	Mon May 23 22:25:40 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
diff -r 000000000000 -r 8b449140caa2 GPS.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS.h	Mon May 23 22:25:40 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
diff -r 000000000000 -r 8b449140caa2 MasterBeacon.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MasterBeacon.cpp	Mon May 23 22:25:40 2016 +0000
@@ -0,0 +1,84 @@
+#include"WANOT.h"
+
+/*
+ *  Global variables declarations
+ */
+
+extern SuperSlotStates SuperSlotState; 
+
+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[NUMBER_OF_CHANNELS];
+
+extern uint8_t SlotNumber;
+extern uint8_t TDMAChannel;
+
+
+volatile uint8_t Beacon_Tx_Done = 0;
+void SetUp_Beacon_OnTxDone(void)
+{
+    Beacon_Tx_Done = 1;
+    debug("Beacon Tx Done!!\n\r");
+}
+
+
+void SetUp_Beacon(void)
+{
+    debug("Master Set Up Beacon Started...\n\r");
+    
+    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(SET_UP_FREQUENCY);
+
+    Beacon_Tx_Done = 0;
+    RadioEvents.TxDone = SetUp_Beacon_OnTxDone;
+    Radio.Init(&RadioEvents);
+
+    if (TDMAChannel != 0)
+        Radio.Sleep();
+    
+    wait_us(TDMAChannel * BEACON_TIMEOUT_VALUE);
+
+    Buffer[0] = SETUP_BEACON_SYNCWORD;
+    Buffer[1] = TDMAChannel;
+
+    Radio.Send(Buffer, BUFFER_SIZE_RTS);
+
+    while(Beacon_Tx_Done != 1);
+
+    debug("Beacon Sent\n\r");
+
+    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]);
+     
+    debug("Master Set Up Beacon Done!!\n\r");
+    //Sleep untill setup phase RTC
+}
\ No newline at end of file
diff -r 000000000000 -r 8b449140caa2 MasterBeacon.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MasterBeacon.h	Mon May 23 22:25:40 2016 +0000
@@ -0,0 +1,7 @@
+#ifndef _MASTERBEACON_H_
+#define _MASTERBEACON_H_
+#include "WANOT.h"
+
+
+void SetUp_Beacon(void);
+#endif //_MASTERBEACON_H_
\ No newline at end of file
diff -r 000000000000 -r 8b449140caa2 MasterData.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MasterData.cpp	Mon May 23 22:25:40 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
diff -r 000000000000 -r 8b449140caa2 MasterSetUp.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MasterSetUp.cpp	Mon May 23 22:25:40 2016 +0000
@@ -0,0 +1,186 @@
+
+#include "WANOT.h"
+
+/*
+ *  Global variables declarations
+ */
+ 
+extern SuperSlotStates SuperSlotState;
+
+volatile MasterSetUpStates MasterSetUpState = sendBeacon;
+
+volatile msgType messageType = msgRTS;
+
+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;
+
+static Timer timer;
+static int begin, end;
+
+void SetUp_OnTxDone(void)
+{
+    if(MasterSetUpState != Wait_for_JoinReq)
+        Radio.Rx(RX_TIMEOUT_VALUE);
+    else
+        Radio.Rx(1.5 * RX_TIMEOUT_VALUE);
+    debug("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("OnRxDone!!\n\r");
+
+    switch (MasterSetUpState) {
+        case Wait_for_RTS:
+            messageType = msgRTS;
+            if (messageType == Buffer[0]) {
+                MasterSetUpState = Send_CTS;
+                debug("RTS Packet\n\r");
+            } else {
+                MasterSetUpState = sendBeacon;
+                debug("RTS Packet Mismatch\n\r");
+            }
+            break;
+
+        case Wait_for_JoinReq:
+            messageType = msgJoinReq;
+            if (messageType == Buffer[0]) {
+                MasterSetUpState = Send_JoinAccept;
+                debug("JoinReq Packet\n\r");
+            } else {
+                MasterSetUpState = sendBeacon;
+                debug("JoinReq Packet Mismatch\n\r");
+            }
+            break;
+
+        case Wait_for_Ack:
+            messageType = msgAck;
+            if (messageType == Buffer[0]) {
+                MasterSetUpState = AckDone;
+                debug("Ack Packet\n\r");
+            } else {
+                MasterSetUpState = sendBeacon;
+                debug("Ack Packet Mistmatch\n\r");
+
+            }
+            break;
+
+        default:
+            break;
+    }
+
+
+}
+
+
+
+void SetUp_OnTxTimeout(void)
+{
+
+}
+
+void SetUp_OnRxTimeout(void)
+{
+    MasterSetUpState = sendBeacon;
+    debug("OnRxTimeout!!\n\r");
+
+}
+
+void SetUp_OnRxError(void)
+{
+    MasterSetUpState = sendBeacon;
+}
+
+void MasterSetUp()
+{
+    debug("Master Set Up Phase Started...\n\r");
+    
+    timer.start();
+    begin = timer.read_us();
+    
+    // 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);
+    
+    uint8_t Beacon_Counter = 0;
+
+    while (SuperSlotState == SetUp_Phase) {
+        switch (MasterSetUpState) {
+            case sendBeacon:
+                if(Beacon_Counter <=4) {
+                    Beacon_Counter++;
+                    Buffer[0] = SETUP_BEACON_SYNCWORD;
+                    Radio.Send(Buffer, BUFFER_SIZE_RTS);
+                    debug("Sending Beacon\n\r");
+                    MasterSetUpState = Wait_for_RTS;
+                } else {
+                    debug("Beacon Timed Out without SLaves\n\r");
+                    MasterSetUpState = Slave_Not_Found;
+                    Beacon_Counter = 0;
+                }
+                break;
+
+            case Send_CTS:
+                messageType = msgCTS;
+                Buffer[0] = messageType;
+                Buffer[1] = SnrValue;
+                Radio.Send(Buffer, BUFFER_SIZE_CTS);
+                debug("Sending CTS\n\r");
+                MasterSetUpState = Wait_for_JoinReq;
+                break;
+
+            case Send_JoinAccept:
+                messageType = msgJoinAccept;
+                Buffer[0] = messageType;
+                Buffer[11] = 5;
+                Radio.Send(Buffer, BUFFER_SIZE_JoinAccept);
+                debug("Sending JoinAccept\n\r");
+                MasterSetUpState = Wait_for_Ack;
+                break;
+
+            case AckDone:
+                debug("Ack done: +1 \n\r");
+                MasterSetUpState = sendBeacon;
+                end = timer.read_us();
+                debug("Registeration took : %f S\n\r", (end-begin)/1000000.0);
+                break;
+
+            case Slave_Not_Found:
+                debug("Slave Not Found .. Sleep");
+                Radio.Sleep();
+                MasterSetUpState = sendBeacon;
+                break;
+
+            case Wait_for_Ack:
+            case Wait_for_RTS:
+            case Wait_for_JoinReq:
+                break;
+            default:
+                break;
+
+        }
+
+    }
+    debug("Master Set Up Phase Finished...\n\r");
+}
\ No newline at end of file
diff -r 000000000000 -r 8b449140caa2 MasterSetUp.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MasterSetUp.h	Mon May 23 22:25:40 2016 +0000
@@ -0,0 +1,29 @@
+#ifndef _MASTERSETUP_H_
+#define _MASTERSETUP_H_
+
+#include"WANOT.h"
+
+typedef enum {
+    sendBeacon = 0,
+    Wait_for_RTS,
+    Send_CTS,
+    Wait_for_JoinReq,
+    Send_JoinAccept,
+    AckDone,
+    Wait_for_Ack,
+    Slave_Not_Found
+} MasterSetUpStates;
+
+typedef enum {
+    msgRTS = 0x11,
+    msgCTS = 0x12,
+    msgJoinReq = 0x13,
+    msgJoinAccept = 0x14,
+    msgAck = 0x15
+
+} msgType;
+
+void MasterSetUp();
+
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 8b449140caa2 MasterTDMA.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MasterTDMA.cpp	Mon May 23 22:25:40 2016 +0000
@@ -0,0 +1,181 @@
+#include "WANOT.h"
+
+/*
+ *  Global variables declarations
+ */
+
+extern SuperSlotStates SuperSlotState;
+
+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[NUMBER_OF_CHANNELS];
+
+extern uint8_t SlotNumber;
+extern uint8_t TDMAChannel;
+
+volatile MasterTDMAStates MasterTDMAState = TDMA_sendBeacon;
+volatile TDMA_msgType TDMA_messageType = TDMA_msgRTS;
+volatile uint8_t Beacon_Counter = 0;
+
+static Timer timer;
+static int begin, end;
+
+void TDMA_OnTxDone(void)
+{
+    if( MasterTDMAState != TDMA_Wait_for_Data ){
+        Radio.Rx(RX_TIMEOUT_VALUE);
+        debug("TDMA OnTxDone!!\n\r");
+    }   else    {
+        Radio.Rx(4*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("OnRxDone!!\n\r SNR = %d , RSSI = %d\n\r",snr, rssi);
+
+    switch (MasterTDMAState) {
+        case TDMA_Wait_for_RTS:
+            TDMA_messageType = TDMA_msgRTS;
+            if (TDMA_messageType == Buffer[0]) {
+                MasterTDMAState = TDMA_Send_CTS;
+                debug("RTS Packet\n\r");
+            } else {
+                MasterTDMAState = TDMA_sendBeacon;
+                debug("RTS Packet Mismatch\n\r");
+            }
+            break;
+
+        case TDMA_Wait_for_Data:
+            TDMA_messageType = TDMA_msgData;
+            if (TDMA_messageType == Buffer[0]) {
+                MasterTDMAState = TDMA_Send_Ack;
+            } else {
+                MasterTDMAState = TDMA_sendBeacon;
+            }
+            break;
+
+        default:
+            break;
+
+
+    }
+
+
+}
+
+void TDMA_OnTxTimeout(void)
+{
+
+}
+
+void TDMA_OnRxTimeout(void)
+{
+    MasterTDMAState = TDMA_sendBeacon;
+    debug("OnRxTimeout!!\n\r");
+
+}
+
+void TDMA_OnRxError(void)
+{
+    MasterTDMAState = TDMA_sendBeacon;
+}
+
+void MasterTDMA(uint8_t SlaveLocalID)
+{
+    debug("Master TDMA Phase Started...\n\r");
+    
+    timer.start();
+    begin = timer.read_us();
+    
+    MasterTDMAState = TDMA_sendBeacon;
+    
+    // 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.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);
+
+    while (SuperSlotState ==  TDMA_Phase) {
+        switch (MasterTDMAState) {
+            case TDMA_sendBeacon:
+                if (Beacon_Counter < 2) {
+                    Beacon_Counter++;
+                    Buffer[0] = SETUP_BEACON_SYNCWORD;
+                    Buffer[1] = SlaveLocalID;
+                    Radio.Send(Buffer, BUFFER_SIZE_RTS);
+                    debug("TDMA_sendBeacon\n\r");
+                    MasterTDMAState = TDMA_Wait_for_RTS;
+                } else {
+                    MasterTDMAState = TDMA_Slave_Not_Found;
+                    Beacon_Counter = 0;
+                }
+                break;
+
+            case TDMA_Send_CTS:
+                TDMA_messageType = TDMA_msgCTS;
+                Buffer[0] = TDMA_messageType;
+                Buffer[1] = SnrValue;
+                Radio.Send(Buffer, BUFFER_SIZE_CTS);
+                debug("RTS Received\n\r");
+                MasterTDMAState = TDMA_Wait_for_Data;
+                break;
+
+            case TDMA_Send_Ack:
+                TDMA_messageType = TDMA_msgAck;
+                Buffer[0] = TDMA_messageType;
+                Radio.Send(Buffer, BUFFER_SIZE_JoinAccept);
+                debug("Data Received\n\r");
+                end = timer.read_us();
+                debug("TDMA took : %f S\n\r", (end-begin+20000)/1000000.0);
+                debug("Master TDMA Slot Finished...\n\r");
+                return;
+
+            case TDMA_Slave_Not_Found:
+                debug("Case of Slave Not Found\n\r");
+                Radio.Sleep();
+                wait_us(TDMA_TIME_OUT_VALUE);
+                MasterTDMAState = TDMA_sendBeacon;
+                break;
+
+            case TDMA_Wait_for_RTS:
+            case TDMA_Wait_for_Data:
+                break;
+            default:
+                break;
+
+        }
+
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 8b449140caa2 MasterTDMA.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MasterTDMA.h	Mon May 23 22:25:40 2016 +0000
@@ -0,0 +1,26 @@
+#ifndef _MASTERTDMA_H_
+#define _MASTERTDMA_H_
+
+#include "WANOT.h"
+
+typedef enum {
+    TDMA_sendBeacon = 0,
+    TDMA_Wait_for_RTS,
+    TDMA_Send_CTS,
+    TDMA_Wait_for_Data,
+    TDMA_Send_Ack,
+    TDMA_Slave_Not_Found
+} MasterTDMAStates;
+
+typedef enum {
+    TDMA_msgRTS = 0x11,
+    TDMA_msgCTS = 0x12,
+    TDMA_msgData = 0x13,
+    TDMA_msgAck = 0x14
+
+} TDMA_msgType;
+
+void MasterTDMA(uint8_t SlaveLocalID);
+
+
+#endif //_MASTERTDMA_H_
\ No newline at end of file
diff -r 000000000000 -r 8b449140caa2 SX1276Lib.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SX1276Lib.lib	Mon May 23 22:25:40 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Semtech/code/SX1276Lib/#3778e6204cc1
diff -r 000000000000 -r 8b449140caa2 SuperSlot.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SuperSlot.cpp	Mon May 23 22:25:40 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
diff -r 000000000000 -r 8b449140caa2 SuperSlot.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SuperSlot.h	Mon May 23 22:25:40 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
diff -r 000000000000 -r 8b449140caa2 WANOT.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WANOT.h	Mon May 23 22:25:40 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 "MasterSetUp.h"
+#include "MasterBeacon.h"
+#include "MasterTDMA.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
diff -r 000000000000 -r 8b449140caa2 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 23 22:25:40 2016 +0000
@@ -0,0 +1,54 @@
+#include"WANOT.h"
+
+/*
+ *  Global variables declarations
+ */
+
+/*!
+ * Radio events function pointer
+ */
+RadioEvents_t RadioEvents;
+SX1276MB1xAS Radio(NULL);
+
+extern SuperSlotStates SuperSlotState;
+
+Timer timer;
+int begin, end;
+
+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 Master Started...\n\r");
+
+    char StoreRead[50];
+    GPS_Read(StoreRead);
+
+    SuperSlotInit();
+    
+    uint8_t SlaveLocalID = 1;
+
+    while(1)    {
+
+        switch(SuperSlotState) {
+            case SetUp_Beacon_Phase:
+                SetUp_Beacon();
+                break;
+
+            case SetUp_Phase:
+                MasterSetUp();
+                break;
+
+            case TDMA_Phase:
+                MasterTDMA(SlaveLocalID);
+                SlaveLocalID++;
+                break;
+
+        }
+    }
+
+}
diff -r 000000000000 -r 8b449140caa2 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon May 23 22:25:40 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7c328cabac7e
\ No newline at end of file