NXC: set / change Brick name?
Re: NXC: set / change Brick name?
In recent versions of BricxCC you can also double click on the NXT Name in the Diagnostic tool to change the brick's name. The SetBrickDataName function which used to exist did not properly "commit" the name change. There isn't currently any way to do it from within a running program.
John Hansen
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: NXC: set / change Brick name?
Is there a way to change the brick name in program?
Re: NXC: set / change Brick name?
afanofosc wrote:There isn't currently any way to do it from within a running program.
...studbrickmaster wrote:Is there a way to change the brick name in program?
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Re: NXC: set / change Brick name?
Sorry I missed that.muntoo wrote:afanofosc wrote:There isn't currently any way to do it from within a running program....studbrickmaster wrote:Is there a way to change the brick name in program?
Re: NXC: set / change Brick name?
Understandable. John does write pretty cryptic messages - in fact, he stopped using AES a few years ago.studbrickmaster wrote:Sorry I missed that.
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
-
- Posts: 117
- Joined: 27 Dec 2010, 19:27
Re: NXC: set / change Brick name?
Oh god, I spent so much time trying to change the name of the brick from a program, before I found this post.
I tried SysIOMapWrite, SysIOMapWriteByID, SysCommExecuteFunction with INTF_SETBTNAME, but nothing... yet, different experiences.
1) SysCommExecuteFunction with INTF_SETBTNAME doesn't work at all. I tried passing the new name in the parameter "Name" of the structure CommExecuteFunctionType, but didn't work.
2) SysIOMapWrite and ..ByID seem to work, until I restart the NXT. The new name appears in the top bar of the screen, and if you check the Diagnostic tool in BricxCC, the new name is there. As soon as you restart it, the old name comes back.
I'm just curious, why is it behaving like this? And why changing throught Diagnostics works?
I tried SysIOMapWrite, SysIOMapWriteByID, SysCommExecuteFunction with INTF_SETBTNAME, but nothing... yet, different experiences.
1) SysCommExecuteFunction with INTF_SETBTNAME doesn't work at all. I tried passing the new name in the parameter "Name" of the structure CommExecuteFunctionType, but didn't work.
2) SysIOMapWrite and ..ByID seem to work, until I restart the NXT. The new name appears in the top bar of the screen, and if you check the Diagnostic tool in BricxCC, the new name is there. As soon as you restart it, the old name comes back.
I'm just curious, why is it behaving like this? And why changing throught Diagnostics works?
-
- Posts: 117
- Joined: 27 Dec 2010, 19:27
Re: NXC: set / change Brick name? (Solution)
Good news! Found a way to do it! (John, maybe you find it usefull to add to the Enhanced FW)
After digging in the FW, this is what I got:
- Apperantly, an IOMapWrite only writes to the IOMap, which produces a change in the screen but not in the Bluetooth device. This makes sense.
- On the other hand, the FW command SETBTNAME, which is invoqued by the NXC function SysCommExecuteFunction with Cmd = INTF_SETBTNAME, only updates the brick name in the Bluetooth device, by copying the one stored in the IOMap.
So, combining both, we get the name actually changed:
But now, looking deeper in the firmware, the variable UBYTE *pName, is anyway passed to the function cCommReq, which makes it quite trivial to use the element Name in the structure CommExecuteFunctionType to actually change the name of the brick only using SysCommExecuteFunction().
I changed a couple of lines, not more, and made it work. I added the following lines to the FW (in "case: SETBTNAME", c_comm.c):
...and removed the same lines from the case "SETBRICKNAME", c_comm.c, which were being executed for the remote control request (like used in Diagnostics).
Now, the NXC code looks like:
I guess this peice of code is similar to the old "SetBrickName". I am not an expert in the FW stuff, but it seems a worth change(?).
After digging in the FW, this is what I got:
- Apperantly, an IOMapWrite only writes to the IOMap, which produces a change in the screen but not in the Bluetooth device. This makes sense.
- On the other hand, the FW command SETBTNAME, which is invoqued by the NXC function SysCommExecuteFunction with Cmd = INTF_SETBTNAME, only updates the brick name in the Bluetooth device, by copying the one stored in the IOMap.
So, combining both, we get the name actually changed:
Code: Select all
task main(){
byte data[];
IOMapWriteType IOargs;
CommExecuteFunctionType Fargs;
IOargs.ModuleName = CommModuleName;
IOargs.Offset = CommOffsetBrickDataName;
ArrayBuild(data, "Ricardo");
IOargs.Buffer = data;
SysIOMapWrite(IOargs);
Fargs.Cmd = INTF_SETBTNAME;
SysCommExecuteFunction(Fargs);
while(true);
}
But now, looking deeper in the firmware, the variable UBYTE *pName, is anyway passed to the function cCommReq, which makes it quite trivial to use the element Name in the structure CommExecuteFunctionType to actually change the name of the brick only using SysCommExecuteFunction().
I changed a couple of lines, not more, and made it work. I added the following lines to the FW (in "case: SETBTNAME", c_comm.c):
Code: Select all
cCommInsertBtName(IOMapComm.BrickData.Name, pName);
pMapUi->Flags |= UI_REDRAW_STATUS;
Now, the NXC code looks like:
Code: Select all
task main(){
CommExecuteFunctionType Fargs;
Fargs.Cmd = INTF_SETBTNAME;
Fargs.Name = "Ricardo";
SysCommExecuteFunction(Fargs);
while(true);
}
Re: NXC: set / change Brick name?
Just for the record, there's a direct command to change the NXT's name -- maybe one can inspect the underlying firmware code?
Edit: Never mind, I just saw that that's what you didAppendix 1-LEGO MINDSTORMS NXT Communication protocol.pdf wrote: SET BRICK NAME COMMAND
Byte 0: 0x01
Byte 1: 0x98
Byte 2-17: New name of brick (15 characters + null terminator)
RWTH - Mindstorms NXT Toolbox for MATLAB
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
Re: NXC: set / change Brick name?
Can someone persuade me that changing the brick's name from a running program is a Really Important Feature? What does this buy you?
John Hansen
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
-
- Posts: 117
- Joined: 27 Dec 2010, 19:27
Re: NXC: set / change Brick name?
I agree it is usefull very very rarely. I understand it may not be worth the time/effort/risk(?) to change. But I give my example:
When I run the program on my robot, I need it to be visible to connect with a PC application that only connects to the right NXT device with a specific name. If that name is changed, the app fails. Because it is possible to change this BT name remotely, by whoever accesses it, I need to ensure that everytime I start the program, the NXT name remains the same.
When I run the program on my robot, I need it to be visible to connect with a PC application that only connects to the right NXT device with a specific name. If that name is changed, the app fails. Because it is possible to change this BT name remotely, by whoever accesses it, I need to ensure that everytime I start the program, the NXT name remains the same.
Who is online
Users browsing this forum: No registered users and 7 guests