static int encode_decode_tests(void)
{
    char buf[100];
    ademco_contactid_receiver_state_t *receiver;
    ademco_contactid_sender_state_t *sender;
    logging_state_t *logging;
    ademco_contactid_report_t result;
    int i;

    printf("Encode and decode tests\n");

    if ((receiver = ademco_contactid_receiver_init(NULL, NULL, NULL)) == NULL)
        return 2;
    logging = ademco_contactid_receiver_get_logging_state(receiver);
    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
    span_log_set_tag(logging, "Ademco-rx");

    if ((sender = ademco_contactid_sender_init(NULL, NULL, NULL)) == NULL)
        return 2;
    logging = ademco_contactid_sender_get_logging_state(sender);
    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
    span_log_set_tag(logging, "Ademco-tx");

    for (i = 0;  i < 5;  i++)
    {
        if (encode_msg(buf, &reports[i]) < 0)
        {
            printf("Bad encode message\n");
            return -1;
        }
        printf("'%s'\n", buf);
        if (decode_msg(&result, buf))
        {
            printf("Bad decode message\n");
            return -1;
        }
        ademco_contactid_receiver_log_msg(receiver, &result);
        printf("\n");
        if (memcmp(&reports[i], &result, sizeof(result)))
        {
            printf("Received message does not match the one sent\n");
            return -1;
        }
    }

    if (encode_msg(buf, &reports[5]) >= 0)
    {
        printf("Incorrectly good message\n");
        return -1;
    }
    printf("'%s'\n", buf);
    printf("\n");
    printf("    Passed\n");
    return 0;
}
Пример #2
0
static void dtmf_digit_delivery(void *user_data, const char *digits, int len)
{
    ademco_contactid_receiver_state_t *s;
    ademco_contactid_report_t report;

    s = (ademco_contactid_receiver_state_t *) user_data;
    memcpy(&s->rx_digits[s->rx_digits_len], digits, len);
    s->rx_digits_len += len;
    if (s->rx_digits_len == 16)
    {
        s->rx_digits[16] = '\0';
        if (decode_msg(&report, s->rx_digits) == 0)
        {
            ademco_contactid_receiver_log_msg(s, &report);
            if (s->callback)
                s->callback(s->callback_user_data, &report);
            s->step++;
        }
        s->rx_digits_len = 0;
    }
}