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

Committer:
JamieB
Date:
Tue Nov 16 19:01:34 2021 +0000
Revision:
66:066b16c6c34f
Parent:
35:7ecf25d9c414
Child:
69:47f800793d00
Changed Buffered Serial to Read Raw Serial in RX Interrupt

Who changed what in which revision?

UserRevisionLine numberNew 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 35:7ecf25d9c414 7 #include "LTCApp.h"
AndyA 35:7ecf25d9c414 8 #include "LowPassFilter.h"
AndyA 0:97661408d0f9 9
AndyA 0:97661408d0f9 10 extern const char* VIPSStatusMessages[];
AndyA 35:7ecf25d9c414 11 struct UserSettings_s;
AndyA 0:97661408d0f9 12
AndyA 35:7ecf25d9c414 13 class VIPSSerial
AndyA 35:7ecf25d9c414 14 {
AndyA 0:97661408d0f9 15
AndyA 35:7ecf25d9c414 16 public:
AndyA 0:97661408d0f9 17
AndyA 1:dd1f7e162f91 18 VIPSSerial(const PinName Tx, const PinName Rx);
AndyA 1:dd1f7e162f91 19 void run(void);
AndyA 35:7ecf25d9c414 20 bool setFilters(struct UserSettings_s *settings);
AndyA 0:97661408d0f9 21
AndyA 0:97661408d0f9 22 // send all position outputs rather than just when requested.
AndyA 0:97661408d0f9 23 void sendAllUpdated(bool enable);
AndyA 0:97661408d0f9 24
AndyA 0:97661408d0f9 25 // send a position output for the requested time. Times are based on the global TimeSinceLastFrame timer.
AndyA 0:97661408d0f9 26 position* sendPositionForTime(uint32_t timeValue);
AndyA 35:7ecf25d9c414 27 position* getWaitingPostion()
AndyA 35:7ecf25d9c414 28 {
AndyA 35:7ecf25d9c414 29 position *ptr = outputPtr;
AndyA 35:7ecf25d9c414 30 outputPtr=NULL;
AndyA 35:7ecf25d9c414 31 return ptr;
AndyA 35:7ecf25d9c414 32 }
AndyA 0:97661408d0f9 33
AndyA 1:dd1f7e162f91 34 static void getCRC(void *data, int len, void *checksum);
AndyA 1:dd1f7e162f91 35
AndyA 3:14d241e29be3 36 // void setOutMask(uint32_t outputMask) {_outputMask = outputMask;};
AndyA 3:14d241e29be3 37
AndyA 35:7ecf25d9c414 38 bool EnableSmoothing(bool enabled)
AndyA 35:7ecf25d9c414 39 {
AndyA 35:7ecf25d9c414 40 hyperSmoothEnabled = enabled;
AndyA 35:7ecf25d9c414 41 return hyperSmoothEnabled;
AndyA 35:7ecf25d9c414 42 };
AndyA 35:7ecf25d9c414 43 bool SmoothingEnabled(void)
AndyA 35:7ecf25d9c414 44 {
AndyA 35:7ecf25d9c414 45 return hyperSmoothEnabled;
AndyA 35:7ecf25d9c414 46 };
JamieB 66:066b16c6c34f 47 bool ForceSmoothing(bool enabled)
JamieB 66:066b16c6c34f 48 {
JamieB 66:066b16c6c34f 49 forcedHyperSmooth = enabled;
JamieB 66:066b16c6c34f 50 hyperSmoothEnabled = enabled;
JamieB 66:066b16c6c34f 51 return hyperSmoothEnabled;
JamieB 66:066b16c6c34f 52 };
JamieB 66:066b16c6c34f 53 bool ForceSmoothingEnabled(bool enabled)
JamieB 66:066b16c6c34f 54 {
JamieB 66:066b16c6c34f 55 return forcedHyperSmooth;
JamieB 66:066b16c6c34f 56 };
AndyA 35:7ecf25d9c414 57 int GetSmoothLevel(void)
AndyA 35:7ecf25d9c414 58 {
AndyA 35:7ecf25d9c414 59 return SmoothBy;
AndyA 35:7ecf25d9c414 60 };
AndyA 35:7ecf25d9c414 61 bool SetSmoothLevel (const int newSmooth)
AndyA 35:7ecf25d9c414 62 {
AndyA 35:7ecf25d9c414 63 if (newSmooth == SmoothBy) return false;
AndyA 35:7ecf25d9c414 64 SmoothBy = newSmooth;
AndyA 35:7ecf25d9c414 65 SmoothRunning = false;
AndyA 35:7ecf25d9c414 66 return true;
AndyA 35:7ecf25d9c414 67 };
AndyA 35:7ecf25d9c414 68 void EnableBypass(bool enable)
AndyA 35:7ecf25d9c414 69 {
AndyA 35:7ecf25d9c414 70 BypassMode = enable;
AndyA 35:7ecf25d9c414 71 };
AndyA 16:a8d3a0dbe4bf 72 void bypassTx(char byte);
AndyA 18:ad407a2ed4c9 73 void sendQueued(void);
AndyA 16:a8d3a0dbe4bf 74
AndyA 0:97661408d0f9 75 private:
AndyA 0:97661408d0f9 76
AndyA 0:97661408d0f9 77 struct posAndTime_s {
AndyA 0:97661408d0f9 78 uint32_t time;
AndyA 0:97661408d0f9 79 position pos;
AndyA 0:97661408d0f9 80 };
AndyA 0:97661408d0f9 81
AndyA 16:a8d3a0dbe4bf 82 void smoothOutputPacket(position *posPtr);
AndyA 1:dd1f7e162f91 83 void onSerialRx(void);
AndyA 0:97661408d0f9 84 void processRxMessage();
AndyA 0:97661408d0f9 85 bool checkCRC(unsigned char* data);
AndyA 0:97661408d0f9 86 void sendResponse(unsigned char function, unsigned char* data, int dataLen);
AndyA 18:ad407a2ed4c9 87 void queueResponse(unsigned char function, unsigned char* data, int dataLen);
AndyA 0:97661408d0f9 88 void sendAck(unsigned char function);
AndyA 0:97661408d0f9 89 void sendNack(unsigned char function);
AndyA 0:97661408d0f9 90 void sendVBOXTime();
AndyA 0:97661408d0f9 91 void parsePostionInput_legacy();
AndyA 0:97661408d0f9 92 void parsePostionInput_mocap();
AndyA 0:97661408d0f9 93 bool checkNewPacketRC(unsigned char* data);
AndyA 1:dd1f7e162f91 94 RawSerial _port;
AndyA 0:97661408d0f9 95 unsigned char messageInBuffer[128];
AndyA 35:7ecf25d9c414 96 unsigned char messageOutBuffer[16];
AndyA 35:7ecf25d9c414 97 #define posHistoryLen 3
AndyA 0:97661408d0f9 98 struct posAndTime_s lastPositions[posHistoryLen];
AndyA 0:97661408d0f9 99 int nextPosition;
AndyA 14:76083dc18b0d 100 struct posAndTime_s lastPos; // the most recent position received
AndyA 14:76083dc18b0d 101 struct posAndTime_s prevPos; // the most last but one position received
AndyA 0:97661408d0f9 102
AndyA 0:97661408d0f9 103 position outputPosition;
AndyA 0:97661408d0f9 104 position *outputPtr;
AndyA 0:97661408d0f9 105
AndyA 0:97661408d0f9 106 int messagePrt;
AndyA 0:97661408d0f9 107 int messageLength;
AndyA 0:97661408d0f9 108 int statusMessage;
AndyA 0:97661408d0f9 109 bool enableAllUpdates;
AndyA 0:97661408d0f9 110 bool newFormatMsg;
AndyA 16:a8d3a0dbe4bf 111 bool hyperSmoothEnabled;
JamieB 66:066b16c6c34f 112 bool forcedHyperSmooth;
AndyA 0:97661408d0f9 113 uint32_t pointCount;
AndyA 3:14d241e29be3 114 uint32_t _outputMask;
AndyA 0:97661408d0f9 115
AndyA 18:ad407a2ed4c9 116 int queueLen;
AndyA 16:a8d3a0dbe4bf 117 int SmoothBy;
AndyA 35:7ecf25d9c414 118 // total as a float we would start to see rounding errors at valuses of ~20m
AndyA 16:a8d3a0dbe4bf 119 double XSmoothTotal;
AndyA 16:a8d3a0dbe4bf 120 double YSmoothTotal;
AndyA 16:a8d3a0dbe4bf 121 double ZSmoothTotal;
AndyA 16:a8d3a0dbe4bf 122 bool SmoothRunning;
AndyA 16:a8d3a0dbe4bf 123 bool BypassMode;
AndyA 35:7ecf25d9c414 124 LowPassFilter yFilter;
AndyA 35:7ecf25d9c414 125 LowPassFilter xFilter;
AndyA 35:7ecf25d9c414 126 LowPassFilter zFilter;
AndyA 35:7ecf25d9c414 127 LowPassFilter rollFilter;
AndyA 35:7ecf25d9c414 128 LowPassFilter pitchFilter;
AndyA 35:7ecf25d9c414 129 LowPassFilter yawFilter;
AndyA 0:97661408d0f9 130 };
AndyA 0:97661408d0f9 131
AndyA 0:97661408d0f9 132 #endif