FreeCalypso > hg > gsm-codec-lib
comparison hrutil/tw5b-dump.c @ 559:707d6f7a54dc
hrutil: new program tw5b-dump
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Thu, 06 Feb 2025 09:32:18 +0000 |
| parents | miscutil/tw5a-dump.c@86d4ec69b36c |
| children | 7bce90c844c2 |
comparison
equal
deleted
inserted
replaced
| 558:a81ce3cd38a7 | 559:707d6f7a54dc |
|---|---|
| 1 /* | |
| 2 * This program reads a TW-TS-005 Annex B hexadecimal file | |
| 3 * and dumps all frames in human-readable form. | |
| 4 */ | |
| 5 | |
| 6 #include <stdio.h> | |
| 7 #include <stdint.h> | |
| 8 #include <stdlib.h> | |
| 9 #include <string.h> | |
| 10 #include <strings.h> | |
| 11 #include "../libgsmhr1/tw_gsmhr.h" | |
| 12 #include "../libtest/tw5reader.h" | |
| 13 | |
| 14 main(argc, argv) | |
| 15 char **argv; | |
| 16 { | |
| 17 FILE *hexf; | |
| 18 unsigned lineno; | |
| 19 uint8_t frame[TWTS005_MAX_FRAME]; | |
| 20 unsigned frame_len, ft; | |
| 21 int16_t params[GSMHR_NUM_PARAMS]; | |
| 22 int rc; | |
| 23 | |
| 24 if (argc != 2) { | |
| 25 fprintf(stderr, "usage: %s hex-file\n", argv[0]); | |
| 26 exit(1); | |
| 27 } | |
| 28 hexf = fopen(argv[1], "r"); | |
| 29 if (!hexf) { | |
| 30 perror(argv[1]); | |
| 31 exit(1); | |
| 32 } | |
| 33 lineno = 0; | |
| 34 for (;;) { | |
| 35 rc = twts005_read_frame(hexf, &lineno, frame, &frame_len); | |
| 36 if (rc < 0) { | |
| 37 fprintf(stderr, "%s line %u: not valid TW-TS-005\n", | |
| 38 argv[1], lineno); | |
| 39 exit(1); | |
| 40 } | |
| 41 if (!rc) | |
| 42 break; | |
| 43 switch (frame_len) { | |
| 44 case 0: | |
| 45 printf("line %u: NULL frame\n", lineno); | |
| 46 break; | |
| 47 case 1: | |
| 48 if (frame[0] & 0x80) | |
| 49 goto invalid; | |
| 50 ft = frame[0] >> 4; | |
| 51 switch (ft) { | |
| 52 case 1: | |
| 53 printf("line %u: Invalid_SID frame\n", lineno); | |
| 54 break; | |
| 55 case 7: | |
| 56 printf("line %u: No_Data frame\n", lineno); | |
| 57 break; | |
| 58 default: | |
| 59 goto invalid; | |
| 60 } | |
| 61 printf(" ToC=%02X (DTXd=%u UFI=%u TAF=%u)\n", frame[0], | |
| 62 (frame[0] >> 3) & 1, (frame[0] >> 1) & 1, | |
| 63 frame[0] & 1); | |
| 64 break; | |
| 65 case GSMHR_FRAME_LEN_RPF: | |
| 66 printf("line %u: TS 101 318 frame\n", lineno); | |
| 67 gsmhr_unpack_ts101318(frame, params); | |
| 68 print_frame_params(params); | |
| 69 break; | |
| 70 case GSMHR_FRAME_LEN_5993: | |
| 71 if (frame[0] & 0x80) | |
| 72 goto invalid; | |
| 73 ft = frame[0] >> 4; | |
| 74 switch (ft) { | |
| 75 case 0: | |
| 76 printf("line %u: good speech frame\n", lineno); | |
| 77 break; | |
| 78 case 2: | |
| 79 printf("line %u: good SID frame\n", lineno); | |
| 80 break; | |
| 81 case 6: | |
| 82 printf("line %u: bad speech frame\n", lineno); | |
| 83 break; | |
| 84 default: | |
| 85 goto invalid; | |
| 86 } | |
| 87 printf(" ToC=%02X (DTXd=%u UFI=%u TAF=%u)\n", frame[0], | |
| 88 (frame[0] >> 3) & 1, (frame[0] >> 1) & 1, | |
| 89 frame[0] & 1); | |
| 90 gsmhr_unpack_ts101318(frame + 1, params); | |
| 91 print_frame_params(params); | |
| 92 break; | |
| 93 default: | |
| 94 invalid: | |
| 95 fprintf(stderr, | |
| 96 "%s line %u: not a valid GSM-HR frame\n", | |
| 97 argv[1], lineno); | |
| 98 exit(1); | |
| 99 } | |
| 100 } | |
| 101 exit(0); | |
| 102 } |
