Log in Register

Login to your account

Username
Password *
Remember Me

Create an account

Fields marked with an asterisk (*) are required.
Name
Username
Password *
Verify password *
Email *
Verify email *
Captcha *
Welcome, Guest
Username: Password: Remember me

TOPIC: [Résolu] Parser xPL

Parser xPL 13 Mar 2014 20:07 #1

Bonjour,
Je teste un arduino 328 nano avec un contrôleur Ethernet ENC28J60.
Le but est dialoguer via le protocole xPL avec la librairie de ce site : http://code.google.com/p/xpl-arduino/

L'envoi de message xPL fonctionne, par contre à la réception, je bloque Wassat

Le parse décode bien la trame xPL mais je n'arrive pas à passer dans le If qui valide le schema-class et le schema-type.
J'ai laissé les valeurs par défauts control.basic, mais rien à faire et le debug avec serial.print est un peu light....

Si vous avez une idée je suis preneur.

A+
  • manumdk
  • Nophoto
  • OFFLINE
  • Fresh Boarder
  • Rank0
  • Posts: 4
  • Karma: 0
The administrator has disabled public write access.

Parser xPL 14 Mar 2014 11:53 #2

salut,

on utilise cet lib, sans problème. Donne un peu de détail sur ton pb parce que là...

Chez nous on a un truc du genre:
void AfterParseAction(xPL_Message * message)
{
    if (xpl.TargetIsMe(message))
    {
        if (message->IsSchema_P(PSTR("lighting"), PSTR("basic"))){
            Serial.println(F("new lighting.basic"));
            lighting_basic(message);
        }else
        if (message->IsSchema_P(PSTR("lighting"), PSTR("request"))){
            Serial.println(F("new lighting.request"));
            lighting_request(message);
        }else
        if (message->IsSchema_P(PSTR("shutter"), PSTR("basic"))){
            Serial.println(F("new shutter.basic"));
            shutter_basic(message);
        }else
        if (message->IsSchema_P(PSTR("shutter"), PSTR("request"))){
            Serial.println(F("new lighting.request"));
            shutter_request(message);
        }else
        if (message->IsSchema_P(PSTR("switch"), PSTR("request"))){
            Serial.println(F("new switch.request"));
            switch_request(message);
        }else
        if (message->IsSchema_P(PSTR("sensor"), PSTR("request"))){
            Serial.println(F("new sensor.request"));
            sensor_request(message);
        }
    #ifdef DEBUG_INCOMING
    // show message
    Serial.println(F("---------- xPL mess reception -----------"));
    Serial.println(message->toString());
    #endif
}

Gromain
  • gromain
  • Avatar 2013 01 07
  • OFFLINE
  • Administrateur
  • Administrateur
  • Posts: 153
  • Thank you received: 10
  • Karma: 3
The administrator has disabled public write access.

Parser xPL 14 Mar 2014 17:41 #3

Le code que j'utilise avec plein de de print Blush
/*
 * xPL.Arduino v0.1, xPL Implementation for Arduino
 *
 * This code is parsing a xPL message stored in 'received' buffer
 * - isolate and store in 'line' buffer each part of the message -> detection of EOL character (DEC 10)
 * - analyse 'line', function of its number and store information in xpl_header memory
 * - check for each step if the message respect xPL protocol
 * - parse each command line
 *
 * Copyright (C) 2012 johan@pirlouit.ch, olivier.lebrun@gmail.com
 * Original version by Gromain59@gmail.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
 
#include <xPL.h>
#include <EtherCard.h>

byte Ethernet::buffer[XPL_MESSAGE_BUFFER_MAX];
xPL xpl;
 
// Init du serveur HTTP
uint8_t mymac[6] = { 0x54,0x55,0x58,0x10,0x00,0x11 };
uint8_t myip[4] = { 192,168,1,133 };
uint8_t gwip[4] = { 192,168,1,254};
 
// Ethercard seems to only send broadcast on this addr
// find using xpl-perl, don't forget to add "--define broadcast=0.0.0.0" to the xpl-hub
uint8_t broadcast[4] = { 255,255,255,255};
 
void SendUdPMessage(char *buffer)
{
    ether.sendUdp (buffer, strlen(buffer), xpl.udp_port, broadcast, xpl.udp_port);
}
 
void AfterParseAction(xPL_Message * message)
{
    // show message     
    Serial.println("********************************************");
    Serial.println("********  AfterParseAction : Debut *********");
    Serial.print(message->toString());  
 
 
    if (xpl.TargetIsMe(message))
    {
      Serial.println("********************************************");
      Serial.println("********   xpl.TargetIsMe : Debut   ********");
 
     if (message->IsSchema(PSTR("control"), PSTR("basic")))
      {
        Serial.println("is lighting.basic OK");  
      }
 
      Serial.println("********    xpl.TargetIsMe : Fin    ********");
      Serial.println("******************************************** ");
    }
    Serial.println("********  AfterParseAction :  Fin   ********");
    Serial.println("******************************************** ");  
 
 
}
 
void setup()
{
  Serial.begin(115200);
  Serial.println("Setup");
 
  ether.begin(sizeof Ethernet::buffer, mymac,10);
  ether.staticSetup(myip, gwip);
 
  xpl.SendExternal = &SendUdPMessage;  // pointer to the send callback
  xpl.AfterParseAction = &AfterParseAction;  // pointer to a post parsing action callback 
  //xpl.SetSource_P(PSTR("arduino"), PSTR("nano"), PSTR("ext")); // parameters for hearbeat message
  //xpl.SetSource_P(PSTR("android"), PSTR("acer"), PSTR("manu")); // parameters for hearbeat message
 xpl.SetSource_P(PSTR("smgpoe"), PSTR("lamp"), PSTR("1")); // parameters for hearbeat message
 
  Serial.println("Fin Setup");
}
 
void loop()
{
   xpl.Process();  // heartbeat management
 
   word len = ether.packetReceive();
   if( len > 0 ) 
   {
     Serial.println("Receive");
     // Check if Xpl UDP packet
     if( isXpl( Ethernet::buffer ) )
     {
       char xPLMessageBuff[XPL_MESSAGE_BUFFER_MAX];
       ByteToChar(Ethernet::buffer, xPLMessageBuff, len);
 
       // parse message
       Serial.println("******************************************** ");
       Serial.println("********  ParseInputMessage : Debut  ********");
       xpl.ParseInputMessage(xPLMessageBuff); 
       Serial.println("********   ParseInputMessage : Fin   ********");
       Serial.println("******************************************** ");
       Serial.println();
 
 
       Serial.println("******************************************** ");
       Serial.println("********     Show xPLMessageBuff :   ********");
       Serial.println(xPLMessageBuff);
       Serial.println("********     fin du buffer           ********");
       Serial.println("******************************************** ");
     }
   }
}
 
boolean isXpl( uint8_t *buffer)
{
  return ( buffer[IP_PROTO_P] == IP_PROTO_UDP_V
            && buffer[UDP_DST_PORT_L_P] == XPL_PORT_L
            && buffer[UDP_DST_PORT_H_P] == XPL_PORT_H);
}
 
// convert byte* to char*
void ByteToChar(byte* bytes, char* chars, unsigned int count)
{
    for(unsigned int j = 0, i = UDP_DATA_P; i < count; i++)
    {
    	chars[j++] = (char)bytes[i];
    }
}

Le log qui en ressort :
******************************************** 
Receive
******************************************** 
********  ParseInputMessage : Debut  ********
********************************************
********  AfterParseAction : Debut *********
xpl-cmnd
{
hop=1
source=smgpoe-lamp.1
target=*
}
control.basic
{
device=led
type=variable
}
********  AfterParseAction :  Fin   ********
******************************************** 
********   ParseInputMessage : Fin   ********
******************************************** 
 

Je ne passe jamais dans la condition :
if (message->IsSchema(PSTR("control"), PSTR("basic")))
{
Serial.println("is lighting.basic OK");
}


Je ressaye avec ton exemple.
Merci
  • manumdk
  • Nophoto
  • OFFLINE
  • Fresh Boarder
  • Rank0
  • Posts: 4
  • Karma: 0
The administrator has disabled public write access.

Parser xPL 14 Mar 2014 17:56 #4

Effectivement, avec ton exemple c'est beaucoup plus simple et fonctionnel Wink

Merci
  • manumdk
  • Nophoto
  • OFFLINE
  • Fresh Boarder
  • Rank0
  • Posts: 4
  • Karma: 0
The administrator has disabled public write access.

Parser xPL 15 Mar 2014 12:08 #5

tant mieux Smile

avec atmega328, on est vite à cours de ram, donc bien calibrer le buffer xPL

Gromain
  • gromain
  • Avatar 2013 01 07
  • OFFLINE
  • Administrateur
  • Administrateur
  • Posts: 153
  • Thank you received: 10
  • Karma: 3
The administrator has disabled public write access.
The following user(s) said Thank You: manumdk

Parser xPL 16 Mar 2014 08:21 #6

En fait, je vais me servir de mon nano328 que pour gérer le portail, le portillon, l'éclairage extérieur, bref ça ressemble à des entrés/sorties XPL, ça devrait rentrer Smile

Merci
  • manumdk
  • Nophoto
  • OFFLINE
  • Fresh Boarder
  • Rank0
  • Posts: 4
  • Karma: 0
The administrator has disabled public write access.

[Résolu] Parser xPL 16 Mar 2014 08:22 #7

Ce topic a été indiqué comme résolu
  • manumdk
  • Nophoto
  • OFFLINE
  • Fresh Boarder
  • Rank0
  • Posts: 4
  • Karma: 0
The administrator has disabled public write access.
Backtotop