houss red
/
Master_F
Master Implementation of WANOT
MasterBeacon.cpp@0:8b449140caa2, 2016-05-23 (annotated)
- Committer:
- semsem
- Date:
- Mon May 23 22:25:40 2016 +0000
- Revision:
- 0:8b449140caa2
V0.2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
semsem | 0:8b449140caa2 | 1 | #include"WANOT.h" |
semsem | 0:8b449140caa2 | 2 | |
semsem | 0:8b449140caa2 | 3 | /* |
semsem | 0:8b449140caa2 | 4 | * Global variables declarations |
semsem | 0:8b449140caa2 | 5 | */ |
semsem | 0:8b449140caa2 | 6 | |
semsem | 0:8b449140caa2 | 7 | extern SuperSlotStates SuperSlotState; |
semsem | 0:8b449140caa2 | 8 | |
semsem | 0:8b449140caa2 | 9 | extern RadioEvents_t RadioEvents; |
semsem | 0:8b449140caa2 | 10 | extern SX1276MB1xAS Radio; |
semsem | 0:8b449140caa2 | 11 | |
semsem | 0:8b449140caa2 | 12 | extern uint16_t BufferSize; |
semsem | 0:8b449140caa2 | 13 | extern uint8_t Buffer[]; |
semsem | 0:8b449140caa2 | 14 | |
semsem | 0:8b449140caa2 | 15 | extern int16_t RssiValue; |
semsem | 0:8b449140caa2 | 16 | extern int8_t SnrValue; |
semsem | 0:8b449140caa2 | 17 | |
semsem | 0:8b449140caa2 | 18 | extern uint32_t LORA_Channels[NUMBER_OF_CHANNELS]; |
semsem | 0:8b449140caa2 | 19 | |
semsem | 0:8b449140caa2 | 20 | extern uint8_t SlotNumber; |
semsem | 0:8b449140caa2 | 21 | extern uint8_t TDMAChannel; |
semsem | 0:8b449140caa2 | 22 | |
semsem | 0:8b449140caa2 | 23 | |
semsem | 0:8b449140caa2 | 24 | volatile uint8_t Beacon_Tx_Done = 0; |
semsem | 0:8b449140caa2 | 25 | void SetUp_Beacon_OnTxDone(void) |
semsem | 0:8b449140caa2 | 26 | { |
semsem | 0:8b449140caa2 | 27 | Beacon_Tx_Done = 1; |
semsem | 0:8b449140caa2 | 28 | debug("Beacon Tx Done!!\n\r"); |
semsem | 0:8b449140caa2 | 29 | } |
semsem | 0:8b449140caa2 | 30 | |
semsem | 0:8b449140caa2 | 31 | |
semsem | 0:8b449140caa2 | 32 | void SetUp_Beacon(void) |
semsem | 0:8b449140caa2 | 33 | { |
semsem | 0:8b449140caa2 | 34 | debug("Master Set Up Beacon Started...\n\r"); |
semsem | 0:8b449140caa2 | 35 | |
semsem | 0:8b449140caa2 | 36 | Radio.SetTxConfig(MODEM_LORA, TX_OUTPUT_POWER, 0, SET_UP_LORA_BANDWIDTH, |
semsem | 0:8b449140caa2 | 37 | SET_UP_LORA_SPREADING_FACTOR, LORA_CODINGRATE, |
semsem | 0:8b449140caa2 | 38 | LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, |
semsem | 0:8b449140caa2 | 39 | SET_UP_LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, |
semsem | 0:8b449140caa2 | 40 | LORA_IQ_INVERSION_ON, 2000000); |
semsem | 0:8b449140caa2 | 41 | |
semsem | 0:8b449140caa2 | 42 | Radio.SetRxConfig(MODEM_LORA, SET_UP_LORA_BANDWIDTH, SET_UP_LORA_SPREADING_FACTOR, |
semsem | 0:8b449140caa2 | 43 | LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, |
semsem | 0:8b449140caa2 | 44 | LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0, |
semsem | 0:8b449140caa2 | 45 | SET_UP_LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, |
semsem | 0:8b449140caa2 | 46 | LORA_IQ_INVERSION_ON, true); |
semsem | 0:8b449140caa2 | 47 | Radio.SetChannel(SET_UP_FREQUENCY); |
semsem | 0:8b449140caa2 | 48 | |
semsem | 0:8b449140caa2 | 49 | Beacon_Tx_Done = 0; |
semsem | 0:8b449140caa2 | 50 | RadioEvents.TxDone = SetUp_Beacon_OnTxDone; |
semsem | 0:8b449140caa2 | 51 | Radio.Init(&RadioEvents); |
semsem | 0:8b449140caa2 | 52 | |
semsem | 0:8b449140caa2 | 53 | if (TDMAChannel != 0) |
semsem | 0:8b449140caa2 | 54 | Radio.Sleep(); |
semsem | 0:8b449140caa2 | 55 | |
semsem | 0:8b449140caa2 | 56 | wait_us(TDMAChannel * BEACON_TIMEOUT_VALUE); |
semsem | 0:8b449140caa2 | 57 | |
semsem | 0:8b449140caa2 | 58 | Buffer[0] = SETUP_BEACON_SYNCWORD; |
semsem | 0:8b449140caa2 | 59 | Buffer[1] = TDMAChannel; |
semsem | 0:8b449140caa2 | 60 | |
semsem | 0:8b449140caa2 | 61 | Radio.Send(Buffer, BUFFER_SIZE_RTS); |
semsem | 0:8b449140caa2 | 62 | |
semsem | 0:8b449140caa2 | 63 | while(Beacon_Tx_Done != 1); |
semsem | 0:8b449140caa2 | 64 | |
semsem | 0:8b449140caa2 | 65 | debug("Beacon Sent\n\r"); |
semsem | 0:8b449140caa2 | 66 | |
semsem | 0:8b449140caa2 | 67 | Radio.SetTxConfig(MODEM_LORA, TX_OUTPUT_POWER, 0, SET_UP_LORA_BANDWIDTH, |
semsem | 0:8b449140caa2 | 68 | SET_UP_LORA_SPREADING_FACTOR, LORA_CODINGRATE, |
semsem | 0:8b449140caa2 | 69 | LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, |
semsem | 0:8b449140caa2 | 70 | SET_UP_LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, |
semsem | 0:8b449140caa2 | 71 | LORA_IQ_INVERSION_ON, 2000000); |
semsem | 0:8b449140caa2 | 72 | |
semsem | 0:8b449140caa2 | 73 | Radio.SetRxConfig(MODEM_LORA, SET_UP_LORA_BANDWIDTH, SET_UP_LORA_SPREADING_FACTOR, |
semsem | 0:8b449140caa2 | 74 | LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, |
semsem | 0:8b449140caa2 | 75 | LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0, |
semsem | 0:8b449140caa2 | 76 | SET_UP_LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, |
semsem | 0:8b449140caa2 | 77 | LORA_IQ_INVERSION_ON, true); |
semsem | 0:8b449140caa2 | 78 | |
semsem | 0:8b449140caa2 | 79 | |
semsem | 0:8b449140caa2 | 80 | Radio.SetChannel(LORA_Channels[TDMAChannel]); |
semsem | 0:8b449140caa2 | 81 | |
semsem | 0:8b449140caa2 | 82 | debug("Master Set Up Beacon Done!!\n\r"); |
semsem | 0:8b449140caa2 | 83 | //Sleep untill setup phase RTC |
semsem | 0:8b449140caa2 | 84 | } |