uint8_t msController::msDeviceInquiry(msInquiryResponse_t * const Inquiry)
{
msCommandBlockWrapper_t CommandBlockWrapper = (msCommandBlockWrapper_t)
{
.Signature = CBWSIGNATURE,
.Tag = ++CBWTag,
.TransferLength = sizeof(msInquiryResponse_t),
.Flags = CMDDIRDATAIN,
.LUN = 0,
.CommandLength = 6,
.CommandData = {CMDINQUIRY,0x00,0x00,0x00,0x00,0x00}
};
Serial.printf("## msDeviceInquiry before do command %u\n", sizeof(msInquiryResponse_t) );
uint8_t retval = msDoCommand(&CommandBlockWrapper, Inquiry);
Serial.printf("## msDeviceInquiry after do command %u\n", retval );
return retval;
}
...
uint8_t msController::msDoCommand(msCommandBlockWrapper_t *CBW, void *buffer)
{
if(CBWTag == 0xFFFFFFFF)
CBWTag = 1;
if((CBW->Flags == CMDDIRDATAIN)) { // Data from device
if (!queue_Data_Transfer(datapipeOut, CBW, sizeof(msCommandBlockWrapper_t), this)) {
println("msController::msDoCommand QDT failed CMDDIRDATAIN OUT");
}
if (!queue_Data_Transfer(datapipeIn, buffer, CBW->TransferLength, this)) {
println("msController::msDoCommand QDT failed CMDDIRDATAIN IN");
}
while(!msOutCompleted); // Wait for out transaction to complete.
println("msDoCommand after msOutCompleted loop");
while(!msInCompleted); // Wait for in transaction to complete.
println("msDoCommand after msInCompleted loop");
} else { // Data to device
if (!queue_Data_Transfer(datapipeOut, CBW, sizeof(msCommandBlockWrapper_t), this)) {
println("msController::msDoCommand QDT failed ELSE OUT");
}
while(!msOutCompleted); // Wait for out transaction to complete.
if (!queue_Data_Transfer(datapipeOut, buffer, CBW->TransferLength, this)) {
println("msController::msDoCommand QDT failed ELSE OUT 2");
}
while(!msOutCompleted); // Wait for second out transaction to complete.
}
// Reset completion flags.
msOutCompleted = false;
msInCompleted = false;
return msGetCSW(); // Get status of last transaction
}