#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include "proto.h"
Go to the source code of this file.
Defines | |
#define | ION_SERIO_FLAGS CS8 |
#define | ION_SERIO_SPEED B115200 |
#define | ION_POWER_MODES 7 |
Functions | |
static void | usage () |
static void | parse_args (int argc, char **argv) |
int | main (int argc, char **argv) |
Variables | |
char * | modes [ION_POWER_MODES] |
#define ION_POWER_MODES 7 |
Definition at line 54 of file kbdpower.c.
#define ION_SERIO_FLAGS CS8 |
Copyright (C) 2008 iRex Technologies B.V. All rights reserved.
Definition at line 51 of file kbdpower.c.
#define ION_SERIO_SPEED B115200 |
Definition at line 52 of file kbdpower.c.
int main | ( | int | argc, | |
char ** | argv | |||
) |
Definition at line 84 of file kbdpower.c.
References data, fatal(), ION_POWER_MODES, ION_SERIO_FLAGS, ION_SERIO_SPEED, IONKBD_REQ_SET_POWER, IONKBD_RESP_STATUS, ionkbd_send_request(), modes, parse_args(), port_open(), and usage().
00085 { 00086 uint8_t rcmd, rlen,i, len; 00087 uint8_t data[16], rdata[16]; 00088 int powermode, delay, param; 00089 00090 param = -1; 00091 len = 2; 00092 // check arguments 00093 parse_args(argc, argv); 00094 if ((argc-optind)<3) 00095 { 00096 usage(); 00097 } 00098 // open device 00099 port_open(argv[optind], ION_SERIO_FLAGS, ION_SERIO_SPEED); 00100 powermode = 1; 00101 delay = atoi(argv[optind+2]); 00102 if ((argc-optind)==4) 00103 { 00104 param = atoi(argv[optind+3]); 00105 len = 3; 00106 } 00107 // find mode number 00108 for (i=0;i<ION_POWER_MODES;i++) 00109 { 00110 if (strcmp(modes[i], argv[optind+1])==0) 00111 { 00112 break; 00113 } 00114 powermode <<= 1; 00115 } 00116 if (i==ION_POWER_MODES) 00117 { 00118 fatal("Power mode '%s' not understood", argv[optind+1]); 00119 } 00120 // setup and send request 00121 data[0] = powermode; 00122 data[1] = delay; 00123 data[2] = param; 00124 //printf("sending command [%d]: %d %d %d\n", len, powermode, delay, param); 00125 printf("Switching to power mode '%s' (%d)\n", modes[i], powermode); 00126 i = 0; 00127 while (i<5) 00128 { 00129 if (!ionkbd_send_request( 00130 IONKBD_REQ_SET_POWER, len, 00131 data, &rcmd, &rlen, rdata)) 00132 { 00133 if (rcmd==IONKBD_RESP_STATUS) 00134 { 00135 printf("Mode change successful\n"); 00136 return 0; 00137 } 00138 else if (rcmd>=0x80) 00139 { 00140 printf("Ignoring update packet: 0x%02X\n", rcmd); 00141 } 00142 else 00143 { 00144 printf("Unexpected response: 0x%02X\n", rcmd); 00145 i++; 00146 } 00147 } 00148 else 00149 { 00150 i++; 00151 } 00152 } 00153 printf("Mode change failed\n"); 00154 00155 return 1; 00156 }
static void parse_args | ( | int | argc, | |
char ** | argv | |||
) | [static] |
Definition at line 173 of file kbdpower.c.
References usage().
00174 { 00175 int c; 00176 00177 while (( c = getopt(argc, argv, "h")) != -1) 00178 { 00179 switch (c) 00180 { 00181 case 'h': 00182 default: 00183 usage(); 00184 break; 00185 } 00186 } 00187 }
static void usage | ( | ) | [static] |
Definition at line 159 of file kbdpower.c.
References ION_POWER_MODES, and modes.
00160 { 00161 int i; 00162 printf("kbdpower - \n"); 00163 printf(" usage: kbdpower <options> <serial port> <power mode> <delay>\n"); 00164 printf(" options:\n"); 00165 printf(" -h This text\n"); 00166 printf(" power modes:\n"); 00167 for (i=0;i<ION_POWER_MODES;i++) 00168 printf(" %s\n", modes[i]); 00169 exit(1); 00170 }
char* modes[ION_POWER_MODES] |
{ "reboot", "on", "idle", "standby", "hibernate", "off", "warmreboot", }
Definition at line 56 of file kbdpower.c.