Hey Everybody,
I am writing code in C using an Arduino MEGA 2560 and a 4D Systems uLCD-70DT.
I like to write my own code for many of the small operations that I do...I definitely understand everything better and I am glutton for punishment.
I would like to write a string to a string object in Visi Genie. I created an function called updateHomeGPSCoords() to update the home GPS coordinates on the uLCD-70DT that I entered on a numeric keypad. This seems simple enough.
In pseudocode, all I need to do is:
write cmd (0x02)
write id (0x02 for the particular string that I want to update)
write the string length (or should this be string length + 1 ?
write each character of the string
write the checksum
...and this should work.
I am a bit confused about whether or not I have to add 1 to the string length to account for the null character. I have tried both ways with no success.
Let's say that my string is str[] = "+26.1619". Is my string actually "+26.1619\0"? What is the strlen(str)? 8 or 9? I still have to add a period in my code below. And I am not sure whether to use strcpy() to add the + sign and the decimal? Or maybe strcat(). I see that there are subtleties with both.
In my case, my code looks like the following. I have tried this with and without the gpsHOME.latsgn. I have also tried this with just j and also with j+1. Nothing seems to get written to the uLCD-70DT.
void updateHomeGPSCoords(byte CMD, byte ID)
{
//calculate checksum
checksum = CMD;
checksum ^= ID;
checksum ^= j; // j is a counter used somewhere else in my program that is a measure of string length.
checksum ^= gpsHOME.latsgn; //this is either a '+' or '-' sign to account for N-S or E-W for heading to precede the degree coordinates
for(int i=0; i<j; i++)checksum ^= gpsHOME.latCoords[i];
//write to uLCD-70DT
uLCD.write(CMD);
uLCD.write(ID);
uLCD.write(j+1);
uLCD.write(gpsHOME.latsgn);
for(int i=0; i<j; i++)uLCD.write(gpsHOME.latCoords[i]);
uLCD.write(checksum);
}
TIA,
--Neal
I am writing code in C using an Arduino MEGA 2560 and a 4D Systems uLCD-70DT.
I like to write my own code for many of the small operations that I do...I definitely understand everything better and I am glutton for punishment.
I would like to write a string to a string object in Visi Genie. I created an function called updateHomeGPSCoords() to update the home GPS coordinates on the uLCD-70DT that I entered on a numeric keypad. This seems simple enough.
In pseudocode, all I need to do is:
write cmd (0x02)
write id (0x02 for the particular string that I want to update)
write the string length (or should this be string length + 1 ?
write each character of the string
write the checksum
...and this should work.
I am a bit confused about whether or not I have to add 1 to the string length to account for the null character. I have tried both ways with no success.
Let's say that my string is str[] = "+26.1619". Is my string actually "+26.1619\0"? What is the strlen(str)? 8 or 9? I still have to add a period in my code below. And I am not sure whether to use strcpy() to add the + sign and the decimal? Or maybe strcat(). I see that there are subtleties with both.
In my case, my code looks like the following. I have tried this with and without the gpsHOME.latsgn. I have also tried this with just j and also with j+1. Nothing seems to get written to the uLCD-70DT.
void updateHomeGPSCoords(byte CMD, byte ID)
{
//calculate checksum
checksum = CMD;
checksum ^= ID;
checksum ^= j; // j is a counter used somewhere else in my program that is a measure of string length.
checksum ^= gpsHOME.latsgn; //this is either a '+' or '-' sign to account for N-S or E-W for heading to precede the degree coordinates
for(int i=0; i<j; i++)checksum ^= gpsHOME.latCoords[i];
//write to uLCD-70DT
uLCD.write(CMD);
uLCD.write(ID);
uLCD.write(j+1);
uLCD.write(gpsHOME.latsgn);
for(int i=0; i<j; i++)uLCD.write(gpsHOME.latCoords[i]);
uLCD.write(checksum);
}
TIA,
--Neal
Comment