Basic MAC data interface for LoRa transceiver
Dependents: LoRaBaseStation LoRaTerminal
Diff: AlohaTransceiver.cpp
- Revision:
- 22:2e39f382f782
- Parent:
- 21:3b86a44b98c8
- Child:
- 23:4b51a8e27f6a
--- a/AlohaTransceiver.cpp Thu Sep 01 01:00:09 2016 +0000 +++ b/AlohaTransceiver.cpp Fri Sep 02 03:22:24 2016 +0000 @@ -214,6 +214,26 @@ } case LOWPOWER: { + // transmit packet when the radio is free + while (AlohaTxQueue.getCounter() > 0) + { + AlohaFrame *frame = AlohaTxQueue.dequeue(); + + // create a buffer for transmit + uint8_t frame_length = frame->getPayloadLength() + FIXED_BYTE; + uint8_t buffer[frame_length]; // 4 fix fields + memset(buffer, 0x0, sizeof(buffer)); + + // copy content to buffer + frame->serialize(buffer); + + // send to radio + Radio.Send(buffer, frame_length); + + // free memory + delete frame; + } + break; } default: @@ -233,45 +253,32 @@ } // create a new frame - AlohaFrame frame; - uint8_t frame_length = payload_length + FIXED_BYTE; + AlohaFrame *frame = new AlohaFrame(); - frame.setType(AlohaFrame::Aloha_Data); - frame.setPayloadLength(payload_length); - frame.setSourceAddress(deviceId); - frame.setDestinationAddress(dest_addr & 0x0f); - frame.setFullMessageFlag(0x1); - frame.setSequenceID(seqid[dest_addr]++); // use dest_addr as key for accessing sequence id + // set properfies + frame->setType(AlohaFrame::Aloha_Data); + frame->setPayloadLength(payload_length); + frame->setSourceAddress(deviceId); + frame->setDestinationAddress(dest_addr & 0x0f); + frame->setFullMessageFlag(0x1); + frame->setSequenceID(seqid[dest_addr]++); // use dest_addr as key for accessing sequence id // the seqid should increase as it successfully transmit the packet + + // set payload for (uint8_t i = 0; i < payload_length; i++) { - frame.setPayload(i, payload[i]); + frame->setPayload(i, payload[i]); } // calculate crc - frame.generateCrc(); - - // create a buffer for transmit - uint8_t buffer[frame_length]; // 4 fix fields - memset(buffer, 0x0, sizeof(buffer)); - - // copy content to buffer - frame.serialize(buffer); + frame->generateCrc(); - // send to radio - Radio.Send(buffer, frame_length); - - State = LOWPOWER; - + // push frame to the back of queue + AlohaTxQueue.enqueue(frame); + return true; } -bool AlohaTransceiver::send(AlohaFrame *frame) -{ - // TODO: finish this - return false; -} - void AlohaTransceiver::registerType(AlohaFrame::AlohaType_t type, aloha_callback_func f) { AlohaTypeCallbackTable[type] = f;