NXC: set / change Brick name?

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: set / change Brick name?

Post by afanofosc »

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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
bungeshea
Posts: 207
Joined: 14 Aug 2011, 08:45
Location: Australia
Contact:

Re: NXC: set / change Brick name?

Post by bungeshea »

Is there a way to change the brick name in program?
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: set / change Brick name?

Post by muntoo »

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?
...
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
bungeshea
Posts: 207
Joined: 14 Aug 2011, 08:45
Location: Australia
Contact:

Re: NXC: set / change Brick name?

Post by bungeshea »

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?
...
Sorry I missed that. :?
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: set / change Brick name?

Post by muntoo »

studbrickmaster wrote:Sorry I missed that. :?
Understandable. :) John does write pretty cryptic messages - in fact, he stopped using AES a few years ago. ;)
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
ricardocrl
Posts: 117
Joined: 27 Dec 2010, 19:27

Re: NXC: set / change Brick name?

Post by ricardocrl »

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?
ricardocrl
Posts: 117
Joined: 27 Dec 2010, 19:27

Re: NXC: set / change Brick name? (Solution)

Post by ricardocrl »

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:

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; 
...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:

Code: Select all

task main(){
     CommExecuteFunctionType Fargs;

     Fargs.Cmd = INTF_SETBTNAME;
     Fargs.Name = "Ricardo";
     SysCommExecuteFunction(Fargs);
     
     while(true);
}
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(?).
linusa
Posts: 228
Joined: 16 Oct 2010, 11:44
Location: Aachen, Germany
Contact:

Re: NXC: set / change Brick name?

Post by linusa »

Just for the record, there's a direct command to change the NXT's name -- maybe one can inspect the underlying firmware code?
Appendix 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)
Edit: Never mind, I just saw that that's what you did
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
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: set / change Brick name?

Post by afanofosc »

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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
ricardocrl
Posts: 117
Joined: 27 Dec 2010, 19:27

Re: NXC: set / change Brick name?

Post by ricardocrl »

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.
Post Reply

Who is online

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