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.
18 #include <sys/types.h>
28 #include "gsm-common.h"
32 /* FIXME: I have timersub defined in sys/time.h :-( PJ
33 FIXME: Jano wants this function too... PJ
35 int timersub(struct timeval *a, struct timeval *b, struct timeval *result) {
37 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;
38 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;
39 if ((result)->tv_usec < 0) {
41 (result)->tv_usec += 1000000;
49 int GetLine(FILE *File, char *Line, int count) {
53 if (fgets(Line, count, File)) {
54 ptr=Line+strlen(Line)-1;
56 while ( (*ptr == '\n' || *ptr == '\r') && ptr>=Line) *ptr--='\0';
65 * like atoi, but of a non-null-terminated string of a specified portion
67 int mem_to_int(const char str[], int len)
71 strncpy(aux, str, len);
79 * make hexdump of Message
82 void hexdump(u16 MessageLength, u8 *MessageBuffer)
92 for (count = 0; count < MessageLength; count ++)
96 switch (MessageBuffer[count]) {
98 sprintf(hex1,"%02x ",MessageBuffer[count]);
102 if (isprint(MessageBuffer[count]))
103 sprintf(hex1,"%02x%c ",MessageBuffer[count],MessageBuffer[count]);
105 sprintf(hex1,"%02x ",MessageBuffer[count]);
107 if (isprint(MessageBuffer[count])) sprintf(hex2,"%c",MessageBuffer[count]);
108 else strcpy(hex2,".");
112 if ( n!=15 && count != MessageLength-1 ) hex1[3]='|';
114 strcat(string1,hex1);
115 strcat(string2,hex2);
117 if ( n==15 || count == MessageLength-1 )
119 fprintf(stdout,"%-60s%03x %s\n",string1,count+1,string2);
126 if (n!=0) fprintf (stdout,_("\n"));
131 void txhexdump(u16 MessageLength, u8 *MessageBuffer)
136 for (count = 0; count < MessageLength; count ++)
139 fprintf(stdout,_("%02x"),MessageBuffer[count]);
140 switch (MessageBuffer[count]) {
142 fprintf(stdout,_(" |"));
145 if (isprint(MessageBuffer[count])) fprintf(stdout, _("%c|"),MessageBuffer[count]);
146 else fprintf(stdout,_(" |"));
152 fprintf (stdout,_("\n"));
157 if (n!=0) fprintf (stdout,_("\n"));