Bluetooth send float

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Bluetooth send float

Post by HaWe »

:)
mcsummation
Posts: 220
Joined: 23 Jan 2012, 17:07
Location: Round Rock, TX

Re: Bluetooth send float

Post by mcsummation »

I did something that I know I shouldn't do - I updated the firmware without seeing what files were on the brick. I noticed something was missing when I turned the brick on and got no "startup" sound. I found that file, but now I'm wondering what other files need to be on the brick. Anyone have a list?
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: Bluetooth send float

Post by afanofosc »

Congratulations! You now have a very nice quiet NXT. I very much prefer to not have my NXT making noises all the time so the enhanced NBC/NXC firmware does not include the system sounds. It also does not include the rpgreader.sys file that is required to "run" RPG programs (the 5 step scripts that you can write on the brick using its menus).

You can get these files if you want them by flashing the standard LEGO NXT firmware which can be downloaded from the LEGO MINDSTORMS site. Once you have the standard firmware on your NXT you can copy the sound files to your computer using the NXT Explorer tool. Then you can flash the enhanced NBC/NXC firmware and afterward copy the sound files back to your NXT.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mcsummation
Posts: 220
Joined: 23 Jan 2012, 17:07
Location: Round Rock, TX

Re: Bluetooth send float

Post by mcsummation »

I had suspected that's what I would need to do. (I went back to the default Lego version of 1.31.) I have now done that and uploaded only those files I want. In the process, I've captured onto my laptop all the files involved.
mcsummation
Posts: 220
Joined: 23 Jan 2012, 17:07
Location: Round Rock, TX

Re: Bluetooth send float

Post by mcsummation »

afanofosc wrote: The existing SendResponseString could also be used like this:

Code: Select all

inline char SendResponseFloat(byte queue, float val)
{
  string tmp = FlattenVar(val);
  return SendResponseString(queue, tmp);
}
These are completely untested.
At the time you wrote this, I didn't think it would work. I didn't fully understand (not sure I do today) how strings work in NXC. I was thinking "standard C" where a string has a null character at the end. Since the floats usually have 1 or more zeroes in them, I didn't think the string stuff would work. Now that I understand that the strings in NXC are more like C+++ strings (have a length attribute with them) and not null terminated, it does indeed work. This morning I have rewritten my three BT.float functions using ...String functions. Works very well.

When I was working on some Bluetooth I/O enhancements in Code::Blocks, I noticed that the message buffers had both a length and a null character at the end. ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: Bluetooth send float

Post by afanofosc »

By way of clarification, strings in the NXT firmware are null terminated, as in they have a null at the end. StrLen is defined as ArrayLen - 1. The length of each array in a program is stored in a field in the array's dope vector structure which is stored in the dope vector array that is part of each program. This array is used to manage dynamically sized types (i.e., arrays) in the NXT firmware VM. Calling ArrayInit both initializes the memory for an array and sets the length field for that array.

So a flattened float = a 5 element long array of bytes ending with a null (aka a string). ArrayLen = 5, StrLen = 4 even if there are zeros before the zero in the 5th element.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 3 guests