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 AFramework::MTempMaster::programsManager(const bool read){ //da fare ADateTime currentClk; Program prg; AString str; if(!m_flag){ return false; } if(read){ for(uint8 i = 0; i < _MTEMP_ROOM_VEC_SIZE; i++){ if(m_rooms[i].currentTemperature() != 0){ //se il sensore è vivo str.clear(); str = m_rooms[i].sensorAddress(); m_rooms[i].setTemperature(readTemp(str, 1000)); //aggiorno la temperatura } } } if(m_clk->isGood()){ currentClk = m_clk->currentTime(); for(uint8 i=0; i < _MTEMP_ROOM_VEC_SIZE; i++){ prg = m_rooms[i].program(currentClk.Weekday()); if(m_rooms[i].isAuto()){ if(prg.isEnabled()){ if( ((prg.startHours() == currentClk.hours() && prg.startMinutes() <= currentClk.minutes()) || (prg.startHours() < currentClk.hours())) && ((prg.endHours() == currentClk.hours() && prg.endMinutes() >= currentClk.minutes()) || (prg.endHours() > currentClk.hours()))) { if(m_rooms[i].currentTemperature() <= prg.targetTemperature()){ m_rooms[i].on(); }else{ m_rooms[i].off(); } }else{ m_rooms[i].off(); } }else{ m_rooms[i].off(); } } if(m_rooms[i].isForcedOff()){ //se lo spegnimento è forzato m_rooms[i].off(); //metto off la porta } if(m_rooms[i].isForcedOn()){ m_rooms[i].on(); //metto on la porta } } }else{ m_lcd->clear(); m_lcd->write("Errore ora"); System::delay(1000); } return false; }