Page 2 of 4

Re: NXC: set / change Brick name?

Posted: 26 Feb 2011, 05:39
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

Re: NXC: set / change Brick name?

Posted: 29 Apr 2011, 01:11
by bungeshea
Is there a way to change the brick name in program?

Re: NXC: set / change Brick name?

Posted: 29 Apr 2011, 01:14
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?
...

Re: NXC: set / change Brick name?

Posted: 29 Apr 2011, 02:20
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. :?

Re: NXC: set / change Brick name?

Posted: 29 Apr 2011, 04:31
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. ;)

Re: NXC: set / change Brick name?

Posted: 27 Mar 2012, 09:14
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?

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

Posted: 27 Mar 2012, 14:05
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(?).

Re: NXC: set / change Brick name?

Posted: 27 Mar 2012, 22:08
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

Re: NXC: set / change Brick name?

Posted: 27 Mar 2012, 23:28
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

Re: NXC: set / change Brick name?

Posted: 28 Mar 2012, 10:04
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.