Basic MAC data interface for LoRa transceiver
Dependents: LoRaBaseStation LoRaTerminal
Diff: AlohaTransceiver.cpp
- Revision:
- 24:8f31c33c7675
- Parent:
- 23:4b51a8e27f6a
- Child:
- 25:bcd1cee4e5a8
diff -r 4b51a8e27f6a -r 8f31c33c7675 AlohaTransceiver.cpp --- a/AlohaTransceiver.cpp Fri Sep 02 04:20:26 2016 +0000 +++ b/AlohaTransceiver.cpp Fri Sep 02 04:43:42 2016 +0000 @@ -243,35 +243,51 @@ } } -bool send(BasicPacket *packet) -{ - return true; -} - -bool AlohaTransceiver::send(uint8_t *payload, uint8_t payload_length, uint8_t dest_addr) -{ - // assume the user will not transmit payload longer than 16 bytes - if (payload_length > 16) - { - return false; - } +bool AlohaTransceiver::send(BasicPacket *packet) +{ + // for the reason that we only transmit basic packet format, the + // length is always 8 + uint8_t payload_length = 8; + + // get destination address + uint8_t destination_address = findNextHop(packet->getDestinationID()); + + // serialize the packet from upper layer + uint8_t buffer[payload_length]; + memset(buffer, 0x0, sizeof(buffer)); + + // copy bytes into buffer + packet->serialize(buffer); // create a new frame AlohaFrame *frame = new AlohaFrame(); // set properfies + // set payload as data frame->setType(AlohaFrame::Aloha_Data); + + // set payload length (8 bytes for BasicPacket) frame->setPayloadLength(payload_length); + + // set mac layer device id frame->setSourceAddress(deviceId); - frame->setDestinationAddress(dest_addr & 0x0f); + + // set mac layer destination id + // for multiple hop system, the destination is the next hop + // in this case, we use destination id from upper layer + frame->setDestinationAddress(packet->getDestinationID()); + + // set full message flag (always true in this case) 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 + // use dest_addr as key for accessing sequence id + // the seqid should increase as it successfully transmit the packet + frame->setSequenceID(seqid[destination_address]++); + // set payload for (uint8_t i = 0; i < payload_length; i++) { - frame->setPayload(i, payload[i]); + frame->setPayload(i, buffer[i]); } // calculate crc @@ -279,7 +295,7 @@ // push frame to the back of queue AlohaTxQueue.enqueue(frame); - + return true; } @@ -313,6 +329,12 @@ deviceId = id; } +uint8_t AlohaTransceiver::findNextHop(uint8_t addr) +{ + // TODO: maintain a routing lookup table for choosing shortest path + return addr; +} + #if USE_MODEM_LORA == 1 AlohaTransceiver::LoRaSettings_t *AlohaTransceiver::getSettings() { @@ -385,3 +407,4 @@ debug( "> OnRxError\n\r" ); #endif } +