The script developed for usb are from outsource. Everything seems to work correctly, but during a read operation, an empty buffer of length 128 bytes are sent and after execute the library (libusb_interrupt_transfer), there an updated value(rsp) of length 128.This return value will be used to determine which drive managed to toggle LED. However, the return value are always inconsistent.
//@file hk_arm.cpp
void arm_comm_eusb2(char *cmd, char *rsp, int num_reads, int time_delay)
{
int ret = 0, num;
if(eusb_handle==NULL) {
fprintf(stderr, "No eusb handle\n");
return;
}
if(cmd==NULL) {
fprintf(stderr, "No command buffer\n");
return;
}
if(num_reads>5) num_reads = 5;
if(num_reads<0) num_reads = 0;
ret = libusb_interrupt_transfer((libusb_device_handle *)eusb_handle, 0x04, (unsigned char *)cmd, 32, &num, 1000);
if(ret < 0) {
fprintf(stderr, "usb_interrupt_write error(cmd %s]!\n", cmd);
}
if (rsp == NULL) {
return;
}
MyDelay(time_delay);
while(num_reads--) {
//intermittent result of rsp
ret = libusb_interrupt_transfer((libusb_device_handle *)eusb_handle, 0x83, (unsigned char *)rsp, 128, &num, 5000);
if(ret < 0) {
fprintf(stderr, "usb_interrupt_read error!\n");
}
}
}
int arm_read_word_eusb2(char *cmd, int* slotvalue, int time_delay)
{
char msg[32];
char rsp[128];
int i;
memset(rsp, 0, 128);
memset(msg, 0, 32);
memcpy(msg, cmd, 32);
arm_comm_eusb2(msg, rsp, 1, time_delay);
//if (strncmp(rsp, "*SRESET>OK", 10) == 0) {
for(i=0; i<8; i++){
slotvalue[i] = rsp[i*2+8]- '0';
//slotvalue[i+8] = rsp[i*2+8]- '0';
//fprintf(stderr,"slot %d: value=%d\n", i,slotvalue[i]);
}
//}
// fprintf(stderr, "[%s]:%s\n", cmd, rsp);
return 1;
}
void eusb_removeReset(int * slot_value, int value)
{
char buf[32];
memset(buf, 0, 32);
memset(eusb_slot, 0, sizeof(eusb_slot));
sprintf(buf, "@RRESET %d ", value);
arm_read_word_eusb2(buf, slot_value, value );
return;
}
//file util.cpp
void eusb_checkrreset(int value)
{
int i;
int slot_value[16];
if((Mach.eusb_board1 == false) && (Mach.eusb_board2 == false)){
fprintf(stderr,"Mach.eusb_board1 and Mach.eusb_board1 are false\n");
mark_all_devices_bad(SS_EUSBARMERR);
return;
}
if(Mach.eusb_board1)
eusb_removeReset(slot_value, value);
if(Mach.eusb_board2)
eusb_removeReset2(slot_value, value);
power_recycle_all(false, 1);
for (i = 0; i < NUMSLOT; i++) {
if (eusb_slot[i]==1){
if (is_slot_active(i) == 0){
fprintf(stderr,"slot %d: remove reset fail\n", i);
flag_slot_error(i, SS_EUSBRRESETERR);
}else
fprintf(stderr,"slot %d: remove reset pass\n", i);
if (slot_value[i] == 0){
fprintf(stderr,"slot %d: activity fail\n", i);
flag_slot_error(i, SS_EUSBACTERR);
}else
fprintf(stderr,"slot %d: activity pass\n", i);
}
}
}