Pages: [1]   Go Down
Author Topic: FileIO.cpp fix on File::doBuffer()  (Read 852 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  uint8_t cmd[] = {'G', handle, sizeof(buffer)};
to
Code:
  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)
Logged

Offline Offline
Edison Member
*
Karma: 38
Posts: 1380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Have you upgraded the Yún? If you've just got it, then it needs to be upgraded! Check out the tutorial

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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

* test1.txt (0.06 KB - downloaded 20 times.)
* test4.txt (0.07 KB - downloaded 14 times.)
« Last Edit: November 25, 2013, 06:41:56 am by fabiog45 » Logged

Offline Offline
Edison Member
*
Karma: 38
Posts: 1380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Have you upgraded the Yún? If you've just got it, then it needs to be upgraded! Check out the tutorial

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@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:
#!/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.
Logged

C.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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.
 smiley
fabiog45
Logged

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Great!

thank you for the clear bug report and for the feedback smiley-wink
Logged

C.

Pages: [1]   Go Up
Jump to: