First version, development moved to 5110-connected machine
[gnokii.git] / common / data / at-emulator.c
index 41445c8..5f84b0b 100644 (file)
@@ -14,6 +14,8 @@
   
 */
 
+#include "config.h"
+
 #define                __data_at_emulator_c
 
 
@@ -50,28 +52,32 @@ bool ATEM_Initialised = false;      /* Set to true once initialised */
 extern bool    CommandMode;
 extern int ConnectCount;
 
-char ModelName[80]; /* This seems to be needed to avoid seg-faults */
-char PortName[80];
+static char ModelName[80]; /* This seems to be needed to avoid seg-faults */
+static char PortName[80];
 
 
        /* Local variables */
-int    PtyRDFD;        /* File descriptor for reading and writing to/from */
-int    PtyWRFD;        /* pty interface - only different in debug mode. */ 
+extern int     PtyRDFD;        /* File descriptor for reading and writing to/from */
+extern int     PtyWRFD;        /* pty interface - only different in debug mode. */ 
+
+static u8      ModemRegisters[MAX_MODEM_REGISTERS];
+static char    CmdBuffer[MAX_CMD_BUFFERS][CMD_BUFFER_LENGTH];
+static int     CurrentCmdBuffer;
+static int     CurrentCmdBufferIndex;
+static bool    VerboseResponse;        /* Switch betweek numeric (4) and text responses (ERROR) */
+static char    IncomingCallNo;
+static int     MessageFormat;          /* Message Format (text or pdu) */
 
-u8     ModemRegisters[MAX_MODEM_REGISTERS];
-char   CmdBuffer[MAX_CMD_BUFFERS][CMD_BUFFER_LENGTH];
-int    CurrentCmdBuffer;
-int    CurrentCmdBufferIndex;
-bool   VerboseResponse;        /* Switch betweek numeric (4) and text responses (ERROR) */
-char    IncomingCallNo;
-int     MessageFormat;          /* Message Format (text or pdu) */
+static void    ATEM_ParseAT(char *cmd_buffer);
 
        /* Current command parser */
-void   (*Parser)(char *);
+static void    (*Parser)(char *);
 //void         (*Parser)(char *) = ATEM_ParseAT; /* Current command parser */
 
-GSM_MemoryType         SMSType;
-int    SMSNumber;
+static GSM_MemoryType  SMSType;
+static int     SMSNumber;
+
+static void    ATEM_InitRegisters(void);
 
        /* If initialised in debug mode, stdin/out is used instead
           of ptys for interface. */
@@ -112,7 +118,7 @@ bool        ATEM_Initialise(int read_fd, int write_fd, char *model, char *port)
 }
 
        /* Initialise the "registers" used by the virtual modem. */
-void   ATEM_InitRegisters(void) 
+static void    ATEM_InitRegisters(void) 
 {
 
        ModemRegisters[REG_RINGATA] = 0;
@@ -137,6 +143,7 @@ void ATEM_CallPassup(char c)
        }
 }
 
+static void    ATEM_StringOut(char *buffer);
 
     /* Handler called when characters received from serial port.
        calls state machine code to process it. */
@@ -177,9 +184,13 @@ void       ATEM_HandleIncomingData(char *buffer, int length)
        }
 }     
 
+static bool    ATEM_CommandPlusC(char **buf);
+static bool    ATEM_CommandPlusG(char **buf);
+static int             ATEM_GetNum(char **p);
+static void    ATEM_ParseSMS(char *cmd_buffer);
 
        /* Parser for standard AT commands.  cmd_buffer must be null terminated. */
-void   ATEM_ParseAT(char *cmd_buffer)
+static void    ATEM_ParseAT(char *cmd_buffer)
 {
        char *buf;
        char number[30];
@@ -365,8 +376,10 @@ static void ATEM_HandleSMS()
        return;
 }
 
+static void    ATEM_ParseDIR(char *cmd_buffer);
+
        /* Parser for SMS interactive mode */
-void   ATEM_ParseSMS(char *buff)
+static void    ATEM_ParseSMS(char *buff)
 {
        if (!strcasecmp(buff, "HELP")) {
                ATEM_StringOut(_("\n\rThe following commands work...\n\r"));
@@ -391,7 +404,7 @@ void        ATEM_ParseSMS(char *buff)
 }
 
        /* Parser for DIR sub mode of SMS interactive mode. */
-void   ATEM_ParseDIR(char *buff)
+static void    ATEM_ParseDIR(char *buff)
 {
        switch (toupper(*buff)) {
                case 'P':
@@ -415,7 +428,7 @@ void        ATEM_ParseDIR(char *buff)
  
        /* Handle AT+C commands, this is a quick hack together at this
           stage. */
-bool   ATEM_CommandPlusC(char **buf)
+static bool    ATEM_CommandPlusC(char **buf)
 {
        float           rflevel;
        GSM_RFUnits     rfunits = GRF_CSQ;
@@ -515,7 +528,7 @@ bool        ATEM_CommandPlusC(char **buf)
                switch (**buf) {
                case '=':
                        buf[0]++;
-                       sscanf(*buf, "%d", &index);
+                       index = atoi(*buf);
                        buf[0] += strlen(*buf);
 
                        error = ATEM_ReadSMS(index, SMSType, &message);
@@ -599,7 +612,7 @@ bool        ATEM_CommandPlusC(char **buf)
 }
 
        /* AT+G commands.  Some of these responses are a bit tongue in cheek... */
-bool   ATEM_CommandPlusG(char **buf)
+static bool    ATEM_CommandPlusG(char **buf)
 {
        char            buffer[MAX_LINE_LENGTH];
 
@@ -685,7 +698,7 @@ void        ATEM_ModemResult(int code)
 
        /* Get integer from char-pointer, set pointer to end of number
           stolen basically verbatim from ISDN code.  */
-int ATEM_GetNum(char **p)
+static int ATEM_GetNum(char **p)
 {
        int v = -1;
 
@@ -699,7 +712,7 @@ int ATEM_GetNum(char **p)
        /* Write string to virtual modem port, either pty or
           STDOUT as appropriate.  This function is only used during
           command mode - data pump is used when connected.  */
-void   ATEM_StringOut(char *buffer)
+static void    ATEM_StringOut(char *buffer)
 {
        int             count = 0;
        char    out_char;