Mirror actuator for RT2 lab

Dependencies:   FastPWM

Committer:
altb2
Date:
Sun May 02 08:55:44 2021 +0000
Revision:
16:28b6bb8a4b7f
Parent:
8:49ac75c42da0
Final commit 4 students

Who changed what in which revision?

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