FreeCalypso > hg > freecalypso-tools
view rvinterf/etmsync/tmsaur.c @ 931:bb7a03cc1e43
rvtdump, tfc139: restore old 'TM:' output format
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 23 May 2023 06:04:29 +0000 |
parents | 9da5fb3f42dd |
children |
line wrap: on
line source
/* * This fc-tmsync module implements aur commands and operations. */ #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include "etm.h" #include "audio.h" #include "limits.h" #include "localtypes.h" #include "exitcodes.h" extern u_char rvi_msg[]; extern int rvi_msg_len; do_aur(param, data, size) u_char *data; { u_char cmdpkt[5]; cmdpkt[1] = ETM_AUDIO; cmdpkt[2] = 'R'; cmdpkt[3] = param; etm_pkt_exch(cmdpkt, 3); if (rvi_msg[3]) { fprintf(stderr, "target error %u in response to aur\n", rvi_msg[3]); return(ERROR_TARGET); } if (rvi_msg_len < size + 7) { fprintf(stderr, "target error: aur response too short\n"); return(ERROR_TARGET); } if (rvi_msg[4] != 'R') { fprintf(stderr, "target error: aur response wrong type\n"); return(ERROR_TARGET); } if (rvi_msg[5] != param) { fprintf(stderr, "target error: aur response wrong index\n"); return(ERROR_TARGET); } bcopy(rvi_msg + 6, data, size); return(0); } static int convert_signed_byte(b) { if (b >= 128) b -= 256; return(b); } cmd_aur(argc, argv) char **argv; { unsigned param, word; u_char data[62]; int size, rc, i; param = strtoul(argv[1], 0, 0); switch (param) { case AUDIO_PATH_USED: case AUDIO_MICROPHONE_MODE: case AUDIO_MICROPHONE_GAIN: case AUDIO_MICROPHONE_EXTRA_GAIN: case AUDIO_MICROPHONE_OUTPUT_BIAS: case AUDIO_SPEAKER_MODE: case AUDIO_SPEAKER_GAIN: case AUDIO_SPEAKER_FILTER: case AUDIO_SPEAKER_BUZZER_STATE: case AUDIO_MICROPHONE_SPEAKER_LOOP_SIDETONE: case AUDIO_SPEAKER_VOLUME_LEVEL: size = 1; break; case AUDIO_MICROPHONE_FIR: case AUDIO_SPEAKER_FIR: size = 62; break; case AUDIO_MICROPHONE_SPEAKER_LOOP_AEC: size = 24; break; default: fprintf(stderr, "error: unknown aur parameter\n"); return(ERROR_USAGE); } rc = do_aur(param, data, size); if (rc) return(rc); switch (param) { case AUDIO_PATH_USED: case AUDIO_SPEAKER_VOLUME_LEVEL: printf("%u\n", data[0]); break; case AUDIO_MICROPHONE_MODE: case AUDIO_MICROPHONE_GAIN: case AUDIO_MICROPHONE_EXTRA_GAIN: case AUDIO_MICROPHONE_OUTPUT_BIAS: case AUDIO_SPEAKER_MODE: case AUDIO_SPEAKER_GAIN: case AUDIO_SPEAKER_FILTER: case AUDIO_SPEAKER_BUZZER_STATE: case AUDIO_MICROPHONE_SPEAKER_LOOP_SIDETONE: printf("%d\n", convert_signed_byte(data[0])); break; case AUDIO_MICROPHONE_FIR: case AUDIO_SPEAKER_FIR: fputs("fir-coeff-table\n\n", stdout); for (i = 0; i < 31; i++) { printf("0x%04X", (data[i*2+1] << 8) | data[i*2]); if (i == 7 || i == 15 || i == 23 || i == 30) putchar('\n'); else putchar(' '); } break; case AUDIO_MICROPHONE_SPEAKER_LOOP_AEC: fputs("aec-new", stdout); for (i = 0; i < 12; i++) { putchar(' '); word = (data[i*2+1] << 8) | data[i*2]; if (word) printf("0x%X", word); else putchar('0'); } putchar('\n'); break; } return(0); } cmd_aur_all(argc, argv) char **argv; { u_char data[62]; unsigned mic_mode, speaker_mode, word; int rc, i; rc = do_aur(AUDIO_PATH_USED, data, 1); if (rc) return(rc); printf("voice-path %u\n", data[0]); rc = do_aur(AUDIO_MICROPHONE_MODE, data, 1); if (rc) return(rc); mic_mode = data[0]; switch (mic_mode) { case AUDIO_MICROPHONE_HANDHELD: printf("mic default {\n"); break; case AUDIO_MICROPHONE_HANDFREE: printf("mic aux {\n"); break; case AUDIO_MICROPHONE_HEADSET: printf("mic headset {\n"); break; default: fprintf(stderr, "error: unknown microphone mode 0x%02X\n", mic_mode); return(ERROR_TARGET); } rc = do_aur(AUDIO_MICROPHONE_GAIN, data, 1); if (rc) return(rc); printf("\tgain %d\n", convert_signed_byte(data[0])); if (mic_mode == AUDIO_MICROPHONE_HANDFREE) { rc = do_aur(AUDIO_MICROPHONE_EXTRA_GAIN, data, 1); if (rc) return(rc); printf("\textra-gain %d\n", convert_signed_byte(data[0])); } rc = do_aur(AUDIO_MICROPHONE_OUTPUT_BIAS, data, 1); if (rc) return(rc); printf("\toutput-bias %d\n", convert_signed_byte(data[0])); rc = do_aur(AUDIO_MICROPHONE_FIR, data, 62); if (rc) return(rc); for (i = 0; i < 31; i++) { if ((i % 8) == 0) printf("\tfir %2d", i); printf(" 0x%04X", (data[i*2+1] << 8) | data[i*2]); if (i == 7 || i == 15 || i == 23 || i == 30) putchar('\n'); } puts("}"); rc = do_aur(AUDIO_SPEAKER_MODE, data, 1); if (rc) return(rc); speaker_mode = data[0]; switch (speaker_mode) { case AUDIO_SPEAKER_HANDHELD: printf("speaker ear {\n"); break; case AUDIO_SPEAKER_HANDFREE: printf("speaker aux {\n"); break; case AUDIO_SPEAKER_HEADSET: printf("speaker headset {\n"); break; case AUDIO_SPEAKER_HANDHELD_HANDFREE: printf("speaker ear+aux {\n"); break; default: fprintf(stderr, "error: unknown speaker mode 0x%02X\n", speaker_mode); return(ERROR_TARGET); } rc = do_aur(AUDIO_SPEAKER_GAIN, data, 1); if (rc) return(rc); printf("\tgain %d\n", convert_signed_byte(data[0])); rc = do_aur(AUDIO_SPEAKER_FILTER, data, 1); if (rc) return(rc); printf("\taudio-filter %d\n", convert_signed_byte(data[0])); rc = do_aur(AUDIO_SPEAKER_FIR, data, 62); if (rc) return(rc); for (i = 0; i < 31; i++) { if ((i % 8) == 0) printf("\tfir %2d", i); printf(" 0x%04X", (data[i*2+1] << 8) | data[i*2]); if (i == 7 || i == 15 || i == 23 || i == 30) putchar('\n'); } puts("}"); rc = do_aur(AUDIO_MICROPHONE_SPEAKER_LOOP_SIDETONE, data, 1); if (rc) return(rc); printf("sidetone %d\n", convert_signed_byte(data[0])); rc = do_aur(AUDIO_MICROPHONE_SPEAKER_LOOP_AEC, data, 24); if (rc) return(rc); fputs("aec-new", stdout); for (i = 0; i < 12; i++) { putchar(' '); word = (data[i*2+1] << 8) | data[i*2]; if (word) printf("0x%X", word); else putchar('0'); } putchar('\n'); return(0); }