summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/cec.c49
1 files changed, 41 insertions, 8 deletions
diff --git a/cmd/cec.c b/cmd/cec.c
index 4ad8b1b..a733e28 100644
--- a/cmd/cec.c
+++ b/cmd/cec.c
@@ -37,6 +37,7 @@ const char* usage =
" -active : send Active Source packet\n"
" -decode <byte1> ... : decode cec packet\n"
" -button <addr> <command> <duration> : simulate a button press\n"
+" -test <device2> <addr2> : use a second device and adress to run a loopback test\n"
"\n\n";
void debug(enum CEC_Debug reason, struct CEC_Device* device, struct CEC_Packet* packet)
@@ -85,14 +86,14 @@ 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)
+void init_device(struct CEC_Device* 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;
+ 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)
@@ -193,6 +194,34 @@ void dump()
}
}
+void test(const char* hardware, uint8_t addr)
+{
+ struct CEC_Device dst;
+
+ init_device(&dst, hardware);
+ dst.logical_address = addr;
+ CEC_TX_Ping(&dst, dst.logical_address);
+
+ while(1) {
+ CEC_Receive(&device);
+ CEC_Receive(&dst);
+ //usleep(10000);
+
+ struct CEC_Packet p;
+ uint8_t* byte = ((uint8_t*)&p)+3;
+
+ int count = random() % 16;
+ for(p.length = 1; p.length<count; p.length++) {
+ *byte++ = random();
+ }
+
+ p.dst = addr;
+ p.src = device.logical_address;
+ p.opcode = CEC_Abort;
+ CEC_Transmit(&device, &p);
+ }
+}
+
int main(int argc, const char* argv[])
{
int i;
@@ -206,7 +235,7 @@ int main(int argc, const char* argv[])
for(i=1; i<argc; i++) {
if (!strncmp("-msp430", argv[i], 8)) {
- init_device(argv[++i]);
+ init_device(&device, argv[++i]);
} else if (!strncmp("-phys", argv[i], 6)) {
device.physical_address = parse_physical(&i, argc, argv);
@@ -272,6 +301,10 @@ int main(int argc, const char* argv[])
device_type = parse_device_type(&i, argc, argv);
CEC_Alloc_Addr(&device, device_type);
+ } else if (!strncmp("-test", argv[i], 6)) {
+ const char* hw = argv[++i];
+ test(hw, parse_addr(&i, argc, argv));
+
} else {
print_help(argv[0], "Unknown command");
}