Hello,
I realise this is probably quite simple but could anyone enlighten me as to the correct way to append a vector to a vector of vectors?
The source code below compiles and runs, but if you have two vectors of 64 x unsigned char (usbDataInBuffer) and you append one, and then append the other to the vector of vectors (pinTable) it will be found that the last row of unsigned char in the pinTable vector has twice the number of elements as the first row. Furthermore it will be seen that the extra data in the second row of pinTable will be a copy of the data which is supposed to be there.
Clearly I'm screwing something up here. All help appreciated.
The code is from the PC software side of a bespoke data acquisition (imaging) system for measurements in the field of microelectronics. The PC software is Qt, with Libusb 1.0 dealing with the interaction between Qt and the Linux USB kernel driver. The firmware side is based around a Microchip PIC 18F4550. I can guarantee that the PIC is sending the right data (2 packets of 64 x unsigned char).
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
/* Reads the number and positioning of the devices attached to the backplane.
* and returns it to the PC for viewing. This command must be run when the device is connected
* and prior to reading back any data. This is because the PIC firmware relys on being able to interogate
* the pinTable to see which devices constitute a "frame" depending on how many cards are plugged into the backplane
*/
QVector< QVector<unsigned char> > UsbConnection::readTable()
{
unsigned char OutputPacketBuffer[64] = {0};
unsigned char InputPacketBuffer[64] = {0};
int transferedBuffer;
unsigned char i,j;
QVector < unsigned char > usbDataInBuffer;
QVector< QVector< unsigned char > > pinTable;
// use this function to read back the device info from one of the modules
OutputPacketBuffer[0] = 0x83;
libusb_bulk_transfer(handle, EP_OUT, &OutputPacketBuffer[0], 64, &transferedBuffer, 1000);
for(i=0;i<2;i++)
{
libusb_bulk_transfer(handle, EP_IN, &InputPacketBuffer[0],64, &transferedBuffer, 1000);
for(j=0;j<64;j++)
{
usbDataInBuffer.push_back(InputPacketBuffer[j]);
}
pinTable.append(usbDataInBuffer);
}
return pinTable;
}
|
Cheers,
James