aanon4 / BlueBasic

BASIC interpreter for CC2540 and CC2541 Bluetooth LE chips
https://gitlab.com/timwilkinson/BlueBasic
97 stars 55 forks source link

Writing Array fails #33

Open kscheff opened 7 years ago

kscheff commented 7 years ago

Hello,

I understand that this repro is kind of "dead" since Tim has left the project. However this is the only place to "hope" for exchange of experience... maybe someone is reading here.

Writing an array to a file works, however after the write command the execution stalls. Here is my program list

10 OPEN 0, READ "A"
15 FOR I = 1 TO 10
20  READ #0, B
30  PRINT I,",",B
40 NEXT I
60 RETURN 
100 OPEN 0, TRUNCATE "A"
110 DIM U(10)
120 WRITE #0, U
140 CLOSE 0
150 RETURN 

goto 100
Bad expression
>> 140 CLOSE 0

I can read the file successfully by walking to its elements via:

run
1,0
2,0
3,0
4,0
5,0
6,0
7,0
8,0
9,0
10,0
OK

The issue I am fighting is that I wanted to implement an IoT data logger for solar cells mounted on the camping car. Therefore I need a way to store and access some historic values. Doing by writing single vars wastes a lot of memory, e.g. each var occupies 8 bytes (examine the reported memory). So I was looking to write an array instead. It looks like that each array element consumes 1 byte.

I have tried to write different array sizes since I suspected an alignment requirements, but this fails, too. I tried array sizes of 1, 2, 3, 4, 5, 8, 16. Also I checked different file name "A" or "F".

Is there anybody out there that have successfully used these functions?

Thanks Kai

kscheff commented 7 years ago

I found a workaround for the issue by not closing the file after WRITE and instead place a RETURN after it. My write routine runs then in a timer interrupt.

Update 30-Aug-2017: This issues is present for all READ and WRITE commands using an array variable as an argument since parse_variable_address() expects braces behind the array name. This leads to an ERROR_EXPRESSION to the following command.

Workaround: After such an command assign an expression with no evaluation requirement. This clears the previous error. See below example line number 30 for such a fix.

10 DIM V(2)
20 READ # SERIAL, V
30 E = E
40 PRINT V(0)
50 PRINT V(1)

It can be fixed in the BlueBasic_Interpreter.c extending the function parse_variable_address() to avoid parsing the index in such cases.

kaiateic commented 7 years ago

Hi Kai,

I think, in some cases, the interpreter goes on to the next command before it is finished with the current command. File IO might be one of them. Try putting DELAY 1000 before your CLOSE command and see if that fixes it.

BTW, we are considering porting BlueBasic to a more modern platform (cc2650). TI seems to be pushing that micro. Do you want to get involved?

Cheers, Kai

kscheff commented 7 years ago

@kaiateic this might be a test worth... be aware there are other issues with the DELAY command when in a GOSUB during a GATT access.

I have looked into the cc2650 for some projects, so far ready modules with this device are rare and expensive (thus I can imagine TI is more interested in pushing this device to get out of the low margin cc2541 modules). However the cc2650 has some nice features like lower power and more processing.

I have the dev kit in my drawer.... so there is interest on my side.

Cheers Kai

kaiateic commented 7 years ago

Great!

Let's take this conversation off line. Email me at kai@eic.nu

ozarchie commented 7 years ago

Hi Kai, Have a look at alibaba-radioland for the cc256x devices. They are now in the $2-4 range. I would be interested in helping port/test Bluebasic. I am currently using the existing code in hydroponic automation. Cheers, ozarchie

On 4 Jan 2017 5:23 AM, "kaiateic" notifications@github.com wrote:

Great!

Let's take this conversation off line. Email me at kai@eic.nu

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/aanon4/BlueBasic/issues/33#issuecomment-270199826, or mute the thread https://github.com/notifications/unsubscribe-auth/AGLdJxOBwImzS5CDyp1nV_2Y4XfWaHiXks5rOqAqgaJpZM4Kv9DN .

kaiateic commented 7 years ago

Hi Ozarchie Email me at the address above and lets take this offline. Kai

kscheff commented 7 years ago

@ozarchie I couldn't find a module with the CC256x device. Currently I am getting CC2541 modules JPY-8 for < $2.30 in quantities of 10. If you a link for a CC256x device please send it to me.

TX Kai

ozarchie commented 7 years ago

Hi Kai, Try http://en.szrfstar.com. I have used them for 254x but not 256x Cheers, John

On 9 Jan 2017 4:05 AM, "kscheff" notifications@github.com wrote:

@ozarchie https://github.com/ozarchie I couldn't find a module with the CC256x device. Currently I am getting CC2541 modules JPY-8 for < $2.30 in quantities of 10. If you a link for a CC256x device please send it to me.

TX Kai

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/aanon4/BlueBasic/issues/33#issuecomment-271167642, or mute the thread https://github.com/notifications/unsubscribe-auth/AGLdJ0G_X7yJ-BBRXh9RfFuI9o6UivNUks5rQSV6gaJpZM4Kv9DN .

kaiateic commented 7 years ago

Looks like there are a lot more FCC certified modules available using Nordic chips than TI. (If it doesn't have shielding, it's not fully certified.) Might be a better idea to port to Nordic instead? Kai

kscheff commented 7 years ago

Bugfix see here: https://github.com/kscheff/BlueBasic/commit/447765a015cdad66632670f79012363768bb4b21