ROBOTC.net forums
http://www.robotc.net/forums/

Making GPS sensor talk to NXTBEE
http://www.robotc.net/forums/viewtopic.php?f=41&t=10983
Page 1 of 1

Author:  t1techno [ Thu Apr 23, 2015 10:29 am ]
Post subject:  Making GPS sensor talk to NXTBEE

We are running code on a robot using multiple sensors and needing to see if something is possible.

Using Dexter industries GPS and NXTBee radio

GPS creates longs for longitude and latitude

I am wanting to create either a string combining the word longitude and the longitude long

And then need to either be able to move through that string one character at a time or convert it to an array of characters.

For people who are familiar with Java - I am looking to see if something like stringname.charAt(location) will return a character

The same can obviously done going through an array of characters one index at a time

The NXTBee will send 1 character at time time easily enough and I can not find a way to send a number or a string as one piece.

Ideas???

Working with students on a tight timeline so any help will be appreciated

Author:  mightor [ Thu Apr 23, 2015 10:38 am ]
Post subject:  Re: Making GPS sensor talk to NXTBEE

char strIndex(const string &sString, const short nIndex); may be the function you're looking for.
You can also "convert" the string to a char array by simply copying it with memcpy();
Code:
char array[100];
string foo = "hello world";
memcpy(&array[0], foo, strlen(foo) + 1));

Make sure the array is large enough to hold the string :)
= Xander

Author:  t1techno [ Thu Apr 23, 2015 12:06 pm ]
Post subject:  Re: Making GPS sensor talk to NXTBEE

Thanks for quick response - the string and char part I understand now.

Will Robot C let you copy a long into a string?

Author:  mightor [ Thu Apr 23, 2015 12:14 pm ]
Post subject:  Re: Making GPS sensor talk to NXTBEE

You mean convert it to ascii? sure, just use snprintf() :)

= Xander

Author:  t1techno [ Thu Apr 23, 2015 1:47 pm ]
Post subject:  Re: Making GPS sensor talk to NXTBEE

So I can copy a long into a string

task main()
{
string message;
long longitude = 10234161;
wait1Msec(1000);
snprintf(longitude, message); or did you mean sprintf(longitude, message);


}

Author:  mightor [ Thu Apr 23, 2015 3:59 pm ]
Post subject:  Re: Making GPS sensor talk to NXTBEE

snprintf(ppDest, nDestLength, pzFormatString, ...); is the call, you can also use sprintf, if you don't want to specify the max length of the receiving buffer:
Code:
task main()
{
  char msg[20];
  long longitude = 10234161;
  snprintf(msg, 20, "%d", longitude);
  writeDebugStreamLine(msg);
 
  string foo;
  sprintf(foo, "%d", longitude);
  writeDebugStreamLine(foo);
}

= Xander

Author:  mightor [ Thu Apr 23, 2015 4:01 pm ]
Post subject:  Re: Making GPS sensor talk to NXTBEE

Btw, do not cross post in multiple sub forums. I have deleted the other post.

= Xander

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/