diff options
author | Christian König <chrissi@zweiundvierzig.(none)> | 2010-05-27 22:26:19 +0200 |
---|---|---|
committer | Christian König <chrissi@zweiundvierzig.(none)> | 2010-05-27 22:26:19 +0200 |
commit | 0208bfa252046a44dbb2d25a40f8d5e01057253b (patch) | |
tree | a0e5cf5380857bdf55ea5c41d43f7674bee3253d /lib | |
parent | 104643686853c5d21aa7e742877559519c77078b (diff) |
Implement some handlers in cec.c
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cec.h | 8 | ||||
-rw-r--r-- | lib/commands.c | 38 | ||||
-rw-r--r-- | lib/device.c | 8 |
3 files changed, 51 insertions, 3 deletions
@@ -546,12 +546,18 @@ struct CEC_Device }; extern void CEC_Init_Device(struct CEC_Device* device); +extern int CEC_Alloc_Addr(struct CEC_Device* device, enum CEC_Device_Type device_type); +extern void CEC_Unrecognized_Opcode(struct CEC_Device* device, struct CEC_Packet* packet); + extern void CEC_Dump_Packet(FILE* stream, struct CEC_Packet* packet); extern void CEC_Receive(struct CEC_Device* device); extern int CEC_Transmit(struct CEC_Device* device, struct CEC_Packet* packet); extern int CEC_TX_Ping(struct CEC_Device* device, uint8_t addr); +extern int CEC_TX_Feature_Abort(struct CEC_Device* device, uint8_t addr, enum CEC_Opcode opcode, enum CEC_Abort_Reason reason); +extern int CEC_TX_Version(struct CEC_Device* device, uint8_t addr, enum CEC_Version version); +extern int CEC_TX_Report_Power_Status(struct CEC_Device* device, uint8_t addr, enum CEC_Power_Status status); extern int CEC_TX_Standby(struct CEC_Device* device, uint8_t addr); extern int CEC_TX_Abort(struct CEC_Device* device, uint8_t addr); extern int CEC_TX_Give_Audio_Status(struct CEC_Device* device, uint8_t addr); @@ -562,8 +568,6 @@ extern int CEC_TX_Report_Physical_Address(struct CEC_Device* device, enum CEC_De extern int CEC_TX_Active_Source(struct CEC_Device* device); extern int CEC_TX_Set_System_Audio_Mode(struct CEC_Device* device, int mode); -extern int CEC_Alloc_Addr(struct CEC_Device* device, enum CEC_Device_Type device_type); - #pragma pack(pop) #endif diff --git a/lib/commands.c b/lib/commands.c index 4495045..c8426b1 100644 --- a/lib/commands.c +++ b/lib/commands.c @@ -25,6 +25,44 @@ int CEC_TX_Ping(struct CEC_Device* device, uint8_t addr) return CEC_Transmit(device, &packet); } +int CEC_TX_Feature_Abort(struct CEC_Device* device, uint8_t addr, enum CEC_Opcode opcode, enum CEC_Abort_Reason reason) +{ + struct CEC_Packet packet = { + .length = 4, + .src = device->logical_address, + .dst = addr, + .opcode = CEC_Feature_Abort, + }; + packet.feature_opcode = opcode; + packet.abort_reason = reason; + return CEC_Transmit(device, &packet); +} + +int CEC_TX_Version(struct CEC_Device* device, uint8_t addr, enum CEC_Version version) +{ + struct CEC_Packet packet = { + .length = 3, + .src = device->logical_address, + .dst = addr, + .opcode = CEC_Version, + }; + packet.version = version; + return CEC_Transmit(device, &packet); + +} + +int CEC_TX_Report_Power_Status(struct CEC_Device* device, uint8_t addr, enum CEC_Power_Status status) +{ + struct CEC_Packet packet = { + .length = 3, + .src = device->logical_address, + .dst = addr, + .opcode = CEC_Report_Power_Status, + }; + packet.power_status = status; + return CEC_Transmit(device, &packet); +} + int CEC_TX_Standby(struct CEC_Device* device, uint8_t addr) { struct CEC_Packet packet = { diff --git a/lib/device.c b/lib/device.c index 9202b4a..4805473 100644 --- a/lib/device.c +++ b/lib/device.c @@ -43,7 +43,7 @@ void CEC_Init_Device(struct CEC_Device* device) int i; for(i=0;i<0x100;i++) - device->func_handler[i] = NULL; + device->func_handler[i] = &CEC_Unrecognized_Opcode; } void CEC_Receive(struct CEC_Device* device) @@ -111,3 +111,9 @@ int CEC_Alloc_Addr(struct CEC_Device* device, enum CEC_Device_Type device_type) device->logical_address = addr; return CEC_TX_Report_Physical_Address(device, device_type); } + +void CEC_Unrecognized_Opcode(struct CEC_Device* device, struct CEC_Packet* packet) +{ + if(packet->src != 0xF && packet->dst != 0xF) + CEC_TX_Feature_Abort(device, packet->src, packet->opcode, CEC_Unrecognized_opcode); +} |