Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.cinterion.io.ATCommand;
- import coreb.events.CallbackATCommand;
- import java.util.Random;
- /**
- *
- * @author Jure
- */
- public class ATCommandIssuer
- {
- ATCommandData[] ATCommands;
- ATCommandHandler atCommandHandler = ATCommandHandler.getInstance();
- String id;
- String lastResponse = "";
- public ATCommandIssuer(ATCommandData[] ATCommands)
- {
- this.ATCommands = ATCommands;
- Random rand = new Random();
- id = rand.nextInt() + "";
- atCommandHandler.addATCommand(id);
- }
- public void exectute(final CallbackATCommand callback)
- {
- new Thread()
- {
- public void run()
- {
- try
- {
- while(!id.equalsIgnoreCase(atCommandHandler.getThreadId()))
- {
- try
- {
- Thread.sleep(300);
- } catch (Exception e)
- {
- }
- }
- ATCommand m_Cmd = null;
- for(int i = 0; i < ATCommands.length; i++)
- {
- try
- {
- m_Cmd = new ATCommand(true);
- lastResponse = m_Cmd.send(ATCommands[i].atCommand + "\r");
- Thread.sleep (200); // Remember at least to implement 100 ms sleep in order to recevie any URC
- m_Cmd.release();
- }
- catch (Exception e)
- {
- m_Cmd.release();
- }
- }
- atCommandHandler.commandFinished();
- if(lastResponse.length() > 4)
- {
- if(lastResponse.substring(lastResponse.length() - 4, lastResponse.length()-2).equalsIgnoreCase("OK"))
- {
- callback.onSuccess(lastResponse);
- }
- else
- {
- callback.onFailure(lastResponse);
- }
- }
- }
- catch (Exception e)
- {
- atCommandHandler.commandFinished();
- callback.onError(e.toString());
- errorLogger.addError(e.toString(), false);
- }
- }
- }.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement