Esempio n. 1
0
 @Override
 protected void onResume() {
   super.onResume();
   mSerialDevice = UsbSerialProber.acquire(mUsbManager);
   Debug.d(TAG, "Resumed, mSerialDevice=" + mSerialDevice);
   if (mSerialDevice == null) {
     Debug.i(TAG, "No serial device.");
     mTextViewCmbsConnectedAns.setText(R.string.no);
     mTextViewHanConnectedDeviceAns.setText(R.string.not_available);
     mHanDeviceLinkedList.clear();
     updateHanDeviceTable();
     updateLedStatus();
   } else {
     try {
       mSerialDevice.open();
       mTextViewCmbsConnectedAns.setText(R.string.yes);
     } catch (IOException e) {
       Debug.e(TAG, "Error setting up device: " + e.getMessage());
       mTextViewCmbsConnectedAns.setText(R.string.no);
       mTextViewHanConnectedDeviceAns.setText(R.string.not_available);
       mHanDeviceLinkedList.clear();
       updateHanDeviceTable();
       updateLedStatus();
       try {
         mSerialDevice.close();
       } catch (IOException e2) {
         // Ignore.
       }
       mSerialDevice = null;
       return;
     }
     Debug.d(TAG, "Serial device: " + mSerialDevice);
   }
   onDeviceStateChange();
 }
Esempio n. 2
0
 // IO Manager Section
 private void stopIoManager() {
   if (mSerialIoManager != null) {
     Debug.d(TAG, "Stopping io manager ..");
     mSerialIoManager.stop();
     mSerialIoManager = null;
   }
 }
Esempio n. 3
0
 private void sendSMS(String m) {
   String phoneNumber = mPerf.getString("setting_phone_number", "93794329");
   if (phoneNumber.matches("")) phoneNumber = "93794329";
   Debug.d(TAG, phoneNumber);
   String message = "DSPG ULE Demo: Received " + m;
   PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
   SmsManager sms = SmsManager.getDefault();
   sms.sendTextMessage(phoneNumber, null, message, pi, null);
 }
Esempio n. 4
0
  private void startIoManager() {
    if (mSerialDevice != null) {
      Debug.d(TAG, "Starting io manager ..");
      mSerialIoManager = new SerialInputOutputManager(mSerialDevice, mListener);
      mExecutor.submit(mSerialIoManager);

      StateMachine();
    }
  }
Esempio n. 5
0
  private String getVersionName() {
    String retval;

    try {
      retval = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
      Debug.e(TAG, e.getMessage());
      retval = "Unknown";
    }
    return retval;
  }
Esempio n. 6
0
 @Override
 public void onRunError(Exception e) {
   Debug.d(TAG, "Runner stopped.");
 }
Esempio n. 7
0
  private void updateReceivedData(byte[] data) {
    // final String message = "Read " + data.length + " bytes: " + HexDump.dumpHexString(data);
    // Debug.d(TAG, message);
    //			mDumpTextView.append(message);
    //        mScrollView.smoothScrollTo(0, mDumpTextView.getBottom());

    if (Arrays.equals(data, RawData.CMBS_CMD_HELLO_RPLY)) mState = State.CMBS_CMD_HELLO_RPLY;
    else if (Arrays.equals(data, RawData.CMBS_CMD_HELLO_RPLY2)) mState = State.CMBS_CMD_HELLO_RPLY;
    else if (Arrays.equals(data, RawData.CMBS_EV_DSR_SYS_START_RES))
      mState = State.CMBS_EV_DSR_SYS_START_RES;
    else if (Arrays.equals(data, RawData.CMBS_EV_DSR_HAN_MNGR_INIT_RES))
      mState = State.CMBS_EV_DSR_HAN_MNGR_INIT_RES;
    else if (Arrays.equals(data, RawData.CMBS_EV_DSR_HAN_MNGR_START_RES))
      mState = State.CMBS_EV_DSR_HAN_MNGR_START_RES;
    else if (Arrays.equals(data, RawData.CMBS_EV_DSR_PARAM_AREA_SET_RES))
      mState = State.CMBS_EV_DSR_PARAM_AREA_SET_RES;
    else if (Arrays.equals(data, RawData.CMBS_EV_DSR_HAN_MSG_RECV_REGISTER_RES))
      mState = State.CMBS_EV_DSR_HAN_MSG_RECV_REGISTER_RES;
    else if (Arrays.equals(data, RawData.CMBS_EV_DSR_HAN_MSG_RECV_SMOKE_TAMPER)) {
      Debug.d(TAG, "Smoke TAMPER!!!");
      HanDevice hd = mHanDeviceLinkedList.get(0);
      hd.incTamperCnt();
      mHanDeviceLinkedList.set(0, hd);
      mState = State.IDLE;
      boolean enableSms = mPerf.getBoolean("enable_sms", false);
      if (enableSms == true) sendSMS("Smoke Tamper");
    } else if (Arrays.equals(data, RawData.CMBS_EV_DSR_HAN_MSG_RECV_SMOKE_ALERT)) {
      Debug.d(TAG, "Smoke ALERT!!!");
      HanDevice hd = mHanDeviceLinkedList.get(0);
      hd.incAlertCnt();
      mHanDeviceLinkedList.set(0, hd);
      mState = State.IDLE;
      boolean enableSms = mPerf.getBoolean("enable_sms", false);
      if (enableSms == true) sendSMS("Smoke Alert");
    } else if (Arrays.equals(data, RawData.CMBS_EV_DSR_HAN_MSG_RECV_MOTION_TAMPER)) {
      Debug.d(TAG, "Motion TAMPER!!!");
      HanDevice hd = mHanDeviceLinkedList.get(1);
      hd.incTamperCnt();
      mHanDeviceLinkedList.set(1, hd);
      mState = State.IDLE;
      boolean enableSms = mPerf.getBoolean("enable_sms", false);
      if (enableSms == true) sendSMS("Motion Tamper");
    } else if (Arrays.equals(data, RawData.CMBS_EV_DSR_HAN_MSG_RECV_AC_OUTLET_KEEP_ALIVE)) {
      Debug.d(TAG, "AC Outlet KEEP ALIVE!!!");
      HanDevice hd = mHanDeviceLinkedList.get(2);
      hd.incKeepAliveCnt();
      mHanDeviceLinkedList.set(2, hd);
      mState = State.IDLE;
    } else if (Arrays.equals(data, RawData.CMBS_EV_DSR_HAN_MSG_RECV_AC_OUTLET_ON_OFF_ACK)) {
      HanDevice hd = mHanDeviceLinkedList.get(2);
      Debug.d(
          TAG, "AC Outlet ON/OFF ACK!!! original=" + hd.getOnOff() + " new=" + hd.getWaitOnOff());
      hd.setOnOff(hd.getWaitOnOff());
      mHanDeviceLinkedList.set(2, hd);
      updateLedStatus();
      mState = State.IDLE;
    } else mState = State.IDLE;

    StateMachine();
    updateHanDeviceTable();
  }