B
Bubba
Greetings,
I got a GPS tracker that can operate via GPRS. The software provided
with it is... well, BAD. Bad as in not-useful-at-all bad. Not only it
uses practically no advance options that tracker provides of
whatsoever, but it works only on Windows and it requires way too much
tampering for such simple task.
So, since the GPRS communication protocol was also provided, I figured
to create my own custom based GPRS communication software. Here are the
relevant extracts from the begining of the protocol:
§
Depending on the direction of the GPRS package, the communication
protocol is defined as following format
A. The GPRS package from call center to track unit:
@@ + L + ID (7byte) + command (2byte) + DATA + checksum(2byte) +\r\n
B. The GPRS package from track unit to call center:
$$ + L + ID (7byte) + command (2byte) + DATA + checksum(2byte) + \r\n
....
Login after power on
Command code: 0x5000
After the IP/PORT/APN is set ,the tracker unit apply for GPRS service
by sending command every 30 second until it login the server.
For example:
Login command from tracker unit to server to apply GPRS service:
$$ + L + ID + 0x5000 + Checksum(2byte) + \r\n
Following message will be send back from server when the server
receive the login command
@@ + L + ID + 0x4000 + 1B Flag + Checksum(2byte) +\r\n
1B Flag:
= 0x00 means login failed
= 0x01 means login success
§
I am supplying the main loop for receiving data from the tracker:
#define rwerror(x) { if (x < 0) fprintf (stderr, "r/w error\n"); }
....
while (1)
{
struct sockaddr_in client_info;
unsigned int client_info_size = sizeof(client_info);
int session_socket = accept (main_socket, (struct sockaddr *) &client_info, &client_info_size);
if (session_socket < 0)
{
if (errno==EINTR)
continue;
perror("accept");
usleep(100);
continue;
}
session_number+=1;
char * who_is_it = inet_ntoa(client_info.sin_addr);
printf("[session %d accepted from %s]\n", session_number, who_is_it);
memset (buffer, '\0', 256);
r = read (session_socket,buffer,256); //cita duljinu vektora
rwerror (r);
puts (buffer);
printf("\n[session %d dissconnected]\n", session_number);
close(session_socket);
}
This should, as far as I understood from the communication protocol,
receive this type of command:
$$ + L + ID (7byte) + command (2byte) + DATA + checksum(2byte) + \r\n
However, the best I got was this:
bubba@korea:~/gps_server$ ./server1.out 12345
Listening on port 12345
[session 1 accepted from 212.15.188.234]
$$
[session 1 dissconnected]
[session 2 accepted from 212.15.188.234]
$$
[session 2 dissconnected]
[session 3 accepted from 212.15.188.234]
$$
[session 3 dissconnected]
^C
bubba@korea:~/gps_server$
I presume that the problem is in "read" function, that is, it is
probably "too fast" to "grab" all the date from the tracker. If so, can
it be fixed? Or am I doing it totally wrong?
TIA!
I got a GPS tracker that can operate via GPRS. The software provided
with it is... well, BAD. Bad as in not-useful-at-all bad. Not only it
uses practically no advance options that tracker provides of
whatsoever, but it works only on Windows and it requires way too much
tampering for such simple task.
So, since the GPRS communication protocol was also provided, I figured
to create my own custom based GPRS communication software. Here are the
relevant extracts from the begining of the protocol:
§
Depending on the direction of the GPRS package, the communication
protocol is defined as following format
A. The GPRS package from call center to track unit:
@@ + L + ID (7byte) + command (2byte) + DATA + checksum(2byte) +\r\n
B. The GPRS package from track unit to call center:
$$ + L + ID (7byte) + command (2byte) + DATA + checksum(2byte) + \r\n
....
Login after power on
Command code: 0x5000
After the IP/PORT/APN is set ,the tracker unit apply for GPRS service
by sending command every 30 second until it login the server.
For example:
Login command from tracker unit to server to apply GPRS service:
$$ + L + ID + 0x5000 + Checksum(2byte) + \r\n
Following message will be send back from server when the server
receive the login command
@@ + L + ID + 0x4000 + 1B Flag + Checksum(2byte) +\r\n
1B Flag:
= 0x00 means login failed
= 0x01 means login success
§
I am supplying the main loop for receiving data from the tracker:
#define rwerror(x) { if (x < 0) fprintf (stderr, "r/w error\n"); }
....
while (1)
{
struct sockaddr_in client_info;
unsigned int client_info_size = sizeof(client_info);
int session_socket = accept (main_socket, (struct sockaddr *) &client_info, &client_info_size);
if (session_socket < 0)
{
if (errno==EINTR)
continue;
perror("accept");
usleep(100);
continue;
}
session_number+=1;
char * who_is_it = inet_ntoa(client_info.sin_addr);
printf("[session %d accepted from %s]\n", session_number, who_is_it);
memset (buffer, '\0', 256);
r = read (session_socket,buffer,256); //cita duljinu vektora
rwerror (r);
puts (buffer);
printf("\n[session %d dissconnected]\n", session_number);
close(session_socket);
}
This should, as far as I understood from the communication protocol,
receive this type of command:
$$ + L + ID (7byte) + command (2byte) + DATA + checksum(2byte) + \r\n
However, the best I got was this:
bubba@korea:~/gps_server$ ./server1.out 12345
Listening on port 12345
[session 1 accepted from 212.15.188.234]
$$
[session 1 dissconnected]
[session 2 accepted from 212.15.188.234]
$$
[session 2 dissconnected]
[session 3 accepted from 212.15.188.234]
$$
[session 3 dissconnected]
^C
bubba@korea:~/gps_server$
I presume that the problem is in "read" function, that is, it is
probably "too fast" to "grab" all the date from the tracker. If so, can
it be fixed? Or am I doing it totally wrong?
TIA!