X-Git-Url: http://cloudbase.mooo.com/gitweb/irmp.git/blobdiff_plain/95eab03cca00d71c839a8f265ca0d9fbf3b41c44..fe4e457a53eb42c0ca3f910a47350ac0b9411155:/irmp.c diff --git a/irmp.c b/irmp.c index ab3d59f..04f8eae 100644 --- a/irmp.c +++ b/irmp.c @@ -1,9 +1,9 @@ /*--------------------------------------------------------------------------------------------------------------------------------------------------- * irmp.c - infrared multi-protocol decoder, supports several remote control protocols * - * Copyright (c) 2009-2012 Frank Meyer - frank(at)fli4l.de + * Copyright (c) 2009-2013 Frank Meyer - frank(at)fli4l.de * - * $Id: irmp.c,v 1.130 2012/11/06 10:19:41 fm Exp $ + * $Id: irmp.c,v 1.137 2013/01/17 07:33:13 fm Exp $ * * ATMEGA88 @ 8 MHz * @@ -11,7 +11,7 @@ * * ATtiny87, ATtiny167 * ATtiny45, ATtiny85 - * ATtiny84 + * ATtiny44, ATtiny84 * ATmega8, ATmega16, ATmega32 * ATmega162 * ATmega164, ATmega324, ATmega644, ATmega644P, ATmega1284 @@ -42,7 +42,8 @@ IRMP_SUPPORT_RC6_PROTOCOL == 1 || \ IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 || \ IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 || \ - IRMP_SUPPORT_IR60_PROTOCOL + IRMP_SUPPORT_IR60_PROTOCOL == 1 || \ + IRMP_SUPPORT_A1TVBOX_PROTOCOL == 1 # define IRMP_SUPPORT_MANCHESTER 1 #else # define IRMP_SUPPORT_MANCHESTER 0 @@ -372,12 +373,22 @@ #define BOSE_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BOSE_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) #define BOSE_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * 100.0e-3 * MAX_TOLERANCE_20 + 0.5) +#define A1TVBOX_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * A1TVBOX_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define A1TVBOX_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * A1TVBOX_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define A1TVBOX_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * A1TVBOX_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define A1TVBOX_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * A1TVBOX_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define A1TVBOX_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * A1TVBOX_BIT_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) +#define A1TVBOX_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * A1TVBOX_BIT_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) +#define A1TVBOX_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * A1TVBOX_BIT_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) +#define A1TVBOX_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * A1TVBOX_BIT_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) + #define AUTO_FRAME_REPETITION_LEN (uint16_t)(F_INTERRUPTS * AUTO_FRAME_REPETITION_TIME + 0.5) // use uint16_t! #ifdef ANALYZE # define ANALYZE_PUTCHAR(a) { if (! silent) { putchar (a); } } # define ANALYZE_ONLY_NORMAL_PUTCHAR(a) { if (! silent && !verbose) { putchar (a); } } # define ANALYZE_PRINTF(...) { if (verbose) { printf (__VA_ARGS__); } } +# define ANALYZE_ONLY_NORMAL_PRINTF(...) { if (! silent && !verbose) { printf (__VA_ARGS__); } } # define ANALYZE_NEWLINE() { if (verbose) { putchar ('\n'); } } static int silent; static int time_counter; @@ -386,6 +397,7 @@ static int verbose; # define ANALYZE_PUTCHAR(a) # define ANALYZE_ONLY_NORMAL_PUTCHAR(a) # define ANALYZE_PRINTF(...) +# define ANALYZE_ONLY_NORMAL_PRINTF(...) # define ANALYZE_NEWLINE() #endif @@ -397,7 +409,7 @@ static void (*irmp_callback_ptr) (uint8_t); * Protocol names *--------------------------------------------------------------------------------------------------------------------------------------------------- */ -#if IRMP_PROTOCOL_NAMES == 1 +#if defined(UNIX_OR_WINDOWS) || IRMP_PROTOCOL_NAMES == 1 char * irmp_protocol_names[IRMP_N_PROTOCOLS + 1] = { @@ -432,7 +444,8 @@ irmp_protocol_names[IRMP_N_PROTOCOLS + 1] = "NEC42", "LEGO", "THOMSON", - "BOSE" + "BOSE", + "A1TVBOX", }; #endif @@ -446,7 +459,9 @@ irmp_protocol_names[IRMP_N_PROTOCOLS + 1] = #include "irmpextlog.h" #else // normal UART log (IRMP_EXT_LOGGING == 0) #define BAUD 9600L +#ifndef UNIX_OR_WINDOWS #include +#endif #ifdef UBRR0H @@ -497,6 +512,7 @@ irmp_protocol_names[IRMP_N_PROTOCOLS + 1] = void irmp_uart_init (void) { +#ifndef UNIX_OR_WINDOWS #if (IRMP_EXT_LOGGING == 0) // use UART UART0_UBRRH = UBRRH_VALUE; // set baud rate UART0_UBRRL = UBRRL_VALUE; @@ -512,6 +528,7 @@ irmp_uart_init (void) #else // other log method initextlog(); #endif //IRMP_EXT_LOGGING +#endif // UNIX_OR_WINDOWS } /*--------------------------------------------------------------------------------------------------------------------------------------------------- @@ -523,6 +540,7 @@ irmp_uart_init (void) void irmp_uart_putc (unsigned char ch) { +#ifndef UNIX_OR_WINDOWS #if (IRMP_EXT_LOGGING == 0) while (!(UART0_UCSRA & UART0_UDRE_BIT_VALUE)) { @@ -533,6 +551,9 @@ irmp_uart_putc (unsigned char ch) #else sendextlog(ch); //Use external log #endif +#else + fputc (ch, stderr); +#endif // UNIX_OR_WINDOWS } /*--------------------------------------------------------------------------------------------------------------------------------------------------- @@ -544,6 +565,8 @@ irmp_uart_putc (unsigned char ch) #define ENDBITS 1000 // number of sequenced highbits to detect end #define DATALEN 700 // log buffer size +#if 0 // old log routine + static void irmp_log (uint8_t val) { @@ -613,6 +636,98 @@ irmp_log (uint8_t val) } } +#else // new log routine + +static void +irmp_log (uint8_t val) +{ + static uint8_t buf[DATALEN]; // logging buffer + static uint16_t buf_idx; // index + static uint8_t startcycles; // current number of start-zeros + static uint16_t cnt; // counts sequenced highbits - to detect end + static uint8_t last_val = 1; + + if (! val && (startcycles < STARTCYCLES) && !buf_idx) // prevent that single random zeros init logging + { + startcycles++; + } + else + { + startcycles = 0; + + if (! val || buf_idx != 0) // start or continue logging on "0", "1" cannot init logging + { + if (last_val == val) + { + cnt++; + + if (val && cnt > ENDBITS) // if high received then look at log-stop condition + { // if stop condition is true, output on uart + uint8_t i8; + uint16_t i; + uint16_t j; + uint8_t v = '1'; + uint16_t d; + + for (i8 = 0; i8 < STARTCYCLES; i8++) + { + irmp_uart_putc ('0'); // the ignored starting zeros + } + + for (i = 0; i < buf_idx; i++) + { + d = buf[i]; + + if (d == 0xff) + { + i++; + d = buf[i]; + i++; + d |= ((uint16_t) buf[i] << 8); + } + + for (j = 0; j < d; j++) + { + irmp_uart_putc (v); + } + + v = (v == '1') ? '0' : '1'; + } + + for (i8 = 0; i8 < 20; i8++) + { + irmp_uart_putc ('1'); + } + + irmp_uart_putc ('\n'); + buf_idx = 0; + last_val = 1; + cnt = 0; + } + } + else if (buf_idx < DATALEN - 3) + { + if (cnt >= 0xff) + { + buf[buf_idx++] = 0xff; + buf[buf_idx++] = (cnt & 0xff); + buf[buf_idx] = (cnt >> 8); + } + else + { + buf[buf_idx] = cnt; + } + + buf_idx++; + cnt = 1; + last_val = val; + } + } + } +} + +#endif + #else #define irmp_log(val) #endif //IRMP_LOGGING @@ -1238,6 +1353,32 @@ static const PROGMEM IRMP_PARAMETER bose_param = #endif +#if IRMP_SUPPORT_A1TVBOX_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER a1tvbox_param = +{ + IRMP_A1TVBOX_PROTOCOL, // protocol: ir protocol + + A1TVBOX_BIT_PULSE_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse + A1TVBOX_BIT_PULSE_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse + A1TVBOX_BIT_PAUSE_LEN_MIN, // pause_1_len_min: here: minimum length of short pause + A1TVBOX_BIT_PAUSE_LEN_MAX, // pause_1_len_max: here: maximum length of short pause + 0, // pulse_0_len_min: here: not used + 0, // pulse_0_len_max: here: not used + 0, // pause_0_len_min: here: not used + 0, // pause_0_len_max: here: not used + A1TVBOX_ADDRESS_OFFSET, // address_offset: address offset + A1TVBOX_ADDRESS_OFFSET + A1TVBOX_ADDRESS_LEN, // address_end: end of address + A1TVBOX_COMMAND_OFFSET, // command_offset: command offset + A1TVBOX_COMMAND_OFFSET + A1TVBOX_COMMAND_LEN, // command_end: end of command + A1TVBOX_COMPLETE_DATA_LEN, // complete_len: complete length of frame + A1TVBOX_STOP_BIT, // stop_bit: flag: frame has stop bit + A1TVBOX_LSB, // lsb_first: flag: LSB first + A1TVBOX_FLAGS // flags: some flags +}; + +#endif + static uint8_t irmp_bit; // current bit position static IRMP_PARAMETER irmp_param; @@ -1292,6 +1433,15 @@ irmp_init (void) GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; #endif GPIO_Init(IRMP_PORT, &GPIO_InitStructure); +#elif defined(STELLARIS_ARM_CORTEX_M4) + // Enable the GPIO port + ROM_SysCtlPeripheralEnable(IRMP_PORT_PERIPH); + + // Set as an input + ROM_GPIODirModeSet(IRMP_PORT_BASE, IRMP_PORT_PIN, GPIO_DIR_MODE_IN); + ROM_GPIOPadConfigSet(IRMP_PORT_BASE, IRMP_PORT_PIN, + GPIO_STRENGTH_2MA, + GPIO_PIN_TYPE_STD_WPU); #else // AVR IRMP_PORT &= ~(1<= DENON_AUTO_REPETITION_PAUSE_LEN && last_irmp_denon_command != 0) + if (denon_repetition_len < 0xFFFF) // avoid overflow of counter { - ANALYZE_PRINTF ("%8.3fms error 6: did not receive inverted command repetition\n", - (double) (time_counter * 1000) / F_INTERRUPTS); - last_irmp_denon_command = 0; + denon_repetition_len++; + + if (denon_repetition_len >= DENON_AUTO_REPETITION_PAUSE_LEN && last_irmp_denon_command != 0) + { + ANALYZE_PRINTF ("%8.3fms error 6: did not receive inverted command repetition\n", + (double) (time_counter * 1000) / F_INTERRUPTS); + last_irmp_denon_command = 0; + denon_repetition_len = 0xFFFF; + } } #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1 } @@ -2175,6 +2332,20 @@ irmp_ISR (void) else #endif // IRMP_SUPPORT_LEGO_PROTOCOL == 1 +#if IRMP_SUPPORT_A1TVBOX_PROTOCOL == 1 + if (irmp_pulse_time >= A1TVBOX_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= A1TVBOX_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= A1TVBOX_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= A1TVBOX_START_BIT_PAUSE_LEN_MAX) + { // it's A1TVBOX + ANALYZE_PRINTF ("protocol = A1TVBOX, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + A1TVBOX_START_BIT_PULSE_LEN_MIN, A1TVBOX_START_BIT_PULSE_LEN_MAX, + A1TVBOX_START_BIT_PAUSE_LEN_MIN, A1TVBOX_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &a1tvbox_param; + last_pause = 0; + last_value = 1; + } + else +#endif // IRMP_SUPPORT_RC6_PROTOCOL == 1 + { ANALYZE_PRINTF ("protocol = UNKNOWN\n"); // irmp_busy_flag = FALSE; @@ -2999,7 +3170,7 @@ irmp_ISR (void) if (irmp_start_bit_detected && irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 0) // enough bits received? { - if (last_irmp_command == irmp_tmp_command && repetition_len < AUTO_FRAME_REPETITION_LEN) + if (last_irmp_command == irmp_tmp_command && key_repetition_len < AUTO_FRAME_REPETITION_LEN) { repetition_frame_number++; } @@ -3013,8 +3184,8 @@ irmp_ISR (void) if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && (repetition_frame_number == 1 || repetition_frame_number == 2)) { ANALYZE_PRINTF ("code skipped: SIRCS auto repetition frame #%d, counter = %d, auto repetition len = %d\n", - repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN); - repetition_len = 0; + repetition_frame_number + 1, key_repetition_len, AUTO_FRAME_REPETITION_LEN); + key_repetition_len = 0; } else #endif @@ -3024,8 +3195,8 @@ irmp_ISR (void) if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL && repetition_frame_number == 1) { ANALYZE_PRINTF ("code skipped: KASEIKYO auto repetition frame #%d, counter = %d, auto repetition len = %d\n", - repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN); - repetition_len = 0; + repetition_frame_number + 1, key_repetition_len, AUTO_FRAME_REPETITION_LEN); + key_repetition_len = 0; } else #endif @@ -3035,8 +3206,8 @@ irmp_ISR (void) if (irmp_param.protocol == IRMP_SAMSUNG32_PROTOCOL && (repetition_frame_number & 0x01)) { ANALYZE_PRINTF ("code skipped: SAMSUNG32 auto repetition frame #%d, counter = %d, auto repetition len = %d\n", - repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN); - repetition_len = 0; + repetition_frame_number + 1, key_repetition_len, AUTO_FRAME_REPETITION_LEN); + key_repetition_len = 0; } else #endif @@ -3046,8 +3217,8 @@ irmp_ISR (void) if (irmp_param.protocol == IRMP_NUBERT_PROTOCOL && (repetition_frame_number & 0x01)) { ANALYZE_PRINTF ("code skipped: NUBERT auto repetition frame #%d, counter = %d, auto repetition len = %d\n", - repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN); - repetition_len = 0; + repetition_frame_number + 1, key_repetition_len, AUTO_FRAME_REPETITION_LEN); + key_repetition_len = 0; } else #endif @@ -3066,22 +3237,29 @@ irmp_ISR (void) irmp_protocol = irmp_param.protocol; // store protocol irmp_address = irmp_tmp_address; // store address - irmp_command = irmp_tmp_command ; // store command + irmp_command = irmp_tmp_command; // store command } else { - if ((irmp_tmp_command & 0x03) == 0) + if ((irmp_tmp_command & 0x03) == 0x00) { - ANALYZE_PRINTF ("%8.3fms waiting for inverted command repetition\n", (double) (time_counter * 1000) / F_INTERRUPTS); + ANALYZE_PRINTF ("%8.3fms info Denon: waiting for inverted command repetition\n", (double) (time_counter * 1000) / F_INTERRUPTS); last_irmp_denon_command = irmp_tmp_command; + denon_repetition_len = 0; + irmp_ir_detected = FALSE; } - else + else if ((irmp_tmp_command & 0x03) == 0x03) { - ANALYZE_PRINTF ("%8.3fms got unexpected inverted command, ignoring it\n", (double) (time_counter * 1000) / F_INTERRUPTS); + ANALYZE_PRINTF ("%8.3fms error Denon: got unexpected inverted command, ignoring it\n", (double) (time_counter * 1000) / F_INTERRUPTS); last_irmp_denon_command = 0; + irmp_ir_detected = FALSE; + } + else // fm 2013-01-17: 0x01 or 0x10: there is no inverted command + { + irmp_protocol = irmp_param.protocol; // store protocol + irmp_address = irmp_tmp_address; // store address + irmp_command = irmp_tmp_command; // store command } - irmp_ir_detected = FALSE; - repetition_len = 0; } } else @@ -3108,18 +3286,19 @@ irmp_ISR (void) #if IRMP_SUPPORT_NEC_PROTOCOL == 1 if (irmp_param.protocol == IRMP_NEC_PROTOCOL && irmp_bit == 0) // repetition frame { - if (repetition_len < NEC_FRAME_REPEAT_PAUSE_LEN_MAX) + if (key_repetition_len < NEC_FRAME_REPEAT_PAUSE_LEN_MAX) { - ANALYZE_PRINTF ("Detected NEC repetition frame, repetition_len = %d\n", repetition_len); + ANALYZE_PRINTF ("Detected NEC repetition frame, key_repetition_len = %d\n", key_repetition_len); + ANALYZE_ONLY_NORMAL_PRINTF("REPETETION FRAME "); irmp_tmp_address = last_irmp_address; // address is last address irmp_tmp_command = last_irmp_command; // command is last command irmp_flags |= IRMP_FLAG_REPETITION; - repetition_len = 0; + key_repetition_len = 0; } else { - ANALYZE_PRINTF ("Detected NEC repetition frame, ignoring it: timeout occured, repetition_len = %d > %d\n", - repetition_len, NEC_FRAME_REPEAT_PAUSE_LEN_MAX); + ANALYZE_PRINTF ("Detected NEC repetition frame, ignoring it: timeout occured, key_repetition_len = %d > %d\n", + key_repetition_len, NEC_FRAME_REPEAT_PAUSE_LEN_MAX); irmp_ir_detected = FALSE; } } @@ -3205,7 +3384,7 @@ irmp_ISR (void) { if (last_irmp_command == irmp_tmp_command && last_irmp_address == irmp_tmp_address && - repetition_len < IRMP_KEY_REPETITION_LEN) + key_repetition_len < IRMP_KEY_REPETITION_LEN) { irmp_flags |= IRMP_FLAG_REPETITION; } @@ -3213,7 +3392,7 @@ irmp_ISR (void) last_irmp_address = irmp_tmp_address; // store as last address, too last_irmp_command = irmp_tmp_command; // store as last command, too - repetition_len = 0; + key_repetition_len = 0; } else { @@ -3235,6 +3414,12 @@ irmp_ISR (void) } } } + +#if defined(STELLARIS_ARM_CORTEX_M4) + // Clear the timer interrupt + TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); +#endif + return (irmp_ir_detected); } @@ -3604,6 +3789,10 @@ get_fdc_key (uint16_t cmd) static int analyze = FALSE; static int list = FALSE; static IRMP_DATA irmp_data; +static int expected_protocol; +static int expected_address; +static int expected_command; +static int do_check_expected_values; static void next_tick (void) @@ -3627,8 +3816,8 @@ next_tick (void) { if ((key >= 0x20 && key < 0x7F) || key >= 0xA0) { - printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x, key = '%c'\n", - irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key, key); + printf ("p=%2d (%s), a=0x%04x, c=0x%04x, f=0x%02x, asc=0x%02x, key='%c'", + irmp_data.protocol, irmp_protocol_names[irmp_data.protocol], irmp_data.address, irmp_data.command, irmp_data.flags, key, key); } else if (key == '\r' || key == '\t' || key == KEY_ESCAPE || (key >= 0x80 && key <= 0x9F)) // function keys { @@ -3669,19 +3858,39 @@ next_tick (void) default : p = ""; break; } - printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x, key = %s\n", - irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key, p); + printf ("p=%2d (%s), a=0x%04x, c=0x%04x, f=0x%02x, asc=0x%02x, key=%s", + irmp_data.protocol, irmp_protocol_names[irmp_data.protocol], irmp_data.address, irmp_data.command, irmp_data.flags, key, p); } else { - printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x\n", - irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key); + printf ("p=%2d (%s), a=0x%04x, c=0x%04x, f=0x%02x, asc=0x%02x", + irmp_data.protocol, irmp_protocol_names[irmp_data.protocol], irmp_data.address, irmp_data.command, irmp_data.flags, key); } } else { - printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x\n", - irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags); + printf ("p=%2d (%s), a=0x%04x, c=0x%04x, f=0x%02x", + irmp_data.protocol, irmp_protocol_names[irmp_data.protocol], irmp_data.address, irmp_data.command, irmp_data.flags); + } + + if (do_check_expected_values) + { + if (irmp_data.protocol != expected_protocol || + irmp_data.address != expected_address || + irmp_data.command != expected_command) + { + printf ("\nerror 7: expected values differ: p=%2d (%s), a=0x%04x, c=0x%04x\n", + expected_protocol, irmp_protocol_names[expected_protocol], expected_address, expected_command); + } + else + { + printf (" checked!\n"); + } + do_check_expected_values = FALSE; // only check 1st frame in a line! + } + else + { + putchar ('\n'); } } } @@ -3843,13 +4052,81 @@ main (int argc, char ** argv) } else { + char buf[1024]; + char * p; + int idx = -1; + puts ("-------------------------------------------------------------------"); putchar (ch); + while ((ch = getchar()) != '\n' && ch != EOF) { if (ch != '\r') // ignore CR in DOS/Windows files { + if (ch == '[' && idx == -1) + { + idx = 0; + } + else if (idx >= 0) + { + if (ch == ']') + { + do_check_expected_values = FALSE; + buf[idx] = '\0'; + idx = -1; + + expected_protocol = atoi (buf); + + if (expected_protocol > 0) + { + p = buf; + while (*p) + { + if (*p == 'x') + { + p++; + + if (sscanf (p, "%x", &expected_address) == 1) + { + do_check_expected_values = TRUE; + } + break; + } + p++; + } + + if (do_check_expected_values) + { + do_check_expected_values = FALSE; + + while (*p) + { + if (*p == 'x') + { + p++; + + if (sscanf (p, "%x", &expected_command) == 1) + { + do_check_expected_values = TRUE; + } + break; + } + p++; + } + + if (do_check_expected_values) + { + // printf ("!%2d %04x %04x!\n", expected_protocol, expected_address, expected_command); + } + } + } + } + else if (idx < 1024 - 2) + { + buf[idx++] = ch; + } + } putchar (ch); } }