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:
Thu Feb 03 11:50:12 2022 +0000
Revision:
69:47f800793d00
Parent:
66:066b16c6c34f
Child:
72:da2f1df6a50d
v24, Added TCP upload of VIPS configuration to Rover

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