[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Duplicated code in gsm-statemachine.c
From: |
Pavel Machek |
Subject: |
Duplicated code in gsm-statemachine.c |
Date: |
Thu, 30 May 2002 11:12:48 +0200 |
User-agent: |
Mutt/1.3.28i |
Hi!
Please, try not to write duplicated code. Also someone tell me if t
really is in tenths of second, I'm not 100% sure. Will commit to CVS
soon.
Pavel
--- gnokii.ofic/common/gsm-statemachine.c Thu May 2 11:06:05 2002
+++ gnokii.new/common/gsm-statemachine.c Thu May 30 02:13:27 2002
@@ -200,9 +200,12 @@
}
-/* This function is for convinience only */
-/* It is called after SM_SendMessage and blocks until a response is received */
-GSM_Error SM_BlockTimeout(GSM_Statemachine *state, GSM_Data *data, int
waitfor, int t)
+/* This function is for convinience only
+ It is called after SM_SendMessage and blocks until a response is received
+
+ t is in tenths of second
+*/
+static GSM_Error __SM_BlockTimeout(GSM_Statemachine *state, GSM_Data *data,
int waitfor, int t, int noretry)
{
int retry, timeout;
GSM_State s;
@@ -222,45 +225,32 @@
dprintf("SM_Block Retry - %d\n", retry);
SM_Reset(state);
- if (retry < 2) SM_SendMessage(state, state->LastMsgSize,
state->LastMsgType, state->LastMsg);
+ if ((retry < 2) && (!noretry))
+ SM_SendMessage(state, state->LastMsgSize,
state->LastMsgType, state->LastMsg);
}
return GE_TIMEOUT;
}
+GSM_Error SM_BlockTimeout(GSM_Statemachine *state, GSM_Data *data, int
waitfor, int t)
+{
+ return __SM_BlockTimeout(state, data, waitfor, t, 0);
+}
+
GSM_Error SM_Block(GSM_Statemachine *state, GSM_Data *data, int waitfor)
{
- return SM_BlockTimeout(state, data, waitfor, 30);
+ return __SM_BlockTimeout(state, data, waitfor, 30, 0);
}
/* This function is equal to SM_Block except it does not retry the message */
GSM_Error SM_BlockNoRetryTimeout(GSM_Statemachine *state, GSM_Data *data, int
waitfor, int t)
{
- int retry, timeout;
- GSM_State s;
- GSM_Error err;
-
- for (retry = 0; retry < 3; retry++) {
- timeout = t;
- err = SM_WaitFor(state, data, waitfor);
- if (err != GE_NONE) return err;
-
- do { /* ~3secs timeout */
- s = SM_Loop(state, 1); /* Timeout=100ms */
- timeout--;
- } while ((timeout > 0) && (s == WaitingForResponse));
-
- if (s == ResponseReceived) return SM_GetError(state, waitfor);
-
- SM_Reset(state);
- }
-
- return GE_TIMEOUT;
+ return __SM_BlockTimeout(state, data, waitfor, t, 1);
}
GSM_Error SM_BlockNoRetry(GSM_Statemachine *state, GSM_Data *data, int waitfor)
{
- return SM_BlockNoRetryTimeout(state, data, waitfor, 50);
+ return __SM_BlockTimeout(state, data, waitfor, 100, 1);
}
/* Just to do things neatly */
Binary files gnokii.ofic/common/libgnokii.so and gnokii.new/common/libgnokii.so
differ
diff -ur -x .dep* -x .hdep* -x *.[oas] -x *~ -x #* -x *CVS* -x *.orig -x *.rej
-x *.old -x .menu* -x asm -x local.h -x System.map -x autoconf.h -x compile.h
-x version.h -x .version -x defkeymap.c -x uni_hash.tbl -x zImage -x vmlinux -x
vmlinuz -x TAGS -x bootsect -x *RCS* -x conmakehash -x map -x build -x build -x
configure -x *target* -x *.flags -x *.bak gnokii.ofic/common/links/Makefile
gnokii.new/common/links/Makefile
--- gnokii.ofic/common/links/Makefile Wed May 29 13:32:43 2002
+++ gnokii.new/common/links/Makefile Wed May 29 13:53:29 2002
@@ -22,7 +22,6 @@
cbus.o \
atbus.o \
fbus-3110.o \
- m2bus.o \
utils.o
all: LINKS.o
diff -ur -x .dep* -x .hdep* -x *.[oas] -x *~ -x #* -x *CVS* -x *.orig -x *.rej
-x *.old -x .menu* -x asm -x local.h -x System.map -x autoconf.h -x compile.h
-x version.h -x .version -x defkeymap.c -x uni_hash.tbl -x zImage -x vmlinux -x
vmlinuz -x TAGS -x bootsect -x *RCS* -x conmakehash -x map -x build -x build -x
configure -x *target* -x *.flags -x *.bak gnokii.ofic/common/links/atbus.c
gnokii.new/common/links/atbus.c
--- gnokii.ofic/common/links/atbus.c Mon May 20 00:18:47 2002
+++ gnokii.new/common/links/atbus.c Tue Apr 30 00:34:19 2002
@@ -26,6 +26,8 @@
*/
+#define DEBUG
+
/* System header files */
#include <stdio.h>
#include <string.h>
Only in gnokii.new/common/phones: .#Makefile.1.12
Only in gnokii.new/gnokii: .#gnokii.c.1.238
Only in gnokii.new/gnokii: .#gnokii.c.1.240
Only in gnokii.new/gnokii: .#gnokii.c.1.241
Binary files gnokii.ofic/gnokii/gnokii and gnokii.new/gnokii/gnokii differ
diff -ur -x .dep* -x .hdep* -x *.[oas] -x *~ -x #* -x *CVS* -x *.orig -x *.rej
-x *.old -x .menu* -x asm -x local.h -x System.map -x autoconf.h -x compile.h
-x version.h -x .version -x defkeymap.c -x uni_hash.tbl -x zImage -x vmlinux -x
vmlinuz -x TAGS -x bootsect -x *RCS* -x conmakehash -x map -x build -x build -x
configure -x *target* -x *.flags -x *.bak gnokii.ofic/gnokii/gnokii.c
gnokii.new/gnokii/gnokii.c
--- gnokii.ofic/gnokii/gnokii.c Wed May 29 13:33:06 2002
+++ gnokii.new/gnokii/gnokii.c Thu May 30 02:29:50 2002
@@ -411,6 +411,35 @@
exit(1);
}
+static GSM_Error readtext(SMS_UserData *udata, int input_len)
+{
+ char message_buffer[255 * GSM_MAX_SMS_LENGTH];
+ int chars_read;
+
+ fprintf(stderr, _("Please enter SMS text. End your input with
<cr><control-D>:"));
+
+ /* Get message text from stdin. */
+ chars_read = fread(message_buffer, 1, sizeof(message_buffer), stdin);
+
+ if (chars_read == 0) {
+ fprintf(stderr, _("Couldn't read from stdin!\n"));
+ return GE_INTERNALERROR;
+ } else if (chars_read > input_len || chars_read > sizeof(udata->u.Text)
- 1) {
+ fprintf(stderr, _("Input too long! (%d, maximum is %d)\n"),
chars_read, input_len);
+ return GE_INTERNALERROR;
+ }
+
+ /* Null terminate. */
+ message_buffer[chars_read] = 0x00;
+ if (udata->Type != SMS_iMelodyText && chars_read > 0 &&
message_buffer[chars_read - 1] == '\n')
+ message_buffer[--chars_read] = 0x00;
+ strncpy(udata->u.Text, message_buffer, chars_read);
+ udata->u.Text[chars_read] = 0;
+ udata->Length = chars_read;
+
+ return GE_NONE;
+}
+
/* Send SMS messages. */
static int sendsms(int argc, char *argv[])
{
@@ -418,8 +447,7 @@
GSM_Error error;
/* The maximum length of an uncompressed concatenated short message is
255 * 153 = 39015 default alphabet characters */
- char message_buffer[255 * GSM_MAX_SMS_LENGTH];
- int input_len, chars_read;
+ int input_len;
int i;
struct option options[] = {
@@ -504,30 +532,14 @@
sendsms_usage();
}
}
-
- fprintf(stderr, _("Please enter SMS text. End your input with
<cr><control-D>:"));
-
- /* Get message text from stdin. */
- chars_read = fread(message_buffer, 1, sizeof(message_buffer), stdin);
-
- if (chars_read == 0) {
- fprintf(stderr, _("Couldn't read from stdin!\n"));
- return -1;
- } else if (chars_read > input_len || chars_read >
sizeof(sms.UserData[0].u.Text) - 1) {
- fprintf(stderr, _("Input too long! (%d, maximum is %d)\n"),
chars_read, input_len);
- return -1;
- }
-
- /* Null terminate. */
- message_buffer[chars_read] = 0x00;
- if (sms.UserData[0].Type != SMS_iMelodyText && chars_read > 0 &&
message_buffer[chars_read - 1] == '\n')
- message_buffer[--chars_read] = 0x00;
- if (chars_read < 1) {
+
+ error = readtext(&sms.UserData[0], input_len);
+ if (error != GE_NONE) return -1;
+ if (sms.UserData[0].Length < 1) {
fprintf(stderr, _("Empty message. Quitting.\n"));
return -1;
}
- strncpy(sms.UserData[0].u.Text, message_buffer, chars_read);
- sms.UserData[0].u.Text[chars_read] = 0;
+
data.SMS = &sms;
/* Send the message. */
@@ -1449,8 +1461,9 @@
sms.UserData[1].Type = SMS_NoData;
if (sms.UserData[0].u.Bitmap.type == GSM_PictureMessage) {
sms.UserData[1].Type = SMS_PlainText;
+ readtext(&sms.UserData[1], 120);
sms.UserData[2].Type = SMS_NoData;
- strcpy(sms.UserData[1].u.Text, "testtest");
+ // strcpy(sms.UserData[1].u.Text, "Ahoj, tohle je
mala zprava na testovani telefonu");
}
/* Send the message. */
Binary files gnokii.ofic/gnokiid/gnokiid and gnokii.new/gnokiid/gnokiid differ
Only in gnokii.new/include: .#gsm-sms.h.1.38
Only in gnokii.new/testsuite: .#out.11.ringtone.1.1
Only in gnokii.new/testsuite: .#out.13.emspicture.1.1
Only in gnokii.new/testsuite: .#out.14.oplogo-xpm.1.2
Only in gnokii.new/testsuite: .#out.14.oplogo-xpm.1.3
Only in gnokii.new/testsuite: .#test.12.picture.1.1
Only in gnokii.new/testsuite: .#test.12.picture.1.2
Only in gnokii.new/testsuite: .#test.14.oplogo-xpm.1.2
Only in gnokii.new/testsuite: .#testit.1.7
Only in gnokii.new/testsuite: core
diff -ur -x .dep* -x .hdep* -x *.[oas] -x *~ -x #* -x *CVS* -x *.orig -x *.rej
-x *.old -x .menu* -x asm -x local.h -x System.map -x autoconf.h -x compile.h
-x version.h -x .version -x defkeymap.c -x uni_hash.tbl -x zImage -x vmlinux -x
vmlinuz -x TAGS -x bootsect -x *RCS* -x conmakehash -x map -x build -x build -x
configure -x *target* -x *.flags -x *.bak
gnokii.ofic/testsuite/myout.12.picture gnokii.new/testsuite/myout.12.picture
--- gnokii.ofic/testsuite/myout.12.picture Thu May 30 01:14:23 2002
+++ gnokii.new/testsuite/myout.12.picture Thu May 30 11:03:55 2002
@@ -1,21 +1,19 @@
Sending Multipart Message: Picture Message.
-SMS is too long? 448
+Please enter SMS text. End your input with <cr><control-D>:Bitmap is not of
right size?!
+SMS is too long? 311
DCS: 0xf5
-Length: 0x1c0
-UserDataLength: 0x1bf
+Length: 0x137
+UserDataLength: 0x137
ValidityIndicator: 0
-UserData:
F4F29C4E2FCFE930060100003048010000F800000061B0000001FC00000061B0000001AC0000006000000000F80E3E1C6DB0000001741F3F366DB00000032631B36379B00000030631B3637DB0000006073FB3366DB0000006071FB31C65B000000607018000000000000E0F018000000000001F0F8F8000000000001F1F078000000000000FFE000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-Will need 4 sms-es
+UserData:
3002010000481C010000F800000061B0000001FC00000061B0000001AC0000006000000000F80E3E1C6DB0000001741F3F366DB00000032631B36379B00000030631B3637DB0000006073FB3366DB0000006071FB31C65B000000607018000000000000E0F018000000000001F0F8F8000000000001F1F078000000000000FFE00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003041686F6A2C20746F686C65206A65206D616C61207A7072617661206E6120746573746F76616E692074656C65666F6E75
+Will need 3 sms-es
Sending sms #0
-AT+???=160
-0051000A00604043133000F50094FFF29C4E2FCFE9000000040100000000000000F4F29C4E2FCFE930060100003048010000F800000061B0000001FC00000061B0000001AC0000006000000000F80E3E1C6DB0000001741F3F366DB00000032631B36379B00000030631B3637DB0000006073FB3366DB0000006071FB31C65B000000607018000000000000E0F018000000000001F0F8F8000000000001F1F0780
+AT+???=153
+0051000A00604043133000F5008C0B0504158A00000003CE03013002010000481C010000F800000061B0000001FC00000061B0000001AC0000006000000000F80E3E1C6DB0000001741F3F366DB00000032631B36379B00000030631B3637DB0000006073FB3366DB0000006071FB31C65B000000607018000000000000E0F018000000000001F0F8F8000000000001F1F078000000000000FFE
Sending sms #1
-AT+???=160
-0051000A00604043133000F50094FFF29C4E2FCFE900000004020000000000000000000000000FFE00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+AT+???=153
+0051000A00604043133000F5008C0B0504158A00000003CE03020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Sending sms #2
-AT+???=160
-0051000A00604043133000F50094FFF29C4E2FCFE90000000403000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-Sending sms #3
-AT+???=160
-0051000A00604043133000F50094FFF29C4E2FCFE90000000404000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+AT+???=80
+0051000A00604043133000F500430B0504158A00000003CE03030000000000003041686F6A2C20746F686C65206A65206D616C61207A7072617661206E6120746573746F76616E692074656C65666F6E75
Send succeeded!
diff -ur -x .dep* -x .hdep* -x *.[oas] -x *~ -x #* -x *CVS* -x *.orig -x *.rej
-x *.old -x .menu* -x asm -x local.h -x System.map -x autoconf.h -x compile.h
-x version.h -x .version -x defkeymap.c -x uni_hash.tbl -x zImage -x vmlinux -x
vmlinuz -x TAGS -x bootsect -x *RCS* -x conmakehash -x map -x build -x build -x
configure -x *target* -x *.flags -x *.bak gnokii.ofic/testsuite/out.12.picture
gnokii.new/testsuite/out.12.picture
--- gnokii.ofic/testsuite/out.12.picture Wed May 29 13:33:06 2002
+++ gnokii.new/testsuite/out.12.picture Thu May 30 02:21:16 2002
@@ -1,6 +1,19 @@
-AT+???=???
-0051000A81604043133000F5A98C0B0504158A00000003CE03013002010000481C010000F800000061B0000001FC00000061B0000001AC0000006000000000F80E3E1C6DB0000001741F3F366DB00000032631B36379B00000030631B3637DB0000006073FB3366DB0000006071FB31C65B000000607018000000000000E0F018000000000001F0F8F8000000000001F1F078000000000000FFE
-AT+???=???
-0051000A81604043133000F5A98C0B0504158A00000003CE03020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-AT+???=???
-0051000A81604043133000F5A9430B0504158A00000003CE03030000000000003041686F6A2C20746F686C65206A65206D616C61207A7072617661206E6120746573746F76616E692074656C65666F6E7500000000000000000000000000000000000000000000000000000000000000000000000000000000
+Sending Multipart Message: Picture Message.
+Bitmap is not of right size?!
+SMS is too long? 311
+DCS: 0xf5
+Length: 0x137
+UserDataLength: 0x137
+ValidityIndicator: 0
+UserData:
3002010000481C010000F800000061B0000001FC00000061B0000001AC0000006000000000F80E3E1C6DB0000001741F3F366DB00000032631B36379B00000030631B3637DB0000006073FB3366DB0000006071FB31C65B000000607018000000000000E0F018000000000001F0F8F8000000000001F1F078000000000000FFE00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003041686F6A2C20746F686C65206A65206D616C61207A7072617661206E6120746573746F76616E692074656C65666F6E75
+Will need 3 sms-es
+Sending sms #0
+AT+???=153
+0051000A00604043133000F5008C0B0504158A00000003CE03013002010000481C010000F800000061B0000001FC00000061B0000001AC0000006000000000F80E3E1C6DB0000001741F3F366DB00000032631B36379B00000030631B3637DB0000006073FB3366DB0000006071FB31C65B000000607018000000000000E0F018000000000001F0F8F8000000000001F1F078000000000000FFE
+Sending sms #1
+AT+???=153
+0051000A00604043133000F5008C0B0504158A00000003CE03020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+Sending sms #2
+AT+???=80
+0051000A00604043133000F500430B0504158A00000003CE03030000000000003041686F6A2C20746F686C65206A65206D616C61207A7072617661206E6120746573746F76616E692074656C65666F6E75
+Send succeeded!
diff -ur -x .dep* -x .hdep* -x *.[oas] -x *~ -x #* -x *CVS* -x *.orig -x *.rej
-x *.old -x .menu* -x asm -x local.h -x System.map -x autoconf.h -x compile.h
-x version.h -x .version -x defkeymap.c -x uni_hash.tbl -x zImage -x vmlinux -x
vmlinuz -x TAGS -x bootsect -x *RCS* -x conmakehash -x map -x build -x build -x
configure -x *target* -x *.flags -x *.bak gnokii.ofic/testsuite/test.12.picture
gnokii.new/testsuite/test.12.picture
--- gnokii.ofic/testsuite/test.12.picture Wed May 29 13:33:06 2002
+++ gnokii.new/testsuite/test.12.picture Thu May 30 02:30:32 2002
@@ -1,4 +1,4 @@
#
# Try to send a picture SMS.
#
-$GNOKII --sendlogo picture 0604343103 ../Docs/gnokiiop.xpm "Ahoj, tohle je
mala zprava na testovani telefonu"
+echo "Ahoj, tohle je mala zprava na testovani telefonu" | $GNOKII --sendlogo
picture 0604343103 ../Docs/gnokiiop.xpm
--
(about SSSCA) "I don't say this lightly. However, I really think that the U.S.
no longer is classifiable as a democracy, but rather as a plutocracy." --hpa
- Duplicated code in gsm-statemachine.c,
Pavel Machek <=