static void parse_tone_set(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur) { super_tone_tx_state_t tone; printf("Parsing tone set\n"); cur = cur->xmlChildrenNode; while (cur) { if (strcmp((char *) cur->name + strlen((char *) cur->name) - 5, "-tone") == 0) { printf("Hit %s\n", cur->name); tone_tree = NULL; parse_tone(&tone_tree, doc, ns, cur); super_tone_tx_init(&tone, tone_tree); //printf("Len %p %p %d %d\n", (void *) tone.levels[0], (void *) tone_tree, tone_tree->length, tone_tree->tone); play_tones(&tone, 99999999); super_tone_tx_free_tone(tone_tree); } /*endif*/ cur = cur->next; } /*endwhile*/ }
static int parse_tone(super_tone_tx_step_t **tree, xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur) { xmlChar *x; float f1; float f2; float f_tol; float l1; float l2; float length; float length_tol; int cycles; super_tone_tx_step_t *treep; cur = cur->xmlChildrenNode; while (cur) { if (xmlStrcmp(cur->name, (const xmlChar *) "step") == 0) { printf("Step - "); /* Set some defaults */ f1 = 0.0; f2 = 0.0; f_tol = 1.0; l1 = -11.0; l2 = -11.0; length = 0.0; length_tol = 10.0; cycles = 1; if ((x = xmlGetProp(cur, (const xmlChar *) "freq"))) { sscanf((char *) x, "%f [%f%%]", &f1, &f_tol); sscanf((char *) x, "%f+%f [%f%%]", &f1, &f2, &f_tol); printf("Frequency=%.2f+%.2f [%.2f%%]", f1, f2, f_tol); xmlFree(x); } if ((x = xmlGetProp(cur, (const xmlChar *) "level"))) { if (sscanf((char *) x, "%f+%f", &l1, &l2) < 2) l2 = l1; printf("Level=%.2f+%.2f", l1, l2); xmlFree(x); } if ((x = xmlGetProp(cur, (const xmlChar *) "length"))) { sscanf((char *) x, "%f [%f%%]", &length, &length_tol); printf("Length=%.2f [%.2f%%]", length, length_tol); xmlFree(x); } if ((x = xmlGetProp(cur, (const xmlChar *) "recognition-length"))) { printf("Recognition length='%s'", x); xmlFree(x); } if ((x = xmlGetProp(cur, (const xmlChar *) "cycles"))) { if (strcasecmp((char *) x, "endless") == 0) cycles = 0; else cycles = atoi((char *) x); printf("Cycles=%d ", cycles); xmlFree(x); } if ((x = xmlGetProp(cur, (const xmlChar *) "recorded-announcement"))) { printf("Recorded announcement='%s'", x); xmlFree(x); } printf("\n"); treep = super_tone_tx_make_step(NULL, f1, l1, f2, l2, length*1000.0 + 0.5, cycles); *tree = treep; tree = &(treep->next); parse_tone(&(treep->nest), doc, ns, cur); } /*endif*/ cur = cur->next; } /*endwhile*/ return 0; }
static int parse_tone(super_tone_rx_descriptor_t *desc, int tone_id, super_tone_tx_step_t **tree, xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur) { xmlChar *x; float f1; float f2; float f_tol; float l1; float l2; float length; float length_tol; float recognition_length; float recognition_length_tol; int cycles; super_tone_tx_step_t *treep; int min_duration; int max_duration; cur = cur->xmlChildrenNode; while (cur) { if (xmlStrcmp(cur->name, (const xmlChar *) "step") == 0) { printf("Step - "); /* Set some defaults */ f1 = 0.0; f2 = 0.0; f_tol = 1.0; l1 = -11.0; l2 = -11.0; length = 0.0; length_tol = 10.0; recognition_length = 0.0; recognition_length_tol = 10.0; cycles = 1; if ((x = xmlGetProp(cur, (const xmlChar *) "freq"))) { sscanf((char *) x, "%f [%f%%]", &f1, &f_tol); sscanf((char *) x, "%f+%f [%f%%]", &f1, &f2, &f_tol); printf(" Frequency=%.2f+%.2f [%.2f%%]", f1, f2, f_tol); } if ((x = xmlGetProp(cur, (const xmlChar *) "level"))) { if (sscanf((char *) x, "%f+%f", &l1, &l2) < 2) l2 = l1; printf(" Level=%.2f+%.2f", l1, l2); } if ((x = xmlGetProp(cur, (const xmlChar *) "length"))) { sscanf((char *) x, "%f [%f%%]", &length, &length_tol); printf(" Length=%.2f [%.2f%%]", length, length_tol); } if ((x = xmlGetProp(cur, (const xmlChar *) "recognition-length"))) { sscanf((char *) x, "%f [%f%%]", &recognition_length, &recognition_length_tol); printf(" Recognition length=%.2f [%.2f%%]", recognition_length, recognition_length_tol); } if ((x = xmlGetProp(cur, (const xmlChar *) "cycles"))) { if (strcasecmp((char *) x, "endless") == 0) cycles = 0; else cycles = atoi((char *) x); printf(" Cycles='%d' ", cycles); } if ((x = xmlGetProp(cur, (const xmlChar *) "recorded-announcement"))) printf(" Recorded announcement='%s'", x); printf("\n"); if (f1 || f2 || length) { /* TODO: This cannot handle cycling patterns */ if (length == 0.0) { if (recognition_length) min_duration = recognition_length*1000.0 + 0.5; else min_duration = 700; max_duration = 0; } else { if (recognition_length) min_duration = recognition_length*1000.0 + 0.5; else min_duration = (length*1000.0 + 0.5)*(1.0 - length_tol/100.0) - 30; max_duration = (length*1000.0 + 0.5)*(1.0 + length_tol/100.0) + 30; } printf(">>>Detector element %10d %10d %10d %10d\n", (int) (f1 + 0.5), (int) (f2 + 0.5), min_duration, max_duration); super_tone_rx_add_element(desc, tone_id, f1 + 0.5, f2 + 0.5, min_duration, max_duration); } treep = super_tone_tx_make_step(NULL, f1, l1, f2, l2, length*1000.0 + 0.5, cycles); *tree = treep; tree = &(treep->next); parse_tone(desc, tone_id, &(treep->nest), doc, ns, cur); } /*endif*/ cur = cur->next; } /*endwhile*/ return 0; }
static void parse_tone_set(super_tone_rx_descriptor_t *desc, xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur) { int tone_id; printf("Parsing tone set\n"); cur = cur->xmlChildrenNode; while (cur) { if (strcmp((char *) cur->name, "dial-tone") == 0) { printf("Hit %s\n", cur->name); tone_id = super_tone_rx_add_tone(desc); dialtone_tree = NULL; parse_tone(desc, tone_id, &dialtone_tree, doc, ns, cur); tone_names[tone_id] = "Dial tone"; } else if (strcmp((char *) cur->name, "ringback-tone") == 0) { printf("Hit %s\n", cur->name); tone_id = super_tone_rx_add_tone(desc); ringback_tree = NULL; parse_tone(desc, tone_id, &ringback_tree, doc, ns, cur); tone_names[tone_id] = "Ringback tone"; } else if (strcmp((char *) cur->name, "busy-tone") == 0) { printf("Hit %s\n", cur->name); tone_id = super_tone_rx_add_tone(desc); busytone_tree = NULL; parse_tone(desc, tone_id, &busytone_tree, doc, ns, cur); tone_names[tone_id] = "Busy tone"; } else if (strcmp((char *) cur->name, "number-unobtainable-tone") == 0) { printf("Hit %s\n", cur->name); tone_id = super_tone_rx_add_tone(desc); nutone_tree = NULL; parse_tone(desc, tone_id, &nutone_tree, doc, ns, cur); tone_names[tone_id] = "NU tone"; } else if (strcmp((char *) cur->name, "congestion-tone") == 0) { printf("Hit %s\n", cur->name); tone_id = super_tone_rx_add_tone(desc); congestiontone_tree = NULL; parse_tone(desc, tone_id, &congestiontone_tree, doc, ns, cur); tone_names[tone_id] = "Congestion tone"; } else if (strcmp((char *) cur->name, "waiting-tone") == 0) { printf("Hit %s\n", cur->name); tone_id = super_tone_rx_add_tone(desc); waitingtone_tree = NULL; parse_tone(desc, tone_id, &waitingtone_tree, doc, ns, cur); tone_names[tone_id] = "Waiting tone"; } /*endif*/ cur = cur->next; } /*endwhile*/ }