| 1 | /*****************************************************************************/ |
| 2 | |
| 3 | /* |
| 4 | * xfhdlcst_main.C -- kernel hdlc radio modem driver status display utility. |
| 5 | * |
| 6 | * Copyright (C) 1996,1997,2000 Thomas Sailer ([email protected]) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA |
| 21 | * 02110-1301, USA. |
| 22 | * |
| 23 | * Please note that the GPL allows you to use the driver, NOT the radio. |
| 24 | * In order to use the radio, you need a license from the communications |
| 25 | * authority of your country. |
| 26 | * |
| 27 | * |
| 28 | * History: |
| 29 | * 0.1 14.12.1996 Started |
| 30 | * 0.2 11.05.1997 introduced hdrvcomm.h |
| 31 | * 0.3 05.01.2000 upgraded to fltk 1.0.7 |
| 32 | */ |
| 33 | |
| 34 | /*****************************************************************************/ |
| 35 | |
| 36 | #include <stdlib.h> |
| 37 | #include <stdio.h> |
| 38 | #include <unistd.h> |
| 39 | #include <string.h> |
| 40 | #include <sys/types.h> |
| 41 | #include <net/if.h> |
| 42 | #include "hdrvcomm.h" |
| 43 | #include "xfhdlcst.h" |
| 44 | |
| 45 | #include <config.h> |
| 46 | #include <scm-version.h> |
| 47 | |
| 48 | /* ---------------------------------------------------------------------- */ |
| 49 | |
| 50 | static char *progname; |
| 51 | static bool update = true; |
| 52 | |
| 53 | /* ---------------------------------------------------------------------- */ |
| 54 | |
| 55 | void cb_quit(Fl_Button *, long) |
| 56 | { |
| 57 | exit(0); |
| 58 | } |
| 59 | |
| 60 | /* ---------------------------------------------------------------------- */ |
| 61 | |
| 62 | void cb_timer(void *) |
| 63 | { |
| 64 | update = true; |
| 65 | } |
| 66 | |
| 67 | /* ---------------------------------------------------------------------- */ |
| 68 | |
| 69 | static const char *usage_str = |
| 70 | "[-i smif]\n" |
| 71 | " -i: specify the name of the baycom kernel driver interface\n\n"; |
| 72 | |
| 73 | /* ---------------------------------------------------------------------- */ |
| 74 | |
| 75 | int main(int argc, char *argv[]) |
| 76 | { |
| 77 | int c, i; |
| 78 | int ret; |
| 79 | struct hdrvc_channel_state cs; |
| 80 | struct sm_ioctl smi; |
| 81 | char buf[32]; |
| 82 | char name[64]; |
| 83 | |
| 84 | progname = *argv; |
| 85 | printf("%s: Version " FULL_VER "; (C) 1996,1997,2000 by Thomas Sailer HB9JNX/AE4WA\n", *argv); |
| 86 | hdrvc_args(&argc, argv, "bc0"); |
| 87 | for (i = 1; i < argc; ) { |
| 88 | c = i; |
| 89 | Fl::arg(argc, argv, c); |
| 90 | if (c <= 0) { |
| 91 | i++; |
| 92 | continue; |
| 93 | } |
| 94 | memmove(&argv[i], &argv[i+c], (argc-i) * sizeof(char *)); |
| 95 | argc -= c; |
| 96 | } |
| 97 | #if 0 |
| 98 | while ((ret = getopt(argc, argv, "")) != -1) { |
| 99 | switch (ret) { |
| 100 | default: |
| 101 | printf("usage: %s %s", *argv, usage_str); |
| 102 | exit(-1); |
| 103 | } |
| 104 | } |
| 105 | #endif |
| 106 | hdrvc_init(); |
| 107 | |
| 108 | create_the_forms(); |
| 109 | Fl::add_timeout(0.1, cb_timer); |
| 110 | /* |
| 111 | * set driver and modem name |
| 112 | */ |
| 113 | ret = hdrvc_get_mode_name(name, sizeof(name)); |
| 114 | if (ret < 0) { |
| 115 | perror("hdrvc_get_mode_name"); |
| 116 | modename->hide(); |
| 117 | } else |
| 118 | modename->value(name); |
| 119 | ret = hdrvc_get_driver_name(name, sizeof(name)); |
| 120 | if (ret < 0) { |
| 121 | perror("hdrvc_get_driver_name"); |
| 122 | drivername->hide(); |
| 123 | } else |
| 124 | drivername->value(name); |
| 125 | /* |
| 126 | * check for soundmodem driver |
| 127 | */ |
| 128 | ret = hdrvc_sm_ioctl(SMCTL_GETDEBUG, &smi); |
| 129 | if (ret < 0) { |
| 130 | tdemodcyc->hide(); |
| 131 | tmodcyc->hide(); |
| 132 | tintfreq->hide(); |
| 133 | tdmares->hide(); |
| 134 | demodcyc->hide(); |
| 135 | modcyc->hide(); |
| 136 | intfreq->hide(); |
| 137 | dmares->hide(); |
| 138 | } |
| 139 | hdlcst->show(); |
| 140 | for (;;) { |
| 141 | Fl::wait(); |
| 142 | if (!update) |
| 143 | continue; |
| 144 | update = false; |
| 145 | Fl::add_timeout(0.5, cb_timer); |
| 146 | /* |
| 147 | * display state |
| 148 | */ |
| 149 | ret = hdrvc_get_channel_state(&cs); |
| 150 | if (ret >= 0) { |
| 151 | ptt->value(cs.ptt); |
| 152 | dcd->value(cs.dcd); |
| 153 | sprintf(buf, "%ld", cs.tx_packets); |
| 154 | txpacket->value(buf); |
| 155 | sprintf(buf, "%ld", cs.tx_errors); |
| 156 | txerror->value(buf); |
| 157 | sprintf(buf, "%ld", cs.rx_packets); |
| 158 | rxpacket->value(buf); |
| 159 | sprintf(buf, "%ld", cs.rx_errors); |
| 160 | rxerror->value(buf); |
| 161 | } |
| 162 | ret = hdrvc_sm_ioctl(SMCTL_GETDEBUG, &smi); |
| 163 | if (ret >= 0) { |
| 164 | sprintf(buf, "%d", smi.data.dbg.int_rate); |
| 165 | intfreq->value(buf); |
| 166 | sprintf(buf, "%d", smi.data.dbg.mod_cycles); |
| 167 | modcyc->value(buf); |
| 168 | sprintf(buf, "%d", smi.data.dbg.demod_cycles); |
| 169 | demodcyc->value(buf); |
| 170 | sprintf(buf, "%d", smi.data.dbg.dma_residue); |
| 171 | dmares->value(buf); |
| 172 | } |
| 173 | } |
| 174 | exit (0); |
| 175 | } |