gnokii-users
[Top][All Lists]
Advanced

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

let gnokii know about Bosch 909


From: Ladislav Michl
Subject: let gnokii know about Bosch 909
Date: Fri, 22 Nov 2002 15:46:17 +0100
User-agent: Mutt/1.2.5i

Hi,

this patch prepares gnokii for Bosch 909 support. SMS reading doesn't work
yet (will fix it later). There are also bits of Dancall update. Let me know
if I broke anything.

Regards,
        ladis

Index: gnokii/common/phones/Makefile
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/phones/Makefile,v
retrieving revision 1.14
diff -u -r1.14 Makefile
--- gnokii/common/phones/Makefile       5 Jun 2002 23:53:48 -0000       1.14
+++ gnokii/common/phones/Makefile       22 Nov 2002 14:19:39 -0000
@@ -23,10 +23,10 @@
        nk6510.o \
        nk6100.o \
        atgen.o \
+       atbosch.o \
        ateric.o \
        atnok.o \
        atsie.o \
-       dc2711.o \
        fake.o \
        nk6160.o
 
Index: gnokii/common/links/cbus.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/links/cbus.c,v
retrieving revision 1.18
diff -u -r1.18 cbus.c
--- gnokii/common/links/cbus.c  28 Sep 2002 23:51:37 -0000      1.18
+++ gnokii/common/links/cbus.c  22 Nov 2002 14:20:49 -0000
@@ -23,12 +23,11 @@
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
   Copyright (C) 2001 Pavel Machek <address@hidden>
-  Copyright (C) 2001 Michl Ladislav <address@hidden>
+  Copyright (C) 2001, 2002 Ladislav Michl <address@hidden>
 
  */
 
 /* System header files */
-
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -36,9 +35,6 @@
 
 /* Various header file */
 #include "config.h"
-#ifndef DEBUG
-#define DEBUG
-#endif
 #include "misc.h"
 #include "gsm-data.h"
 #include "gsm-ringtones.h"
@@ -46,63 +42,16 @@
 #include "device.h"
 
 #include "links/cbus.h"
-
-static gn_error CBUS_Loop(struct timeval *timeout);
-static bool CBUS_OpenSerial();
-static void CBUS_RX_StateMachine(unsigned char rx_byte);
-static int CBUS_SendMessage(u16 messagesize, u8 messagetype, unsigned char 
*message);
-
-/* FIXME - pass device_* the link stuff?? */
-/* FIXME - win32 stuff! */
-
+#include "links/atbus.h"
 
 /* Some globals */
+static GSM_Statemachine *statemachine;
 
-static GSM_Link *glink;
-static GSM_Phone *gphone;
-static CBUS_Link clink;        /* CBUS specific stuff, internal to this file */
-
-static int init_okay = 0;
-int seen_okay;
-char reply_buf[10240];
+/* CBUS specific stuff, internal to this file */
+static CBUS_Link clink;
 
-/*--------------------------------------------------------------------------*/
 
-static bool CBUS_OpenSerial()
-{
-       int result;
-       result = device_open(glink->PortDevice, false, false, false, 
GCT_Serial);
-       if (!result) {
-               perror(_("Couldn't open CBUS device"));
-               return (false);
-       }
-       device_changespeed(9600);
-       device_setdtrrts(1, 0);
-       return (true);
-}
-
-/* -------------------------------------------------------------------- */
-
-static int xread(unsigned char *d, int len)
-{
-       int res;
-       while (len) {
-               res = device_read(d, len);
-               if (res == -1) {
-                       if (errno != EAGAIN) {
-                               dprintf("I/O error : %m?!\n");
-                               return -1;
-                       } else device_select(NULL);
-               } else {
-                       d += res;
-                       len -= res;
-                       dprintf("(%d)", len);
-               }
-       }
-       return 0;
-}
-
-static int xwrite(unsigned char *d, int len)
+static gn_error bus_write(unsigned char *d, int len)
 {
        int res;
        while (len) {
@@ -110,138 +59,155 @@
                if (res == -1) {
                        if (errno != EAGAIN) {
                                dprintf("I/O error : %m?!\n");
-                               return -1;
+                               return GN_ERR_FAILED;
                        }
                } else {
                        d += res;
                        len -= res;
-                       dprintf("<%d>", len);
                }
        }
-       return 0;
+       return GN_ERR_NONE;
 }
 
-static void say(unsigned char *c, int len)
+static gn_error bus_read(unsigned char *rx_byte, unsigned int timeout)
 {
-       unsigned char d[10240];
-
-       xwrite(c, len);
-       xread(d, len);
-       if (memcmp(c, d, len)) {
-               int i;
-               dprintf("Did not get my own echo?: ");
-               for (i = 0; i < len; i++)
-                       dprintf("%x ", d[i]);
-               dprintf("\n");
-       }
-}
+       int res;
+       struct timeval tv;
+       
+       tv.tv_sec = 0;
+       tv.tv_usec = 1000 * timeout;
+//     res = device_select(&tv);
+       res = device_select(NULL);
+       if (res > 0)
+               res = device_read(rx_byte, 1);
+       else
+               return GN_ERR_TIMEOUT;
 
-static int waitack(void)
-{
-       unsigned char c;
-       dprintf("Waiting ack\n");
-       if (xread(&c, 1) == 0) {
-               dprintf("Got %x\n", c);
-               if (c != 0xa5)
-                       dprintf("???\n");
-               else return 1;
-       } else dprintf("Timeout?\n");
-       return 0;
+       /* This traps errors from device_read */
+       if (res > 0)
+               return GN_ERR_NONE;
+       else
+               return GN_ERR_INTERNALERROR;
 }
 
-static void sendpacket(unsigned char *msg, int len, unsigned short cmd)
+static gn_error send_packet(unsigned char *msg, int len, unsigned short cmd, 
bool init)
 {
-       unsigned char p[10240], csum = 0;
-       int pos;
+       unsigned char p[1024], csum = 0;
+       int i, pos;
 
-       p[0] = 0x34;
+       p[0] = (init) ? 0x38 : 0x34;
        p[1] = 0x19;
        p[2] = cmd & 0xff;
-       p[3] = 0x68;
+       p[3] = (init) ? 0x70 : 0x68;
        p[4] = len & 0xff;
        p[5] = len >> 8;
        memcpy(p+6, msg, len);
 
        pos = 6+len;
-       {
-               int i;
-               for (i = 0; i < pos; i++) {
-                       csum = csum ^ p[i];
-               }
-       }
+       for (i = 0; i < pos; i++)
+               csum ^= p[i];
        p[pos] = csum;
-       {
-               int i;
-               dprintf("Sending: ");
-               for (i = 0; i <= pos; i++) {
-                       dprintf("%x ", p[i]);
-               }
-               dprintf("\n");
-       }
-       say(p, pos+1);
-       waitack();
-}
-
-/* -------------------------------------------------------------------- */
+       dprintf("CBUS: sending ");
+       for (i = 0; i <= pos; i++)
+               dprintf("%02x ", p[i]);
+       dprintf("\n");
 
+       return bus_write(p, pos+1);
+}
 
-static gn_error CommandAck(int messagetype, unsigned char *buffer, int length)
+static void send_ack(void)
 {
-       dprintf("[ack]");
-       return GN_ERR_NONE;
+       dprintf("CBUS: sending ack\n");
+       bus_write("\xa5", 1);
 }
 
-static gn_error PhoneReply(int messagetype, unsigned char *buffer, int length)
+static void dump_packet(CBUS_IncomingFrame *frame)
 {
-       if (!strncmp(buffer, "OK", 2)) {
-               seen_okay = 1;
-               dprintf("Phone okays\n");
-       } else {
-               strncpy(reply_buf, buffer, length);
-               reply_buf[length+1] = '\0';
-               dprintf("Phone says: %s\n", reply_buf);
-       }
-       {
-               u8 buf[2] = { 0x3e, 0x68 };
-               usleep(10000);
-               CBUS_SendMessage(2, 0x3f, buf);
-       }
-
-       return GN_ERR_NONE;
+       int i;
+       
+       fprintf(stderr, "Hdr: %02x %02x   ", frame->FrameHeader1, 
frame->FrameHeader2);
+       fprintf(stderr, (frame->FrameHeader1 == 0x19) ? "->\n" : "<-\n");
+       fprintf(stderr, "Cmd: %02x %02x\n", frame->FrameType1, 
frame->FrameType2);
+       fprintf(stderr, "Len: %d\n", frame->MessageLength);
+       fprintf(stderr, "Data: ");
+       for (i = 0; i < frame->BufferCount; i++)
+               fprintf(stderr, "%02x ", frame->buffer[i]);
+       fprintf(stderr, "\n");
 }
 
-void sendat(unsigned char *msg)
+static void incoming_frame(unsigned char cmd1, unsigned char cmd2)
 {
-       usleep(10000);
-       dprintf("AT command: %s\n", msg);
-       CBUS_SendMessage(strlen(msg), 0x3c, msg);
-       seen_okay = 0;
-       while (!seen_okay)
-               CBUS_Loop(NULL);
-//     getpacket();    /* This should be phone's acknowledge of AT command */
+       switch(cmd2) {
+       case 0x68:
+               switch (cmd1) {
+               case 0x3d:
+                       dprintf("CBUS: <- AT command confirmed\n");
+                       break;
+               case 0x3e:
+                       dprintf("CBUS: <- AT command reply\n");
+                       break;
+               default:
+                       dprintf("CBUS: Unknown incoming frame (%02x/68)\n", 
cmd1);
+               }
+               break;
+       case 0x70:
+               switch (cmd1) {
+               case 0x91:
+                       dprintf("CBUS: <- Bus ready\n");
+                       break;
+               default:
+                       dprintf("CBUS: Unknown incoming frame (%02x/70)\n", 
cmd1);
+                       break;
+               }
+               break;
+       default:
+               dprintf("CBUS: Unknown incoming frame (%02x/%02x)\n", cmd1, 
cmd2);
+               break;
+       }
 }
 
-
-/* -------------------------------------------------- */
-
-/* RX_State machine for receive handling.  Called once for each character
-   received from the phone. */
-
-static void internal_dispatch(GSM_Link *glink, GSM_Phone *gphone, int type, u8 
*buf, int len)
+static void outgoing_frame(unsigned char cmd1, unsigned char cmd2)
 {
-       switch(type) {
-       case '=': CommandAck(type, buf, len);
+       switch(cmd2) {
+       case 0x68:
+               switch (cmd1) {
+               case 0x3c:
+                       dprintf("CBUS: -> AT command\n");
+                       break;
+               case 0x3f:
+                       dprintf("CBUS: -> AT reply confirmed\n");
+                       break;
+               default:
+                       dprintf("CBUS: Unknown frame (%02x/68)\n", cmd1);
+                       break;
+               }
                break;
-       case '>': PhoneReply(type, buf, len);
+       case 0x70:
+               switch (cmd1) {
+               case 0xa6:
+                       dprintf("CBUS: -> Init 0xa6\n");
+                       break;
+               case 0x90:
+                       dprintf("CBUS: -> Init 0x90\n");
+                       break;
+               default:
+                       dprintf("CBUS: Unknown frame (%02x/70)\n", cmd1);
+                       break;
+               }
                break;
-       default: dprintf("Unknown Frame Type 68/ %02x\n", type);
+       default:
+               dprintf("CBUS: Unknown frame (%02x/%02x)\n", cmd1, cmd2);
                break;
        }
 }
 
-static void CBUS_RX_StateMachine(unsigned char rx_byte)
+/* state machine for receive handling. Called once for each character
+   received from the phone. */
+
+static CBUS_PKT_State state_machine(unsigned char rx_byte)
 {
-       CBUS_IncomingFrame *i = &clink.i;
+       CBUS_PKT_State state = CBUS_PKT_None;
+       CBUS_IncomingFrame *i = &clink.frame;
 
        /* checksum is XOR of all bytes in the frame */
        if (i->state != CBUS_RX_GetCSum) i->checksum ^= rx_byte;
@@ -262,6 +228,7 @@
                                }
                                break;
                        default:
+                               dprintf("CBUS: discarding (%02x)\n", rx_byte);
                                break;
                }
                if (i->state != CBUS_RX_Header) {
@@ -272,13 +239,11 @@
                }
                break;
 
-       /* FIXME: Do you know exact meaning? just mail me. ladis. */
        case CBUS_RX_FrameType1:
                i->FrameType1 = rx_byte;
                i->state = CBUS_RX_FrameType2;
                break;
 
-       /* FIXME: Do you know exact meaning? just mail me. ladis. */
        case CBUS_RX_FrameType2:
                i->FrameType2 = rx_byte;
                i->state = CBUS_RX_GetLengthLB;
@@ -293,7 +258,7 @@
        /* message length - high byte */
        case CBUS_RX_GetLengthHB:
                i->MessageLength = i->MessageLength | rx_byte << 8;
-               /* there are also empty commands */
+               /* there are also empty messages */
                if (i->MessageLength == 0)
                        i->state = CBUS_RX_GetCSum;
                else
@@ -302,10 +267,9 @@
 
        /* get each byte of the message body */
        case CBUS_RX_GetMessage:
-               i->buffer[i->BufferCount++] = rx_byte;
-               /* avoid buffer overflow */
-               if (i->BufferCount > CBUS_MAX_MSG_LENGTH) {
-                       dprintf("CBUS: Message buffer overun - resetting\n");
+               i->buffer[i->BufferCount] = rx_byte;
+               /* avoid buffer overflow */             if (i->BufferCount > 
CBUS_MAX_MSG_LENGTH) {
+               dprintf("CBUS: Message buffer overun - resetting\n");
                        i->state = CBUS_RX_Header;
                        break;
                }
@@ -318,78 +282,219 @@
        case CBUS_RX_GetCSum:
                /* compare against calculated checksum. */
                if (i->checksum == rx_byte) {
-                       u8 ack = 0xa5;
-
-                       xwrite(&ack, 1);
-                       xread(&ack, 1);
-                       if (ack != 0xa5)
-                               dprintf("ack lost, expect armagedon!\n");
-
-                       /* Got checksum, matches calculated one, so
-                        * now pass to appropriate dispatch handler. */
-                       i->buffer[i->MessageLength + 1] = 0;
-                       /* FIXME: really call it :-) */
-
-                       switch(i->FrameType2) {
-                       case 0x68:
-                               internal_dispatch(glink, gphone, i->FrameType1, 
i->buffer, i->MessageLength);
-                               break;
-                       case 0x70:
-                               if (i->FrameType1 == 0x91) {
-                                       init_okay = 1;
-                                       dprintf("Registration acknowledged\n");
-                               } else
-                                       dprintf("Unknown message\n");
-                       }
+                       dump_packet(i);
+                       state = CBUS_PKT_Ready;
                } else {
-                       /* checksum doesn't match so ignore. */
-                       dprintf("CBUS: Checksum error; expected: %02x, got: 
%02x", i->checksum, rx_byte);
+                       dprintf("CBUS: Checksum error; expected: %02x, got: 
%02x\n", i->checksum, rx_byte);
+                       state = CBUS_PKT_CSumErr;
                }
-
+               i->buffer[i->MessageLength + 1] = 0;
                i->state = CBUS_RX_Header;
                break;
-
        default:
                break;
        }
+
        i->prev_rx_byte = rx_byte;
+       return state;
 }
 
-static int CBUS_SendMessage(u16 message_length, u8 message_type, unsigned char 
*buffer)
+static gn_error get_packet(void)
 {
-       sendpacket(buffer, message_length, message_type);
-       return true;
+       gn_error res;
+       CBUS_PKT_State state = CBUS_PKT_None;
+       unsigned char rx_byte;
+       int retry = 20;
+       CBUS_IncomingFrame *i = &clink.frame;   
+
+       i->state = CBUS_RX_Header;
+       while (state == CBUS_PKT_None && --retry) {
+               res = bus_read(&rx_byte, 10);
+               if (!res) {
+                       retry = 20;
+                       state = state_machine(rx_byte);
+               } else
+                       usleep(1000);
+//                     if (--retry) {
+//                             usleep(5000);
+//                             continue;
+//                     }
+//                     return res;
+//             }
+//             retry = 20;
+//             state = state_machine(rx_byte);
+       }
+       dprintf("CBUS: Got packet\n");
+       return (res) ? GN_ERR_INTERNALERROR : GN_ERR_NONE;
+}
+
+static gn_error wait_ack(void)
+{
+       gn_error res;
+       unsigned char rx_byte;
+       int retry = 555550;
+
+//     do {
+//             res = bus_read(&rx_byte, 10);
+//             if (!res) {
+//                     device_flush();
+//                     return (rx_byte == 0xa5) ? GE_NONE : GE_INTERNALERROR;
+//             }
+//             usleep(5000);
+//     } while (--retry);
+       while (--retry) {
+               res = bus_read(&rx_byte, 10);
+               if (!res) 
+                       return (rx_byte == 0xa5) ? GN_ERR_NONE : 
GN_ERR_INTERNALERROR;
+               else
+                       usleep(1000);
+       }
+       return GN_ERR_INTERNALERROR;
+}
+
+/* 
+ * send packet and wait for 'ack'. 
+ */
+static gn_error send_packet_ack(unsigned char *msg, int len, unsigned short 
cmd, bool init)
+{
+       gn_error res;
+       int retry = 3;
+       CBUS_IncomingFrame *i = &clink.frame;
+
+       do {
+               retry--;
+               res = send_packet(msg, len, cmd, init);
+               if (res) {
+                       dprintf("CBUS: send_packet failed\n");
+                       continue;
+               }
+               usleep(50000);
+again:
+               res = get_packet();
+               if (res) {
+                       dprintf("CBUS: get_packet failed\n");
+                       continue;
+               }
+               if (i->FrameType1 != cmd) {
+                       dprintf("CBUS: get_packet is not the right packet\n");
+                       goto again;
+               }
+               res = wait_ack();
+               if (res) {
+                       dprintf("CBUS: wait_ack failed\n");
+                       continue;
+               }
+               dprintf("CBUS: Phone acks\n");
+       } while (retry && res);
+       
+       return res;
+}
+
+static gn_error bus_reset(void)
+{
+       gn_error res;
+       CBUS_IncomingFrame *i = &clink.frame;
+
+//     bus_write("\0\0\0\0\0", 5);
+       usleep(1000);
+       send_packet_ack("", 0, 0xa6, true);
+       send_packet_ack("D", 1, 0x90, true);
+       res = get_packet();
+       if (res)
+               return res;
+       if (i->FrameType1 != 0x91) {
+               dprintf("CBUS: Bus reset failed\n");
+               return GN_ERR_NOLINK;
+       }
+       send_ack();
+       usleep(1000);
+       send_ack();
+       usleep(1000);
+       send_ack();
+       usleep(1000);
+       send_ack();
+       dprintf("CBUS: Bus reset ok\n");
+       usleep(100000);
+       return GN_ERR_NONE;
+}
+
+/*
+                       send_ack();
+                       clink.AT_message[0] = GEAT_OK;
+                       strncpy(clink.AT_message + 1, buffer, length);
+                       clink.AT_message_len = length;
+                       send_packet("\x3e\x68", 2, 0x3f, false);
+*/
+
+static gn_error wait_at_confirmation(void)
+{
+       gn_error res;
+       CBUS_IncomingFrame *i = &clink.frame;
+       
+       res = get_packet();
+       if (res)
+               return res;
+       if (i->FrameType1 != 0x3d) {
+               dprintf("CBUS: AT command confirmation expected, but got 
%02x/%02x\n", i->FrameType1, i->FrameType2);
+               return GN_ERR_INTERNALERROR;
+       }
+       dprintf("CBUS: AT command confirmed\n");
+       return GN_ERR_NONE;
+}
+
+static gn_error get_at_reply(void)
+{
+       gn_error res;
+       CBUS_IncomingFrame *i = &clink.frame;
+
+       res = get_packet();
+       if (res)
+               return res;
+       if (i->FrameType2 != 0x3e) {
+               dprintf("CBUS: AT command reply expected, but got %02x/%02x\n", 
i->FrameType1, i->FrameType2);
+               return GN_ERR_INTERNALERROR;
+       }
+       dprintf("CBUS: AT reply: %s", i->buffer);
+       send_ack();
+       return send_packet_ack("\x3e\x68", 2, 0x3f, false);
 }
 
 static gn_error AT_SendMessage(u16 message_length, u8 message_type, unsigned 
char *buffer)
 {
-       sendat(buffer);
+       gn_error res;
+
+       res = send_packet_ack(buffer, message_length, 0x3c, false);
+       if (res)
+               return res;
+       dprintf("CBUS: AT command sent - %s\n", buffer);
+//     usleep(100000);
+       res = wait_at_confirmation();
+       if (res)
+               return res;
+       send_ack();
+       return get_at_reply();
+}
+
+static bool CBUS_OpenSerial(char *device)
+{
+       int result = device_open(device, false, false, false, GCT_Serial);
+       if (!result) {
+               perror(_("Couldn't open CBUS device"));
+               return false;
+       }
+       device_changespeed(9600);
+       device_setdtrrts(1, 0);
        return true;
 }
 
+
 /* This is the main loop function which must be called regularly */
 /* timeout can be used to make it 'busy' or not */
 
-/* ladis: this function ought to be the same for all phones... */
-
 static gn_error CBUS_Loop(struct timeval *timeout)
 {
-       unsigned char buffer[255];
-       int count, res;
-
-       res = device_select(timeout);
-       if (res > 0) {
-               res = device_read(buffer, 255);
-               for (count = 0; count < res; count++)
-                       CBUS_RX_StateMachine(buffer[count]);
-       } else
-               return GN_ERR_TIMEOUT;
-
-       /* This traps errors from device_read */
-       if (res > 0)
-               return GN_ERR_NONE;
-       else
-               return GN_ERR_INTERNALERROR;
+//     SM_IncomingFunction(statemachine, statemachine->LastMsgType, 
clink.AT_message, clink.AT_message_len);
+       return GN_ERR_NONE;
 }
 
 
@@ -401,36 +506,19 @@
        setvbuf(stderr, NULL, _IONBF, 0);
 
        /* 'Copy in' the global structures */
-       glink = &(state->Link);
-       gphone = &(state->Phone);
-
+       statemachine = state;
+               
        /* Fill in the link functions */
-       glink->Loop = &CBUS_Loop;
-       glink->SendMessage = &AT_SendMessage;
+       state->Link.Loop = &CBUS_Loop;
+       state->Link.SendMessage = &AT_SendMessage;
 
-       if (glink->ConnectionType == GCT_Serial) {
-               if (!CBUS_OpenSerial())
+       if (state->Link.ConnectionType == GCT_Serial) {
+               if (!CBUS_OpenSerial(state->Link.PortDevice))
                        return GN_ERR_FAILED;
        } else {
-               dprintf("Device not supported by CBUS");
+               dprintf("Device not supported by CBUS\n");
                return GN_ERR_FAILED;
        }
 
-       dprintf("Saying hello...");
-       {
-               char init1[] = { 0, 0x38, 0x19, 0xa6, 0x70, 0x00, 0x00, 0xf7, 
0xa5 };
-               say(init1, 8);
-               say(init1, 8);
-       }
-       usleep(10000);
-       dprintf("second hello...");
-       {
-               char init1[] = { 0x38, 0x19, 0x90, 0x70, 0x01, 0x00, 0x1f, 0xdf 
};
-               say(init1, 8);
-               if (!waitack())
-                       return GN_ERR_BUSY;
-       }
-       while (!init_okay)
-               CBUS_Loop(NULL);
-       return GN_ERR_NONE;
+       return bus_reset();
 }
Index: gnokii/include/links/cbus.h
===================================================================
RCS file: /cvsroot/gnokii/gnokii/include/links/cbus.h,v
retrieving revision 1.7
diff -u -r1.7 cbus.h
--- gnokii/include/links/cbus.h 28 Sep 2002 23:51:38 -0000      1.7
+++ gnokii/include/links/cbus.h 22 Nov 2002 14:21:26 -0000
@@ -34,20 +34,27 @@
 #define CBUS_MAX_TRANSMIT_LENGTH 256
 #define CBUS_MAX_MSG_LENGTH 256
 
-enum CBUS_RX_States {
+typedef enum {
        CBUS_RX_Header,
        CBUS_RX_FrameType1,
        CBUS_RX_FrameType2,
        CBUS_RX_GetLengthLB,
        CBUS_RX_GetLengthHB,
        CBUS_RX_GetMessage,
-       CBUS_RX_GetCSum
-};
+       CBUS_RX_GetCSum,
+       CBUS_RX_GetAck
+} CBUS_RX_State;
+
+typedef enum {
+       CBUS_PKT_None,
+       CBUS_PKT_Ready,
+       CBUS_PKT_CSumErr
+} CBUS_PKT_State;
 
 typedef struct{
        int checksum;
        int BufferCount;
-       enum CBUS_RX_States state;
+       CBUS_RX_State state;
        int FrameHeader1;
        int FrameHeader2;
        int FrameType1;
@@ -63,11 +70,9 @@
 } CBUS_OutgoingMessage;
 
 typedef struct{
-       CBUS_IncomingFrame i;
+       CBUS_IncomingFrame frame;
 } CBUS_Link;
 
 gn_error CBUS_Initialise(GSM_Statemachine *state);
-
-void sendat(unsigned char *msg);
 
 #endif   /* #ifndef __cbus_h */
Index: gnokii/include/phones/atgen.h
===================================================================
RCS file: /cvsroot/gnokii/gnokii/include/phones/atgen.h,v
retrieving revision 1.9
diff -u -r1.9 atgen.h
--- gnokii/include/phones/atgen.h       28 Sep 2002 23:51:38 -0000      1.9
+++ gnokii/include/phones/atgen.h       22 Nov 2002 14:21:45 -0000
@@ -34,6 +34,7 @@
 
 typedef enum {
        GOPAT_GetCharset = GOP_Max,
+       GOPAT_SetCharset,
        GOPAT_SetPDUMode,
        GOPAT_Prompt,
        GOPAT_Max       /* don't append anything after this entry */
Index: gnokii/common/phones/atgen.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/phones/atgen.c,v
retrieving revision 1.58
diff -u -r1.58 atgen.c
--- gnokii/common/phones/atgen.c        29 Sep 2002 19:29:26 -0000      1.58
+++ gnokii/common/phones/atgen.c        22 Nov 2002 14:22:43 -0000
@@ -40,9 +40,10 @@
 #include "gsm-encoding.h"
 #include "phones/generic.h"
 #include "phones/atgen.h"
+#include "phones/atbosch.h"
 #include "phones/ateric.h"
-#include "phones/atsie.h"
 #include "phones/atnok.h"
+#include "phones/atsie.h"
 #include "links/atbus.h"
 #ifndef WIN32
 #  include "links/cbus.h"
@@ -83,6 +84,7 @@
 static gn_error AT_GetSMS(GSM_Data *data, GSM_Statemachine *state);
 static gn_error AT_DeleteSMS(GSM_Data *data, GSM_Statemachine *state);
 static gn_error AT_GetCharset(GSM_Data *data, GSM_Statemachine *state);
+static gn_error AT_SetCharset(GSM_Data *data, GSM_Statemachine *state);
 static gn_error AT_GetSMSCenter(GSM_Data *data, GSM_Statemachine *state);
 static gn_error AT_EnterSecurityCode(GSM_Data *data, GSM_Statemachine *state);
 static gn_error AT_GetSecurityCodeStatus(GSM_Data *data, GSM_Statemachine 
*state);
@@ -118,6 +120,7 @@
        { GOP_GetSMS, AT_GetSMS, ReplyGetSMS },
        { GOP_DeleteSMS, AT_DeleteSMS, Reply },
        { GOPAT_GetCharset, AT_GetCharset, ReplyGetCharset },
+       { GOPAT_SetCharset, AT_SetCharset, Reply },
        { GOP_GetSMSCenter, AT_GetSMSCenter, ReplyGetSMSCenter },
        { GOP_GetSecurityCodeStatus, AT_GetSecurityCodeStatus, 
ReplyGetSecurityCodeStatus },
        { GOP_EnterSecurityCode, AT_EnterSecurityCode, Reply },
@@ -307,7 +310,7 @@
 }
 
 
-/* SetCharset
+/* AT_SetCharset
  *
  * before we start sending or receiving phonebook entries from the phone,
  * we should set a charset. this is done once before the first read or write.
@@ -339,34 +342,34 @@
  *
  * GSM_Data has no field for charset so i misuse Model.
  */
-static gn_error SetCharset(GSM_Statemachine *state)
+static gn_error AT_SetCharset(GSM_Data *data, GSM_Statemachine *state)
 {
        char req[128];
        char charsets[256];
+       GSM_Data tmpdata;
        gn_error ret = GN_ERR_NONE;
-       GSM_Data data;
 
        if (atcharset == CHARNONE) {
                /* check if ucs2 is available */
                sprintf(req, "AT+CSCS=?\r");
                ret = SM_SendMessage(state, 10, GOPAT_GetCharset, req);
-               if (ret != GN_ERR_NONE)
+               if (ret)
                        return GN_ERR_NOTREADY;
-               GSM_DataClear(&data);
+               GSM_DataClear(&tmpdata);
                *charsets = '\0';
-               data.Model = charsets;
-               ret = SM_BlockNoRetry(state, &data, GOPAT_GetCharset);
-               if (ret != GN_ERR_NONE) {
+               tmpdata.Model = charsets;
+               ret = SM_BlockNoRetry(state, &tmpdata, GOPAT_GetCharset);
+               if (ret) {
                        *charsets = '\0';
                }
                else if (strstr(charsets, "UCS2")) {
                        /* ucs2 charset found. try to set it */
                        sprintf(req, "AT+CSCS=\"UCS2\"\r");
                        ret = SM_SendMessage(state, 15, GOP_Init, req);
-                       if (ret != GN_ERR_NONE)
+                       if (ret)
                                return GN_ERR_NOTREADY;
-                       GSM_DataClear(&data);
-                       ret = SM_BlockNoRetry(state, &data, GOP_Init);
+                       GSM_DataClear(&tmpdata);
+                       ret = SM_BlockNoRetry(state, &tmpdata, GOP_Init);
                        if (ret == GN_ERR_NONE)
                                atcharset = CHARUCS2;
                }
@@ -381,19 +384,19 @@
                                /* try to set hex charset */
                                sprintf(req, "AT+CSCS=\"HEX\"\r");
                                ret = SM_SendMessage(state, 14, GOP_Init, req);
-                               if (ret != GN_ERR_NONE)
+                               if (ret)
                                        return GN_ERR_NOTREADY;
-                               GSM_DataClear(&data);
-                               ret = SM_BlockNoRetry(state, &data, GOP_Init);
+                               GSM_DataClear(&tmpdata);
+                               ret = SM_BlockNoRetry(state, &tmpdata, 
GOP_Init);
                                if (ret == GN_ERR_NONE)
                                        atcharset = CHARHEXGSM;
                        } else {
                                sprintf(req, "AT+CSCS=\"GSM\"\r");
                                ret = SM_SendMessage(state, 14, GOP_Init, req);
-                               if (ret != GN_ERR_NONE)
+                               if (ret)
                                        return GN_ERR_NOTREADY;
-                               GSM_DataClear(&data);
-                               ret = SM_BlockNoRetry(state, &data, GOP_Init);
+                               GSM_DataClear(&tmpdata);
+                               ret = SM_BlockNoRetry(state, &tmpdata, 
GOP_Init);
                                if (ret == GN_ERR_NONE)
                                        atcharset = CHARGSM;
                        }
@@ -535,17 +538,16 @@
        char req[128];
        gn_error ret;
 
-       ret = SetCharset(state);
-       if (ret != GN_ERR_NONE)
+       ret = state->Phone.Functions(GOPAT_SetCharset, &data, state);
+       if (ret)
                return ret;
        ret = AT_SetMemoryType(data->PhonebookEntry->MemoryType,  state);
-       if (ret != GN_ERR_NONE)
+       if (ret)
                return ret;
        sprintf(req, "AT+CPBR=%d\r", data->PhonebookEntry->Location);
        if (SM_SendMessage(state, strlen(req), GOP_ReadPhonebook, req) != 
GN_ERR_NONE)
                return GN_ERR_NOTREADY;
-       ret = SM_BlockNoRetry(state, data, GOP_ReadPhonebook);
-       return ret;
+       return SM_BlockNoRetry(state, data, GOP_ReadPhonebook);
 }
 
 
@@ -1214,9 +1216,15 @@
 
        SM_Initialise(state);
 
+       /* Dancall is crap and not real AT phone */
+       if (!strcmp(setupdata->Model, "dancall")) {
+               data.Manufacturer = "dancall";
+               dprintf("Dancall initialisation completed\n");
+               return GN_ERR_NONE;
+       }
+       
        SoftReset(&data, state);
        SetEcho(&data, state);
-       StoreDefaultCharset(state);
 
        /*
         * detect manufacturer and model for further initialization
@@ -1230,12 +1238,16 @@
        ret = state->Phone.Functions(GOP_GetManufacturer, &data, state);
        if (ret != GN_ERR_NONE) return ret;
 
-       if (!strncasecmp(manufacturer, "ericsson", 8))
+       if (!strncasecmp(manufacturer, "bosch", 5))
+               AT_InitBosch(state, model, setupdata->Model);
+       else if (!strncasecmp(manufacturer, "ericsson", 8))
                AT_InitEricsson(state, model, setupdata->Model);
-       if (!strncasecmp(manufacturer, "siemens", 7))
-               AT_InitSiemens(state, model, setupdata->Model);
-       if (!strncasecmp(manufacturer, "nokia", 5))
+       else if (!strncasecmp(manufacturer, "nokia", 5))
                AT_InitNokia(state, model, setupdata->Model);
+       else if (!strncasecmp(manufacturer, "siemens", 7))
+               AT_InitSiemens(state, model, setupdata->Model);
+       
+       StoreDefaultCharset(state);
 
        dprintf("Initialisation completed\n");
 
--- /dev/null   2002-11-20 10:52:22.000000000 +0100
+++ gnokii/include/phones/atbosch.h     2002-11-19 21:20:30.000000000 +0100
@@ -0,0 +1,37 @@
+/*
+
+  $Id: ateric.h,v 1.3 2002/03/28 21:37:49 pkot Exp $
+
+  G N O K I I
+
+  A Linux/Unix toolset and driver for mobile phones.
+
+  This file is part of gnokii.
+
+  Gnokii is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  Gnokii is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with gnokii; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+  Copyright 2002 Ladislav Michl <address@hidden>
+
+  This file provides functions specific to at commands on ericsson
+  phones. See README for more details on supported mobile phones.
+
+*/
+
+#ifndef __atbosch_h_
+#define __atbosch_h_
+
+void AT_InitBosch(GSM_Statemachine *state, char* foundmodel, char* setupmodel);
+
+#endif
--- /dev/null   2002-11-20 10:52:22.000000000 +0100
+++ gnokii/common/phones/atbosch.c      2002-11-22 14:17:01.000000000 +0100
@@ -0,0 +1,71 @@
+/*
+
+  $Id: ateric.c,v 1.5 2002/07/26 21:00:59 bozo Exp $
+
+  G N O K I I
+
+  A Linux/Unix toolset and driver for mobile phones.
+
+  This file is part of gnokii.
+
+  Gnokii is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  Gnokii is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with gnokii; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+  Copyright 2002 Ladislav Michl <address@hidden>
+
+  This file provides functions specific to at commands on ericsson
+  phones. See README for more details on supported mobile phones.
+
+*/
+
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "misc.h"
+#include "gsm-common.h"
+#include "gsm-statemachine.h"
+#include "phones/generic.h"
+#include "phones/atgen.h"
+#include "phones/atbosch.h"
+#include "links/atbus.h"
+
+static gn_error GetCharset(GSM_Data *data, GSM_Statemachine *state)
+{
+       data->Model = "HEX";
+       return GN_ERR_NONE;
+}
+
+static gn_error SetCharset(GSM_Data *data, GSM_Statemachine *state)
+{
+       return GN_ERR_NONE;
+}
+
+static gn_error Unsupported(GSM_Data *data, GSM_Statemachine *state)
+{
+       return GN_ERR_NOTSUPPORTED;
+}
+
+void AT_InitBosch(GSM_Statemachine *state, char *foundmodel, char *setupmodel)
+{
+       AT_InsertRecvFunction(GOPAT_GetCharset, NULL);
+       AT_InsertSendFunction(GOPAT_GetCharset, GetCharset);
+       AT_InsertRecvFunction(GOPAT_SetCharset, NULL);
+       AT_InsertSendFunction(GOPAT_SetCharset, SetCharset);
+       /* phone lacks many usefull commands :( */
+       AT_InsertSendFunction(GOP_GetBatteryLevel, Unsupported);
+       AT_InsertSendFunction(GOP_GetRFLevel, Unsupported);
+       AT_InsertSendFunction(GOP_GetSecurityCodeStatus, Unsupported);
+       AT_InsertSendFunction(GOP_EnterSecurityCode, Unsupported);
+}




reply via email to

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