Found in "gnokii-working" directory, some November-patches version
[gnokii.git] / common / links / fbus.c
index 4b19e5f..7d20039 100644 (file)
   The various routines are called FBUS_(whatever).
 
   $Log$
-  Revision 1.1.1.2  2001/11/27 22:01:16  short
-  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Tue Nov 27 22:58 CET 2001
-
-  Revision 1.14  2001/11/27 12:19:01  pkot
-  Cleanup, indentation, ANSI complaint preprocesor symbols (Jan Kratochvil, me)
-
-  Revision 1.13  2001/11/17 20:14:15  pkot
-  Nasty bug with counting message length. Workaround applied. Needs fixing.
-
-  Revision 1.12  2001/11/15 12:04:05  pkot
-  Faster initialization for 6100 series (don't check for dlr3 cable)
+  Revision 1.1.1.3  2002/04/03 00:08:07  short
+  Found in "gnokii-working" directory, some November-patches version
 
   Revision 1.11  2001/09/09 21:45:49  machek
   Cleanups from Ladislav Michl <ladis@psi.cz>:
 #include "links/utils.h"
 
 #ifndef WIN32
-#  include "device.h"
+  #include "device.h"
 #else
-#  include "win32/winserial.h"
-#  define device_write(a, b) WriteCommBlock(a, b)
-#  define device_read(a, b) ReadCommBlock(a, b)
-#  define sleep(x) Sleep((x) * 1000)
-#  define usleep(x) Sleep(((x) < 1000) ? 1 : ((x) / 1000))
+  #include "win32/winserial.h"
+  #define device_write(a, b) WriteCommBlock(a, b)
+  #define device_read(a, b) ReadCommBlock(a, b)
+  #define sleep(x) Sleep((x) * 1000)
+  #define usleep(x) Sleep(((x) < 1000) ? 1 : ((x) / 1000))
 #endif
 
 #define __links_fbus_c
 /* Some globals */
 
 static GSM_Link *glink;
-static GSM_Statemachine *statemachine;
+static GSM_Statemachine *FBUS_statemachine;
 static FBUS_Link flink;                /* FBUS specific stuff, internal to this file */
 
 
@@ -166,9 +157,9 @@ void FBUS_RX_StateMachine(unsigned char rx_byte)
 
 #if 0
        if (isprint(rx_byte))
-               dprintf("[%02x%c]", (unsigned char) rx_byte, rx_byte);
+               fprintf(stderr, "[%02x%c]", (unsigned char) rx_byte, rx_byte);
        else
-               dprintf("[%02x ]", (unsigned char) rx_byte);
+               fprintf(stderr, "[%02x ]", (unsigned char) rx_byte);
 #endif
 
        /* XOR the byte with the current checksum */
@@ -319,11 +310,11 @@ void FBUS_RX_StateMachine(unsigned char rx_byte)
                                                        m->Malloced = 0;
                                                        m->MessageBuffer = NULL;
                                                }
-                                               m->Malloced = frm_num * m->MessageLength;
+                                               m->Malloced = frm_num *m->MessageLength;
                                                m->MessageBuffer = (char *) malloc(m->Malloced);
 
                                        } else if (m->FramesToGo != frm_num) {
-                                               dprintf("Missed a frame in a multiframe message.\n");
+                                               fprintf(stdout, "Missed a frame in a multiframe message.\n");
                                                /* FIXME - we should make sure we don't ack the rest etc */
                                        }
 
@@ -333,16 +324,16 @@ void FBUS_RX_StateMachine(unsigned char rx_byte)
                                        }
 
                                        memcpy(m->MessageBuffer + m->MessageLength, i->MessageBuffer,
-                                              i->FrameLength - 2);/* - (i->FrameLength % 2)); */
+                                              i->FrameLength - 2 - (i->FrameLength % 2));
 
-                                       m->MessageLength += i->FrameLength - 2;/* - (i->FrameLength % 2); */
+                                       m->MessageLength += i->FrameLength - 2 - (i->FrameLength % 2);
 
                                        m->FramesToGo--;
 
                                        /* Finally dispatch if ready */
 
                                        if (m->FramesToGo == 0) {
-                                               SM_IncomingFunction(statemachine, i->MessageType, m->MessageBuffer, m->MessageLength);
+                                               SM_IncomingFunction(FBUS_statemachine, i->MessageType, m->MessageBuffer, m->MessageLength);
                                                free(m->MessageBuffer);
                                                m->MessageBuffer = NULL;
                                                m->Malloced = 0;
@@ -537,15 +528,17 @@ int FBUS_TX_SendAck(u8 message_type, u8 message_seq)
 /* newlink is actually part of state - but the link code should not anything about state */
 /* state is only passed around to allow for muliple state machines (one day...) */
 
-GSM_Error FBUS_Initialise(GSM_Link *newlink, GSM_Statemachine *state, int type)
+GSM_Error FBUS_Initialise(GSM_Link *newlink, GSM_Statemachine *state)
 {
        unsigned char init_char = 0x55;
        unsigned char count;
+       static int try = 0;
 
-       if (type > 2) return GE_DEVICEOPENFAILED;
+       try++;
+       if (try > 2) return GE_DEVICEOPENFAILED;
        /* 'Copy in' the global structures */
        glink = newlink;
-       statemachine = state;
+       FBUS_statemachine = state;
 
        /* Fill in the link functions */
        glink->Loop = &FBUS_Loop;
@@ -564,7 +557,7 @@ GSM_Error FBUS_Initialise(GSM_Link *newlink, GSM_Statemachine *state, int type)
        } else {                /* ConnectionType == GCT_Serial */
                 /* FBUS_OpenSerial(0) - try dau-9p
                  * FBUS_OpenSerial(n != 0) - try dlr-3p */
-               if (!FBUS_OpenSerial(type))
+               if (!FBUS_OpenSerial(2 - try))
                        return GE_DEVICEOPENFAILED;
        }