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.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 .
NXC: set / change Brick name?
-
- Posts: 117
- Joined: 27 Dec 2010, 19:27
Re: NXC: set / change Brick name?
Re: NXC: set / change Brick name?
"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.
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.
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC: set / change Brick name?
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.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: NXC: set / change Brick name?
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
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
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC: set / change Brick name?
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);
}
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: NXC: set / change Brick name?
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).
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).
Who is online
Users browsing this forum: Semrush [Bot] and 0 guests