This commit was generated by cvs2svn to compensate for changes in r158,
[gnokii.git] / common / phones / nk2110.c
index 15e528a..bcf6e1b 100644 (file)
 
   Released under the terms of the GNU GPL, see file COPYING for more details.
 
 
   Released under the terms of the GNU GPL, see file COPYING for more details.
 
+  $Log$
+  Revision 1.1.1.3  2002/04/03 00:08:09  short
+  Found in "gnokii-working" directory, some November-patches version
+
+  Revision 1.12  2001/10/21 22:23:56  machek
+  Use symbolic constants instead of numbers
+
+  At least detect when we get other message than we asked for
+
+  Provide option to passively wait for sms-es
+
+  Revision 1.11  2001/08/20 23:27:37  pkot
+  Add hardware shakehand to the link layer (Manfred Jonsson)
+
+  Revision 1.10  2001/07/17 22:46:27  pkot
+  Removed warning when compiling with --enable-debug (Pawel Kot)
+
+  Revision 1.9  2001/06/17 16:42:59  machek
+  Created another level of error message (ddprintf), fixed code not to
+  exit on error condition. Now it is actualy usable on my Philips Velo.
+
+  Revision 1.8  2001/06/16 10:00:41  machek
+  Implement timeouts on waiting for SMS.
+
+  Revision 1.7  2001/06/10 23:49:49  pkot
+  Small fixes to hide compilation warnings and allow gnokii.c to compile
+
+  Revision 1.6  2001/06/10 11:28:00  machek
+  Convert GetSMS/DeleteSMS to new structure.
+
+  Revision 1.5  2001/06/06 09:05:56  machek
+  Convert Grab/Release display to new structure.
+
+  Revision 1.4  2001/05/09 20:18:46  machek
+  Cleaned up code a bit. Made it use device_() interface. Reworked delay
+  system; now it is 4 times faster. 5 times faster if you hold * key on
+  phone (?!).
+
+  Revision 1.3  2001/05/07 14:13:03  machek
+  nokia-2110 module converted to suit new API better. --identify now works.
+
+  Revision 1.2  2001/04/27 16:00:01  machek
+  Better error messages.
+
+  Revision 1.1  2001/04/25 12:54:47  machek
+  Partly converted nokia 2110 to "new" form, and moved it to phone
+  directory.
+
+
   Notice that this code was (partly) converted to "new" structure, but it 
   does not have code for bus separated. I think that separating it would
   be waste of effort...                                        --pavel
   Notice that this code was (partly) converted to "new" structure, but it 
   does not have code for bus separated. I think that separating it would
   be waste of effort...                                        --pavel
@@ -38,7 +87,6 @@
 #include "mbus-2110.h"
 #include "phones/nokia.h"
 #include "device.h"
 #include "mbus-2110.h"
 #include "phones/nokia.h"
 #include "device.h"
-#include "gsm-sms.h"
 
 #include <string.h>
 #include <stdlib.h>
 
 #include <string.h>
 #include <stdlib.h>
@@ -309,7 +357,8 @@ SMS(GSM_SMSMessage *message, int command)
        PacketOK = false;
        pkt[1] = command;
        pkt[2] = 1; /* == LM_SMS_MEM_TYPE_DEFAULT or LM_SMS_MEM_TYPE_SIM or LM_SMS_MEM_TYPE_ME */
        PacketOK = false;
        pkt[1] = command;
        pkt[2] = 1; /* == LM_SMS_MEM_TYPE_DEFAULT or LM_SMS_MEM_TYPE_SIM or LM_SMS_MEM_TYPE_ME */
-       pkt[3] = message->Number;
+       pkt[3] = message->Location;
+       message->MessageNumber = message->Location;
 
        SendCommand(pkt, LM_SMS_COMMAND, sizeof(pkt));
        msleep_poll(300);       /* We have to keep acknowledning phone's data */
 
        SendCommand(pkt, LM_SMS_COMMAND, sizeof(pkt));
        msleep_poll(300);       /* We have to keep acknowledning phone's data */
@@ -321,8 +370,8 @@ SMS(GSM_SMSMessage *message, int command)
                eprintf("Something is very wrong with SMS\n");
                return GE_BUSY; /* FIXME */
        }
                eprintf("Something is very wrong with SMS\n");
                return GE_BUSY; /* FIXME */
        }
-       if ((SMSData[2]) && (SMSData[2] != message->Number)) {
-               eprintf("Wanted message @%d, got message at @%d!\n", message->Number, SMSData[2]);
+       if ((SMSData[2]) && (SMSData[2] != message->Location)) {
+               eprintf("Wanted message @%d, got message at @%d!\n", message->Location, SMSData[2]);
                return GE_BUSY;
        }
        return (GE_NONE);
                return GE_BUSY;
        }
        return (GE_NONE);
@@ -332,23 +381,28 @@ SMS(GSM_SMSMessage *message, int command)
 static GSM_Error
 DecodeIncomingSMS(GSM_SMSMessage *m)
 {
 static GSM_Error
 DecodeIncomingSMS(GSM_SMSMessage *m)
 {
-       GSM_Error error;
-       int len, i;
-
-       error = GE_NONE;
-/*     Should be moved to gsm-sms.c */
-
+       int i, len;
        ddprintf("Status: " );
        switch (SMSData[3]) {
        ddprintf("Status: " );
        switch (SMSData[3]) {
-       case 7: m->Type = SMS_Submit;  /* m->Status = GSS_NOTSENTREAD; */ ddprintf("not sent\n"); break;
-       case 5: m->Type = SMS_Submit;  /* m->Status = GSS_SENTREAD;    */ ddprintf("sent\n"); break;
-       case 3: m->Type = SMS_Deliver; /* m->Status = GSS_NOTSENTREAD; */ ddprintf("not read\n"); break;
-       case 1: m->Type = SMS_Deliver; /* m->Status = GSS_SENTREAD;    */ ddprintf("read\n"); break;
+       case 7: m->Type = GST_MO; m->Status = GSS_NOTSENTREAD; ddprintf("not sent\n"); break;
+       case 5: m->Type = GST_MO; m->Status = GSS_SENTREAD; ddprintf("sent\n"); break;
+       case 3: m->Type = GST_MT; m->Status = GSS_NOTSENTREAD; ddprintf("not read\n"); break;
+       case 1: m->Type = GST_MT; m->Status = GSS_SENTREAD; ddprintf("read\n"); break;
        }
 
        }
 
-       UnpackDateTime(SMSData+7, &m->Time);
+       /* Date is at SMSData[7]; this code is copied from fbus-6110.c*/
+       {
+               int offset = -32 + 7;
+               m->Time.Year=10*(SMSData[32+offset]&0x0f)+(SMSData[32+offset]>>4);
+               m->Time.Month=10*(SMSData[33+offset]&0x0f)+(SMSData[33+offset]>>4);
+               m->Time.Day=10*(SMSData[34+offset]&0x0f)+(SMSData[34+offset]>>4);
+               m->Time.Hour=10*(SMSData[35+offset]&0x0f)+(SMSData[35+offset]>>4);
+               m->Time.Minute=10*(SMSData[36+offset]&0x0f)+(SMSData[36+offset]>>4);
+               m->Time.Second=10*(SMSData[37+offset]&0x0f)+(SMSData[37+offset]>>4);
+               m->Time.Timezone=(10*(SMSData[38+offset]&0x07)+(SMSData[38+offset]>>4))/4;
+       }
 
 
-       m->Length = len = SMSData[14];
+       len = SMSData[14];
        ddprintf("%d bytes: ", len );
        for (i = 0; i<len; i++)
                ddprintf("%c", SMSData[15+i]);
        ddprintf("%d bytes: ", len );
        for (i = 0; i<len; i++)
                ddprintf("%c", SMSData[15+i]);
@@ -356,18 +410,17 @@ DecodeIncomingSMS(GSM_SMSMessage *m)
 
        if (len>160)
                eprintf("Magic not allowed\n");
 
        if (len>160)
                eprintf("Magic not allowed\n");
-       memset(m->MessageText, 0, 161);
+       memset(m->MessageText, 0, sizeof(m->MessageText));
        strncpy(m->MessageText, (void *) &SMSData[15], len);
        strncpy(m->MessageText, (void *) &SMSData[15], len);
-
+       m->MessageTextLength = len;     /* we currently do not support UDH & 8-bit so it is simple */
+       m->EightBit = false;
        ddprintf("Text is %s\n", m->MessageText);
 
        ddprintf("Text is %s\n", m->MessageText);
 
-       /* 
-       Originator address is at 15+i,
-          followed by message center addres (?)
-       */
+       /* Originator address is at 15+i,
+          followed by message center addres (?) */
        {
                char *s = (char *) &SMSData[15+i];      /* We discard volatile. Make compiler quiet. */
        {
                char *s = (char *) &SMSData[15+i];      /* We discard volatile. Make compiler quiet. */
-               strcpy(m->RemoteNumber.number, s);
+               strcpy(m->Sender, s);
                s+=strlen(s)+1;
                strcpy(m->MessageCenter.Number, s);
                ddprintf("Sender = %s, MessageCenter = %s\n", m->Sender, m->MessageCenter.Name);
                s+=strlen(s)+1;
                strcpy(m->MessageCenter.Number, s);
                ddprintf("Sender = %s, MessageCenter = %s\n", m->Sender, m->MessageCenter.Name);
@@ -375,15 +428,14 @@ DecodeIncomingSMS(GSM_SMSMessage *m)
 
        m->MessageCenter.No = 0;
        strcpy(m->MessageCenter.Name, "(unknown)");
 
        m->MessageCenter.No = 0;
        strcpy(m->MessageCenter.Name, "(unknown)");
-       m->UDH_No = 0;
-
-       return error;
+       m->UDHPresent = false;
+       return GE_NONE;
 }
 
 static GSM_Error
 GetSMSMessage(GSM_SMSMessage *m)
 {
 }
 
 static GSM_Error
 GetSMSMessage(GSM_SMSMessage *m)
 {
-       if (m->Number > 10)
+       if (m->Location > 10)
                return GE_INVALIDSMSLOCATION;
 
        if (SMS(m, LM_SMS_READ_STORED_DATA) != GE_NONE)
                return GE_INVALIDSMSLOCATION;
 
        if (SMS(m, LM_SMS_READ_STORED_DATA) != GE_NONE)
@@ -405,7 +457,7 @@ GetSMSMessage(GSM_SMSMessage *m)
 static GSM_Error
 SendSMSMessage(GSM_SMSMessage *m)
 {
 static GSM_Error
 SendSMSMessage(GSM_SMSMessage *m)
 {
-       if (m->Number > 10)
+       if (m->Location > 10)
                return GE_INVALIDSMSLOCATION;
 
        if (SMSData[0] != 0x0b) {
                return GE_INVALIDSMSLOCATION;
 
        if (SMSData[0] != 0x0b) {
@@ -609,7 +661,7 @@ HandlePacket(void)
                return ((PacketData[4] & 0xf) != 0);
                /* Make all but last fragment "secret" */
 
                return ((PacketData[4] & 0xf) != 0);
                /* Make all but last fragment "secret" */
 
-       default: dprintf("Unknown response %dx\n", PacketData[3]); 
+       default: dprintf("Unknown response %x\n", (unsigned int)PacketData[3]); 
                 return 0;
        }       
 }
                 return 0;
        }       
 }
@@ -632,7 +684,7 @@ SigHandler(int status)
 //      dprintf("(%x)", b, Index);
                if (!Index && b != MYID && b != 0xf8 && b != 0x00) /* MYID is code of computer */ {
                        /* something strange goes from phone. Just ignore it */
 //      dprintf("(%x)", b, Index);
                if (!Index && b != MYID && b != 0xf8 && b != 0x00) /* MYID is code of computer */ {
                        /* something strange goes from phone. Just ignore it */
-                       ddprintf("Get [%02X %c]\n", b, b >= 0x20 ? b : '.' );
+                       ddprintf( "Get [%02X %c]\n", b, b >= 0x20 ? b : '.' );
                        continue;
                } else {
                        pkt[Index++] = b;
                        continue;
                } else {
                        pkt[Index++] = b;
@@ -643,7 +695,7 @@ SigHandler(int status)
                        }
                        if(Index >= Length) {
                                if((pkt[0] == MYID || pkt[0]==0xf8) && pkt[1] == 0x00) /* packet from phone */ {
                        }
                        if(Index >= Length) {
                                if((pkt[0] == MYID || pkt[0]==0xf8) && pkt[1] == 0x00) /* packet from phone */ {
-                                       ddprintf("Phone: ");
+                                       ddprintf( _("Phone: ") );
                                        for( j = 0; j < Length; j++ ) {
                                                b = pkt[j];
                                                ddprintf( "[%02X %c]", b, b >= 0x20 ? b : '.' );
                                        for( j = 0; j < Length; j++ ) {
                                                b = pkt[j];
                                                ddprintf( "[%02X %c]", b, b >= 0x20 ? b : '.' );
@@ -958,7 +1010,7 @@ static GSM_Error SMS_Reserve(GSM_Statemachine *sm)
                eprintf("Bad reply trying to reserve SMS-es\n");
        if (SMSData[0] != LM_SMS_PP_RESERVE_COMPLETE)
                eprintf("Not okay trying to reserve SMS-es (%d)\n", SMSData[0]);
                eprintf("Bad reply trying to reserve SMS-es\n");
        if (SMSData[0] != LM_SMS_PP_RESERVE_COMPLETE)
                eprintf("Not okay trying to reserve SMS-es (%d)\n", SMSData[0]);
-       return GE_NONE;
+
 }
 
 static GSM_Error SMS_Slave(GSM_Statemachine *sm)
 }
 
 static GSM_Error SMS_Slave(GSM_Statemachine *sm)
@@ -985,14 +1037,12 @@ static GSM_Error SMS_Slave(GSM_Statemachine *sm)
                                eprintf("New message indicated @%d\n", SMSData[2]);
                                msleep_poll(200);
                                memset(&m, 0, sizeof(m));
                                eprintf("New message indicated @%d\n", SMSData[2]);
                                msleep_poll(200);
                                memset(&m, 0, sizeof(m));
-                               m.Number = SMSData[2];
+                               m.Location = SMSData[2];
                                m.MemoryType = GMT_ME;
                                if (GetSMSMessage(&m) != GE_NONE)
                                        eprintf("Could not find promissed message?\n");
                                m.MemoryType = GMT_ME;
                                if (GetSMSMessage(&m) != GE_NONE)
                                        eprintf("Could not find promissed message?\n");
-#if 0
                                else
                                else
-                                       slave_process(&m, SMSData[2]);
-#endif
+                                       /*slave_process(&m, SMSData[2])*/;
                        }
                        break;
                default:
                        }
                        break;
                default:
@@ -1118,10 +1168,11 @@ WritePhonebookLocation(GSM_PhonebookEntry *entry)
 }
 
 static GSM_Error
 }
 
 static GSM_Error
-GetSMSStatus(GSM_SMSMemoryStatus *Status)
+GetSMSStatus(GSM_SMSStatus *Status)
 {
 {
-       Status->Unread = 0;
-       Status->Number = 5;
+       Status->UnRead = 0;
+       Status->Used   = 0;
+       Status->Slots  = 5;
        return GE_NONE;
 }
 
        return GE_NONE;
 }
 
@@ -1170,7 +1221,6 @@ GSM_Functions N2110_Functions = {
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
-       NULL,
        SendRLPFrame,
        NULL,
        EnableDisplayOutput,
        SendRLPFrame,
        NULL,
        EnableDisplayOutput,