Clean up the testcode
This commit is contained in:
parent
9ce06c0292
commit
d7dedd3baa
3 changed files with 41 additions and 66 deletions
|
@ -22,7 +22,7 @@ EXE_SUFFIX =
|
||||||
#USBLIBS = -L/usr/local/lib -lusb
|
#USBLIBS = -L/usr/local/lib -lusb
|
||||||
#EXE_SUFFIX = .exe
|
#EXE_SUFFIX = .exe
|
||||||
|
|
||||||
NAME = set-led
|
NAME = test
|
||||||
|
|
||||||
OBJECTS = opendevice.o $(NAME).o
|
OBJECTS = opendevice.o $(NAME).o
|
||||||
|
|
||||||
|
|
BIN
client/set-led
BIN
client/set-led
Binary file not shown.
|
@ -27,30 +27,16 @@ respectively.
|
||||||
#include "../firmware/requests.h" /* custom request numbers */
|
#include "../firmware/requests.h" /* custom request numbers */
|
||||||
#include "../firmware/usbconfig.h" /* device's VID/PID and names */
|
#include "../firmware/usbconfig.h" /* device's VID/PID and names */
|
||||||
|
|
||||||
static void usage(char *name)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "usage:\n");
|
|
||||||
fprintf(stderr, " %s on ....... turn on LED\n", name);
|
|
||||||
fprintf(stderr, " %s off ...... turn off LED\n", name);
|
|
||||||
fprintf(stderr, " %s status ... ask current status of LED\n", name);
|
|
||||||
#if ENABLE_TEST
|
|
||||||
fprintf(stderr, " %s test ..... run driver reliability test\n", name);
|
|
||||||
#endif /* ENABLE_TEST */
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
usb_dev_handle *handle = NULL;
|
usb_dev_handle *handle = NULL;
|
||||||
const unsigned char rawVid[2] = {USB_CFG_VENDOR_ID}, rawPid[2] = {USB_CFG_DEVICE_ID};
|
const unsigned char rawVid[2] = {USB_CFG_VENDOR_ID}, rawPid[2] = {USB_CFG_DEVICE_ID};
|
||||||
char vendor[] = {USB_CFG_VENDOR_NAME, 0}, product[] = {USB_CFG_DEVICE_NAME, 0};
|
char vendor[] = {USB_CFG_VENDOR_NAME, 0}, product[] = {USB_CFG_DEVICE_NAME, 0};
|
||||||
char buffer[4];
|
char buffer[4];
|
||||||
int cnt, vid, pid, isOn;
|
int cnt, vid, pid;
|
||||||
|
|
||||||
usb_init();
|
usb_init();
|
||||||
if(argc < 2){ /* we need at least one argument */
|
|
||||||
usage(argv[0]);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
/* compute VID/PID from usbconfig.h so that there is a central source of information */
|
/* compute VID/PID from usbconfig.h so that there is a central source of information */
|
||||||
vid = rawVid[1] * 256 + rawVid[0];
|
vid = rawVid[1] * 256 + rawVid[0];
|
||||||
pid = rawPid[1] * 256 + rawPid[0];
|
pid = rawPid[1] * 256 + rawPid[0];
|
||||||
|
@ -81,55 +67,44 @@ int cnt, vid, pid, isOn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(strcasecmp(argv[1], "status") == 0){
|
int i,x,y,z,onoff = 0;
|
||||||
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_STATUS, 0, 0, buffer, sizeof(buffer), 5000);
|
while (1)
|
||||||
if(cnt < 1){
|
{
|
||||||
if(cnt < 0){
|
onoff = (onoff == 0) ? 1 : 0;
|
||||||
fprintf(stderr, "USB error: %s\n", usb_strerror());
|
for (x = 0; x <3; x++)
|
||||||
}else{
|
for (y = 0; y <3; y++)
|
||||||
fprintf(stderr, "only %d bytes received.\n", cnt);
|
for (z = 0; z <3; z++)
|
||||||
}
|
{
|
||||||
}else{
|
for (i = 0; i < 4; i++)
|
||||||
printf("LED is %s\n", buffer[0] ? "on" : "off");
|
{
|
||||||
}
|
int v = 0;
|
||||||
}else if((isOn = (strcasecmp(argv[1], "on") == 0)) || strcasecmp(argv[1], "off") == 0){
|
if (i == 0)
|
||||||
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, isOn, 0, buffer, 0, 5000);
|
v = x;
|
||||||
if(cnt < 0){
|
if (i == 1)
|
||||||
fprintf(stderr, "USB error: %s\n", usb_strerror());
|
v = y;
|
||||||
}
|
if (i == 2)
|
||||||
#if ENABLE_TEST
|
v = z;
|
||||||
}else if(strcasecmp(argv[1], "test") == 0){
|
if (i == 3)
|
||||||
int i;
|
v = onoff;
|
||||||
srandomdev();
|
cnt = -1;
|
||||||
for(i = 0; i < 50000; i++){
|
do {
|
||||||
int value = random() & 0xffff, index = random() & 0xffff;
|
sleep(1);
|
||||||
int rxValue, rxIndex;
|
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, v, 0, buffer, 0, 5000);
|
||||||
if((i+1) % 100 == 0){
|
if (cnt < 0)
|
||||||
fprintf(stderr, "\r%05d", i+1);
|
{
|
||||||
fflush(stderr);
|
if(usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0){
|
||||||
}
|
fprintf(stderr, "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid, pid);
|
||||||
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_ECHO, value, index, buffer, sizeof(buffer), 5000);
|
|
||||||
if(cnt < 0){
|
|
||||||
fprintf(stderr, "\nUSB error in iteration %d: %s\n", i, usb_strerror());
|
|
||||||
break;
|
|
||||||
}else if(cnt != 4){
|
|
||||||
fprintf(stderr, "\nerror in iteration %d: %d bytes received instead of 4\n", i, cnt);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
rxValue = ((int)buffer[0] & 0xff) | (((int)buffer[1] & 0xff) << 8);
|
|
||||||
rxIndex = ((int)buffer[2] & 0xff) | (((int)buffer[3] & 0xff) << 8);
|
|
||||||
if(rxValue != value || rxIndex != index){
|
|
||||||
fprintf(stderr, "\ndata error in iteration %d:\n", i);
|
|
||||||
fprintf(stderr, "rxValue = 0x%04x value = 0x%04x\n", rxValue, value);
|
|
||||||
fprintf(stderr, "rxIndex = 0x%04x index = 0x%04x\n", rxIndex, index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fprintf(stderr, "\nTest completed.\n");
|
|
||||||
#endif /* ENABLE_TEST */
|
|
||||||
}else{
|
|
||||||
usage(argv[0]);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} while (cnt < 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stdout, "%d %d %d %d\n",x,y,z,onoff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
usb_close(handle);
|
usb_close(handle);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in a new issue