Esempio n. 1
0
int main(int argc, const char * argv[])
{
  string      errmsg;

  // Setup the API to use local USB devices
  if(yRegisterHub("usb", errmsg) != YAPI_SUCCESS) {
    cerr << "RegisterHub error: " << errmsg << endl;
    return 1;
  }

  if(argc < 2)
    usage(argv[0]);

  YModule *module = yFindModule(argv[1]);  // use serial or logical name

  if (module->isOnline()) {
    if (argc >= 3) {
      string newname =  argv[2];
      if (!yCheckLogicalName(newname)) {
        cerr << "Invalid name (" << newname << ")" << endl;
        usage(argv[0]);
      }
      module->set_logicalName(newname);
      module->saveToFlash();
    }
    cout << "Current name: " << module->get_logicalName() << endl;
  } else {
    cout << argv[1] << " not connected (check identification and USB cable)"
         << endl;
  }
  yFreeAPI();
  return 0;
}
Esempio n. 2
0
int main(int argc, const char * argv[])
{
    string       errmsg;
    string       target;
    YCurrent    *sensor;
    YCurrent    *sensorAC;
    YCurrent    *sensorDC;
    YModule     *m;

    if (argc < 2)  usage(argv[0]);
    
    target = (string) argv[1];
    
    // Setup the API to use local USB devices
    if (yRegisterHub("usb", errmsg) != YAPI_SUCCESS) {
        cerr << "RegisterHub error: " << errmsg << endl;
        return 1;
    }

    if (target == "any") {
        // retreive any voltage sensor (can be AC or DC)
        sensor = yFirstCurrent();
        if (sensor==NULL)
            die ("No module connected");
    } else {
        sensor = yFindCurrent(target + ".current1");
    }
    
    // we need to retreive both DC and AC voltage from the device.    
    if (sensor->isOnline())  {
        m = sensor->get_module();
        sensorDC = yFindCurrent(m->get_serialNumber() + ".current1");
        sensorAC = yFindCurrent(m->get_serialNumber() + ".current2");
      } else {
        die("Module not connected");
      }
    while(1) {
        if (!m->isOnline())  die("Module not connected");        
        cout << "Current,  DC : " << sensorDC->get_currentValue() << " mA";
        cout << "   AC : " << sensorAC->get_currentValue() << " mA";
        cout << "  (press Ctrl-C to exit)" << endl;
        ySleep(1000,errmsg);
    };
        
    return 0;
}
Esempio n. 3
0
static int upgradeSerialList(vector<string> allserials)
{
  string      errmsg;


  for (std::vector<string>::iterator it = allserials.begin() ; it != allserials.end();
       ++it) {
    string serial = *it;
    YModule *module = YModule::FindModule(serial);
    string product = module->get_productName();
    string current = module->get_firmwareRelease();

    // check if a new firmare is available on yoctopuce.com
    string newfirm = module->checkFirmware("www.yoctopuce.com", true);
    if (newfirm == "") {
      cout << product << " " << serial << "(rev=" << current << ") is up to date" << endl;
    } else {
      cout << product << " " << serial << "(rev=" << current <<
           ") need be updated with firmare : " << endl;
      cout << "    " << newfirm << endl;
      // execute the firmware upgrade
      YFirmwareUpdate update = module->updateFirmware(newfirm);
      int status = update.startUpdate();
      do {
        int newstatus = update.get_progress();
        if (newstatus != status)
          cout << newstatus << "% " << update.get_progressMessage() << endl;
        YAPI::Sleep(500, errmsg);
        status = newstatus;
      } while (status < 100 && status >= 0);
      if (status < 0) {
        cout << "Firmware Update failed: " << update.get_progressMessage() << endl;
        exit(1);
      } else {
        if (module->isOnline()) {
          cout << status << "% Firmware Updated Successfully!" << endl;
        } else {
          cout << status << " Firmware Update failed: module " << serial << " is not online" <<
               endl;
          exit(1);
        }
      }
    }
  }
  return 0;
}
Esempio n. 4
0
int main(int argc, const char * argv[])
{
    string      errmsg;
    
    // Setup the API to use local USB devices
    if(yRegisterHub("usb", errmsg) != YAPI_SUCCESS) {
        cerr << "RegisterHub error: " << errmsg << endl;
        return 1;
    }
    
    if(argc < 2)
        usage(argv[0]);
    
    YModule *module = yFindModule(argv[1]);  // use serial or logical name
    
    if (module->isOnline()) {
        if (argc > 2) {
            if (string(argv[2]) == "ON")
                module->set_beacon(Y_BEACON_ON);
            else
                module->set_beacon(Y_BEACON_OFF);
        }
        cout << "serial:       " << module->get_serialNumber() << endl;
        cout << "logical name: " << module->get_logicalName() << endl;
        cout << "luminosity:   " << module->get_luminosity() << endl;
        cout << "beacon:       ";
        if (module->get_beacon()==Y_BEACON_ON)
            cout << "ON" << endl;
        else
            cout << "OFF" << endl;
        cout << "upTime:       " << module->get_upTime()/1000 << " sec" << endl;
        cout << "USB current:  " << module->get_usbCurrent() << " mA" << endl;
        cout << "Logs:"<< endl << module->get_lastLogs() << endl;
    } else {
        cout << argv[1] << " not connected (check identification and USB cable)"
        << endl;
    }
    return 0;
}