-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SD get pointer block #528
Comments
item = SD file (get) pointer emits item = fp; It should instead emit item = ftell(fp); In propeller C, this value is negative. It might be better to use a larger routine that returns a pre-digested value that the user can apply in SD file (set) pointer. Also, SD file (set) pointer = item emits fp = item. It should instead emit fseek(fp, item, SEEK_CUR); |
@AndyLindsay, I am not quite getting the exact purpose of the get pointer block mode. If the block is supposed to seek, wouldn't we need an input value to say how far to seek from the current position? As it is now, it just returns the FILE *. |
@zfi, I'm suggesting that the SD file (set) pointer = item blocks emit fseek(fp, item, SEEK_CUR); That will move the pointer to the desired position in the file. In the example, I'm using the item variable, and assuming it stores an int, but it could also be a value block. For SD file (get) pointer, I'm suggesting that it call ftell(fp), which returns the pointer's offset in the file. So, in item = SD file (get) pointer, the item variable would receive the result of the ftell(fp) call. |
Regarding the SD file (set/get) pointer, I do agree that it would make sense to have two separate blocks: SD file set pointer = and = SD file get pointer. This would be consistent with the most basic operations in Pin states, where we have make PIN (0) = [high] and = check PIN [0]. Their functions are inverses of each other, and so they separate blocks, one with the input shape, and the other with the output shape. The SD blocks have not received much use yet, so I would not expect changing them from one to two blocks would have minimal impact. |
@zfi, P.S. Regarding what I said about the SD file (set) pointer = item blocks emitting fseek(fp, item, SEEK_CUR), are you suggesting to use fseek(fp, item, SEEK_SET) instead? If so, I agree. Sorry, got my constants mixed up. |
The single block will continue to offer file pointer 'get' and 'set' functionality until we refactor this into two separate blocks. The 'set' mode now uses fseek() with an anchor reference to the start of the file (SEEK_SET). The block, when configured initially to the 'set' mode will generate console error messages if the mode is changed to 'get' while the block is attached to any other block. It is this behavior that is driving the requirement for separate blocks for 'set' and 'get'. |
This issue is addressed in v.1.5.7 released on 1/16/2021. |
@VonSzarvas, can you confirm that the SD file get/set pointer is working more to your liking? We can close this issue if it is resolved. |
I'm not sure what GET Pointer is returning, or how SET pointer is supposed to operate. To me something seems off, but if Andy is happy then I'm good to accept my understanding is out of sync, and sure, close this issue. In the attached example, an existing file is opened. GET pointer is 0. ie. As this test shows, SET pointer doesn't set the character position, and GET pointer doesn't return the character position. Whereas, the Blockly docs currently show : The SD file set block sets or retrieves the current file pointer (location in characters where reads or writes begin from). |
@VonSzarvas and @zfi, I didn't notice the fine print where it said that ftell doesn't return meaningful values for text files. Sorry about that! The SD file get pointer will need different C code. Based on my C tests, the SD file set pointer block should work fine, but I will send an update after testing with the blocks. |
cplusplus.com says this about ftell (source):
With that in mind, I started looking for ftell values in C. The test code below was returning zero every time. As soon as I put fgetc calls before each ftell, it seemed to return an accurate offset from the end of the file. ...up until that offset exceeds 15. Then, the number is 15 regardless. Below is example code and the output. Could this be a PropGCC issue, or just a coding error on my part? Example code
Output c = n |
@zfi, The SD file set pointer feature:
The SD file get pointer feature:
|
The cloud compiler is using this version of propgcc:
What version should the cloud compiler use if it 's not this version? The next issue would be figuring out which branch of that propgcc repo to use. @PropGit, Can you lend a hand in locating a more current version of the propgcc compiler? |
v1_0_0_2411 is the correct version. In testing that fix, it does appear to correctly reflect the pointer after fseek, but it does not provide correct updates after fread. |
Add the SD pointer block and set to "get".
Notice the block is not formed to allow the result variable to be attached.
Click code and get white screen. Click compile and error or hang.
The text was updated successfully, but these errors were encountered: