コード例 #1
0
        @Override
        public void addSensor(int deviceID, int sensor, int sampleInterval) throws RemoteException {
          synchronized (mDeviceMap) {
            synchronized (mSeedNodeMap) {
              Device device = mDeviceMap.get(deviceID);
              device.addSensor(sensor, sampleInterval);
              SeedNode existingSeed = mSeedNodeMap.get(sensor);
              if (existingSeed != null) {
                existingSeed.attachDevice(device);
                existingSeed.startSensor();
              } else {
                SeedNode seed = new SeedNode(SensorType.getSensorName(sensor), sensor, device);
                mSeedNodeMap.put(sensor, seed);
                mNodeNameMap.put("|" + SensorType.getSensorName(sensor), seed);
              }
              DebugHelper.log(TAG, "Added sensor type: " + sensor);

              /*for (Map.Entry<Integer, SeedNode> entry: mSeedNodeMap.entrySet()) {
              	sensor = entry.getKey();
              	SeedNode node = entry.getValue();
              	DebugHelper.log(TAG, node.getClass().getName() + ": " + sensor + " device: " + node.getAttachedDevice());
              }*/
            }
          }
        }
コード例 #2
0
  public SerialMessage getValueMessage(SensorType type) {
    if (getVersion() == 1) {
      logger.debug(
          "NODE {}: Node doesn't support SENSOR_BINARY_GET with SensorType", getNode().getNodeId());
      return null;
    }

    logger.debug(
        "NODE {}: Creating new message for application command SENSOR_BINARY_GET for {}",
        getNode().getNodeId(),
        type);
    SerialMessage result =
        new SerialMessage(
            getNode().getNodeId(),
            SerialMessageClass.SendData,
            SerialMessageType.Request,
            SerialMessageClass.ApplicationCommandHandler,
            SerialMessagePriority.Get);

    ByteArrayOutputStream outputData = new ByteArrayOutputStream();
    outputData.write(getNode().getNodeId());
    outputData.write(3);
    outputData.write(getCommandClass().getKey());
    outputData.write(SENSOR_BINARY_GET);
    outputData.write(type.getKey());

    result.setMessagePayload(outputData.toByteArray());
    return result;
  }
コード例 #3
0
        @Override
        public void handleMessage(Message msg) {
          switch (msg.what) {
            case MSG_PUSH_DATA:
              Bundle bundle = (Bundle) msg.obj;
              int sensor = bundle.getInt(BUNDLE_SENSOR);
              SeedNode seed = mSeedNodeMap.get(sensor);

              if (seed == null) {
                // throw new UnsupportedOperationException("No SeedNode for SensorType: " + sensor);
                DebugHelper.log(TAG, "No SeedNode for SensorType: " + sensor);
                return;
              }

              int deviceID = bundle.getInt(BUNDLE_DEVICE_ID);

              if (seed.getAttachedDevice() != mDeviceMap.get(deviceID)) {
                DebugHelper.log(
                    TAG,
                    "Unmatched seed node and attached device(sensor: "
                        + sensor
                        + ", attempted device ID: "
                        + deviceID);
                return;
              }

              String type = bundle.getString(BUNDLE_TYPE);
              int length = bundle.getInt(BUNDLE_LENGTH);
              String name = SensorType.getSensorName(sensor);
              long timestamp = bundle.getLong(BUNDLE_TIMESTAMP);

              // show notification
              showNotification(sensor, name);

              if (type.equals("double[]")) {
                seed.input(name, type, bundle.getDoubleArray(BUNDLE_DATA), length, timestamp);
              } else if (type.equals("double")) {
                seed.input(name, type, bundle.getDouble(BUNDLE_DATA), length, timestamp);
              } else if (type.equals("int[]")) {
                seed.input(name, type, bundle.getIntArray(BUNDLE_DATA), length, timestamp);
              } else if (type.equals("int")) {
                seed.input(name, type, bundle.getInt(BUNDLE_DATA), length, timestamp);
              } else if (type.equals("String")) {
                seed.input(name, type, bundle.getString(BUNDLE_DATA), length, timestamp);
              } else {
                throw new IllegalArgumentException("Unknown data_type: " + type);
              }
              break;

            default:
              super.handleMessage(msg);
              break;
          }
        }
コード例 #4
0
ファイル: GPS.java プロジェクト: yuhan210/Mobility-Detector
  @Override
  public void changeSettings(String settings) {
    String[] splitted = settings.split(FieldDelimiter);
    if (splitted.length != 3 || !splitted[0].equals(type.toString()))
      throw new RuntimeException("wrong setting string for gps: " + settings);

    // cancel the current scanning
    locationManager.removeUpdates(locationListener);

    this.isEnabled = (splitted[1].equals("1"));
    this.scanIntervalInMs = Integer.parseInt(splitted[2]);
    System.out.println("change GPS settings to: (" + isEnabled + ", " + scanIntervalInMs + ")");
    if (isEnabled)
      locationManager.requestLocationUpdates(
          LocationManager.GPS_PROVIDER, scanIntervalInMs, 0, locationListener);
    else logger.flushFile(type);
  }
コード例 #5
0
        @Override
        public void removeDevice(int deviceID) throws RemoteException {
          synchronized (mDeviceMap) {
            synchronized (mSeedNodeMap) {
              Device removedDevice = mDeviceMap.remove(deviceID);
              if (removedDevice != null) {
                Sensor[] sensors = removedDevice.getSensorList();
                for (Sensor sensor : sensors) {
                  SeedNode seed = mSeedNodeMap.get(sensor.getSensorID());
                  if (seed.isConnected()) {
                    seed.detachDevice();
                  } else {
                    mSeedNodeMap.remove(sensor.getSensorID());
                    mNodeNameMap.remove("|" + SensorType.getSensorName(sensor.getSensorID()));
                  }
                }
                DebugHelper.log(TAG, "Removed device ID: " + deviceID);
                mNotification.showNotificationNow("Removed device ID " + deviceID);
              }
            }
          }
          // print seed map
          DebugHelper.log(TAG, "Printing mSeedNodeMap..");
          for (Map.Entry<Integer, SeedNode> entry : mSeedNodeMap.entrySet()) {
            int sensor = entry.getKey();
            SeedNode node1 = entry.getValue();
            DebugHelper.log(
                TAG,
                node1.getClass().getName()
                    + ": "
                    + sensor
                    + " device: "
                    + node1.getAttachedDevice());
          }
          DebugHelper.log(TAG, "Done.");

          // print node name map
          DebugHelper.log(TAG, "Printing mNodeNameMap..");
          for (Map.Entry<String, DataFlowNode> entry : mNodeNameMap.entrySet()) {
            String nodeName = entry.getKey();
            DataFlowNode node2 = entry.getValue();
            DebugHelper.log(TAG, nodeName + ": " + node2.getClass().getName());
          }
          DebugHelper.log(TAG, "Done.");
        }
コード例 #6
0
  /**
   * {@inheritDoc}
   *
   * @throws ZWaveSerialMessageException
   */
  @Override
  public void handleApplicationCommandRequest(SerialMessage serialMessage, int offset, int endpoint)
      throws ZWaveSerialMessageException {
    logger.trace("Handle Message Sensor Binary Request");
    logger.debug(
        "NODE {}: Received SENSOR_BINARY command V{}", getNode().getNodeId(), getVersion());
    int command = serialMessage.getMessagePayloadByte(offset);
    switch (command) {
      case SENSOR_BINARY_REPORT:
        logger.trace("Process Sensor Binary Report");
        int value = serialMessage.getMessagePayloadByte(offset + 1);

        SensorType sensorType = SensorType.UNKNOWN;
        if (getVersion() > 1 && serialMessage.getMessagePayload().length > offset + 2) {
          logger.debug(
              "Processing Sensor Type {}", serialMessage.getMessagePayloadByte(offset + 2));
          // For V2, we have the sensor type after the value
          sensorType = SensorType.getSensorType(serialMessage.getMessagePayloadByte(offset + 2));
          logger.debug("Sensor Type is {}", sensorType);
          if (sensorType == null) {
            sensorType = SensorType.UNKNOWN;
          }
        }

        logger.debug(
            "NODE {}: Sensor Binary report, type={}, value={}",
            getNode().getNodeId(),
            sensorType.getLabel(),
            value);

        ZWaveBinarySensorValueEvent zEvent =
            new ZWaveBinarySensorValueEvent(getNode().getNodeId(), endpoint, sensorType, value);
        getController().notifyEventListeners(zEvent);

        dynamicDone = true;
        break;
      case SENSOR_BINARY_SUPPORTEDSENSOR_REPORT:
        logger.trace("Process Sensor Binary Supported Sensors Report");

        int numBytes = serialMessage.getMessagePayload().length - offset - 1;

        for (int i = 0; i < numBytes; ++i) {
          for (int bit = 0; bit < 8; ++bit) {
            if (((serialMessage.getMessagePayloadByte(offset + i + 1)) & (1 << bit)) == 0) {
              continue;
            }

            int index = (i << 3) + bit;
            if (index >= SensorType.values().length) {
              continue;
            }

            // (n)th bit is set. n is the index for the sensor type enumeration.
            // sensor type seems to be supported, add it to the list if it's not already there.
            types.add(SensorType.getSensorType(index));
            logger.debug(
                "NODE {}: found binary sensor {}",
                getNode().getNodeId(),
                SensorType.getSensorType(index));
          }
        }

        initialiseDone = true;
        break;
      default:
        logger.warn(
            String.format(
                "NODE %d: Unsupported Command 0x%02X for command class %s (0x%02X).",
                getNode().getNodeId(),
                command,
                getCommandClass().getLabel(),
                getCommandClass().getKey()));
    }
  }
コード例 #7
0
 public void testGetByCode() {
   SensorType typeT = SensorType.getByCode('T');
   assertEquals(SensorType.TEMPERATURE, typeT);
 }
コード例 #8
0
 public void testGetValidLetters() {
   String codes = SensorType.getValidLetters();
   assertNotNull(codes);
   assertEquals(SensorType.values().length, codes.length());
   System.out.println(codes);
 }
コード例 #9
0
 public void testGetByCodeInvalidType() {
   SensorType typeT = SensorType.getByCode('z');
   assertEquals(SensorType.INVALID, typeT);
 }