Home | History | Annotate | Line # | Download | only in tadpolectl
tadpolectl.c revision 1.2
      1 /* $NetBSD: tadpolectl.c,v 1.2 1999/12/20 09:51:53 jdc Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Tim Rightnour.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *      This product includes software developed by the NetBSD
     21  *      Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <ctype.h>
     40 #include <err.h>
     41 #include <stdio.h>
     42 #include <string.h>
     43 #include <stdlib.h>
     44 #include <fcntl.h>
     45 #include <unistd.h>
     46 #include <sys/ioctl.h>
     47 #include <sys/types.h>
     48 #include <sys/envsys.h>
     49 #include <machine/apmvar.h>
     50 #include <machine/tctrl.h>
     51 
     52 int aflag, nflag, wflag, dev;
     53 
     54 #define PROTO(x) int x __P((int, int, int));
     55 void usage __P((void));
     56 static void parse __P((char *));
     57 char *dashdot __P((char *));
     58 int main __P((int, char *[]));
     59 PROTO(hw_version)
     60 PROTO(hw_microcontroller_version)
     61 PROTO(hw_poweroncycles)
     62 PROTO(hw_poweronseconds)
     63 PROTO(hw_power_mains)
     64 PROTO(hw_power_battery_int)
     65 PROTO(hw_power_battery_ext)
     66 PROTO(hw_power_battery_int_chargerate)
     67 PROTO(hw_power_battery_ext_chargerate)
     68 PROTO(hw_power_battery_int_chargelevel)
     69 PROTO(hw_power_battery_ext_chargelevel)
     70 PROTO(hw_video_external)
     71 PROTO(hw_video_lid)
     72 PROTO(hw_video_syncinva)
     73 PROTO(hw_video_syncinvb)
     74 PROTO(hw_video_compsync)
     75 PROTO(hw_video_tft_brightness)
     76 PROTO(hw_speaker_freq)
     77 PROTO(hw_speaker_volume)
     78 PROTO(hw_kbd_repeat_delay)
     79 PROTO(hw_kbd_repeat_speed)
     80 PROTO(hw_mouse_recalibrate)
     81 PROTO(hw_power_battery_chargedisabled)
     82 PROTO(hw_mouse_disable)
     83 PROTO(hw_kbd_click)
     84 PROTO(hw_mouse_intclick)
     85 PROTO(hw_mouse_extclick)
     86 PROTO(hw_mouse_sensitivity)
     87 
     88 #define NUM_MIBS 28
     89 #define TABLE(n) { __STRING(n), 0, n }
     90 
     91 struct {
     92 	char *mib;
     93 	int value;
     94 	int (*funcptr)(int, int, int);
     95 } table[NUM_MIBS] = {
     96 	TABLE(hw_microcontroller_version),
     97 	TABLE(hw_version),
     98 	TABLE(hw_poweroncycles),
     99 	TABLE(hw_poweronseconds),
    100 	TABLE(hw_power_mains),
    101 	TABLE(hw_power_battery_int),
    102 	TABLE(hw_power_battery_ext),
    103 	TABLE(hw_power_battery_chargedisabled),
    104 	TABLE(hw_power_battery_int_chargerate),
    105 	TABLE(hw_power_battery_ext_chargerate),
    106 	TABLE(hw_power_battery_int_chargelevel),
    107 	TABLE(hw_power_battery_ext_chargelevel),
    108 	TABLE(hw_video_external),
    109 	TABLE(hw_video_lid),
    110 	TABLE(hw_video_syncinva),
    111 	TABLE(hw_video_syncinvb),
    112 	TABLE(hw_video_compsync),
    113 	TABLE(hw_video_tft_brightness),
    114 	TABLE(hw_speaker_freq),
    115 	TABLE(hw_speaker_volume),
    116 	TABLE(hw_kbd_repeat_delay),
    117 	TABLE(hw_kbd_repeat_speed),
    118 	TABLE(hw_kbd_click),
    119 	TABLE(hw_mouse_recalibrate),
    120 	TABLE(hw_mouse_disable),
    121 	TABLE(hw_mouse_intclick),
    122 	TABLE(hw_mouse_extclick),
    123 	TABLE(hw_mouse_sensitivity),
    124 };
    125 
    126 #define FUNC(x) \
    127 int \
    128 x(read, new, num) \
    129 	int read, new, num;
    130 
    131 #define READ_REQ(a, b, c) \
    132 	req.cmdbuf[0] = a; \
    133 	req.cmdlen = b; \
    134 	req.rsplen = c; \
    135 	ioctl(dev, TCTRL_CMD_REQ, &req)
    136 
    137 #define WRITE_REQ(a, b, c) \
    138 	req.cmdbuf[0] = a; \
    139 	req.cmdlen = b; \
    140 	req.rsplen = c; \
    141 	ioctl(dev, TCTRL_CMD_REQ, &req)
    142 
    143 #define READ_ONLY \
    144 	if (!read) \
    145 		return(0)
    146 
    147 /* hardware functions */
    148 
    149 FUNC(hw_mouse_sensitivity)
    150 {
    151 	struct tctrl_req req;
    152 
    153 	req.cmdbuf[1] = 0xff;
    154 	req.cmdbuf[2] = 0x00;
    155 	READ_REQ(0x2c, 3, 2);
    156 	table[num].value = req.rspbuf[0];
    157 	if (read)
    158 		return(1);
    159 	if (new == 0)
    160 		req.cmdbuf[2] = 0x00;
    161 	else if (new > 255)
    162 		req.cmdbuf[2] = 0xff;
    163 	else
    164 		req.cmdbuf[2] = new;
    165 	req.cmdbuf[1] = 0x00;
    166 	WRITE_REQ(0x2c, 3, 2);
    167 	req.cmdbuf[1] = 0xff;
    168 	req.cmdbuf[2] = 0x00;
    169 	READ_REQ(0x2c, 3, 2);
    170 	table[num].value = req.rspbuf[0];
    171 	return(1);
    172 }
    173 
    174 FUNC(hw_power_battery_chargedisabled)
    175 {
    176 	struct tctrl_req req;
    177 
    178 	req.cmdbuf[1] = 0xff;
    179 	req.cmdbuf[2] = 0x00;
    180 	READ_REQ(0x22, 3, 2);
    181 	table[num].value = req.rspbuf[0]&0x01 ? 1 : 0;
    182 	if (read)
    183 		return(1);
    184 	if (new == 0)
    185 		req.cmdbuf[2] = 0x00;
    186 	else
    187 		req.cmdbuf[2] = 0x01;
    188 	req.cmdbuf[1] = ~0x01;
    189 	WRITE_REQ(0x22, 3, 2);
    190 	req.cmdbuf[1] = 0xff;
    191 	req.cmdbuf[2] = 0x00;
    192 	READ_REQ(0x22, 3, 2);
    193 	table[num].value = req.rspbuf[0]&0x01 ? 1 : 0;
    194 	return(1);
    195 }
    196 
    197 FUNC(hw_mouse_disable)
    198 {
    199 	struct tctrl_req req;
    200 
    201 	req.cmdbuf[1] = 0xff;
    202 	req.cmdbuf[2] = 0x00;
    203 	READ_REQ(0x22, 3, 2);
    204 	table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
    205 	if (read)
    206 		return(1);
    207 	if (new == 0)
    208 		req.cmdbuf[2] = 0x00;
    209 	else
    210 		req.cmdbuf[2] = 0x02;
    211 	req.cmdbuf[1] = ~0x02;
    212 	WRITE_REQ(0x22, 3, 2);
    213 	req.cmdbuf[1] = 0xff;
    214 	req.cmdbuf[2] = 0x00;
    215 	READ_REQ(0x22, 3, 2);
    216 	table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
    217 	return(1);
    218 }
    219 
    220 FUNC(hw_kbd_click)
    221 {
    222 	struct tctrl_req req;
    223 
    224 	req.cmdbuf[1] = 0xff;
    225 	req.cmdbuf[2] = 0x00;
    226 	READ_REQ(0x22, 3, 2);
    227 	table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
    228 	if (read)
    229 		return(1);
    230 	if (new == 0)
    231 		req.cmdbuf[2] = 0x00;
    232 	else
    233 		req.cmdbuf[2] = 0x04;
    234 	req.cmdbuf[1] = ~0x04;
    235 	WRITE_REQ(0x22, 3, 2);
    236 	req.cmdbuf[1] = 0xff;
    237 	req.cmdbuf[2] = 0x00;
    238 	READ_REQ(0x22, 3, 2);
    239 	table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
    240 	return(1);
    241 }
    242 
    243 FUNC(hw_mouse_intclick)
    244 {
    245 	struct tctrl_req req;
    246 
    247 	req.cmdbuf[1] = 0xff;
    248 	req.cmdbuf[2] = 0x00;
    249 	READ_REQ(0x22, 3, 2);
    250 	table[num].value = req.rspbuf[0]&0x08 ? 1 : 0;
    251 	if (read)
    252 		return(1);
    253 	if (new == 0)
    254 		req.cmdbuf[2] = 0x00;
    255 	else
    256 		req.cmdbuf[2] = 0x08;
    257 	req.cmdbuf[1] = ~0x08;
    258 	WRITE_REQ(0x22, 3, 2);
    259 	req.cmdbuf[1] = 0xff;
    260 	req.cmdbuf[2] = 0x00;
    261 	READ_REQ(0x22, 3, 2);
    262 	table[num].value = req.rspbuf[0]&0x08 ? 1 : 0;
    263 	return(1);
    264 }
    265 
    266 FUNC(hw_mouse_extclick)
    267 {
    268 	struct tctrl_req req;
    269 
    270 	req.cmdbuf[1] = 0xff;
    271 	req.cmdbuf[2] = 0x00;
    272 	READ_REQ(0x22, 3, 2);
    273 	table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
    274 	if (read)
    275 		return(1);
    276 	if (new == 0)
    277 		req.cmdbuf[2] = 0x00;
    278 	else
    279 		req.cmdbuf[2] = 0x10;
    280 	req.cmdbuf[1] = ~0x10;
    281 	WRITE_REQ(0x22, 3, 2);
    282 	req.cmdbuf[1] = 0xff;
    283 	req.cmdbuf[2] = 0x00;
    284 	READ_REQ(0x22, 3, 2);
    285 	table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
    286 	return(1);
    287 }
    288 
    289 /* ARGSUSED */
    290 FUNC(hw_mouse_recalibrate)
    291 {
    292 	struct tctrl_req req;
    293 
    294 	table[num].value = 0;
    295 	if (read)
    296 		return(1);
    297 	READ_REQ(0x36, 1, 1);
    298 	return(1);
    299 }
    300 
    301 FUNC(hw_kbd_repeat_delay)
    302 {
    303 	struct tctrl_req req;
    304 
    305 	req.cmdbuf[1] = 0xff;
    306 	req.cmdbuf[2] = 0x00;
    307 	READ_REQ(0x28, 3, 2);
    308 	table[num].value = req.rspbuf[0];
    309 	if (read)
    310 		return(1);
    311 	if (new == 0)
    312 		req.cmdbuf[2] = 0x00;
    313 	else if (new > 255)
    314 		req.cmdbuf[2] = 0xff;
    315 	else
    316 		req.cmdbuf[2] = new;
    317 	req.cmdbuf[1] = 0x00;
    318 	WRITE_REQ(0x28, 3, 2);
    319 	req.cmdbuf[1] = 0xff;
    320 	req.cmdbuf[2] = 0x00;
    321 	READ_REQ(0x28, 3, 2);
    322 	table[num].value = req.rspbuf[0];
    323 	return(1);
    324 }
    325 
    326 FUNC(hw_kbd_repeat_speed)
    327 {
    328 	struct tctrl_req req;
    329 
    330 	req.cmdbuf[1] = 0xff;
    331 	req.cmdbuf[2] = 0x00;
    332 	READ_REQ(0x29, 3, 2);
    333 	table[num].value = req.rspbuf[0];
    334 	if (read)
    335 		return(1);
    336 	if (new == 0)
    337 		req.cmdbuf[2] = 0x00;
    338 	else if (new > 255)
    339 		req.cmdbuf[2] = 0xff;
    340 	else
    341 		req.cmdbuf[2] = new;
    342 	req.cmdbuf[1] = 0x00;
    343 	WRITE_REQ(0x29, 3, 2);
    344 	req.cmdbuf[1] = 0xff;
    345 	req.cmdbuf[2] = 0x00;
    346 	READ_REQ(0x29, 3, 2);
    347 	table[num].value = req.rspbuf[0];
    348 	return(1);
    349 }
    350 
    351 FUNC(hw_speaker_freq)
    352 {
    353 	struct tctrl_req req;
    354 
    355 	table[num].value = 0;
    356 	if (read)
    357 		return(1);
    358 	req.cmdbuf[1] = new * 256;
    359 	req.cmdbuf[2] = new % 256;
    360 	WRITE_REQ(0x37, 3, 1);
    361 	return(1);
    362 }
    363 
    364 FUNC(hw_speaker_volume)
    365 {
    366 	struct tctrl_req req;
    367 
    368 	req.cmdbuf[1] = 0xff;
    369 	req.cmdbuf[2] = 0x00;
    370 	READ_REQ(0x23, 3, 2);
    371 	table[num].value = req.rspbuf[0];
    372 	if (read)
    373 		return(1);
    374 	if (new == 0)
    375 		req.cmdbuf[2] = 0x00;
    376 	else if (new > 255)
    377 		req.cmdbuf[2] = 0xff;
    378 	else
    379 		req.cmdbuf[2] = new;
    380 	req.cmdbuf[1] = 0x00;
    381 	WRITE_REQ(0x23, 3, 2);
    382 	req.cmdbuf[1] = 0xff;
    383 	req.cmdbuf[2] = 0x00;
    384 	READ_REQ(0x23, 3, 2);
    385 	table[num].value = req.rspbuf[0];
    386 	return(1);
    387 }
    388 
    389 FUNC(hw_video_tft_brightness)
    390 {
    391 	struct tctrl_req req;
    392 
    393 	req.cmdbuf[1] = 0xff;
    394 	req.cmdbuf[2] = 0x00;
    395 	READ_REQ(0x24, 3, 2);
    396 	table[num].value = req.rspbuf[0];
    397 	if (read)
    398 		return(1);
    399 	if (new == 0)
    400 		req.cmdbuf[2] = 0x00;
    401 	else if (new > 255)
    402 		req.cmdbuf[2] = 0xff;
    403 	else
    404 		req.cmdbuf[2] = new;
    405 	req.cmdbuf[1] = 0x00;
    406 	WRITE_REQ(0x24, 3, 2);
    407 	req.cmdbuf[1] = 0xff;
    408 	req.cmdbuf[2] = 0x00;
    409 	READ_REQ(0x24, 3, 2);
    410 	table[num].value = req.rspbuf[0];
    411 	return(1);
    412 }
    413 
    414 FUNC(hw_video_syncinva)
    415 {
    416 	struct tctrl_req req;
    417 
    418 	req.cmdbuf[1] = 0xff;
    419 	req.cmdbuf[2] = 0x00;
    420 	READ_REQ(0x21, 3, 2);
    421 	table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
    422 	if (read)
    423 		return(1);
    424 	if (new == 0)
    425 		req.cmdbuf[2] = 0x00;
    426 	else
    427 		req.cmdbuf[2] = 0x02;
    428 	req.cmdbuf[1] = ~0x02;
    429 	WRITE_REQ(0x21, 3, 2);
    430 	req.cmdbuf[1] = 0xff;
    431 	req.cmdbuf[2] = 0x00;
    432 	READ_REQ(0x21, 3, 2);
    433 	table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
    434 	return(1);
    435 }
    436 
    437 FUNC(hw_video_syncinvb)
    438 {
    439 	struct tctrl_req req;
    440 
    441 	req.cmdbuf[1] = 0xff;
    442 	req.cmdbuf[2] = 0x00;
    443 	READ_REQ(0x21, 3, 2);
    444 	table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
    445 	if (read)
    446 		return(1);
    447 	if (new == 0)
    448 		req.cmdbuf[2] = 0x00;
    449 	else
    450 		req.cmdbuf[2] = 0x04;
    451 	req.cmdbuf[1] = ~0x04;
    452 	WRITE_REQ(0x21, 3, 2);
    453 	req.cmdbuf[1] = 0xff;
    454 	req.cmdbuf[2] = 0x00;
    455 	READ_REQ(0x21, 3, 2);
    456 	table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
    457 	return(1);
    458 }
    459 
    460 FUNC(hw_video_compsync)
    461 {
    462 	struct tctrl_req req;
    463 
    464 	req.cmdbuf[1] = 0xff;
    465 	req.cmdbuf[2] = 0x00;
    466 	READ_REQ(0x21, 3, 2);
    467 	table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
    468 	if (read)
    469 		return(1);
    470 	if (new == 0)
    471 		req.cmdbuf[2] = 0x00;
    472 	else
    473 		req.cmdbuf[2] = 0x10;
    474 	req.cmdbuf[1] = ~0x10;
    475 	WRITE_REQ(0x21, 3, 2);
    476 	req.cmdbuf[1] = 0xff;
    477 	req.cmdbuf[2] = 0x00;
    478 	READ_REQ(0x21, 3, 2);
    479 	table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
    480 	return(1);
    481 }
    482 
    483 /* ARGSUSED */
    484 FUNC(hw_video_lid)
    485 {
    486 	struct tctrl_req req;
    487 	short i;
    488 
    489 	READ_ONLY;
    490 	READ_REQ(0x11, 1, 3);
    491 	i = (req.rspbuf[0]<<8) + req.rspbuf[1];
    492 	table[num].value = i&0x0040 ? 0 : 1;
    493 	return(1);
    494 }
    495 
    496 /* ARGSUSED */
    497 FUNC(hw_video_external)
    498 {
    499 	struct tctrl_req req;
    500 	short i;
    501 
    502 	READ_ONLY;
    503 	READ_REQ(0x11, 1, 3);
    504 	i = (req.rspbuf[0]<<8) + req.rspbuf[1];
    505 	table[num].value = i&0x0008 ? 1 : 0;
    506 	return(1);
    507 }
    508 
    509 /* ARGSUSED */
    510 FUNC(hw_power_battery_int_chargelevel)
    511 {
    512 	struct tctrl_req req;
    513 
    514 	READ_ONLY;
    515 	READ_REQ(0x7a, 1, 3);
    516 	table[num].value = req.rspbuf[0] == 0xfb ? 0 : req.rspbuf[0];
    517 	return(1);
    518 
    519 }
    520 
    521 /* ARGSUSED */
    522 FUNC(hw_power_battery_ext_chargelevel)
    523 {
    524 	struct tctrl_req req;
    525 
    526 	READ_ONLY;
    527 	READ_REQ(0x7b, 1, 3);
    528 	table[num].value = req.rspbuf[0] == 0xfb ? 0 : req.rspbuf[0];
    529 	return(1);
    530 }
    531 
    532 FUNC(hw_power_battery_int_chargerate)
    533 {
    534 	struct tctrl_req req;
    535 
    536 	READ_REQ(0x18, 1, 2);
    537 	table[num].value = req.rspbuf[0];
    538 	if (read)
    539 		return(1);
    540 	req.cmdbuf[1] = new < 255 ? new : 255;
    541 	WRITE_REQ(0x39, 2, 1);
    542 	READ_REQ(0x18, 1, 2);
    543 	table[num].value = req.rspbuf[0];
    544 	return(1);
    545 }
    546 
    547 FUNC(hw_power_battery_ext_chargerate)
    548 {
    549 	struct tctrl_req req;
    550 
    551 	READ_REQ(0x18, 1, 2);
    552 	table[num].value = req.rspbuf[0];
    553 	if (read)
    554 		return(1);
    555 	req.cmdbuf[1] = new < 255 ? new : 255;
    556 	WRITE_REQ(0x39, 2, 1);
    557 	READ_REQ(0x18, 1, 2);
    558 	table[num].value = req.rspbuf[0];
    559 	return(1);
    560 }
    561 
    562 /* ARGSUSED */
    563 FUNC(hw_power_battery_ext)
    564 {
    565 	int i;
    566 	struct tctrl_req req;
    567 
    568 	READ_ONLY;
    569 	READ_REQ(0x11, 1, 3);
    570 	i = (req.rspbuf[0]<<8) + req.rspbuf[1];
    571 	table[num].value = i&0x0004 ? 1 : 0;
    572 	return(1);
    573 }
    574 
    575 /* ARGSUSED */
    576 FUNC(hw_power_battery_int)
    577 {
    578 	int i;
    579 	struct tctrl_req req;
    580 
    581 	READ_ONLY;
    582 	READ_REQ(0x11, 1, 3);
    583 	i = (req.rspbuf[0]<<8) + req.rspbuf[1];
    584 	table[num].value = i&0x0002 ? 1 : 0;
    585 	return(1);
    586 }
    587 
    588 /* ARGSUSED */
    589 FUNC(hw_power_mains)
    590 {
    591 	int i;
    592 	struct tctrl_req req;
    593 
    594 	READ_ONLY;
    595 	READ_REQ(0x11, 1, 3);
    596 	i = (req.rspbuf[0]<<8) + req.rspbuf[1];
    597 	table[num].value = i&0x0001 ? 1 : 0;
    598 	return(1);
    599 }
    600 
    601 /* ARGSUSED */
    602 FUNC(hw_poweroncycles)
    603 {
    604 	struct tctrl_req req;
    605 
    606 	READ_ONLY;
    607 	READ_REQ(0x09, 1, 5);
    608 	table[num].value = (req.rspbuf[0]<<24)+(req.rspbuf[1]<<16)+
    609 	    (req.rspbuf[2]<<8)+req.rspbuf[3];
    610 	return(1);
    611 }
    612 
    613 /* ARGSUSED */
    614 FUNC(hw_poweronseconds)
    615 {
    616 	struct tctrl_req req;
    617 
    618 	READ_ONLY;
    619 	READ_REQ(0x0a, 1, 5);
    620 	table[num].value = (req.rspbuf[0]<<24)+(req.rspbuf[1]<<16)+
    621 	    (req.rspbuf[2]<<8)+req.rspbuf[3];
    622 	return(1);
    623 }
    624 
    625 /* ARGSUSED */
    626 FUNC(hw_microcontroller_version)
    627 {
    628 	char *bufp, buf[BUFSIZ];
    629 	struct tctrl_req req;
    630 
    631 	READ_ONLY;
    632 	READ_REQ(0x04, 1, 3);
    633 	bufp = buf;
    634 	sprintf(bufp, "%d%d", req.rspbuf[0]*1000, req.rspbuf[1]*10);
    635 	table[num].value = atoi(strdup(bufp));
    636 	return(1);
    637 }
    638 
    639 
    640 /* ARGSUSED */
    641 FUNC(hw_version)
    642 {
    643 	char *bufp, buf[BUFSIZ];
    644 	struct tctrl_req req;
    645 
    646 	READ_ONLY;
    647 	READ_REQ(0x03, 1, 3);
    648 	bufp = buf;
    649 	sprintf(bufp, "%d%d", req.rspbuf[0]*1000, req.rspbuf[1]*10);
    650 	table[num].value = atoi(strdup(bufp));
    651 	return(1);
    652 }
    653 
    654 void
    655 usage()
    656 {
    657 	(void)fprintf(stderr,
    658 	    "usage: tadpolectl [-n] name ...\n"
    659 	    "       tadpolectl [-n] -w name=value\n"
    660 	    "       tadpolectl [-n] -a\n");
    661 	exit(1);
    662 }
    663 
    664 static void
    665 parse(string)
    666 	char *string;
    667 {
    668 	char *cp, buf[BUFSIZ];
    669 	int newval = 0;
    670 	int i, j, ret;
    671 
    672 	string = dashdot(string);
    673 	snprintf(buf, (size_t)BUFSIZ, "%s", string);
    674 	if ((cp = strchr(string, '=')) != NULL) {
    675 		if (!wflag)
    676 			errx(2, "Must specify -w to set variables");
    677 		*strchr(buf, '=') = '\0';
    678 		*cp++ = '\0';
    679 		while (isspace((unsigned char) *cp))
    680 			cp++;
    681 		newval = atoi(cp);
    682 	}
    683 	for (j=0,i=-1; j < NUM_MIBS; j++) {
    684 		if (strcmp(string, table[j].mib) == 0) {
    685 			i = j;
    686 			break;
    687 		}
    688 	}
    689 	if (i == -1)
    690 		errx(2, "Named value does not exist");
    691 
    692 	if (wflag) {
    693 		ret = (*table[i].funcptr)(0, newval, i);
    694 		if (!ret)
    695 			errx(2, "Cannot modify this value");
    696 	} else
    697 		ret = (*table[i].funcptr)(1, 0, i);
    698 	if (nflag)
    699 		printf("%d\n", table[i].value);
    700 	else
    701 		printf("%s = %d\n", dashdot(table[i].mib), table[i].value);
    702 }
    703 
    704 char *
    705 dashdot(string)
    706 	char *string;
    707 {
    708 	char *p;
    709 	char *save;
    710 
    711 	p = strdup(string);
    712 	save = p;
    713 
    714 	for (; (*p = *string) != '\0'; ++p, ++string) {
    715 		if (*p == '.')
    716 			*p = '_';
    717 		else if (*p == '_')
    718 			*p = '.';
    719 	}
    720 	return(save);
    721 }
    722 
    723 int
    724 main(argc, argv)
    725 	int argc;
    726 	char *argv[];
    727 {
    728 	extern int optind;
    729 	int ch, j;
    730 
    731 	while ((ch = getopt(argc, argv, "anw")) != -1) {
    732 		switch (ch) {
    733 
    734 		case 'a':
    735 			aflag = 1;
    736 			break;
    737 		case 'n':
    738 			nflag = 1;
    739 			break;
    740 		case 'w':
    741 			wflag = 1;
    742 			break;
    743 		default:
    744 			usage();
    745 		}
    746 	}
    747 	argc -= optind;
    748 	argv += optind;
    749 
    750 	dev = open("/dev/tctrl0", O_RDONLY, NULL);
    751 
    752 	if (aflag) {
    753 		for (j=0; j < NUM_MIBS; j++) {
    754 			(void)(*table[j].funcptr)(1, 0, j);
    755 			if (nflag)
    756 				printf("%d\n", table[j].value);
    757 			else
    758 				printf("%s = %d\n", dashdot(table[j].mib),
    759 				    table[j].value);
    760 		}
    761 		return(0);
    762 	}
    763 	if (argc == 0)
    764 		usage();
    765 	while (argc-- > 0)
    766 		parse(*argv++);
    767 	return(0);
    768 }
    769