Date:2013-06-23 06:55:58 (6 years 5 months ago)
Author:Werner Almesberger
Commit:a523e8d645348f8b3fb8262ea90c7710c99f1d8a
Message:tools/atrf-txrx/atrf-txrx.c: new option -x to interpret messages as hex strings

Files: tools/atrf-txrx/atrf-txrx.c (7 diffs)

Change Details

tools/atrf-txrx/atrf-txrx.c
272272}
273273
274274
275static void transmit(struct atrf_dsc *dsc, const char *msg, int times)
275static int dehex(uint8_t *buf, const char *s)
276{
277    uint8_t *p;
278    int nibbles = 0;
279    uint8_t v = 0, nibble;
280    char cvt[2] = "?";
281    char *end;
282
283    for (p = buf; *s; s++) {
284        if (strchr(" \t,.:-", *s)) {
285            if (nibbles)
286                *p++ = v;
287            nibbles = 0;
288            continue;
289        }
290        cvt[0] = *s;
291        nibble = strtoul(cvt, &end, 16);
292        if (*end) {
293            fprintf(stderr, "invalid hex character \"%c\"\n", *s);
294            exit(1);
295        }
296        if (nibbles) {
297            *p++ = v << 4 | nibble;
298            nibbles = 0;
299        } else {
300            v = nibble;
301            nibbles++;
302        }
303    }
304    if (nibbles)
305        *p++ = v;
306    return p-buf;
307}
308
309
310static void transmit(struct atrf_dsc *dsc, const char *msg, int hex, int times)
276311{
277312    uint8_t buf[MAX_PSDU];
313    int len;
278314
279315    atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
280316    /*
...... 
286322    /*
287323     * We need to copy the message to append the CRC placeholders.
288324     */
289    strcpy((void *) buf, msg);
290    atrf_buf_write(dsc, buf, strlen(msg)+2);
325    if (hex) {
326        len = dehex(buf, msg);
327    } else {
328        strcpy((void *) buf, msg);
329        len = strlen(msg);
330    }
331    atrf_buf_write(dsc, buf, len+2);
291332
292333    while (run && times--) {
293334        /* @@@ should wait for clear channel */
...... 
590631static void usage(const char *name)
591632{
592633    fprintf(stderr,
593"usage: %s [common_options] [message [repetitions]]\n"
634"usage: %s [common_options] [[-x] message [repetitions]]\n"
594635" %s [common_options] -H [message]\n"
595636" %s [common_options] -E pause_s [repetitions]\n"
596637" %s [common_options] -P [max_wait_s]\n"
597638" %s [common_options] -R [-H|packets size]\n"
598639" %s [common_options] -T offset [command]\n\n"
599640" text message mode:\n"
641" -x message consists of hex bytes, optionally separated by\n"
642" ' ', '.', ',', ':', or '-'\n"
600643" message message string to send (if absent, receive)\n"
601644" repetitions number of times the message is sent (default 1)\n\n"
602645" text message mode (hard MAC):\n"
...... 
662705    int trim = DEFAULT_TRIM, times = 1, bytes;
663706    uint8_t cont_tx = 0;
664707    double pause_s = 0;
708    int hex = 0;
665709    char *end;
666710    int c, freq;
667711    unsigned clkm = 0;
...... 
669713    const char *pcap_file = NULL;
670714    struct atrf_dsc *dsc;
671715
672    while ((c = getopt(argc, argv, "c:C:d:E:f:Ho:p:Pr:Rt:T:")) != EOF)
716    while ((c = getopt(argc, argv, "c:C:d:E:f:Ho:p:Pr:Rt:T:x")) != EOF)
673717        switch (c) {
674718        case 'c':
675719            channel = strtoul(optarg, &end, 0);
...... 
751795            else
752796                usage(*argv);
753797            break;
798        case 'x':
799            hex = 1;
800            break;
754801        default:
755802            usage(*argv);
756803        }
...... 
830877        switch (mode) {
831878        case mode_msg:
832879            set_power_dBm(dsc, power, 1);
833            transmit(dsc, argv[optind], times);
880            transmit(dsc, argv[optind], hex, times);
834881            break;
835882        case mode_hmac:
836883            set_power_dBm(dsc, power, 1);

Archive Download the corresponding diff file



interactive