knx
ETS configurable knx-stack
usb_tunnel_interface.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "config.h"
4 #ifdef USE_USB
5 #include <stdint.h>
6 
7 class CemiServer;
8 class CemiFrame;
9 
11 {
12  KnxTunneling = 0x01,
13  BusAccessServer = 0x0f
14 };
15 
17 {
18  EmiIdNotUsed = 0x00,
19  EMI1 = 0x01,
20  EMI2 = 0x02,
21  CEMI = 0x03
22 };
23 
25 {
31  DeviceFeatureEscape = 0xFF
32 };
33 
35 {
40  ActiveEmiType = 0x05
41 };
42 
44 {
45  public:
46  UsbTunnelInterface(CemiServer& cemiServer, uint16_t manufacturerId, uint16_t maskVersion);
47 
48  void loop();
49 
50  // from cEMI server
51  void sendCemiFrame(CemiFrame& frame);
52 
53  static const uint8_t* getKnxHidReportDescriptor();
54  static uint16_t getHidReportDescriptorLength();
55  static void receiveHidReport(uint8_t const* data, uint16_t bufSize);
56 
57  private:
58  struct _queue_buffer_t
59  {
60  uint8_t* data;
61  uint16_t length;
62  _queue_buffer_t* next;
63  };
64 
65  struct _queue_t
66  {
67  _queue_buffer_t* front = nullptr;
68  _queue_buffer_t* back = nullptr;
69  };
70 
71  static const uint8_t descHidReport[];
72 
73  CemiServer& _cemiServer;
74 
75  uint16_t _manufacturerId;
76  uint16_t _maskVersion;
77 
78  // USB TX queue
79  _queue_t _tx_queue;
80  void addBufferTxQueue(uint8_t* data, uint16_t length);
81  bool isTxQueueEmpty();
82  void loadNextTxFrame(uint8_t** sendBuffer, uint16_t* sendBufferLength);
83 
84  // USB RX queue
85  static _queue_t _rx_queue;
86  static void addBufferRxQueue(const uint8_t* data, uint16_t length);
87  bool isRxQueueEmpty();
88  void loadNextRxBuffer(uint8_t** receiveBuffer, uint16_t* receiveBufferLength);
89  static bool rxHaveCompletePacket;
90 
91  void handleTransferProtocolPacket(uint8_t* data, uint16_t length);
92  void handleHidReportRxQueue();
93  void handleBusAccessServerProtocol(ServiceIdType servId, const uint8_t* requestData, uint16_t packetLength);
94  void sendKnxHidReport(ProtocolIdType protId, ServiceIdType servId, uint8_t* data, uint16_t length);
95 };
96 #endif
This is an implementation of the cEMI server as specified in .
Definition: cemi_server.h:23
static void receiveHidReport(uint8_t const *data, uint16_t bufSize)
void sendCemiFrame(CemiFrame &frame)
UsbTunnelInterface(CemiServer &cemiServer, uint16_t manufacturerId, uint16_t maskVersion)
static const uint8_t * getKnxHidReportDescriptor()
static uint16_t getHidReportDescriptorLength()
@ DeviceFeatureResponse
@ DeviceFeatureInfo
@ DeviceFeatureSet
@ DeviceFeatureGet
@ ServiceIdNotUsed
@ DeviceFeatureEscape
@ EmiIdNotUsed
ProtocolIdType
@ BusAccessServer
@ KnxTunneling
@ SupportedEmiType
@ HostDeviceDescriptorType0
@ BusConnectionStatus
@ ActiveEmiType
@ KnxManufacturerCode