bool AFramework::MTempMaster::saveNetworkConfig(const AString &data) const{ bool flg = false; if(!m_flag){ return false; } AStringList *list = NULL; list = data.split(_MTEMP_SEP); if(list && data.good()){ /* * FORMATO STRINGA CONF * (CLIENT) SSID*KEY*IP*PORT*USER*PASSWORD*[CONF] */ flg = (m_memory->write(_MTEMP_SSID_ADDRESS , list->at(0)) && m_memory->write(_MTEMP_SSID_KEY_ADDRESS , list->at(1)) && m_memory->write(_MTEMP_MASTER_IP_ADDRESS , list->at(2)) && m_memory->write(_MTEMP_MASTER_PORT_ADDRESS , list->at(3)) && m_memory->write(_MTEMP_USERNAME_ADDRESS , list->at(4)) && m_memory->write(_MTEMP_USER_KEY_ADDRESS , list->at(5))); delete list; return flg; } return false; }
void cPluginManager::FindPlugins(void) { AString PluginsPath = FILE_IO_PREFIX + AString( "Plugins/" ); // First get a clean list of only the currently running plugins, we don't want to mess those up for (PluginMap::iterator itr = m_Plugins.begin(); itr != m_Plugins.end();) { if (itr->second == NULL) { PluginMap::iterator thiz = itr; ++thiz; m_Plugins.erase( itr ); itr = thiz; continue; } ++itr; } AStringList Files = GetDirectoryContents(PluginsPath.c_str()); for (AStringList::const_iterator itr = Files.begin(); itr != Files.end(); ++itr) { if ((*itr == ".") || (*itr == "..") || (!cFile::IsFolder(PluginsPath + *itr))) { // We only want folders, and don't want "." or ".." continue; } // Add plugin name/directory to the list if (m_Plugins.find(*itr) == m_Plugins.end()) { m_Plugins[*itr] = NULL; } } }
void SmartMote::config(){ AString conf; AStringList * param = NULL; bool flag; /* se il bottone non è premuto */ if(!checkButton()){ /* ritorno */ return; } /* accendo l'uart */ openUART(); /* inizializzo il modulo come AP */ if(!m_net.initialize(AESP07::APMode)){ /* se fallisce notifico l'errore */ error(); } /* setto il nome come SmartMote e password admin */ if(!m_net.configureAP("SmartMote", "smartmote")){ /* se fallisce notifico l'errore */ error(); } /* imposto l'ip a 192.168.1.1 */ if(!m_net.setIp(AESP07::APMode, "192.168.1.1")){ /* se fallisce notifico l'errore */ error(); } /* disabilito le connessioni multiple */ if(!m_net.setMultipleConnections(false)){ /* se fallisce notifico l'errore */ error(); } /* apro il server sulla porta 8000 */ if(!m_net.listen(8000)){ /* se fallisce notifico l'errore */ error(); } /* aspetto di ricevere la stringa */ while(conf.isEmpty()){ m_net.waitForData(conf); } /* prendo i parametri */ param = conf.split(' '); /* se la stringlist è allocata correttamente */ if(param){ saveSSID(param->at(0)); saveKey(param->at(1)); saveHost(param->at(2)); RTCC.setHours(static_cast<uint32>(param->at(3).toInt32(flag))); RTCC.setMinutes(static_cast<uint32>(param->at(3).toInt32(flag))); RTCC.setSeconds(static_cast<uint32>(param->at(3).toInt32(flag))); }else{ /* altrimenti notifico l'errore */ error(); } /* spengo i led */ turnOffRed(); turnOffGreen(); }
AFramework::uint8 AFramework::MTempMaster::readTemp(AString &addr, const uint32 ms){ AString str; AStringList *list; bool flag = false; if(!m_xbee){ return 0; } addr += _MTEMP_SEP; addr += _MTEMP_TEMPGET; m_xbee->send(addr); if(m_xbee->receive(_MTEMP_BOARD_OK, ms)){ m_xbee->read(str); list = str.split(_MTEMP_SEP); str.clear(); str = list->at(1); delete list; return static_cast<uint8>(str.toInt32(flag)); } return 0; }
/** 列出该文件包内的所有文件 @Param 文件名字列表 @Param 遍历时是否递归 @Param 显示目录而非目录下文件 */ void FZipFilePack::ListFiles( AStringList& fileList,bool bRecurse,bool bDir ) { VFileInfoList::iterator itr; VFileInfoList::iterator end = m_FileInfos.end(); for( itr=m_FileInfos.begin();itr!=end;itr++ ) { if( ((itr->nCompressedSize != (size_t)-1) || (itr->nCompressedSize == (size_t)-1 && bDir)) && (bRecurse || itr->sPath.empty()) ) { fileList.push_back( itr->sFileName ); } } }
/** 查找指定的文件 @Param 存储文件名字的列表 @Param 用于匹配文件名的字符 @Param 遍历时是否递归 @Param 是否遍历目录 */ void FZipFilePack::FindFiles( AStringList& fileList,const AString& pattern, bool bRecurse,bool bDir ) { VFileInfoList::iterator itr; VFileInfoList::iterator end = m_FileInfos.end(); // 如果要查找的字符包含目录,则做一个全匹配 bool full_match = (pattern.find('/') != AString::npos || pattern.find('\\') != AString::npos); // 获取关键字的目录 AString directory; if( full_match ) { size_t pos1 = pattern.rfind( '/' ); size_t pos2 = pattern.rfind( '\\' ); if( pos1 == AString::npos || ((pos2 != AString::npos) && pos1 < pos2) ) pos1 = pos2; if( pos1 != AString::npos ) directory = pattern.substr( 0,pos1+1 ); } // 遍历文件信息 for( itr=m_FileInfos.begin();itr!=end;itr++ ) { if( ((itr->nCompressedSize != (size_t)-1) || (itr->nCompressedSize == (size_t)-1 && bDir)) && (bRecurse || itr->sPath == directory) ) { if( AStringUtil::Match(full_match ? itr->sFileName : itr->sBaseName,pattern) ) fileList.push_back( itr->sFileName ); } } }
void AFramework::MTempMaster::commandExec(const AString &cmd){ AStringList * list; AString str; ADateTime time; bool flag = false; uint8 index = 0; uint8 index1 = 0; list = cmd.split(_MTEMP_SEP); if(list && cmd.good()){ if(list->at(0) == m_username && list->at(1) == m_password){ str = list->at(list->size() - 1); if(str == _MTEMP_TIMESET){ //* (CLIENT) username*password*AA*MM*GG*WD*HH*MM*SS*[TIMESET] if(time.setYear(list->at(2).toInt32(flag)) && flag){ if(time.setMonth(static_cast<ADateTime::Months>(list->at(3).toInt32(flag))) && flag){ if(time.setDayOfMonth(list->at(4).toInt32(flag)) && flag){ if(time.setWeekday(static_cast<ADateTime::Weekdays>(list->at(5).toInt32(flag))) && flag){ if(time.setHours(list->at(6).toInt32(flag)) && flag){ if(time.setMinutes(list->at(7).toInt32(flag)) && flag){ if(time.setSeconds(list->at(8).toInt32(flag)) && flag){ if(m_clk->setTime(time)){ if(m_wifi->send(_MTEMP_BOARD_OK)){ str.clear(); str = m_clk->currentTime().timeToString(); str.prepend("Ora settata\n"); msg(str, 0); delete list; return; } } } } } } } } } }else if(str == _MTEMP_TIMEGET){ //* (CLIENT) username*password*[TIMEGET] //* (SERVER) (AA*MM*GG*WD*HH*MM*SS*[OK] || [FAIL] || [ERROR]) if(m_clk->isGood()){ str.clear(); time = m_clk->currentTime(); str += AString(time.year()); str += _MTEMP_SEP; str += AString(static_cast<uint8>(time.month())); str += _MTEMP_SEP; str += AString(time.dayOfMonth()); str += _MTEMP_SEP; str += AString(static_cast<uint8>(time.Weekday())); str += _MTEMP_SEP; str += AString(time.hours()); str += _MTEMP_SEP; str += AString(time.minutes()); str += _MTEMP_SEP; str += AString(time.seconds()); str += _MTEMP_SEP; str += _MTEMP_BOARD_OK; m_wifi->send(str); delete list; return; }else{ m_wifi->send(_MTEMP_BOARD_FAIL); msg("Errore...\nOrologio"); delete list; return; } delete list; return; }else if(str == _MTEMP_TEMPGET){ //(CLIENT) username*password*R*[TEMPGET] //(SERVER) R*TT*([OK] || [FAIL] || [ERROR]) index = list->at(2).toInt32(flag); if(flag && index < _MTEMP_ROOM_VEC_SIZE){ str.clear(); str += list->at(2); str += _MTEMP_SEP; ///////////////////////////////////////////////////////////////////////////////////////// //AString prova = m_rooms[index].sensorAddress(); //str += AString(readTemp(prova, 500)); str += AString(m_rooms[index].currentTemperature()); ///////////da fare per casa ///////////////////////////////////////////////////////////////////////////////////////////// str += _MTEMP_SEP; str += _MTEMP_BOARD_OK; m_wifi->send(str); delete list; return; }else{ m_wifi->send(_MTEMP_BOARD_FAIL); delete list; return; } delete list; return; }else if(str == _MTEMP_ROOMSTAT){ //(CLIENT) username*password*R*[ROOMSTAT] //(SERVER) (R*NAME*STATE*ISFORCEDON*ISFORCEDOFF*TT*[OK] || [FAIL] || [ERROR]) index = list->at(2).toInt32(flag); if(flag && index < _MTEMP_ROOM_VEC_SIZE){ str.clear(); str += list->at(2); str += _MTEMP_SEP; str += m_rooms[index].roomName(); str += _MTEMP_SEP; str += (m_rooms[index].isOn() ? _MTEMP_ENABLED : _MTEMP_DISABLED); str += _MTEMP_SEP; str += (m_rooms[index].isForcedOn() ? _MTEMP_ENABLED : _MTEMP_DISABLED); str += _MTEMP_SEP; str += (m_rooms[index].isForcedOff() ? _MTEMP_ENABLED : _MTEMP_DISABLED); str += _MTEMP_SEP; /////////////////////////////////////////////////////////////////////////////////////////// //AString prova = m_rooms[index].sensorAddress(); //str += AString(readTemp(prova, 1000)); str += AString(m_rooms[index].currentTemperature()); ////////////////////////////////////////////////////////////////////////////////////////// str += _MTEMP_SEP; str += _MTEMP_BOARD_OK; m_wifi->send(str); }else{ m_wifi->send(_MTEMP_BOARD_FAIL); } delete list; return; }else if(str == _MTEMP_ROOMSET){ //username*password*R*NAME*FORCEON*FORCEOFF*AUTO*[ROOMSET] //([OK] || [FAIL] || [ERROR]) index = list->at(2).toInt32(flag); //numero stanza if(flag && index < _MTEMP_ROOM_VEC_SIZE){ if(m_rooms[index].setRoomName(list->at(3))){ if(m_rooms[index].forceOn(list->at(4) == _MTEMP_ENABLED)){ if(m_rooms[index].forceOff(list->at(5) == _MTEMP_ENABLED)){ if(m_rooms[index].setAuto(list->at(6) == _MTEMP_ENABLED)){ if(m_rooms[index].saveRoom()){ m_wifi->send(_MTEMP_BOARD_OK); delete list; return; } } } } } } m_wifi->send(_MTEMP_BOARD_FAIL); delete list; return; }else if(str == _MTEMP_PROGGET){ //(CLIENT) username*password*R*D*[PROGGET] //(SERVER) (R*D*HS*MS*HE*ME*TT*E*[OK] || [FAIL] || [ERROR]) index = list->at(2).toInt32(flag); //numero stanza if(flag && index < _MTEMP_ROOM_VEC_SIZE){ index1 = list->at(3).toInt32(flag); //numero programma if(flag && index1 > 0 && index1 <= _MTEMP_WEEKPROGRAM_VEC_SIZE){ str.clear(); str += list->at(2); str += _MTEMP_SEP; str += m_rooms[index].program(static_cast<ADateTime::Weekdays>(index1)).toString(); str += _MTEMP_SEP; str += _MTEMP_BOARD_OK; m_wifi->send(str); delete list; return; } } m_wifi->send(_MTEMP_BOARD_FAIL); delete list; return; }else if(str == _MTEMP_PROGSET){ //(CLIENT) username*password*R*D*HS*MS*HE*ME*TT*E*[PROGSET] //(SERVER) ([OK] || [FAIL] || [ERROR]) index = list->at(2).toInt32(flag); //numero stanza if(flag && index < _MTEMP_ROOM_VEC_SIZE){ index1 = list->at(3).toInt32(flag); //numero programma if(flag && index1 > 0 && index1 <= _MTEMP_WEEKPROGRAM_VEC_SIZE){ str.clear(); for(uint8 i = 3; i < 9; i++){ str += list->at(i); str += _MTEMP_SEP; } str += list->at(9); if(m_rooms[index].setProgram((static_cast<ADateTime::Weekdays>(index1)), str)){ if(m_rooms[index].saveProgram(static_cast<ADateTime::Weekdays>(index1))){ m_wifi->send(_MTEMP_BOARD_OK); delete list; return; } } } } m_wifi->send(_MTEMP_BOARD_FAIL); delete list; return; }else if(str == _MTEMP_FORCEON){ //(CLIENT) username*password*R*[FORCEON] //(SERVER) ([OK] || [FAIL] || [ERROR]) index = list->at(2).toInt32(flag); if(flag && index < _MTEMP_ROOM_VEC_SIZE){ m_rooms[index].forceOn(true); m_wifi->send(_MTEMP_BOARD_OK); }else{ m_wifi->send(_MTEMP_BOARD_FAIL); } delete list; return; }else if(str == _MTEMP_FORCEOFF){ //(CLIENT) username*password*R*[FORCEOFF] //(SERVER) ([OK] || [FAIL] || [ERROR]) index = list->at(2).toInt32(flag); if(flag && index < _MTEMP_ROOM_VEC_SIZE){ m_rooms[index].forceOff(true); m_wifi->send(_MTEMP_BOARD_OK); }else{ m_wifi->send(_MTEMP_BOARD_FAIL); } delete list; return; }else{ //altro comando m_wifi->send(_MTEMP_BOARD_FAIL); delete list; return; } }else{ //login fallito m_wifi->send(_MTEMP_BOARD_ERROR); delete list; return; } } //split fallita if(list){ delete list; msg("Errore\nCmd Handler"); m_wifi->send(_MTEMP_BOARD_ERROR); } return; }
bool cPlugin_NewLua::Initialize(void) { cCSLock Lock(m_CriticalSection); if (m_LuaState == NULL) { m_LuaState = lua_open(); luaL_openlibs(m_LuaState); tolua_AllToLua_open(m_LuaState); ManualBindings::Bind(m_LuaState); luaopen_lsqlite3(m_LuaState); luaopen_lxp(m_LuaState); // Inject the identification global variables into the state: lua_pushlightuserdata(m_LuaState, this); lua_setglobal(m_LuaState, LUA_PLUGIN_INSTANCE_VAR_NAME); lua_pushstring(m_LuaState, GetName().c_str()); lua_setglobal(m_LuaState, LUA_PLUGIN_NAME_VAR_NAME); } std::string PluginPath = FILE_IO_PREFIX + GetLocalDirectory() + "/"; // Load all files for this plugin, and execute them AStringList Files = GetDirectoryContents(PluginPath.c_str()); for (AStringList::const_iterator itr = Files.begin(); itr != Files.end(); ++itr) { if (itr->rfind(".lua") == AString::npos) { continue; } AString Path = PluginPath + *itr; int s = luaL_loadfile(m_LuaState, Path.c_str() ); if( report_errors( m_LuaState, s ) ) { LOGERROR("Can't load plugin %s because of an error in file %s", GetLocalDirectory().c_str(), Path.c_str() ); lua_close( m_LuaState ); m_LuaState = 0; return false; } s = lua_pcall(m_LuaState, 0, LUA_MULTRET, 0); if( report_errors( m_LuaState, s ) ) { LOGERROR("Error in plugin %s in file %s", GetLocalDirectory().c_str(), Path.c_str() ); lua_close( m_LuaState ); m_LuaState = 0; return false; } } // for itr - Files[] // Call intialize function if (!PushFunction("Initialize")) { lua_close( m_LuaState ); m_LuaState = 0; return false; } tolua_pushusertype(m_LuaState, this, "cPlugin_NewLua"); if (!CallFunction(1, 1, "Initialize")) { lua_close( m_LuaState ); m_LuaState = 0; return false; } if( !lua_isboolean( m_LuaState, -1 ) ) { LOGWARN("Error in plugin %s Initialize() must return a boolean value!", GetLocalDirectory().c_str() ); lua_close( m_LuaState ); m_LuaState = 0; return false; } bool bSuccess = (tolua_toboolean(m_LuaState, -1, 0) > 0); return bSuccess; }