Page 1 of 2
Bluetooth send float
Posted: 24 Jan 2012, 03:05
by mcsummation
I would like to be able to send a float from an NXT up to the PC using Bluetooth. If someone would tell me where to find the implementation of SendResponseNumber is located, I can implement SendResponseFloat and provide the code for others.
Re: Bluetooth send float
Posted: 24 Jan 2012, 17:55
by afanofosc
Here's the underlying implementation from NXTDefs.h:
Code: Select all
#define __sendResponseNumber(_queue, _val, _result) \
acquire __MWMutex \
add __MWArgs.QueueID, _queue, 10 \
mov __SRNTmpVal, _val \
flatten __MWArgs.Message, __SRNTmpVal \
syscall MessageWrite, __MWArgs \
mov _result, __MWArgs.Result \
release __MWMutex
#define __sendResponseString(_queue, _msg, _result) \
acquire __MWMutex \
add __MWArgs.QueueID, _queue, 10 \
mov __MWArgs.Message, _msg \
syscall MessageWrite, __MWArgs \
mov _result, __MWArgs.Result \
release __MWMutex
You can use something like this:
Code: Select all
#define SendResponseFloat(_queue, _val) \
asm { \
acquire __MWMutex \
add __MWArgs.QueueID, _queue, 10 \
flatten __MWArgs.Message, _val \
syscall MessageWrite, __MWArgs \
mov __RETVAL__, __MWArgs.Result \
release __MWMutex \
}
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.
John Hansen
Re: Bluetooth send float
Posted: 25 Jan 2012, 00:00
by mcsummation
After crawling through the code dribbled out to the .sym file, I finally came up with a couple of functions:
Code: Select all
char SendResponseFloat(byte queue, float val)
{
byte _local_buffer[5];
byte _local_queue = queue + 10;
asm
{
flatten _local_buffer, val
}
_local_buffer[4] = 0;
return(SendMessage (_local_queue, _local_buffer));
}
char ReceiveRemoteFloat(byte queue, bool clear, float & val)
{
byte _local_buffer[5];
bool bErr;
float _local_default = 5;
char cError;
cError = ReceiveMessage (queue, clear, _local_buffer);
asm
{
unflatten val, bErr, _local_buffer, _local_default
}
return(cError);
}
These may not be as good as yours (I'm still trying to come to grips with NBC), but they are working for me.
I've been writing code for 50 years; however, I can always find new ways to "bother" a computer and its various languages.
Re: Bluetooth send float
Posted: 25 Jan 2012, 03:35
by afanofosc
You can see the NBC code generated by the compiler if you are using BricxCC without resorting to the .sym file by simply pressing F12.
John Hansen
Re: Bluetooth send float
Posted: 25 Jan 2012, 22:02
by mcsummation
Since the .sym file has line numbers in it, I find it easier to dig through.
I just started on BricxCC, NBC, and NXC last week, so I've still got a LOT to learn. Although, all of these bear striking resemblance to tools/assemblers/compilers I've used in the past.
Re: Bluetooth send float
Posted: 29 Jan 2012, 22:35
by mcsummation
A problem I ran into was that, using opt=2 in the NXC compiler, caused the brick to hang. I had to use opt=1 (or 0) to get the code to run. Is there some glitch with opt=2? Or did I do some foolish thing?
Edit: Should have included that I'm using BricxCC 3.3.8.9, 1.31 (from Lego) FW, and compiler options of: Use Internal Compiler, Enhanced Firmware, not Ignore system include files, NXT 2.0 compatible firmware, Automatic firmware version, and RICScript.
Re: Bluetooth send float
Posted: 30 Jan 2012, 08:08
by HaWe
using NXC it's always better to download the latest enhanced firmware, I would suggest to change this at first.
Re: Bluetooth send float
Posted: 30 Jan 2012, 18:04
by mcsummation
I downloaded the current "test release" from
http://bricxcc.sourceforge.net/test_releases/ and my code works for all opt levels of the NXC compiler.
Thanks for nudging me in the direction of loading a "test release" on my brick + BricxCC.
Re: Bluetooth send float
Posted: 30 Jan 2012, 18:35
by HaWe
you're welcom!
:)
I guess "nudging " is something meant to be taken nicely or so although I actually have no idea what that means (even Google translate doesn't) ^^
Re: Bluetooth send float
Posted: 30 Jan 2012, 19:31
by mcsummation
to nudge: verb
Prod (someone) gently, typically with one's elbow, in order to draw their attention to something.
Yes, it's meant in a friendly way.