Well, the main problem here is that you don't know when the string will enter from the serial port. For instance, let's see a sample communication:
$GPGGA,154655,4328.1874,N,00340.5185,W,1,03,08.5,-00044.7,M,051.6,M,,*79
$GPGSA,A,2,13,23,25,,,,,,,,,,08.5,08.5,00.9*0E
$GPGSV,3,1,10,02,50,290,26,04,60,210,26,08,33,173,29,10,21,296,00*7E
Making a sample reading like this:
int a = Serial1.available();
if(a){
uint8_t hej[a];
for(int i=0; i<a; i++){
hej[i] = Serial1.read();
}
Serial.print("Received \"");
Serial.write(hej, a);
Serial.println("\"");
}
you will see something like
Received "$GPG"
Received "GA,1546"
Received "5"
Received "5,4"
or, most probably,
Received "$"
Received "G"
Received "P"
Received "G"
Received "G"
Received "A"
so it is difficult to detect where to insert your ID.
I have two solutions for you.
The simpler one is to use the fact that the GPS sends formatted sentences. According to the NMEA specification, the message is at most 82 chars long and is terminated by a LF (0x10) char. This means that you can do something like this (I assume you want to use a 4-chars ID, and in this case the ID is MYID
)
#define ID_LENGHT 5 /* 4 chars and a separator */
#define BUFFERSIZE ID_LENGHT+82 /* ID plus the max NMEA sentence*/
byte recvBuffer[BUFFERSIZE];
byte recvIdx;
void setup()
{
// ... other initialization
// Fill the ID at the beginning, and prepare to store data at the end of ID
memcpy(recvBuffer, "MYID-", ID_LENGHT * sizeof(byte));
recvIdx = ID_LENGHT;
}
void loop()
{
// ... other program
while (Serial1.available())
{
byte ch = Serial1.read();
if (recvIdx >= BUFFERSIZE)
continue; // Should never arrive here, since the sentences are shorter
recvBuffer[recvIdx++] = ch;
if (ch == 0x10) // received LF, so end of sentence
{
// Send the buffer (plus the identifier)
rf95.send(recvBuffer, recvIdx);
// Reset the idx (and so you will overwrite previous buffer
recvIdx = ID_LENGHT;
}
}
// ... Other code
}
This approach transfers a lot more thata then needed, since you want to only transfer the latitude and longitude. So the second (and best) approach in my opinion is to have a NMEA parser on the arduino that extracts the lat and long values you need and then sends a (formatted) message to the master, with ID, lat and long.
This is the best solution, but I don't have experience with NMEA parsers so you'd better try searching online for some library and, most important, have the necessary computational power and flash available to perform this computation