Jordan Brack / SmartWheelsPublic

Dependencies:   TSI USBDevice mbed-dev

Fork of SmartWheels by haofan Zheng

PCConnector/SWUSBServer.h

Committer:
hazheng
Date:
2017-02-10
Revision:
16:66c7a09e71ee
Parent:
13:7dcb1642ef99
Child:
18:bf6c5f8281eb

File content as of revision 16:66c7a09e71ee:

#pragma once
#ifndef SW_USBSERVER_H
#define SW_USBSERVER_H

#define HID_REPORT_LENGTH 64

#define SER_STAT_STOPPED    0
#define SER_STAT_SEARCHING  1
#define SER_STAT_CONNECTING 2
#define SER_STAT_CONNECTED  3
#define SER_STAT_RUNNING    4

#define HANDSHAKE_MSG_TER "SMARTWHEELS_HANDSHAKE_TERMINAL"
#define HANDSHAKE_MSG_PC  "SMARTWHEELS_HANDSHAKE_PC"
#define TICKING_MSG "TICK"

#include <mbed.h>
#include <rtos.h>
#include <list>
#include <string>

namespace SW
{
    class USBServer
    {
    public:
        USBServer(uint16_t vendor_id=0x1234, uint16_t product_id=0x0006);
        
        ~USBServer();
        
        void Update(float deltaTime);
        
        bool PushReliableMsg(const char type, const std::string & msg);
        
        bool PushUnreliableMsg(const char type, const std::string & msg);
        
        void Terminate();
        
        uint8_t GetStatus() const;
        
    private:
        
        bool m_shouldTerminate;
        
        uint8_t m_stat;
        
        Thread * m_usbThread;
        
        Serial * m_usb;
        
        std::list<std::string> m_msgQueue;
        
        Mutex m_qlocker;
        
        float m_tickMsgTimer;
        
        void RunningThread();
        
        void ConnectingThread();
    };
}
#endif