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: SoftSerial MAX14690 Buffer
Fork of rtos_threading_with_callback by
Diff: linkLayerEncoder/linkLayer.cpp
- Revision:
- 2:bf699e054b34
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/linkLayerEncoder/linkLayer.cpp Sun Feb 25 16:40:28 2018 +0000
@@ -0,0 +1,96 @@
+#include "linkLayer.h"
+#include "global.h"
+
+void LinkLayerEncoder::setPacket(linkPacket* p)
+{
+ encoderIndex = 0;
+ lp = p;
+ oneCntr = 0;
+ hasPacket = 1;
+ preambleBits=8;
+ frameTypeBits=8;
+}
+bool LinkLayerEncoder::getNext()
+{
+ if(!hasPacket)//no active packet to send, get next
+ setPacket(txQueue.getNext());//rtos semaphore; wait until new data available
+ if(preambleBits-->0)//send preamble
+ {
+ return preambleBits<7;//send 1111 1110
+ }
+ if(frameTypeBits-->0)//send frametype
+ {
+ unsigned bitIndex = 7-frameTypeBits;
+
+ bool real = (bool)(lp->frameType&(1<<bitIndex));
+ bool returnVal;
+ if(real)
+ {
+ if((oneCntr ++)<6)
+ returnVal=1;
+ else
+ {
+ returnVal=0; // insert stuffing zero
+ frameTypeBits++;//need to transmit one bit next
+ oneCntr=0;
+ }
+ }
+ else
+ {
+ if(oneCntr==6)
+ {
+ returnVal=0; // insert stuffing zero
+ frameTypeBits++;//need to transmit one bit next
+ oneCntr=0;
+ }
+ else
+ {
+ oneCntr=0;
+ returnVal=0;
+ }
+ }
+ return returnVal;
+ }
+ unsigned byteIndex = encoderIndex / 8;
+ unsigned bitIndex = encoderIndex % 8;
+ encoderIndex++;
+
+ bool real = (bool)(lp->payload[byteIndex]&(1<<bitIndex));
+ bool returnVal;
+ if(real)
+ {
+ if((oneCntr ++)<6)
+ returnVal=1;
+ else
+ {
+ returnVal=0; // insert stuffing zero
+ encoderIndex--;//need to transmit one bit next
+ oneCntr=0;
+ }
+ }
+ else
+ {
+ if(oneCntr==6)
+ {
+ returnVal=0; // insert stuffing zero
+ encoderIndex--;//need to transmit one bit next
+ oneCntr=0;
+ }
+ else
+ {
+ oneCntr=0;
+ returnVal=0;
+ }
+ }
+
+
+ byteIndex = encoderIndex / 8;
+ if(byteIndex >= lp->payloadSz)
+ {
+ hasPacket=0;
+ delete lp->payload;
+ delete lp;
+ }
+
+ return returnVal;
+}
\ No newline at end of file
