Go Down

Topic: FileIO.cpp fix on File::doBuffer() (Read 880 times) previous topic - next topic

dreggy

I searched for a github repository for the Bridge library but i didn't found it, so i'm posting here

In the file FileIO.cpp, line 121 you have to change
Code: [Select]
  uint8_t cmd[] = {'G', handle, sizeof(buffer)};
to
Code: [Select]
  uint8_t cmd[] = {'G', handle, sizeof(buffer)-1};

otherwise you will lose bytes while reading files largen then the buffer (maybe because of the shift routine at line 127~128)

Federico Fissore

Thank you for spotting the bug: can you open an issue on the git repo of the IDE? (the cpp side of the bridge is part of it)
https://github.com/arduino/Arduino/issues?direction=desc&sort=created&state=open
Have you upgraded the Yún? If you've just got it, then it needs to be upgraded! Check out the tutorial

fabiog45

#2
Nov 11, 2013, 09:28 am Last Edit: Nov 25, 2013, 12:41 pm by fabiog45 Reason: 1
Hi,
I've done the changes in FileIO.cpp you suggested but I still have problems with "some" files greater than 63 Bytes. I say "some" files because i can read other files bigger than 63 bytes without problems.
Here the code I use for the test
Code: [Select]
#include <Console.h>
#include <FileIO.h>
 
void setup () {
 
 Bridge.begin();
 FileSystem.begin();
 Console.begin();
 // wait for the console
 while (!Console);
   Console.println("Console Ok");
}
 
void loop () {
 
 String fileData;

 File tempFile = FileSystem.open("/mnt/sda1/test1.txt", FILE_READ);
 delay(100);
 if (tempFile) {
   //Console.println("tempFile = true");
   fileData = "";
   while(tempFile.available()>0) {
     //unsigned int h = tempFile.available();
     Console.print(tempFile.available());
     //Console.print(h);
     Console.print(" ");
     delay(20);
     char c = tempFile.read();
     //Console.print(" * ");
     //Console.println(c);
     //Console.print(" - ");
     Console.println(c, DEC);
     fileData += c;
     }
   }
 tempFile.flush();
 Console.println(fileData);
 delay(3000);
 tempFile.close();
}


I use Console only for debugging.
Attached the 2 files I use for test:
- test1.txt (63 bytes, give the above mentionned problem)
- test4.txt (72 bytes, work flawlessy)

Hope somebody could help me.
Thanks in advance.
Fabio Gubler

Federico Fissore

Can you give a spin to a nightly version of the IDE? http://arduino.cc/en/Main/Software#toc4
They includes all the latest fixes including that from dreggy and are candidate to be next IDE release
Have you upgraded the Yún? If you've just got it, then it needs to be upgraded! Check out the tutorial

fabiog45

First of all thanks for your message.
I've given a try to the nightly version of the IDE.
First try :  I've inserted in the IDE 1.5.4 the fileio.cpp and fileio.h files taken from the nightly version of the IDE.
No luck, problem still present.
Second try: I started the full nightly version of the IDE,  loading the sketch to test the read  from a file written on the SD card behaivour.
Again no luck.
I' really curious to understand why whit one test file (test4.txt) I haven't problem and with the other one (test1.txt) such strange error appear.
Thanks again for your help.
Regards.
Fabio


cmaglie

@fabiog45

I've checked your sketch with file1.txt and the problem randomly happens (about 1 time out of 4 or 5).

Would you like to try to change the /usr/bin/run-bridge script on the yun with the following:

Code: [Select]

#!/bin/sh

cd /usr/lib/python2.7/bridge

exec python -u bridge.py 2> /tmp/bridge.py-stderr.log


I've added the "-u" flag on the last line, that tells python to not line-buffer incoming data from the 32u4.
After this change I wasn't able to reproduce the bug, anymore, I want to know how it works for you.
C.

fabiog45

@cmaglie

Hi,
your suggestion seem to have solved the problem I've pointed out.
I've tried several time with different file size and different kind of file and the bug did'nt arose.
Thanks a lot for your help. I've declared the issue as solved.
:)
fabiog45

cmaglie

Great!

thank you for the clear bug report and for the feedback ;)
C.

Go Up