void setup() { USB.begin(); USB.println("PROGRAM: SendAverageTemperature.pde\nUSB port started..."); xbeeZB.init(ZIGBEE,FREQ2_4G,NORMAL); xbeeZB.ON(); xbeeZB.wake(); // For end devices: SM=1!!! delay(3000); // Suppose network parameters are OK! (However: MUST BE DONE IN ORDER TO COME IN VALID ASSOCIATION STATE AFTER SLEEP) if(!xbeeZB.setPAN(panid)) USB.println("setPAN ok"); else USB.println("setPAN error"); if(!xbeeZB.setScanningChannels(0xFF,0xFF)) USB.println("setScanningChannels ok"); else USB.println("setScanningChannels error"); if(!xbeeZB.setDurationEnergyChannels(3)) USB.println("setDurationEnergyChannels ok"); else USB.println("setDurationEnergyChannels error"); if(!xbeeZB.getAssociationIndication()) USB.println("getAssociationIndication ok"); else USB.println("getAssociationIndication error"); xbeeZB.writeValues(); // wait until XBee module is associated checkAssociation(); }
bool setAssociation(const QString &extension, const QString &typeDescription, const QString &friendlyName) { if(!isSupportAssociation()) return false; #ifndef Q_WS_WIN return false; #else QSettings RegCR ("HKEY_CLASSES_ROOT", QSettings::NativeFormat); //Read only on NT+ QSettings RegCU ("HKEY_CURRENT_USER", QSettings::NativeFormat); if (QSysInfo::WindowsVersion < QSysInfo::WV_NT && !RegCR.isWritable()) //Win98 return false; QString ext("." + extension); QString ProgID = makeProgID(extension); //Check if ProgID exists in the registry, otherwise create it. if (!hasProgID(ProgID) && !setProgID(ProgID, typeDescription, friendlyName)) return false; if(checkAssociation(extension)) return true; //Create the associations if (QSysInfo::WindowsVersion >= QSysInfo::WV_NT){ RegCU.setValue("Software/Classes/" + ext + REG_DEFAULT, ProgID); //Extension class //Explorer FileExt association QString FileExtsKey = QString("Software/Microsoft/Windows/CurrentVersion/Explorer/FileExts/") + ext; removeUserChoice(extension); RegCU.remove(FileExtsKey + "/Application"); /// Windows XP }else{ //Windows ME/98/95 support RegCR.setValue(ext + REG_DEFAULT, ProgID); } RegCU.sync(); RegCR.sync(); // SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);// Refresh Explorer cache. return (RegCU.status() == QSettings::NoError && RegCR.status() == QSettings::NoError); #endif // Q_WS_WIN }
void loop() { USB.println("Device enters loop"); measureSensors(); //sendMessage("Test message"); //xbeeZB.init(ZIGBEE,FREQ2_4G,NORMAL); //xbeeZB.ON(); //xbeeZB.wake(); //delay(3000); //checkAssociation(); printCurrentNetworkParams(); sendMessage(aux); // 5.9 Communication module to OFF //xbeeZB.OFF(); //delay(100); //////////////////////////////////////////////// // 6. Entering Deep Sleep mode //////////////////////////////////////////////// USB.println("Entering deep sleep"); RTC.ON(); PWR.deepSleep(sleepTime, RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF); USB.begin(); USB.println("wake"); xbeeZB.ON(); delay(3000); // wait until XBee module is associated checkAssociation(); }
bool clearAssociation(const QString & extension) { if(!isSupportAssociation()) return false; #ifdef Q_WS_WIN if(!checkAssociation(extension)) return true; QString ext("." + extension); QString ProgID = makeProgID(extension); QSettings RegCU("HKEY_CURRENT_USER", QSettings::NativeFormat); QSettings RegCR ("HKEY_CLASSES_ROOT", QSettings::NativeFormat); if (QSysInfo::WindowsVersion < QSysInfo::WV_NT && !RegCR.isWritable()) //Win98 return false; QString fileName = QFileInfo(qApp->applicationFilePath()).fileName(); QString FileExtsKey = QString("Software/Microsoft/Windows/CurrentVersion/Explorer/FileExts/") + ext; /// Windows 7:"/UserChoice/Progid" ; XP: "/Progid" QString CurClassId = (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA) ? RegCU.value(FileExtsKey + "/UserChoice/Progid").toString() : RegCU.value(FileExtsKey + "/Progid").toString(); QString CurAppId = RegCU.value(FileExtsKey + "/Application").toString(); /// Windows XP if (!CurClassId.isEmpty() && ( (CurClassId == ProgID) || (0 == CurClassId.compare(fileName, Qt::CaseInsensitive)) || (0 == CurClassId.compare(QString("Applications\\%1").arg(fileName), Qt::CaseInsensitive)) ) ){ removeUserChoice(extension); } if (!CurAppId.isEmpty() && ( (CurAppId == ProgID) || (0 == CurAppId.compare(fileName, Qt::CaseInsensitive)) ) ){ RegCU.remove(FileExtsKey + "/Application"); } if (QSysInfo::WindowsVersion >= QSysInfo::WV_NT){ if (RegCU.value("Software/Classes/" + ext + REG_DEFAULT).toString() == ProgID) //Only remove if we own it /// This is no recommend to delete in MSDN, case it may cause other problems, such as cannot create new text document if delete '.txt' group. // RegCU.remove("Software/Classes/" + ext); RegCU.remove("Software/Classes/" + ProgID); }else{ //Windows 98 ==> Write to HKCR if (RegCR.value(ext + REG_DEFAULT).toString() == ProgID) // RegCR.remove(ext); RegCR.remove(ProgID); } RegCU.sync(); RegCR.sync(); // SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);// Refresh Explorer cache. return (RegCU.status() == QSettings::NoError && RegCR.status() == QSettings::NoError); #else return false; #endif // Q_WS_WIN }