Page 4 of 4

Re: NXC: set / change Brick name?

Posted: 31 Mar 2012, 18:02
by ricardocrl
doc-helmut wrote:Brickdataneme has to return the correct name as it is, either how long it is, and just how long it is exactly .
Why does it "has to"? It's all related with the firmware. When you call that function, the FW reads the full 16 bytes and returns them, without any further analysis. Of course the name could be analysed and the spaces removed, but it would kill performance. So, instead, if the user needs to remove the necessary spaces, he/she does. Development in embedded systems, like the NXT, is not always clear and fancy, because you deal a lot with limited resources, like speed and memory.

Re: NXC: set / change Brick name?

Posted: 31 Mar 2012, 18:20
by HaWe
"Has to" because it' the name I had given to it.
I gave the Name "001" and I didn't give the name "001____________".
If the function returns more characters than the origin names contains, then it's faulty, no matter why, if it's caused by the firmware or anything like "speed and memory".
To know that's a faulty firmware function doesn't make it correct.

BTW:
maybe this inconsistance is one of the reasons why the set-Name and the Get-Name procedures don't work correctly.

Re: NXC: set / change Brick name?

Posted: 31 Mar 2012, 18:36
by mattallen37
Helmut, just because you set the name to "001" doesn't mean reading the name should return "001". I don't think there is anything wrong with the way it works. Like ricardocrl implied, you're more than welcome to strip the other characters in user-code, if you so desire.

Re: NXC: set / change Brick name?

Posted: 31 Mar 2012, 19:13
by HaWe
haha, mattÛ©Û©Û©Û©Û©Û©Û©Û©Û©Û©Û© , well, I have a different opinion.
If I poll a string from where-ever, I expect to get the correct string back, without any extras how beautiful they ever might be (e.g., little ducky or flowers instead of spaces up to a lenght of 15 or 256 or MaxLongInt) :P

(and now don't come over with a slogan like: "It's not a bug , it's a feature!!!") :P

Re: NXC: set / change Brick name?

Posted: 31 Mar 2012, 19:51
by mattallen37
Is this what you want?

Code: Select all

string GetBrickName(){
  string s_name = BrickDataName();
  byte b_name[15];
  UnflattenVar(s_name, b_name);
  byte name_trimmed_length = 0;
  for(byte i = 0; i < 15; i++){
    if(b_name[i]==0)break;
    name_trimmed_length++;
  }
  byte b_name_trimmed[];
  ArrayInit(b_name_trimmed, 0, name_trimmed_length);
  ArraySubset(b_name_trimmed, b_name, 0, name_trimmed_length);
  string s_name_trimmed = FlattenVar(b_name_trimmed);
  return s_name_trimmed;
}

task main(){
  string name = GetBrickName();
  TextOut(0, LCD_LINE1, "NXT name: " + GetBrickName() + "!");
  NumOut(0, LCD_LINE2, strlen(GetBrickName()));
  while(true);
}

Re: NXC: set / change Brick name?

Posted: 31 Mar 2012, 19:56
by HaWe
Very kind matt♥♥♥♥♥♥♥♥♥♥♥, :D
but no: to have to use an extra function to drop the rest of extra characters of a corrupted string which has been returned by another function is not the way it should be.
Imagine that you'll have to do that with every function of any kind that has to return a string which always is not exactly like the one that it actually had to return..

If there is a function that has to return a string it simply has to return this string exactly, correctly, without any gimmicks (spaces or duckies or flowers).