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.
Diff: Receiver.h
- Revision:
- 6:ac7c0ccf9b5d
- Parent:
- 4:a3c4a43f94f8
- Child:
- 7:332766fb3114
--- a/Receiver.h Mon Oct 23 21:20:08 2017 +0000
+++ b/Receiver.h Tue Oct 24 02:33:50 2017 +0000
@@ -1,93 +1,78 @@
+#ifndef RECEIVER_H
+#define RECEIVER_H
#include "mbed.h"
#include "rtos.h"
+
#include <vector>
-const unsigned char preamble = 85;
+#include "defines.h"
+
+enum Edge
+{
+ rising,
+ falling
+};
+class Receiver
+{
+
+public:
+
+ struct EdgeData {
+ EdgeData(){}
+ EdgeData(int us,Edge value):us_timeStamp(us),value(value) {}
+
+ int us_timeStamp;
+ Edge value;
+ };
+ Receiver();
+ void resetTimer(){time.reset();}
+ EdgeData getNext();
+
+
+
+private:
+ void pushState(Edge edge);
+ void rise();
+ void fall();
-class ReceiverData
+private:
+static const int size = 150;
+
+ Timer time;
+ Semaphore dataReady;
+ EdgeData data[size];
+public:
+ int currentData;
+ int endData;
+};
+
+typedef Receiver::EdgeData EdgeData;
+
+class ManchesterReceiver
{
public:
- ReceiverData():lastTime(0),receiving(false),data(80),temp(0),currentBit(0),ready(false){}
-
- const vector<unsigned char> & receivedData(){ return data; }
-
- bool waiting(){return receiving == false;}
+ void getMessages();
- void fall();
-
- void rise();
-
- void setTime();
-
- void addBit(unsigned char bit);
+private:
+ void getState(Edge &edge, int &timeStamp);
+
+ unsigned char getFirstByte(int &lastTime);
- void start();
- void waitData();
- void clear();
+ bool getByte(int& lastTime, unsigned char &val);
- void timeout();
-
-private:
- Timer time;
- Ticker watchDog;
+ bool getMessage(int lastTime, vector<unsigned char> &message);
- Semaphore dataSemaphore;
+private:
+ Receiver r;
- int lastTime;
- bool receiving;
- bool ready;
-
- vector<unsigned char> data;
- unsigned char temp;
- int currentBit;
+ bool possiblePreamble;
};
-
-
-
-/*
- void* arg = NULL;
- Thread receiver(arg,&receive);
-
- bool bit = false;
- MO = false;
- for(int i = 0; i < 16 ; i++)
- {
- printf("MO\n");
- Thread::wait(us_period/2000);
- MO = bit;
- bit = !bit;
- }
- while(1)
- {
- Thread::wait(2);
- }
-
-void receive(void* args)
-{
- pc.printf("Receive Start\n");
- ReceiverData data;
- while(true)
- {
- data.start();
- data.waitData();
- vector<unsigned char> vec = data.receivedData();
- pc.printf("print");
- for(int i = 0 ; i < vec.size();i++)
- {
- pc.printf("%c",vec[i]);
- }
- }
-}
-
-
-
-
- */
\ No newline at end of file
+#endif
\ No newline at end of file
