X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=include%2FCECExports.h;h=fd6162ced744b2db0e47f2c4bb33f74462f5ca64;hb=ddb76c470aa282f59064c8e2ffe20a0785463167;hp=0aef25c30723e72e5b32fa177a1aeaf86b02e775;hpb=825ddb962b0515e1efb06bb10a1cbb74cde803f8;p=deb_libcec.git diff --git a/include/CECExports.h b/include/CECExports.h index 0aef25c..fd6162c 100644 --- a/include/CECExports.h +++ b/include/CECExports.h @@ -34,9 +34,8 @@ #ifndef CECEXPORTS_H_ #define CECEXPORTS_H_ -#include #include -#include +#include #if !defined(DECLSPEC) #if defined(_WIN32) || defined(_WIN64) @@ -55,11 +54,10 @@ extern "C" { namespace CEC { #endif - #define CEC_MIN_VERSION 2 - #define CEC_LIB_VERSION 2 - #define CEC_SETTLE_DOWN_TIME 1000 - - typedef std::vector cec_frame; + #define CEC_MIN_VERSION 6 + #define CEC_LIB_VERSION 6 + #define CEC_SETTLE_DOWN_TIME 1500 + #define CEC_BUTTON_TIMEOUT 500 typedef enum cec_user_control_code { @@ -243,8 +241,9 @@ namespace CEC { typedef struct cec_log_message { - std::string message; + char message[1024]; cec_log_level level; + int64_t time; } cec_log_message; typedef struct cec_keypress @@ -253,20 +252,156 @@ namespace CEC { unsigned int duration; } cec_keypress; - typedef struct cec_device + typedef struct cec_adapter + { + char path[1024]; + char comm[1024]; + } cec_adapter; + + typedef enum cec_adapter_messagecode + { + MSGCODE_NOTHING = 0, + MSGCODE_PING, + MSGCODE_TIMEOUT_ERROR, + MSGCODE_HIGH_ERROR, + MSGCODE_LOW_ERROR, + MSGCODE_FRAME_START, + MSGCODE_FRAME_DATA, + MSGCODE_RECEIVE_FAILED, + MSGCODE_COMMAND_ACCEPTED, + MSGCODE_COMMAND_REJECTED, + MSGCODE_SET_ACK_MASK, + MSGCODE_TRANSMIT, + MSGCODE_TRANSMIT_EOM, + MSGCODE_TRANSMIT_IDLETIME, + MSGCODE_TRANSMIT_ACK_POLARITY, + MSGCODE_TRANSMIT_LINE_TIMEOUT, + MSGCODE_TRANSMIT_SUCCEEDED, + MSGCODE_TRANSMIT_FAILED_LINE, + MSGCODE_TRANSMIT_FAILED_ACK, + MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA, + MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE, + MSGCODE_FIRMWARE_VERSION, + MSGCODE_START_BOOTLOADER, + MSGCODE_FRAME_EOM = 0x80, + MSGCODE_FRAME_ACK = 0x40, + } cec_adapter_messagecode; + + typedef struct cec_datapacket + { + uint8_t data[100]; + uint8_t size; + + bool empty(void) const { return size == 0; } + bool full(void) const { return size == 100; } + uint8_t operator[](uint8_t pos) const { return pos < size ? data[pos] : 0; } + uint8_t at(uint8_t pos) const { return pos < size ? data[pos] : 0; } + + void shift(uint8_t iShiftBy) + { + if (iShiftBy >= size) + { + clear(); + } + else + { + for (uint8_t iPtr = 0; iPtr < size; iPtr++) + data[iPtr] = (iPtr + iShiftBy < size) ? data[iPtr + iShiftBy] : 0; + size = (uint8_t) (size - iShiftBy); + } + } + + void push_back(uint8_t add) + { + if (size < 100) + data[size++] = add; + } + + void clear(void) + { + memset(data, 0, sizeof(data)); + size = 0; + } + + } cec_datapacket; + + typedef struct cec_adapter_message { - std::string path; - std::string comm; - } cec_device; + cec_datapacket packet; + + bool empty(void) const { return packet.empty(); } + uint8_t operator[](uint8_t pos) const { return packet[pos]; } + uint8_t at(uint8_t pos) const { return packet[pos]; } + uint8_t size(void) const { return packet.size; } + void clear(void) { packet.clear(); } + void shift(uint8_t iShiftBy) { packet.shift(iShiftBy); } + void push_back(uint8_t add) { packet.push_back(add); } + cec_adapter_messagecode message(void) const { return packet.size >= 1 ? (cec_adapter_messagecode) (packet.at(0) & ~(MSGCODE_FRAME_EOM | MSGCODE_FRAME_ACK)) : MSGCODE_NOTHING; } + bool eom(void) const { return packet.size >= 1 ? (packet.at(0) & MSGCODE_FRAME_EOM) != 0 : false; } + bool ack(void) const { return packet.size >= 1 ? (packet.at(0) & MSGCODE_FRAME_ACK) != 0 : false; } + cec_logical_address initiator(void) const { return packet.size >= 2 ? (cec_logical_address) (packet.at(1) >> 4) : CECDEVICE_UNKNOWN; }; + cec_logical_address destination(void) const { return packet.size >= 2 ? (cec_logical_address) (packet.at(1) & 0xF) : CECDEVICE_UNKNOWN; }; + } cec_adapter_message; typedef struct cec_command { - cec_logical_address source; + cec_logical_address initiator; cec_logical_address destination; + bool ack; + bool eom; cec_opcode opcode; - cec_frame parameters; + cec_datapacket parameters; + bool opcode_set; + + static void format(cec_command &command, cec_logical_address initiator, cec_logical_address destination, cec_opcode opcode) + { + command.clear(); + command.initiator = initiator; + command.destination = destination; + command.opcode = opcode; + command.opcode_set = true; + } + + void push_back(uint8_t data) + { + if (!opcode_set) + { + opcode_set = true; + opcode = (cec_opcode) data; + } + else + parameters.push_back(data); + } + + void clear(void) + { + initiator = CECDEVICE_UNKNOWN; + destination = CECDEVICE_UNKNOWN; + ack = false; + eom = false; + opcode_set = false; + opcode = CEC_OPCODE_FEATURE_ABORT; + parameters.clear(); + }; } cec_command; + typedef enum cec_vendor_id + { + CEC_VENDOR_SAMSUNG = 240, + CEC_VENDOR_UNKNOWN = 0 + } vendor_id; + + static const char *CECVendorIdToString(const uint64_t iVendorId) + { + switch (iVendorId) + { + case CEC_VENDOR_SAMSUNG: + return "Samsung"; + default: + return "Unknown"; + } + } + //default physical address 1.0.0.0 #define CEC_DEFAULT_PHYSICAL_ADDRESS 0x1000