Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Mon Nov 23, 2009 11:46 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ]  Bookmark and Share
Author Message
 Post subject: How to jump to starting of the run method means.....
PostPosted: Mon Apr 23, 2007 2:20 pm 
Offline

Joined: Mon Apr 23, 2007 2:10 pm
Posts: 13
The following is my run method:
Code:
public void run()
      {
      intSmsBuf=new Vector();
      try{
      this.sleep(10);}
      catch(Exception e)
      {
      }
      globalBuffer=new byte[512];
      // as for initial default case ate 1, the response is ate 0 OK.
      // it is set to ate 0 and the response is not considered
      //boolean echoFlag=false;
      boolean echoFlag=true;
      boolean newMsgFlag=false;
      openSerialPort();      
      // set command echo mode OFF
      sendEchoOff();
      
      // receive response for echo command
      //echoFlag=getEchoResponse();   reason mentioned when echo flag is declared and initialized   
      getEchoResponse();
      
      // stop receiving new message indications
      offNewMsgIndication();
      
      // get response for command : offNew MsgIndication
      newMsgFlag=getResForNewMsgIndication();
      
      // these two commands are send as startup commands to
      // modem and if it fails to respond to these commands
      // display the dialog " to connect the modem properly
      // and to restart the application
      if(echoFlag==true && newMsgFlag==true) {
         // get database connection
         con=DBOps.getConnection();
         try {
            stmt=con.createStatement();      
            System.out.println("Database connected");
         
           String query9 = "SELECT count(*) from new_sms_send";
           int rows=0;
                        ResultSet rs9= stmt.executeQuery(query9);
           if(rs9.next())
                           rows = rs9.getInt(1);
                     System.out.println("rows are:"+rows);
           ResultSet rs1;
           String query1 = "SELECT * FROM new_sms_send";
                          rs1 =  stmt.executeQuery(query1);
                          System.out.println("query executed");
                           while(rs1.next()){
                                      long mobileNum = rs1.getLong(1);
                                      String sndMsg = rs1.getString(2);
                                      String sender = rs1.getString(3);
                                      int att = rs1.getInt(4);
                            System.out.println("query executed:"+att);
                        String time = rs1.getString(5);
                        String  sndMsgs = sender+"\t\t\n " +"SENDER:\n"+sndMsg;
                       // boolean flag=true;
            if(att==0 )
                {
         

                     //for(int i=0;i<rows;i++)
                     //{
                     sendReply(mobileNum,sndMsgs);
                     boolean status=rcvSendStatus();
                     if(status==true)
                     {
                        //System.out.println("Send Success");      
                          //Connection con = null;
                     try
                     {
                          System.out.println("connecting to dbase");
                                         //con = DBOps.getConnection();
                                //stmt = con.createStatement();
                                         String query = "INSERT INTO sucessful_send " + "values ('"+mobileNum+"', '"+sender.trim()+"', '"+sndMsg.trim()+"','"+time+"')";
                        System.out.println("pasted in suces send table");
                                         System.out.println("INSERT INTO sucessful_send " + "values ('"+mobileNum+"', '"+sender.trim()+"', '"+sndMsg.trim()+"','"+time+"')");
                                         stmt.executeUpdate(query);
                              System.out.println("Send Success");
                                    String query4 = "DELETE FROM new_sms_send WHERE send_time = '"+time+"'";
                                         stmt.executeQuery(query4);
                                         System.out.println("DELETE FROM new_sms_send WHERE send_time = '"+time+"'");
               
                     }
                     catch(Exception e)
                     {
                     }
                     }//end of if for status
                     else
                        {
                        System.out.println("Unable to send the data");
                        }
                  //flag = false;   //}//end of for
                     }//end of if(att==0)
                      continue;
                     }//end of while(rs1)
                while(true)
                            {   
            // if(flag ==false){   
            
                  //message sending part should be done then after database should be update like
                 // send request to get the maximum memory capacity
              sendReqForMaxLoc();   
                             System.out.println("max location");              
         
             // get maximum memory capacity   
              getResForMaxLoc();
              System.out.println("max location12");

             if(MAXLOC > 0 ) {                                    
            // timer for sending the reply
            int delay=1000;
            ActionListener actionListenerForReply=new ActionListener() {
               public void actionPerformed(ActionEvent ae) {
                  try {     
                      sleep(10);   
                  } catch(InterruptedException ie) {
                  }
                  // get msgs from each location ( ie for x locations)
                  for(int i=0;i<MAXLOC;i++) {
                     // send request to get the message or SMS in this case
                     sendReqForMsg(i+1);
                     // receive SMS
                     String rcvMsg=getResForMsg();
                     // parse the msg
                     //System.out.println("parsing started");
                     String[] parMsg=rcvMsg.split(",");
                     String msg=new String();
                     boolean unRead=false;
                     boolean validMsg=false;
                     // if the msg is not an error msg                                          
                     if(parMsg.length > 1) {
                        // if msg is NOT READ
                        if(parMsg[0].trim().equals("+CMGR: \"REC UNREAD\"")) {
                        //if(parMsg[0].trim().equals("+CMGR: \"REC READ\"")) {   
                           //System.out.println("parMsg:"+parMsg[0]);
                           unRead=true;
                        }   
                        
                        //msgType=INVALID;   
                        if(unRead==true) {
                           /*   0                  1            2   3           4        5  6 7 8     9           
                           +CMGR: "REC READ","+919866524337",,"05/08/11,19:10:32+08",145,4,0,0,"+9198450870
                                             012345678901234                                    
                                10   11
                           01",145,15
                           this 1234567890
                           OK */
                           byte crByte[]=new byte[1];
                           crByte[0]=13;
                           String cr=new String(crByte);   
                                    //System.out.println("data is:"+ crByte[0] + "new:" + cr.hashCode());
                           //System.out.println("parsing started2");   
                           //System.out.println("is that:"+parMsg[1]);
                           //System.out.println("is that:"+parMsg[2].hashCode());
                           //System.out.println("is that:"+parMsg[3]);
                           //System.out.println("is that:"+parMsg[4]);
                           //System.out.println("is that:"+parMsg[5].hashCode());
                           //String[] msgSubStr = null;
                           String[] msgSubStr=parMsg[11].split(cr);
                           //System.out.println("data is:"+parMsg[11].split(cr).length);
                           // get the actual msg from the SMS received
                           int msgLen=Integer.parseInt(msgSubStr[0]);
                           System.out.println("data:"+msgSubStr);
                           msg=parMsg[11].substring(3,3+msgLen);
                           //System.out.println("parsing started3"+msgLen);
                           // find the msg type
                           //msgType=getMsgType(msg);
                           System.out.println("msg:"+msg);
                           //System.out.println("msg type:"+msgType);                           
                        }                     
                        //if(unRead==true && msgType!=INVALID) {
                        if(unRead==true ) {                           
                           // if it is unread, store mobile number and
                           // msg in the object of RequestSMS  and store in internal buffer                           
                           reqSMS=new RequestSMS();
                           long mobileNo=Long.parseLong(parMsg[1].substring(4,14));
                           reqSMS.set(mobileNo,msg,parMsg[3]+" "+parMsg[4],false);                        
                           intSmsBuf.add(reqSMS);                        
                        }          
                        // delete SMS from SIM      
                        //deleteSMSFromSIM(i);
                     } // if msg.lENGTH>1

                  }// for < MAXLOC
                  // sort this internal buffer based on date and time
                  RequestSMS reqSMSi,reqSMSj;               
                  for(int i=0;i<intSmsBuf.size();i++) {
                     reqSMSi=(RequestSMS)intSmsBuf.get(i);
                     for(int j=0;j<intSmsBuf.size();j++) {
                        reqSMSj=(RequestSMS)intSmsBuf.get(j);                        
                        if(reqSMSi.dateTime.compareTo(reqSMSj.dateTime) > 0) {
                           intSmsBuf2=(Vector)intSmsBuf.clone();
                           intSmsBuf2.set(i,(RequestSMS)intSmsBuf.get(j));
                           intSmsBuf2.set(j,(RequestSMS)intSmsBuf.get(i));
                           intSmsBuf=(Vector)intSmsBuf2.clone();            
                        }
                     }                  
                  }//end for intsmsbuf   
                  // remove reply msgs from internal buffer which are
                  // successfully send
                  for(int i=0;i<intSmsBuf.size();i++) {
                     reqSMSi=(RequestSMS)intSmsBuf.get(i);                     
                     if(reqSMSi.sentStatus==true) {
                        intSmsBuf.removeElementAt(i);
                        i=i-1;
                     }                  
                  }//end of removebuffer   
            }//end of action performed
            };//end of actionlistener      
                timerTimeOut=new javax.swing.Timer(delay,actionListenerForReply);
            timerTimeOut.setRepeats(true);
            timerTimeOut.start();
         } //end of if for MAXLOC
         else {
            JOptionPane.showMessageDialog(null,"SIM has no memory support","Information",JOptionPane.INFORMATION_MESSAGE);                        
            System.exit(1);            
         }
            
               //flag=true;
               //}
                                        continue;
               }//end of while(1)
                            
              //}//end of while
               }//end of try
                        catch(SQLException se) {
            se.printStackTrace();
            System.out.println(se.getMessage());
            JOptionPane.showMessageDialog(null,"Database connection failed:"+se.getMessage(),"Information",JOptionPane.INFORMATION_MESSAGE);                        
            System.exit(1);                        
         }
       }//end of if where port and database connection
                        else {
         JOptionPane.showMessageDialog(null,"Cannot start the application \n as there is no response from modem","Information",JOptionPane.INFORMATION_MESSAGE);                        
         System.exit(1);
                        }
                        
      }//end of run method

In this above code i am trying to do is if their are records in the database then i am sending sms to that destination number that i got from the datbase, if no records found then i am able to receive messages(towards GSM modem) in to the application.

if at all records are completed then i am able to receive messages,but if after receiving some messages if i updated some records in the table(for sending)the run method is not activated from 1st onwards means it is not able to send the sms's from the database.

So,what i have to do, as i know that the run method will work continuosly but why it is not working please reply to this as early as possible.

Thus it need any extra coding(I used some flag and tested like a producer and consumer problem but no effect on that).


regards,
sasi.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley