-data logging revision

Dependencies:   FastPWM

Committer:
ernstpre
Date:
Tue Aug 24 08:51:13 2021 +0000
Revision:
2:92c25cb669f4
Parent:
0:d2e117716219
Publish Commit 24/8/21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
altb2 0:d2e117716219 1 #ifndef UART_COMM_THREAD_H_
altb2 0:d2e117716219 2 #define UART_COMM_THREAD_H_
altb2 0:d2e117716219 3
altb2 0:d2e117716219 4 #include "GPA.h"
altb2 0:d2e117716219 5 #include "mbed.h"
altb2 0:d2e117716219 6 #include "ThreadFlag.h"
altb2 0:d2e117716219 7 #include "data_structs.h"
altb2 0:d2e117716219 8 #include "data_structs.h"
altb2 0:d2e117716219 9 #include "Mirror_Kinematic.h"
altb2 0:d2e117716219 10
altb2 0:d2e117716219 11 using namespace std;
altb2 0:d2e117716219 12
altb2 0:d2e117716219 13 extern DATA_Xchange data;
altb2 0:d2e117716219 14 extern Mirror_Kinematic mk;
altb2 0:d2e117716219 15
altb2 0:d2e117716219 16
altb2 0:d2e117716219 17 // "protocol" specifics
altb2 0:d2e117716219 18
altb2 0:d2e117716219 19 #define BUF_LEN 20 // max 256
altb2 0:d2e117716219 20 #define DATA_LEN 20 // max 256
altb2 0:d2e117716219 21
altb2 0:d2e117716219 22 // states
altb2 0:d2e117716219 23 #define IDLE 0
altb2 0:d2e117716219 24 #define WAIT 1
altb2 0:d2e117716219 25 #define RECEIVE 2
altb2 0:d2e117716219 26 #define DONE 3
altb2 0:d2e117716219 27
altb2 0:d2e117716219 28 #define LEN_OF_EXP_TYPE2 1 // length in bytes of expected Type
altb2 0:d2e117716219 29 #define NUM_OF_VALUE 7 // number of expected values
altb2 0:d2e117716219 30 #define EXPECTED2 LEN_OF_EXP_TYPE2 * NUM_OF_VALUE // byte per Value * expected values = total expected bytes
altb2 0:d2e117716219 31
altb2 0:d2e117716219 32 extern Mirror_Kinematic mc;
altb2 0:d2e117716219 33
altb2 0:d2e117716219 34 // predefiniton for callback (couldn't implement as member)
altb2 0:d2e117716219 35
altb2 0:d2e117716219 36 class uart_comm_thread{
altb2 0:d2e117716219 37 public:
altb2 0:d2e117716219 38 // public members
altb2 0:d2e117716219 39 uart_comm_thread(BufferedSerial*,float);
altb2 0:d2e117716219 40 virtual ~uart_comm_thread();
altb2 0:d2e117716219 41 void run(void); // runs the statemachine, call this function periodicly, returns true when new data ready (only true for 1 cycle)
altb2 0:d2e117716219 42 // void request(); // request new set of data
altb2 0:d2e117716219 43 void start_uart(void);
altb2 0:d2e117716219 44
altb2 0:d2e117716219 45 // public vars
altb2 0:d2e117716219 46 // public vars
altb2 0:d2e117716219 47 const uint8_t N = DATA_LEN;
altb2 0:d2e117716219 48
altb2 0:d2e117716219 49 uint16_t head[6];
altb2 0:d2e117716219 50 float f_values[20];
altb2 0:d2e117716219 51 uint8_t checksum;
altb2 0:d2e117716219 52 uint8_t buffer[80]; // RX buffer
altb2 0:d2e117716219 53 uint8_t buffCnt; // max 255
altb2 0:d2e117716219 54 uint8_t expected;
altb2 0:d2e117716219 55 uint8_t num_floats;
altb2 0:d2e117716219 56 uint8_t k_write;
altb2 0:d2e117716219 57 void send_text(const char *);
altb2 0:d2e117716219 58 void send_f_data(char,char,uint16_t,float*);
altb2 0:d2e117716219 59 void send_data(char,char,uint16_t,int16_t*);
altb2 0:d2e117716219 60 void send_data(char,char,int16_t);
altb2 0:d2e117716219 61 void send_char_data(char,char,uint8_t);
altb2 0:d2e117716219 62 private:
altb2 0:d2e117716219 63
altb2 0:d2e117716219 64 // private members
altb2 0:d2e117716219 65 void sendCmd(char); // sends comand to device
altb2 0:d2e117716219 66 void callBack(); // ISR for storing serial bytes
altb2 0:d2e117716219 67 void callBack_2(); // ISR for storing serial bytes
altb2 0:d2e117716219 68 void init(); // re initializes the buffers and the statemachine
altb2 0:d2e117716219 69 float Ts;
altb2 0:d2e117716219 70 EventQueue printfQueue;
altb2 0:d2e117716219 71 bool analyse_received_data(void);
altb2 0:d2e117716219 72 bool gpa_stop_sent;
altb2 0:d2e117716219 73
altb2 0:d2e117716219 74 // -------------------
altb2 0:d2e117716219 75 // uint8_t buffer[BUF_LEN]; // RX buffer
altb2 0:d2e117716219 76 // uint8_t buffCnt; // max 255
altb2 0:d2e117716219 77 uint8_t state; // statemachine state variable
altb2 0:d2e117716219 78 BufferedSerial* uart; // pointer to uart for communication with device
altb2 0:d2e117716219 79 ThreadFlag threadFlag;
altb2 0:d2e117716219 80 Thread thread;
altb2 0:d2e117716219 81 Ticker ticker;
altb2 0:d2e117716219 82 Mutex mutex;
altb2 0:d2e117716219 83 void sendThreadFlag();
altb2 0:d2e117716219 84 };
altb2 0:d2e117716219 85
altb2 0:d2e117716219 86 #endif
altb2 0:d2e117716219 87
altb2 0:d2e117716219 88