?? clockrcon.c
字號:
/* $Id: clockrcon.c,v 1.11 2005/12/07 16:16:10 simimeie Exp $ * Clock Remote Controller */#define BV _BV#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <netdb.h>#include <sys/types.h>#include <sys/socket.h>struct ctrlpacket { unsigned char password[9]; unsigned char cmd; unsigned char data[1000];};struct ctrlpacket packet1;unsigned char ledfont[256] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00 - 0x07 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08 - 0x0F */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10 - 0x17 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18 - 0x1F */ 0x00, 0x11, 0x50, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x20 - 0x27 */ 0x6C, 0x36, 0x00, 0x00, 0x06, 0x80, 0x01, 0x98, /* 0x28 - 0x2F (2E=.) */ 0x7E, 0x12, 0xBC, 0xB6, 0xD2, 0xE6, 0xEE, 0x32, /* 0x30 - 0x37 (0 - 7) */ 0xFE, 0xF6, 0x00, 0x00, 0x00, 0x84, 0x00, 0x31, /* 0x38 - 0x3F (8 - 9, ?) */ 0x00, 0xFA, 0xCE, 0x6C, 0x9E, 0xEC, 0xE8, 0x6E, /* 0x40 - 0x47 (41=A) */ 0xDA, 0x12, 0x1E, 0x92, 0x4C, 0x7A, 0x8A, 0x8E, /* 0x48 - 0x4F (H-O) */ 0xF8, 0xF2, 0x88, 0xE6, 0xCC, 0x5E, 0x0E, 0x0F, /* 0x50 - 0x57 (P-W) */ 0xDB, 0xD6, 0xBC, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58 - 0x5F (X-Z, ?) */ 0x00, 0xFA, 0xCE, 0x6C, 0x9E, 0xEC, 0xE8, 0x6E, /* 0x60 - 0x67 (61=a) */ 0xDA, 0x12, 0x1E, 0x92, 0x4C, 0x7A, 0x8A, 0x8E, /* 0x68 - 0x6F (h-o) */ 0xF8, 0xF2, 0x88, 0xE6, 0xCC, 0x5E, 0x0E, 0x0F, /* 0x70 - 0x77 (p-w) */ 0xDB, 0xD6, 0xBC, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78 - 0x7F (x-z, ?) */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80 - 0x87 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88 - 0x8F */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90 - 0x97 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98 - 0x9F */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xA0 - 0xA7 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xA8 - 0xAF */ 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xB0 - 0xB7 (b0=degree) */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xB8 - 0xBF */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xC0 - 0xC7 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xC8 - 0xCF */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xD0 - 0xD7 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xD8 - 0xDF */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xE0 - 0xE7 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xE8 - 0xEF */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xF0 - 0xF7 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xF8 - 0xFF */ };int main(int argc, char ** argv) { struct hostent *hp; struct sockaddr_in sa; int sockout; int i, j, k; if (argc < 4) { fprintf(stderr, "Syntax: clockrcon targethost password command [data]\n"); fprintf(stderr, "where targethost is the hostname or IP of the target\n"); fprintf(stderr, " password is the password of the target\n"); fprintf(stderr, " command is the number of the command:\n"); fprintf(stderr, " 1 Set Display Override\n"); fprintf(stderr, " 2 Set Digit Brightness\n"); fprintf(stderr, " 3 Set Clockface Brightness\n"); fprintf(stderr, " data is additional data as needed by the command\n"); return 1; } memset(packet1.password, 0, 9); strncpy(packet1.password, argv[2], 8); packet1.cmd = strtoul(argv[3], NULL, 10); if ((hp = gethostbyname(argv[1])) == NULL) { fprintf(stderr, "Oops ... unknown host \"%s\"\n", argv[1]); return 2; } memset((char *)&sa, 0, sizeof(sa)); if (sizeof(sa.sin_addr) != hp->h_length) { fprintf(stderr, "Ooops - host \"%s\" resolves to non IPv4-address\n", argv[1]); return 2; } memcpy((char *)&sa.sin_addr, hp->h_addr, hp->h_length); sa.sin_family = hp->h_addrtype; sa.sin_port = htons(31337); sockout = socket(PF_INET, SOCK_DGRAM, 0); if (sockout < 0) { fprintf(stderr, "Could not create socket\n"); return 3; } switch (packet1.cmd) { case 1: /* Display Override */ /* In this case the data has to be 7 hexadecimal bytes */ if ((argc != 11) && (argc != 12) && (argc != 5) && (argc != 6)) { fprintf(stderr, "Error: Command 1 needs either 7 hexadecimal values,\n"); fprintf(stderr, "or a string as parameter\n"); fprintf(stderr, "In both cases, one additional parameter that sets the\n"); fprintf(stderr, "override duration may be given.\n"); return 1; } if ((argc == 11) || (argc == 12)) { /* Raw data for the LED driver chip */ for (i = 0; i < 7; i++) { packet1.data[i] = strtoul(argv[4+i], NULL, 16); } if (argc == 12) { packet1.data[7] = strtoul(argv[11], NULL, 10); } else { packet1.data[7] = 30; /* Default 5 sec */ } } else { /* String - use our internal font. */ printf("Using internal font for "); for (i = 0; i < 7; i++) { packet1.data[i] = 0; } j = strlen(argv[4]); k = 0; for (i = 0; (i+k) < ((j > 6+k) ? 6+k : j); i++) { printf("%02X ", ((unsigned char)(argv[4][i+k]))); packet1.data[i] = ledfont[((unsigned char)(argv[4][i+k]))]; if (argv[4][i+k+1] == '.') { switch(argv[4][i+k]) { case 0x30 ... 0x39: /* 0 - 9 */ case 0x41 ... 0x5a: /* A - Z */ case 0x61 ... 0x7a: /* a - z */ packet1.data[i] |= 0x01; k++; break; }; } } if (argc == 6) { packet1.data[7] = strtoul(argv[5], NULL, 10); } else { packet1.data[7] = 30; /* Default 5 sec */ } printf("\n"); } printf("Sending display override command with raw values: "); for (i = 0; i < 7; i++) { printf("%02X ", packet1.data[i]); } printf("\noverriding display for %3.1f seconds\n", (packet1.data[7] / 6.0)); j = sendto(sockout, &packet1, 18, 0, (struct sockaddr *)&sa, sizeof(sa)); if (j != 18) { fprintf(stderr, "Error sending packet.\n"); } break; case 2: /* Set Display Brightness */ if (argc != 5) { fprintf(stderr, "Error: Command 2 needs one parameter:\n"); fprintf(stderr, "The Display brightness. Valid values are 0 - 7.\n"); return 1; } packet1.data[0] = strtoul(argv[4], NULL, 10) & 0x07; printf("Setting display brightness to %d/7\n", packet1.data[0]); j = sendto(sockout, &packet1, 11, 0, (struct sockaddr *)&sa, sizeof(sa)); if (j != 11) { fprintf(stderr, "Error sending packet.\n"); } break; case 3: /* Set Clockface Brightness */ if (argc != 5) { fprintf(stderr, "Error: Command 3 needs one parameter:\n"); fprintf(stderr, "The Display brightness. Valid values are 0 - 31.\n"); return 1; } packet1.data[0] = strtoul(argv[4], NULL, 10) & 0x1F; printf("Setting display brightness to %d/31\n", packet1.data[0]); j = sendto(sockout, &packet1, 11, 0, (struct sockaddr *)&sa, sizeof(sa)); if (j != 11) { fprintf(stderr, "Error sending packet.\n"); } break; default: fprintf(stderr, "Error: Command %u unknown.\n", packet1.cmd); return 2; }; return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -