summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian König <chrissi@zweiundvierzig.(none)>2010-05-27 22:26:19 +0200
committerChristian König <chrissi@zweiundvierzig.(none)>2010-05-27 22:26:19 +0200
commit0208bfa252046a44dbb2d25a40f8d5e01057253b (patch)
treea0e5cf5380857bdf55ea5c41d43f7674bee3253d
parent104643686853c5d21aa7e742877559519c77078b (diff)
Implement some handlers in cec.c
-rw-r--r--cmd/cec.c38
-rw-r--r--lib/cec.h8
-rw-r--r--lib/commands.c38
-rw-r--r--lib/device.c8
4 files changed, 80 insertions, 12 deletions
diff --git a/cmd/cec.c b/cmd/cec.c
index 2736b2c..215a53a 100644
--- a/cmd/cec.c
+++ b/cmd/cec.c
@@ -19,6 +19,7 @@
#include <cec.h>
struct CEC_Device device;
+enum CEC_Device_Type device_type = CEC_Playback_Device;
const char* usage =
"Usage: %s [commands]\n"
@@ -38,7 +39,7 @@ const char* usage =
" -button <addr> <command> <duration> : simulate a button press\n"
"\n\n";
-static void debug(enum CEC_Debug reason, struct CEC_Device* device, struct CEC_Packet* packet)
+void debug(enum CEC_Debug reason, struct CEC_Device* device, struct CEC_Packet* packet)
{
switch(reason) {
case CEC_RX_Packet:
@@ -57,6 +58,31 @@ static void debug(enum CEC_Debug reason, struct CEC_Device* device, struct CEC_P
fprintf(stderr, "\n");
}
+void handle_address(struct CEC_Device* device, struct CEC_Packet* packet)
+{
+ CEC_TX_Report_Physical_Address(device, device_type);
+}
+
+void handle_version(struct CEC_Device* device, struct CEC_Packet* packet)
+{
+ CEC_TX_Version(device, packet->src, CEC_Version_1_3a);
+}
+
+void handle_power_status(struct CEC_Device* device, struct CEC_Packet* packet)
+{
+ CEC_TX_Report_Power_Status(device, packet->src, CEC_Power_Status_On);
+}
+
+void init_device(const char* hardware)
+{
+ CEC_Init_Device(&device);
+ device.hardware = MSP430_Open_Hardware(hardware);
+ device.func_debug = debug;
+ device.func_handler[CEC_Give_Physical_Address] = handle_address;
+ device.func_handler[CEC_Get_Version] = handle_version;
+ device.func_handler[CEC_Give_Device_Power_Status] = handle_power_status;
+}
+
void print_help(const char* progname, const char* message)
{
if (message != NULL) fprintf(stderr, "%s\n", message);
@@ -155,13 +181,6 @@ void dump()
}
}
-void init_device(const char* hardware)
-{
- CEC_Init_Device(&device);
- device.hardware = MSP430_Open_Hardware(hardware);
- device.func_debug = debug;
-}
-
int main(int argc, const char* argv[])
{
int i;
@@ -238,7 +257,8 @@ int main(int argc, const char* argv[])
} else if (!strncmp("-addr", argv[i], 6)) {
- CEC_Alloc_Addr(&device, parse_device_type(&i, argc, argv));
+ device_type = parse_device_type(&i, argc, argv);
+ CEC_Alloc_Addr(&device, device_type);
} else {
print_help(argv[0], "Unknown command");
diff --git a/lib/cec.h b/lib/cec.h
index 2b156b0..a7cae44 100644
--- a/lib/cec.h
+++ b/lib/cec.h
@@ -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);
+}