This commit was manufactured by cvs2svn to create tag
[gnokii.git] / common / protocol / fbus.c
index 34c0507..e58d0c1 100644 (file)
@@ -60,8 +60,6 @@ u8 MessageBuffer[FBUS_MAX_RECEIVE_LENGTH * 6],MultiMessageBuffer[FBUS_MAX_RECEIV
 
 u8        RequestSequenceNumber = 0x00;
 
-int fbus_decoding=0;
-
 #ifdef DEBUG   
 char *N61_PrintDevice(int Device)
 {
@@ -80,12 +78,11 @@ char *N61_PrintDevice(int Device)
 void N61_RX_DisplayMessage()
 {
 #ifdef DEBUG
-  hexdump(MessageLength-2,MessageBuffer);
-
   fprintf(stdout, _("Msg Dest: %s\n"), N61_PrintDevice(MessageDestination));
   fprintf(stdout, _("Msg Source: %s\n"), N61_PrintDevice(MessageSource));
   fprintf(stdout, _("Msg Type: %02x\n"), MessageType);
-  fprintf(stdout, _("Msg Seq: %d\n"), MessageBuffer[MessageLength-1] & 0x0f);
+
+  hexdump(MessageLength-2,MessageBuffer);
 #endif
 
   AppendLog(MessageBuffer,MessageLength-2,true);
@@ -210,9 +207,6 @@ int FBUS_SendAck(u8 message_type, u8 message_seq) {
 
   unsigned char request[6];
 
-  if (fbus_decoding)
-    return 0;
-
   request[0] = message_type;
   request[1] = message_seq;
 
@@ -239,18 +233,12 @@ void FBUS_Terminate(void)
 
 void FBUS_RX_StateMachine(unsigned char rx_byte) {
 
-#if 0
   static struct timeval time_now, time_last, time_diff;
-#endif
   
   static int checksum[2];
   
   int i=0;
 
-//  if (CurrentConnectionType==GCT_DLR3) {
-//    AT_RX_StateMachine(rx_byte);
-//  } else {
-
 #ifdef DEBUG
   /* For model sniff only display received bytes */
   if (strcmp(GSM_Info->FBUSModels, "sniff"))
@@ -271,7 +259,6 @@ void FBUS_RX_StateMachine(unsigned char rx_byte) {
 
   case FBUS_RX_Discarding:
 
-#if 0
 #ifndef VC6
     gettimeofday(&time_now, NULL);
     timersub(&time_now, &time_last, &time_diff);
@@ -281,21 +268,13 @@ void FBUS_RX_StateMachine(unsigned char rx_byte) {
     }
     /* else fall through to... */
 #endif
-#endif
 
-  case FBUS_RX_Sync: {
-static int discarded=0,discarded55=0;
+  case FBUS_RX_Sync:
 
       if ((CurrentConnectionType==GCT_FBUS && rx_byte == FBUS_FRAME_ID) ||
           ((CurrentConnectionType==GCT_Infrared ||
           CurrentConnectionType==GCT_Tekram) && rx_byte == FBUS_IR_FRAME_ID)) {
 
-       if (discarded) {
-         printf("[discarded %d bytes, %d were NOT 0x55]\n",discarded,discarded-discarded55);
-         discarded=0;
-         discarded55=0;
-         }
-
         BufferCount = 0;
 
        RX_State = FBUS_RX_GetDestination;
@@ -306,16 +285,11 @@ static int discarded=0,discarded55=0;
       } else {
         /* Lost frame sync */
         RX_State = FBUS_RX_Discarding;
-#if 0
 #ifndef VC6
         gettimeofday(&time_last, NULL);
 #endif
-#endif
-       discarded++;
-       if (rx_byte == 0x55)
-         discarded55++;
       }    
-    break;
+    break;
 
   case FBUS_RX_GetDestination:
 
@@ -407,7 +381,6 @@ static int discarded=0,discarded55=0;
 
       /* Is the checksum correct? */
       if (checksum[0] == checksum[1]) {
-u8 msgseq;
          
         if (RX_Multiple) {
 
@@ -429,7 +402,7 @@ u8 msgseq;
            }
            MultiMessageLength=MultiMessageLength+MessageLength-2;
 
-           msgseq=MessageBuffer[MessageLength-1] & 0x0f;
+            FBUS_SendAck(MessageType, MessageBuffer[MessageLength-1] & 0x0f);          
                
             if ((MessageLength > 1) && (MessageBuffer[MessageLength-2] != 0x01))
             {
@@ -443,22 +416,15 @@ u8 msgseq;
               /* Do not debug Ack and RLP frames to detail. */
               if (MessageType != FBUS_FRTYPE_ACK && MessageType != 0xf1)
                 N61_RX_DisplayMessage();
-             else {
-               if (MessageType == FBUS_FRTYPE_ACK)
-                 puts("[ignoring print of ACK]");
-               else
-                 puts("[ignoring print of RLP]");
-               }
 
               GSM->DispatchMessage(MessageLength-2, MessageBuffer, MessageType);
             }
 
-            FBUS_SendAck(MessageType, msgseq);
-
          } else {
 
             /* We do not want to send ACK of ACKs and ACK of RLP frames. */
             if (MessageType != FBUS_FRTYPE_ACK && MessageType != 0xf1) {
+              FBUS_SendAck(MessageType, MessageBuffer[MessageLength-1] & 0x0f);
 
               if ((MessageLength > 1) && (MessageBuffer[MessageLength-2] != 0x01))
               {
@@ -468,16 +434,13 @@ u8 msgseq;
 #endif
                 RX_State = FBUS_RX_Sync;
               }
-
-             msgseq=MessageBuffer[MessageLength-1] & 0x0f;
-             FBUS_SendAck(MessageType, msgseq);
             }
          }
         } else {
-         msgseq=MessageBuffer[MessageLength-1] & 0x0f;
 
           /* We do not want to send ACK of ACKs and ACK of RLP frames. */
           if (MessageType != FBUS_FRTYPE_ACK && MessageType != 0xf1) {
+            FBUS_SendAck(MessageType, MessageBuffer[MessageLength-1] & 0x0f);
 
             if ((MessageLength > 1) && (MessageBuffer[MessageLength-2] != 0x01))
             {
@@ -491,23 +454,17 @@ u8 msgseq;
            }
          }
 
-          if (!RX_Multiple /* && MessageDestination!=FBUS_DEVICE_PHONE */ ) {
+          if (!RX_Multiple && MessageDestination!=FBUS_DEVICE_PHONE ) {
             /* Do not debug Ack and RLP frames to detail. */
             if (MessageType != FBUS_FRTYPE_ACK && MessageType != 0xf1)
               N61_RX_DisplayMessage();
-           else {
-             if (MessageType == FBUS_FRTYPE_ACK)
-               puts("[ignoring print of ACK]");
-             else
-               puts("[ignoring print of RLP]");
-             }
 
             GSM->DispatchMessage(MessageLength-2, MessageBuffer, MessageType);
           }
 
 #ifdef DEBUG
           /* When make debug and message is to phone display it */
-         if (MessageDestination==FBUS_DEVICE_PHONE && !fbus_decoding) {
+         if (MessageDestination==FBUS_DEVICE_PHONE) {
             for (i=MessageLength;i>=0;i--)
               MessageBuffer[i+6]=MessageBuffer[i];
             MessageBuffer[0]=FBUS_FRAME_ID;
@@ -521,12 +478,7 @@ u8 msgseq;
            NULL_TX_DisplayMessage(MessageLength, MessageBuffer);
           }
 #endif   
-          if (MessageType != FBUS_FRTYPE_ACK && MessageType != 0xf1)
-           FBUS_SendAck(MessageType, msgseq);
        }
-#ifdef DEBUG
-       putchar('\n');
-#endif
       } else {
 #ifdef DEBUG
           fprintf(stdout, _("Bad checksum %02x (should be %02x), msg len=%i !\n"),checksum[0],checksum[1],MessageLength);
@@ -550,22 +502,15 @@ u8 msgseq;
 
   }
 #endif
-
-//  }
 }
   
 /* Called by initialisation code to open comm port in asynchronous mode. */
 bool FBUS_OpenSerial(void)
 {
   /* Uncomment, if want to test first method for DLR3 */
-//  unsigned char req[3] = {"AT\r"};  
-//  unsigned char req2[5] = {"AT&F\r"};  
-//  unsigned char req3[13] = {"AT*NOKIAFBUS\r"};  
-
-//  GSM_Error error;
-
-//  GSM_Information *GSMINFOCOPY;
-//  GSM_Functions *GSMCOPY;
+  unsigned char req[3]   = {"AT\r"};  
+  unsigned char req2[5]  = {"AT&F\r"};  
+  unsigned char req3[13] = {"AT*NOKIAFBUS\r"};  
 
   switch (CurrentConnectionType) {
      case GCT_FBUS:
@@ -599,66 +544,33 @@ bool FBUS_OpenSerial(void)
 
        /* There are 2 ways to init DLR in FBUS: Here is first described by
           Reuben Harris [reuben.harris@snowvalley.com] and used in Logo Manager,
-              1. Firstly set the connection baud to 19200, DTR off, RTS off,
-                Parity on, one stop bit, 
-              2. Send "AT\r\n". The response should be "AT\r\n\r\nOK\r\n".
-              3. Send "AT&F\r\n". The response should be "AT&F\r\n\r\nOK\r\n".
-              4. Send "AT*NOKIAFBUS\r\n". The response should be
-                 "AT*NOKIAFBUS\r\n\r\nOK\r\n".
-              5. Set speed to 115200 
+            1. Firstly set the connection baud to 19200, DTR off, RTS off,
+              Parity on, one stop bit, 
+            2. Send "AT\r\n". The response should be "AT\r\n\r\nOK\r\n".
+            3. Send "AT&F\r\n". The response should be "AT&F\r\n\r\nOK\r\n".
+            4. Send "AT*NOKIAFBUS\r\n". The response should be
+               "AT*NOKIAFBUS\r\n\r\nOK\r\n".
+            5. Set speed to 115200 
+          This seems to be compatible with more phones*/
 
-          This is one should be used by us, because seems to be compatible with more
-          phones. But we make something wrong and often phones don't want to start transmision */
-
-       /* Uncomment and test if want */
-//       device_changespeed(19200);
+       device_changespeed(19200);
 
        /*leave RTS low, DTR low for duration of session.*/
-//       device_setdtrrts(0, 0);
-
-       /* Making copy of pointers */
-//       GSMCOPY = GSM;
-//       GSMINFOCOPY =GSM_Info;        
-
-       /* Set pointers to relevant addresses - new "AT" module here is required */
-//       GSM = &Nat_Functions;
-//       GSM_Info = &Nat_Information;
-
-       /* Note: We change Protocol inside function pointed by it.
-       That's why in FBUS_RX_StateMachine we must check it (changing
-       Protocol is not enough), This is for correct work and be sure... */
-//       Protocol = &AT_Functions;
-
-//       error=N6110_SendMessageSequence (50, &CurrentGetHWError, 3, 0x00, req);
-//       if (error!=GE_NONE) return false;
-
-//       error=N6110_SendMessageSequence (50, &CurrentGetHWError, 5, 0x00, req2);
-//       if (error!=GE_NONE) return false;
-
-//       error=N6110_SendMessageSequence (50, &CurrentGetHWError, 13, 0x00, req3);
-//       if (error!=GE_NONE) return false;
-
-       /* Returning to old protocol */
-//       Protocol = &FBUS_Functions;
-
-       /* Returning to old module */
-//       GSM = GSMCOPY;
-//       GSM_Info = GSMINFOCOPY;        
-
-//       device_changespeed(115200);
-
-       /*  Second method for DLR3:
-               Used by some 7110 soft, but not compatible with some other
-               phones supporting DLR3 - 7160, NCP2.0
-              Used in this moment in mygnokii
-       */
+       device_setdtrrts(0, 0);
+                            
+       Protocol->WritePhone (3,req );usleep(300);
+       Protocol->WritePhone (5,req2);usleep(300);
+       Protocol->WritePhone(13,req3);usleep(300);
 
        device_changespeed(115200);
 
-       /*leave RTS low, DTR low for duration of session.*/
-       device_setdtrrts(0, 0);
-      
-       usleep(100000);
+//     /*  Second method for DLR3:
+//         Used by some 7110 soft, but not compatible with some other
+//         phones supporting DLR3 - 7160, NCP2.0*/
+//     device_changespeed(115200);
+//     /*leave RTS low, DTR low for duration of session.*/
+//     device_setdtrrts(0, 0);      
+//     usleep(100000);
 
        CurrentConnectionType=GCT_FBUS;