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:
AndyA
Date:
Thu Aug 05 13:44:45 2021 +0000
Revision:
35:7ecf25d9c414
Parent:
18:ad407a2ed4c9
Child:
65:8ee40ed9295b
Child:
66:066b16c6c34f
filter working

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 };
AndyA 16:a8d3a0dbe4bf 47
AndyA 35:7ecf25d9c414 48 int GetSmoothLevel(void)
AndyA 35:7ecf25d9c414 49 {
AndyA 35:7ecf25d9c414 50 return SmoothBy;
AndyA 35:7ecf25d9c414 51 };
AndyA 35:7ecf25d9c414 52 bool SetSmoothLevel (const int newSmooth)
AndyA 35:7ecf25d9c414 53 {
AndyA 35:7ecf25d9c414 54 if (newSmooth == SmoothBy) return false;
AndyA 35:7ecf25d9c414 55 SmoothBy = newSmooth;
AndyA 35:7ecf25d9c414 56 SmoothRunning = false;
AndyA 35:7ecf25d9c414 57 return true;
AndyA 35:7ecf25d9c414 58 };
AndyA 35:7ecf25d9c414 59 void EnableBypass(bool enable)
AndyA 35:7ecf25d9c414 60 {
AndyA 35:7ecf25d9c414 61 BypassMode = enable;
AndyA 35:7ecf25d9c414 62 };
AndyA 16:a8d3a0dbe4bf 63 void bypassTx(char byte);
AndyA 18:ad407a2ed4c9 64 void sendQueued(void);
AndyA 16:a8d3a0dbe4bf 65
AndyA 0:97661408d0f9 66 private:
AndyA 0:97661408d0f9 67
AndyA 0:97661408d0f9 68 struct posAndTime_s {
AndyA 0:97661408d0f9 69 uint32_t time;
AndyA 0:97661408d0f9 70 position pos;
AndyA 0:97661408d0f9 71 };
AndyA 0:97661408d0f9 72
AndyA 16:a8d3a0dbe4bf 73 void smoothOutputPacket(position *posPtr);
AndyA 1:dd1f7e162f91 74 void onSerialRx(void);
AndyA 0:97661408d0f9 75 void processRxMessage();
AndyA 0:97661408d0f9 76 bool checkCRC(unsigned char* data);
AndyA 0:97661408d0f9 77 void sendResponse(unsigned char function, unsigned char* data, int dataLen);
AndyA 18:ad407a2ed4c9 78 void queueResponse(unsigned char function, unsigned char* data, int dataLen);
AndyA 0:97661408d0f9 79 void sendAck(unsigned char function);
AndyA 0:97661408d0f9 80 void sendNack(unsigned char function);
AndyA 0:97661408d0f9 81 void sendVBOXTime();
AndyA 0:97661408d0f9 82 void parsePostionInput_legacy();
AndyA 0:97661408d0f9 83 void parsePostionInput_mocap();
AndyA 0:97661408d0f9 84 bool checkNewPacketRC(unsigned char* data);
AndyA 1:dd1f7e162f91 85 RawSerial _port;
AndyA 0:97661408d0f9 86 unsigned char messageInBuffer[128];
AndyA 35:7ecf25d9c414 87 unsigned char messageOutBuffer[16];
AndyA 35:7ecf25d9c414 88 #define posHistoryLen 3
AndyA 0:97661408d0f9 89 struct posAndTime_s lastPositions[posHistoryLen];
AndyA 0:97661408d0f9 90 int nextPosition;
AndyA 14:76083dc18b0d 91 struct posAndTime_s lastPos; // the most recent position received
AndyA 14:76083dc18b0d 92 struct posAndTime_s prevPos; // the most last but one position received
AndyA 0:97661408d0f9 93
AndyA 0:97661408d0f9 94 position outputPosition;
AndyA 0:97661408d0f9 95 position *outputPtr;
AndyA 0:97661408d0f9 96
AndyA 0:97661408d0f9 97 int messagePrt;
AndyA 0:97661408d0f9 98 int messageLength;
AndyA 0:97661408d0f9 99 int statusMessage;
AndyA 0:97661408d0f9 100 bool enableAllUpdates;
AndyA 0:97661408d0f9 101 bool newFormatMsg;
AndyA 16:a8d3a0dbe4bf 102 bool hyperSmoothEnabled;
AndyA 0:97661408d0f9 103 uint32_t pointCount;
AndyA 3:14d241e29be3 104 uint32_t _outputMask;
AndyA 0:97661408d0f9 105
AndyA 18:ad407a2ed4c9 106 int queueLen;
AndyA 16:a8d3a0dbe4bf 107 int SmoothBy;
AndyA 35:7ecf25d9c414 108 // total as a float we would start to see rounding errors at valuses of ~20m
AndyA 16:a8d3a0dbe4bf 109 double XSmoothTotal;
AndyA 16:a8d3a0dbe4bf 110 double YSmoothTotal;
AndyA 16:a8d3a0dbe4bf 111 double ZSmoothTotal;
AndyA 16:a8d3a0dbe4bf 112 bool SmoothRunning;
AndyA 16:a8d3a0dbe4bf 113 bool BypassMode;
AndyA 35:7ecf25d9c414 114 LowPassFilter yFilter;
AndyA 35:7ecf25d9c414 115 LowPassFilter xFilter;
AndyA 35:7ecf25d9c414 116 LowPassFilter zFilter;
AndyA 35:7ecf25d9c414 117 LowPassFilter rollFilter;
AndyA 35:7ecf25d9c414 118 LowPassFilter pitchFilter;
AndyA 35:7ecf25d9c414 119 LowPassFilter yawFilter;
AndyA 0:97661408d0f9 120 };
AndyA 0:97661408d0f9 121
AndyA 0:97661408d0f9 122 #endif