intel / zephyr.js

JavaScript* Runtime for Zephyr* OS
Other
180 stars 64 forks source link

[ocf] How to receive argument from terminal when running ocf client #1411

Open wanghongjuan opened 7 years ago

wanghongjuan commented 7 years ago

Description

Now I need to receive a resource object from terminal when running command outdir/linux/release/jslinux, but I am not clear how to do it.

Test Code

client.js

var ocf = require('ocf');
var client = ocf.client;

var updateProperties = {
    range: [0, 255]
};

console.log("Started OCF client");

function errorHandler(error) {
  if (error.deviceId) {
    console.log("Error for device: " + error.deviceId);
  }
}

client.on('error', errorHandler);

function updateResource(resource, data){
    resource.properties.minRange = updateProperties.range[0];
    resource.properties.maxRange = updateProperties.range[1];
    resource.properties.RValue = data[0];
    resource.properties.GValue = data[1];
    resource.properties.BValue = data[2];
    console.log(resource.properties.RValue);
    console.log(resource.properties.GValue);
    console.log(resource.properties.BValue);
  }
  client.update(resource)
  .then(
      function(updateResource){
          if(updateResource == resource){
              console.log('updated resource');
          }
      },
      function(error){
          console.log('failed to update resource with error', error.message);
      }
  )
}
ocf.start();

updateResource(process.argv[2], process.argv[3])

server.js

Steps to reproduce

  1. Build server.js on A101
  2. Connect with BLE
  3. Build and run client.js on linux

Actual Result

Not clear how to receive the argument resource object.

Excepted Result

The client.js can get the argument from terminal and the update method can be executed successfully.

jimmy-huang commented 7 years ago

This will probably be a new feature, like if we want to support the process api