Beispiel #1
0
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 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();
}
Beispiel #3
0
void doit(const AString& input)
{
  LIST_AString words;
  input.split(words);

  for (LIST_AString::iterator it = words.begin(); it != words.end(); ++it)
  {
    AString tmp;
    AString output;
    AWordUtility::getPhoneticForm(*it, tmp);
    AWordUtility::getSoundsLikeForm(tmp, output);

    std::cout << *it << " : " << tmp << " : " << output << std::endl;
  }
}
Beispiel #4
0
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;
}
Beispiel #5
0
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;
}
Beispiel #6
0
void Data::parse_line(AString line) {
    line = line.strip(" \t");
    if (line.startswith("#")) return;

    if (line.contains('=')) {
        std::vector<AString> vec = line.split("=");
        vec[0] = vec[0].strip(" ");
        if (vec[1].contains('#'))
            vec[1] = vec[1].lpartition("#")[0];
        vec[1] = vec[1].strip(" ");


        values[current_category][vec[0]] = vec[1];
    }
    else {
        if (line.startswith("[")) {
            current_category = line.strip("[]");
        }
    }
    //if (line.length() == 0) return;

    //int stage = 0;
    //AString field;
    //AString value;
    //AString category;

    //for (unsigned int i = 0; i < line.length(); i++) {
        //char c = line[i];
        //if (stage == 0) {
            //if ( (c == ' ') || (c == '\t') )
                //continue;
            //else if (c == '=')
                //stage = 1;
            //else if (c == '#')
                //return;
            //else if (c == '[')
                //stage = 3;
            //else
                //field += c;
        //}
        //else if (stage == 1) {
            //if ( (c == ' ') || (c == '\t') )
                //continue;
            //else {
                //stage = 2;
                //value += c;
            //}
        //}
        //else if (stage == 2) {
            //value += c;
        //}
        //else if (stage == 3) {
            //if ( c == ']' ) {
                //current_category = category;
                //return;
            //}
            //else
                //category += c;
        //}
    //}
    //this->values[current_category][field] = value;
}