gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Statemachine, new function


From: Osma Suominen
Subject: Statemachine, new function
Date: Wed, 11 Jun 2003 21:59:57 +0300 (EEST)

Hello,

I posted this addition to the statemachine a while ago but got no
replies. I need this new function for the 3110 (I hope I have this time
grokked everything properly). Not having it keeps me from submitting
recent 3110 work to gnokii CVS.

The function is a version of sm_block that doesn't want a reply message
type, only waits for an ack from the phone. No present drivers are
affected (of course) but this just adds more stuff to the statemachine.

If nobody opposes I'm going to apply this patch on Friday.

-Osma

Index: gsm-statemachine.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/gsm-statemachine.c,v
retrieving revision 1.49
diff -u -r1.49 gsm-statemachine.c
--- gsm-statemachine.c  28 Apr 2003 12:43:39 -0000      1.49
+++ gsm-statemachine.c  11 Jun 2003 18:53:01 -0000
@@ -285,6 +282,37 @@
 gn_error sm_block_no_retry(int waitfor, gn_data *data, struct gn_statemachine 
*state)
 {
        return sm_block_no_retry_timeout(waitfor, 100, data, state);
+}
+
+/* Block waiting for an ack, don't wait for a reply message of any sort */
+gn_error sm_block_ack(struct gn_statemachine *state)
+{
+       int retry;
+       gn_state s;
+       gn_error err;
+       struct timeval now, next, timeout;
+
+       s = state->current_state;
+       timeout.tv_sec = 3;
+       timeout.tv_usec = 0;
+       gettimeofday(&now, NULL);
+       for (retry = 0; retry < 2; retry++) {
+               timeradd(&now, &timeout, &next);
+               do {
+                       s = gn_sm_loop(1, state);  /* Timeout=100ms */
+                       gettimeofday(&now, NULL);
+               } while (timercmp(&next, &now, >) && (s == GN_SM_MessageSent));
+
+               if (s == GN_SM_WaitingForResponse || s == 
GN_SM_ResponseReceived)
+                       return GN_ERR_NONE;
+
+               dprintf("sm_block_ack Retry - %d\n", retry);
+               sm_reset(state);
+               err = sm_message_send(state->last_msg_size, 
state->last_msg_type, state->last_msg, state);
+               if (err != GN_ERR_NONE) return err;
+       }
+
+       return GN_ERR_TIMEOUT;
 }

 /* Just to do things neatly */
Index: gnokii-internal.h
===================================================================
RCS file: /cvsroot/gnokii/gnokii/include/gnokii-internal.h,v
retrieving revision 1.11
diff -u -r1.11 gnokii-internal.h
--- gnokii-internal.h   6 Mar 2003 21:29:04 -0000       1.11
+++ gnokii-internal.h   11 Jun 2003 18:57:32 -0000
@@ -54,6 +54,7 @@
 gn_error sm_block(int waitfor, gn_data *data, struct gn_statemachine *state);
 gn_error sm_block_no_retry_timeout(int waitfor, int t, gn_data *data, struct 
gn_statemachine *state);
 gn_error sm_block_no_retry(int waitfor, gn_data *data, struct gn_statemachine 
*state);
+gn_error sm_block_ack(struct gn_statemachine *state);
 void sm_message_dump(int messagetype, unsigned char *message, int length);
 void sm_unhandled_frame_dump(int messagetype, unsigned char *message, int 
length, struct gn_statemachine *state);


-- 
*** Osma Suominen *** address@hidden *** http://www.iki.fi/ozone/ ***




reply via email to

[Prev in Thread] Current Thread [Next in Thread]