Comment controller la réponse d'une commande


bonjour à tous,

j'ai une fonction qui va envoyer une commande et ca marche bien, sauf que....

voici la commande (regarder surtout  serial.println(response
  • );)
    code: [select]
    int8_t morse::sendatcommand(char* atcommand, char* expected_answer, unsigned int timeout){

        uint8_t x=0,  answer=0;
        char response[100];
        unsigned long previous;

        memset(response, '\0', 100);    // initialice string
       
        delay(100);

        while( _cell.available() > 0) _cell.read();    // clean input buffer

        if (atcommand[0] != '\0')
        {

            _cell.println(atcommand);    // send @ command
        }

        x = 0;
        previous = millis();

        // loop waits answer
        do{
            if(_cell.available() != 0){    // if there data in uart input buffer, reads , checks asnwer
                response[x] = _cell.read();
     
                serial.println(response[x]);
                x++;
                if (strstr(response, expected_answer) != null)    // check if desired answer (ok) in response of module
                {

                    answer = 1;
                }
            }else{
           
             
            }
        }while((answer == 0) && ((millis() - previous) < timeout));    // waits asnwer time out
       

       
        return answer;
    }

    quand je fais ceci, il m'affiche "gps ready"
    code: [select]
    if(sendatcommand("at","gps ready",2000)){
    serial.println("gps ready\n");
    };

    par contre quand je fais
    code: [select]
    if(sendatcommand("at","call ready",2000)){
    serial.println("call ready\n");
    };

    il me retourne rien.

    en fait , ceci serial.println(response
  • ); affiche
    quote

    c
    a
    l
    l

    r
    e
    a
    s
    y
    [vide]
    [vide]

    avec deux vide.

    c'est pourca qu'il n'affiche rien.

    je ne comprends pas car la fonction sendatcomdwait à cette fonction
    code: [select]
    strstr(response, expected_answer)
    donc normalement, dès que ca coincide, il doit retourner true???

    bon, ben non!!!

    alors comment je peux faire pour qu'il ne considère pas les espace après la chaine de caractere demandée, (s'il y des expaces)?
    comme pourrais-je optimiser ceci?

    milles mercis



Arduino Forum > International > Français (Moderators: jfs, Snootlab) > Comment controller la réponse d'une commande


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support