I messed up the merge, so pushing it over to another repo so I don't lose it. Will tidy up and remove later
Dependencies: BufferedSerial FatFileSystemCpp mbed
VIPSSerialProtocol.h@16:a8d3a0dbe4bf, 2021-04-30 (annotated)
- Committer:
- AndyA
- Date:
- Fri Apr 30 11:26:34 2021 +0000
- Revision:
- 16:a8d3a0dbe4bf
- Parent:
- 14:76083dc18b0d
- Child:
- 18:ad407a2ed4c9
Add support for multiple types of FIZ reader.; Added support for digipower FIZ as used by skycam
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AndyA | 0:97661408d0f9 | 1 | #ifndef __VIPSSERIALPROTOCOL_H__ |
AndyA | 0:97661408d0f9 | 2 | #define __VIPSSERIALPROTOCOL_H__ |
AndyA | 0:97661408d0f9 | 3 | |
AndyA | 0:97661408d0f9 | 4 | #include "mbed.h" |
AndyA | 0:97661408d0f9 | 5 | #include "position.h" |
AndyA | 0:97661408d0f9 | 6 | #include "BufferedSerial.h" |
AndyA | 0:97661408d0f9 | 7 | |
AndyA | 0:97661408d0f9 | 8 | extern const char* VIPSStatusMessages[]; |
AndyA | 0:97661408d0f9 | 9 | |
AndyA | 0:97661408d0f9 | 10 | class VIPSSerial { |
AndyA | 0:97661408d0f9 | 11 | |
AndyA | 0:97661408d0f9 | 12 | public: |
AndyA | 0:97661408d0f9 | 13 | |
AndyA | 1:dd1f7e162f91 | 14 | VIPSSerial(const PinName Tx, const PinName Rx); |
AndyA | 1:dd1f7e162f91 | 15 | void run(void); |
AndyA | 0:97661408d0f9 | 16 | |
AndyA | 0:97661408d0f9 | 17 | // send all position outputs rather than just when requested. |
AndyA | 0:97661408d0f9 | 18 | void sendAllUpdated(bool enable); |
AndyA | 0:97661408d0f9 | 19 | |
AndyA | 0:97661408d0f9 | 20 | // send a position output for the requested time. Times are based on the global TimeSinceLastFrame timer. |
AndyA | 0:97661408d0f9 | 21 | position* sendPositionForTime(uint32_t timeValue); |
AndyA | 0:97661408d0f9 | 22 | position* getWaitingPostion() {position *ptr = outputPtr; outputPtr=NULL; return ptr;} |
AndyA | 0:97661408d0f9 | 23 | |
AndyA | 1:dd1f7e162f91 | 24 | static void getCRC(void *data, int len, void *checksum); |
AndyA | 1:dd1f7e162f91 | 25 | |
AndyA | 3:14d241e29be3 | 26 | // void setOutMask(uint32_t outputMask) {_outputMask = outputMask;}; |
AndyA | 3:14d241e29be3 | 27 | |
AndyA | 16:a8d3a0dbe4bf | 28 | bool EnableSmoothing(bool enabled) { hyperSmoothEnabled = enabled; return hyperSmoothEnabled;}; |
AndyA | 16:a8d3a0dbe4bf | 29 | bool SmoothingEnabled(void) { return hyperSmoothEnabled;}; |
AndyA | 16:a8d3a0dbe4bf | 30 | |
AndyA | 16:a8d3a0dbe4bf | 31 | int GetSmoothLevel(void) { return SmoothBy; }; |
AndyA | 16:a8d3a0dbe4bf | 32 | bool SetSmoothLevel (const int newSmooth) { if (newSmooth == SmoothBy) return false; SmoothBy = newSmooth; SmoothRunning = false; return true; }; |
AndyA | 16:a8d3a0dbe4bf | 33 | void EnableBypass(bool enable) { BypassMode = enable;}; |
AndyA | 16:a8d3a0dbe4bf | 34 | void bypassTx(char byte); |
AndyA | 16:a8d3a0dbe4bf | 35 | |
AndyA | 0:97661408d0f9 | 36 | private: |
AndyA | 0:97661408d0f9 | 37 | |
AndyA | 0:97661408d0f9 | 38 | struct posAndTime_s { |
AndyA | 0:97661408d0f9 | 39 | uint32_t time; |
AndyA | 0:97661408d0f9 | 40 | position pos; |
AndyA | 0:97661408d0f9 | 41 | }; |
AndyA | 0:97661408d0f9 | 42 | |
AndyA | 16:a8d3a0dbe4bf | 43 | void smoothOutputPacket(position *posPtr); |
AndyA | 1:dd1f7e162f91 | 44 | void onSerialRx(void); |
AndyA | 0:97661408d0f9 | 45 | void processRxMessage(); |
AndyA | 0:97661408d0f9 | 46 | bool checkCRC(unsigned char* data); |
AndyA | 0:97661408d0f9 | 47 | void sendResponse(unsigned char function, unsigned char* data, int dataLen); |
AndyA | 0:97661408d0f9 | 48 | void sendAck(unsigned char function); |
AndyA | 0:97661408d0f9 | 49 | void sendNack(unsigned char function); |
AndyA | 0:97661408d0f9 | 50 | void sendVBOXTime(); |
AndyA | 0:97661408d0f9 | 51 | void parsePostionInput_legacy(); |
AndyA | 0:97661408d0f9 | 52 | void parsePostionInput_mocap(); |
AndyA | 0:97661408d0f9 | 53 | bool checkNewPacketRC(unsigned char* data); |
AndyA | 1:dd1f7e162f91 | 54 | RawSerial _port; |
AndyA | 0:97661408d0f9 | 55 | unsigned char messageInBuffer[128]; |
AndyA | 0:97661408d0f9 | 56 | unsigned char messageOutBuffer[16]; |
AndyA | 0:97661408d0f9 | 57 | #define posHistoryLen 3 |
AndyA | 0:97661408d0f9 | 58 | struct posAndTime_s lastPositions[posHistoryLen]; |
AndyA | 0:97661408d0f9 | 59 | int nextPosition; |
AndyA | 14:76083dc18b0d | 60 | struct posAndTime_s lastPos; // the most recent position received |
AndyA | 14:76083dc18b0d | 61 | struct posAndTime_s prevPos; // the most last but one position received |
AndyA | 0:97661408d0f9 | 62 | |
AndyA | 0:97661408d0f9 | 63 | position outputPosition; |
AndyA | 0:97661408d0f9 | 64 | position *outputPtr; |
AndyA | 0:97661408d0f9 | 65 | |
AndyA | 0:97661408d0f9 | 66 | int messagePrt; |
AndyA | 0:97661408d0f9 | 67 | int messageLength; |
AndyA | 0:97661408d0f9 | 68 | int statusMessage; |
AndyA | 0:97661408d0f9 | 69 | bool enableAllUpdates; |
AndyA | 0:97661408d0f9 | 70 | bool newFormatMsg; |
AndyA | 16:a8d3a0dbe4bf | 71 | bool hyperSmoothEnabled; |
AndyA | 0:97661408d0f9 | 72 | uint32_t pointCount; |
AndyA | 3:14d241e29be3 | 73 | uint32_t _outputMask; |
AndyA | 0:97661408d0f9 | 74 | |
AndyA | 16:a8d3a0dbe4bf | 75 | int SmoothBy; |
AndyA | 16:a8d3a0dbe4bf | 76 | // total as a float we would start to see rounding errors at valuses of ~20m |
AndyA | 16:a8d3a0dbe4bf | 77 | double XSmoothTotal; |
AndyA | 16:a8d3a0dbe4bf | 78 | double YSmoothTotal; |
AndyA | 16:a8d3a0dbe4bf | 79 | double ZSmoothTotal; |
AndyA | 16:a8d3a0dbe4bf | 80 | bool SmoothRunning; |
AndyA | 16:a8d3a0dbe4bf | 81 | bool BypassMode; |
AndyA | 16:a8d3a0dbe4bf | 82 | |
AndyA | 16:a8d3a0dbe4bf | 83 | |
AndyA | 0:97661408d0f9 | 84 | }; |
AndyA | 0:97661408d0f9 | 85 | |
AndyA | 0:97661408d0f9 | 86 | #endif |