Thank you Vloki for your response.
Yeah, I should make a new button, command, and flag.
but, what about sending procedure, my main problem?
- add a new flag.EEread or something
- in APPcmd() you set this flag when you decode the new command
so"
- Code: Select all
void APP_cmd(void) {
switch (ReceivedDataBuffer[1]) {
case CID_READ_EE: // decoding new command & also sending (CID_READ_EE) as the acknowledge for // the read request
ToSendDataBuffer[1] = CID_READ_EE | ID_MESSAGE; //CID_READ_EE = 0x70;
Flags.EEread = 1;
break;
}}
now, checking new flag :
- Code: Select all
void APP_CustomHIDTasks()
{
if(!HIDRxHandleBusy(USBOutHandle))
APP_usbOUT(); // Data USB(pc) -> PIC
if( (!HIDTxHandleBusy(USBInHandle)){
if(Flags.IN_TODO){
APP_usbIN(); // Data PIC -> USB(pc)
Flags.IN_TODO = 0;
}
else if(Flags.EEread){
for (unsigned char packet_num = 0 ; packet_num < 4 ; packet_num ++)
{
for ( num_of_samples = 2 ; num_of_samples < 64 ; num_of_samples++ )
ToSendDataBuffer[num_of_samples] = my_data; //to fill the buffer with required data
APP_usbIN(); // Data PIC -> USB(pc)
}
Flags.EEread = 0;
}
}//end ProcessIO
should I prepare whole of the data before starting of sending packets? or is it possible to prepare it during every cycle of packet sending (like above line)? these are my main questions.
the PC side:
- Code: Select all
void MainWindow::rxHandler()
{
io_result = hid_read(connected_device, inBuffer, 65);
switch (inBuffer[1] - ID_MESSAGE) //---------------------- MESSAGE
{
case CID_READ_EE:
for (int packet_num = 0; packet_num < max_packet_num ; packet_num++)
{
for (long int count = 0; count < 65; count++){
long int numm = count + packet_num * 64;
my_store[numm] = inBuffer[count];
}
io_result = hid_read(connected_device, inBuffer, 65);
}
myfile.open("file.txt", ios::out | ios::binary);
for (int ii=0 ; ii < 300 ; ii++)
myfile << " " << hex << int(my_store[ii]) << endl;
myfile.close();
break;
}
how should "sending from PIC" and "receiving in PC" become synchronized? what should I do to prevent form packet losses?
given these, what I see in file.txt is the last (4th) packet which is copies 4 times...
it seems only the last packet receives...
should I send a specific packet to show that sending whole of the data is finished?