/** * Switch the relay to the opposite state. * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YWatchdog::toggle(void) { int sta = 0; string fw; YModule* mo = NULL; if (_firm == 0) { mo = this->get_module(); fw = mo->get_firmwareRelease(); if (fw == YModule::FIRMWARERELEASE_INVALID) { return Y_STATE_INVALID; } _firm = atoi((fw).c_str()); } if (_firm < 34921) { sta = this->get_state(); if (sta == Y_STATE_INVALID) { return Y_STATE_INVALID; } if (sta == Y_STATE_B) { this->set_state(Y_STATE_A); } else { this->set_state(Y_STATE_B); } return YAPI_SUCCESS; } else { return this->_setAttr("state","X"); } }
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; }