blob: b6840cc70c7f0acff8ed67d63939731dbcd2c2c6 [file] [log] [blame]
Austin Schuh9b360e92013-03-27 04:47:04 +00001#ifndef GET_H_
2#define GET_H_
3
4#include <sys/socket.h>
5#include <linux/can.h>
Austin Schuh9b360e92013-03-27 04:47:04 +00006
Brian Silverman798c7782013-03-28 16:48:02 -07007#include <memory>
8
9#include "aos/common/util/thread.h"
10
Austin Schuh9b360e92013-03-27 04:47:04 +000011#include "libusb_wrap.h"
12
Austin Schuh9b360e92013-03-27 04:47:04 +000013class DbgReader;
14
Austin Schuh9b360e92013-03-27 04:47:04 +000015class GyroDriver {
16 public:
17 // Constructs a GyroDriver.
18 // GyroDriver takes ownership of the device handle.
19 explicit GyroDriver(LibUSBDeviceHandle *dev_handle);
20 virtual ~GyroDriver();
21
22 // Queues a CAN frame. The driver will copy the frame to reduce memory churn
23 // and non-realtime behavior associated with allocating and deallocating the
24 // messages.
25 // Returns true if the message was queued and false otherwise.
26 bool QueueCanFrame(const struct can_frame &msg);
27
28 // Returns 1 packet worth of debug data from the bulk debug channel.
29 std::string GetDebugData();
30
31 // Waits until a CAN frame is available and returns it.
32 // Returns true if we got a frame and false if we were interrupted.
33 bool GetCanFrame(struct can_frame *msg);
34
35 // Terminates the rx and tx threads in preperation for shutdown.
36 // Not safe for use in signal handlers.
37 void Terminate();
38
39 private:
40 // Class that runs in a seperate thread and receives and queues all messages.
41 class PacketReceiver;
42
43 // USB Device handle.
44 std::unique_ptr<LibUSBDeviceHandle> dev_handle_;
45 // Handle for the object run in the debug thread which prints out debug
46 // information.
47 std::unique_ptr<DbgReader> dbg_;
Austin Schuh9b360e92013-03-27 04:47:04 +000048
49 // Handle for the transmit object which runs in the transmit thread and also
50 // handles priority queueing of packets.
51 //std::unique_ptr<PacketTransmitter> tx_;
52 // Thread handle for the transmit thread.
53 //std::unique_ptr<boost::thread> tx_thread_;
54
55 // Handle for the rx object which runs in the rx thread and also
56 // handles priority queueing of packets.
57 std::unique_ptr<PacketReceiver> rx_;
Austin Schuh9b360e92013-03-27 04:47:04 +000058};
59
Brian Silverman798c7782013-03-28 16:48:02 -070060class DbgReader : public ::aos::util::Thread {
Austin Schuh9b360e92013-03-27 04:47:04 +000061 public:
62 explicit DbgReader(GyroDriver *dev_handle);
63
64 // Serve.
Brian Silverman798c7782013-03-28 16:48:02 -070065 virtual void Run();
Austin Schuh9b360e92013-03-27 04:47:04 +000066
67 private:
68 GyroDriver *gyro_;
69};
70
71#endif // GET_H_