5 A Linux/Unix toolset and driver for Nokia mobile phones.
7 Released under the terms of the GNU GPL, see file COPYING for more details.
16 #include <sys/types.h>
26 #include "gsm-common.h"
30 /* FIXME: I have timersub defined in sys/time.h :-( PJ
31 FIXME: Jano wants this function too... PJ
33 int timersub(struct timeval *a, struct timeval *b, struct timeval *result) {
35 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;
36 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;
37 if ((result)->tv_usec < 0) {
39 (result)->tv_usec += 1000000;
47 int GetLine(FILE *File, char *Line, int count) {
51 if (fgets(Line, count, File)) {
52 ptr=Line+strlen(Line)-1;
54 while ( (*ptr == '\n' || *ptr == '\r') && ptr>=Line) *ptr--='\0';
61 * like atoi, but of a non-null-terminated string of a specified portion
63 int mem_to_int(const char str[], int len)
67 strncpy(aux, str, len);
73 * make hexdump of Message
76 void hexdump(u16 MessageLength, u8 *MessageBuffer)
86 for (count = 0; count < MessageLength; count ++)
90 switch (MessageBuffer[count]) {
92 sprintf(hex1,"%02x ",MessageBuffer[count]);
96 if (isprint(MessageBuffer[count]))
97 sprintf(hex1,"%02x%c ",MessageBuffer[count],MessageBuffer[count]);
99 sprintf(hex1,"%02x ",MessageBuffer[count]);
101 if (isprint(MessageBuffer[count])) sprintf(hex2,"%c",MessageBuffer[count]);
102 else strcpy(hex2,".");
106 if ( n!=15 && count != MessageLength-1 ) hex1[3]='|';
108 strcat(string1,hex1);
109 strcat(string2,hex2);
111 if ( n==15 || count == MessageLength-1 )
113 fprintf(stdout,"%-60s%03x %s\n",string1,count+1,string2);
120 if (n!=0) fprintf (stdout,_("\n"));
125 void txhexdump(u16 MessageLength, u8 *MessageBuffer)
130 for (count = 0; count < MessageLength; count ++)
133 fprintf(stdout,_("%02x"),MessageBuffer[count]);
134 switch (MessageBuffer[count]) {
136 fprintf(stdout,_(" |"));
139 if (isprint(MessageBuffer[count])) fprintf(stdout, _("%c|"),MessageBuffer[count]);
140 else fprintf(stdout,_(" |"));
146 fprintf (stdout,_("\n"));
151 if (n!=0) fprintf (stdout,_("\n"));