-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5489fbd
Showing
5 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*~ | ||
a.out | ||
tmp/ | ||
example | ||
powerusb |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CC=gcc | ||
CFLAGS=-Wall -g | ||
LDFLAGS=-lusb-1.0 -L/lib/x86_64-linux-gnu | ||
|
||
|
||
all: | ||
$(CC) $(CFLAGS) $(LDFLAGS) powerusb.c -o powerusb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
PowerUSB | ||
|
||
set power state | ||
|
||
on off | ||
port1 A B | ||
port2 C D | ||
port3 E P | ||
|
||
get model 0xaa -> (1:basic) | ||
get firmware ver 0xa7 -> 0x0201 == major:2 minor:1 | ||
|
||
get port1 state 0xa1 -> 0: off, 1: on | ||
get port2 state 0xa2 | ||
get port3 state 0xac | ||
|
||
get curr power 0xb1 | ||
ping 0xb2 | ||
|
||
|
||
------------------------------------------------- | ||
$ tail /var/log/messages | ||
Mar 3 09:00:34 sango kernel: [483571.845426] usb 2-4.3: new full speed USB device number 59 using ohci_hcd | ||
Mar 3 09:00:34 sango kernel: [483571.965425] usb 2-4.3: New USB device found, idVendor=04d8, idProduct=003f | ||
Mar 3 09:00:34 sango kernel: [483571.965436] usb 2-4.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0 | ||
Mar 3 09:00:34 sango kernel: [483571.965443] usb 2-4.3: Product: Simple HID Device Demo | ||
Mar 3 09:00:34 sango kernel: [483571.965448] usb 2-4.3: Manufacturer: Microchip Technology Inc. | ||
Mar 3 09:00:34 sango kernel: [483571.978292] generic-usb 0003:04D8:003F.0027: hiddev0,hidraw2: USB HID v1.11 Device [Microchip Technology Inc. Simple HID Device Demo] on usb-0000:00:0b.0-4.3/input0 | ||
------------------------------------------------- | ||
|
||
#define USB_VENDOR 0x04d8 | ||
#define USB_PRODUCT 0x003f | ||
|
||
|
||
|
||
(gdb) p/x buf2 | ||
$1 = {0x1, 0xab, 0xe2, 0x85, 0x21, 0x3c, 0x20, 0x2f, 0x87, 0xcf, 0xc1, 0x1b, 0x96, 0x8d, 0xec, | ||
0xc5, 0xcd, 0xbe, 0x75, 0xb6, 0x3b, 0x98, 0xd5, 0x73, 0xc9, 0xb8, 0x87, 0xbc, 0xa7, 0x15, | ||
0x53, 0x1, 0xa2, 0x9a, 0x4f, 0x1d, 0x8a, 0x1e, 0x93, 0xb9, 0x94, 0x0, 0x70, 0x49, 0x62, 0x9f, | ||
0xfa, 0xf8, 0x36, 0xb8, 0x3f, 0x21, 0x80, 0xe0, 0xd5, 0xc4, 0x26, 0xf2, 0x6, 0x56, 0x2, 0x74, | ||
0xed, 0x6c} | ||
$2 = {0x1, 0xab, 0xe2, 0x85, 0x21, 0x3c, 0x20, 0x2f, 0x87, 0xcf, 0xc1, 0x1b, 0x96, 0x8d, 0xec, | ||
0xc5, 0xcd, 0xbe, 0x75, 0xb6, 0x3b, 0x98, 0xd5, 0x73, 0xc9, 0xb8, 0x87, 0xbc, 0xa7, 0x15, | ||
0x53, 0x1, 0xa2, 0x9a, 0x4f, 0x1d, 0x8a, 0x1e, 0x93, 0xb9, 0x94, 0x0, 0x70, 0x49, 0x62, 0x9f, | ||
0xfa, 0xf8, 0x36, 0xb8, 0x3f, 0x21, 0x80, 0xe0, 0xd5, 0xc4, 0x26, 0xf2, 0x6, 0x56, 0x2, 0x74, | ||
0xed, 0x6c} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include <libusb-1.0/libusb.h> | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
|
||
#define USB_VENDOR_ID 0x04d8 | ||
#define USB_PRODUCT_ID 0x003f | ||
#define ENDPOINT_IN 0x81 | ||
#define ENDPOINT_OUT 0x01 | ||
|
||
#define CMD_GET_MODEL 0xaa | ||
#define CMD_GET_FIRM_VER 0xa7 | ||
#define CMD_GET_STATE1 0xa1 | ||
#define CMD_GET_STATE2 0xa2 | ||
#define CMD_GET_STATE3 0xac | ||
|
||
|
||
|
||
|
||
void send_cmd(struct libusb_device_handle *devh,int cmd) | ||
{ | ||
int r,i; | ||
uint8_t buf[64],buf2[64]; | ||
int size=0; | ||
printf("send_cmd:%x\n",cmd); | ||
|
||
memset(buf, 0xff, sizeof(buf)); | ||
memset(buf2, 0x00, sizeof(buf)); | ||
|
||
buf[0] = cmd; | ||
|
||
r = libusb_interrupt_transfer(devh,ENDPOINT_OUT,buf, sizeof(buf),&size, 1000); | ||
if(r<0) { | ||
perror("libusb_interrupt_transfer"); | ||
exit(1); | ||
} | ||
r = libusb_interrupt_transfer(devh,ENDPOINT_IN,buf2, sizeof(buf2),&size, 1000); | ||
|
||
printf("send_cmd:read:"); | ||
for(i=0;i<2;i++){ | ||
printf("%02x",buf2[i]); | ||
} | ||
printf("\n"); | ||
|
||
} | ||
|
||
|
||
int main(int argc, char **argv) | ||
{ | ||
libusb_context *ctx = NULL; | ||
struct libusb_device_handle *devh = NULL; | ||
int r=1; | ||
|
||
|
||
r = libusb_init(&ctx); | ||
if (r < 0 ) { | ||
printf("usb_init:failed\n"); | ||
exit(1); | ||
} else { | ||
libusb_set_debug(ctx,3); | ||
printf("init done\n"); | ||
} | ||
|
||
devh = libusb_open_device_with_vid_pid(ctx,USB_VENDOR_ID,USB_PRODUCT_ID); | ||
if (devh < 0 ) { | ||
printf("can't find PowerUSB device\n"); | ||
goto out; | ||
|
||
} else { | ||
printf("device opened\n"); | ||
} | ||
|
||
send_cmd(devh,CMD_GET_MODEL); | ||
send_cmd(devh,CMD_GET_FIRM_VER); | ||
send_cmd(devh,CMD_GET_STATE1); | ||
send_cmd(devh,CMD_GET_STATE2); | ||
send_cmd(devh,CMD_GET_STATE3); | ||
|
||
out: | ||
libusb_close(devh); | ||
libusb_exit(ctx); | ||
exit(0); | ||
} |