minipix_uart_interface
A library and examples for the MiniPIX UART interface
gatherer.h
Go to the documentation of this file.
1 #ifndef GATHERER_H
2 #define GATHERER_H
3 
4 #define LLCP_DEBUG_PRINT 0
5 #define SERIAL_BUFFER_SIZE 2048
6 #define MUI_USER_HANDSHAKES 0
7 
8 #ifndef GUI
9 #define GUI 0
10 #endif
11 
12 /* includes //{ */
13 
14 #include <llcp.h>
15 #include <llcp_minipix_messages.h>
16 
17 #if GUI == 1
18 #include <opencv2/opencv.hpp>
19 #include <opencv2/core/core.hpp>
20 #include <opencv2/imgproc/imgproc.hpp>
21 #include <opencv2/highgui/highgui.hpp>
22 #include <opencv2/imgproc.hpp>
23 #include <opencv_helpers.hpp>
24 #endif
25 
26 #include <mutex>
27 #include <chrono>
28 #include <thread>
29 #include <atomic>
30 #include <math.h>
31 
32 #include <serial_port.h>
33 
34 #include <pixel_decoder.h>
35 
36 //}
37 
38 class Gatherer {
39 
40 public:
41  Gatherer(const std::string data_path);
42 
43  void connect(const std::string& serial_port, const int& baud_rate, const bool& virtual_port);
44 
45  void charCallback(const char in);
46 
47  // | --------------------- MiniPIX control -------------------- |
48 
49  void getStatus(void);
50  void getTemperature(void);
51  void measureFrame(const uint16_t& acquisition_time_ms, const uint8_t& mode);
52  void pwr(const bool& state);
53  void maskPixel(const uint8_t& x, const uint8_t& y, const bool state);
54  void setThreshold(const uint16_t& coarse, const uint16_t& fine);
55  void setConfigurationPreset(const uint16_t& preset);
56  void sendAck(bool ack);
57  void getFrameData(void);
58  void stop(void);
59 
60 public:
61  bool measuring_frame_ = false;
62  bool waiting_for_ack_ = false;
63  bool waiting_for_tmp_ = false;
64  bool waiting_for_status_ = false;
65 
66 private:
67  SerialPort serial_port_;
68  std::mutex mutex_serial_port_;
69  uint8_t tx_buffer[SERIAL_BUFFER_SIZE];
70 
71  LLCP_Receiver_t llcp_receiver;
72 
73  std::thread thread_main_;
74  void threadMain(void);
75 
76  std::atomic<bool> initialized_ = false;
77  std::atomic<bool> running_ = true;
78 
79  // | ------------------------ callbacks ----------------------- |
80 
81  void callbackFrameData(const LLCP_Message_t* message_in);
82  void callbackStatus(const LLCP_Message_t* message_in);
83  void callbackTemperature(const LLCP_Message_t* message_in);
84  void callbackFrameTerminator(const LLCP_Message_t* message_in);
85  void callbackAck(const LLCP_Message_t* message_in);
86  void callbackFrameMeasurementFinished(const LLCP_Message_t* message_in);
87  void callbackError(const LLCP_Message_t* message_in);
88 
89  // | --------------------- helper routines -------------------- |
90 
91  void saveFrameDataToFile(const LLCP_FrameDataMsg_t& msg);
92  void bin2hex(const uint8_t x, uint8_t* buffer);
93 
94  // | ------------ saving measured frames to a file ------------ |
95 
96  FILE* measured_data_file_;
97 
98 #if GUI == 1
99  // | ------------------------ plotting ------------------------ |
100 
101  std::thread thread_plot_;
102  void threadPlot(void);
103 
104 
105  cv::Mat frame_top_left;
106  cv::Mat frame_top_right;
107  cv::Mat frame_bot_left;
108  cv::Mat frame_bot_right;
109 
110  std::mutex mutex_cv_frames_;
111 
112 #endif
113 };
114 
115 #endif // GATHERER_H
Gatherer::connect
void connect(const std::string &serial_port, const int &baud_rate, const bool &virtual_port)
Definition: gatherer.cpp:48
serial_port.h
Gatherer
Definition: gatherer.h:38
Gatherer::measuring_frame_
bool measuring_frame_
Definition: gatherer.h:61
Gatherer::pwr
void pwr(const bool &state)
Definition: gatherer.cpp:747
LLCP_Message_t
LLCP_Message_t
Definition: llcp.h:129
Gatherer::waiting_for_tmp_
bool waiting_for_tmp_
Definition: gatherer.h:63
Gatherer::setConfigurationPreset
void setConfigurationPreset(const uint16_t &preset)
Definition: gatherer.cpp:843
Gatherer::maskPixel
void maskPixel(const uint8_t &x, const uint8_t &y, const bool state)
Definition: gatherer.cpp:778
Gatherer::waiting_for_status_
bool waiting_for_status_
Definition: gatherer.h:64
opencv_helpers.hpp
Gatherer::getStatus
void getStatus(void)
Definition: gatherer.cpp:657
SerialPort
Definition: serial_port.h:16
SERIAL_BUFFER_SIZE
#define SERIAL_BUFFER_SIZE
Definition: gatherer.h:5
Gatherer::getFrameData
void getFrameData(void)
Definition: gatherer.cpp:611
LLCP_FrameDataMsg_t
LLCP_FrameDataMsg_t
Definition: llcp_minipix_messages.h:213
Gatherer::charCallback
void charCallback(const char in)
Gatherer::stop
void stop(void)
Definition: gatherer.cpp:59
Gatherer::setThreshold
void setThreshold(const uint16_t &coarse, const uint16_t &fine)
Definition: gatherer.cpp:811
Gatherer::waiting_for_ack_
bool waiting_for_ack_
Definition: gatherer.h:62
Gatherer::Gatherer
Gatherer(const std::string data_path)
Definition: gatherer.cpp:5
pixel_decoder.h
Gatherer::measureFrame
void measureFrame(const uint16_t &acquisition_time_ms, const uint8_t &mode)
Definition: gatherer.cpp:713
Gatherer::sendAck
void sendAck(bool ack)
Definition: gatherer.cpp:633
LLCP_Receiver_t
LLCP_Receiver_t
Definition: llcp.h:107
Gatherer::getTemperature
void getTemperature(void)
Definition: gatherer.cpp:685