Skip to content

Commit

Permalink
Adds support for Arduino 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
tmittet committed Feb 27, 2015
1 parent b7eb74e commit 48291ea
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 22 deletions.
17 changes: 10 additions & 7 deletions examples/Breakfast_Menu/Breakfast_Menu.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/************************************************************************/
/* MicroXPath lib, an XML navigator with a tiny memory footprint, v1.0. */
/* MicroXPath lib, an XML navigator with a tiny memory footprint, v1.1. */
/* */
/* This library is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
Expand All @@ -21,28 +21,29 @@
#include <Ethernet.h>
#include <MicroXPath.h>

#define ETHERNET_MAC (byte[]) {0x54, 0x48, 0x4F, 0x4D, 0x41, 0x53}
#define ETHERNET_STATIC_IP (byte[]) {192, 168, 0, 123}
#define ETHERNET_ERROR_DHCP "E: DHCP"
#define ETHERNET_ERROR_CONNECT "E: Connect"

EthernetClient client;
MicroXPath xPath = MicroXPath();

byte g_mac[] = {0x54, 0x48, 0x4F, 0x4D, 0x41, 0x53};
IPAddress g_ethernetStaticIP(192, 168, 0, 123);

void setup()
{
Serial.begin(9600);
while (!Serial);

if (Ethernet.begin(ETHERNET_MAC))
if (Ethernet.begin(g_mac))
{
Serial.println("Connecting...");
Serial.flush();
}
else
{
Serial.println(ETHERNET_ERROR_DHCP);
Ethernet.begin(ETHERNET_MAC, ETHERNET_STATIC_IP);
Ethernet.begin(g_mac, g_ethernetStaticIP);
}
if (client.connect("www.w3schools.com", 80))
{
Expand All @@ -63,7 +64,8 @@ void loop()
if (client.available())
{
char result[100];
xPath.setPath((const char *[]){ "breakfast_menu", "food", "name" }, 3);
const char *namePath[] = { "breakfast_menu", "food", "name" };
xPath.setPath(namePath, 3);
while (client.available())
{
if (xPath.getValue(client.read(), result, sizeof(result)))
Expand All @@ -74,7 +76,8 @@ void loop()
break;
}
}
xPath.setPath((const char *[]){ "breakfast_menu", "food", "description" }, 3);
const char *descriptionPath[] = { "breakfast_menu", "food", "description" };
xPath.setPath(descriptionPath, 3);
while (client.available())
{
if (xPath.getValue(client.read(), result, sizeof(result)))
Expand Down
17 changes: 10 additions & 7 deletions examples/Breakfast_Menu_PROGMEM/Breakfast_Menu_PROGMEM.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/************************************************************************/
/* MicroXPath lib, an XML navigator with a tiny memory footprint, v1.0. */
/* MicroXPath lib, an XML navigator with a tiny memory footprint, v1.1. */
/* */
/* This library is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
Expand All @@ -22,8 +22,6 @@
#include <MicroXPath_P.h>
#include <avr/pgmspace.h>

#define ETHERNET_MAC (byte[]) {0x54, 0x48, 0x4F, 0x4D, 0x41, 0x53}
#define ETHERNET_STATIC_IP (byte[]) {192, 168, 0, 123}
#define ETHERNET_ERROR_DHCP "E: DHCP"
#define ETHERNET_ERROR_CONNECT "E: Connect"

Expand All @@ -35,20 +33,23 @@ const char g_Description[] PROGMEM = "description";
EthernetClient client;
MicroXPath_P xPath = MicroXPath_P();

byte g_mac[] = {0x54, 0x48, 0x4F, 0x4D, 0x41, 0x53};
IPAddress g_ethernetStaticIP(192, 168, 0, 123);

void setup()
{
Serial.begin(9600);
while (!Serial);

if (Ethernet.begin(ETHERNET_MAC))
if (Ethernet.begin(g_mac))
{
Serial.println("Connecting...");
Serial.flush();
}
else
{
Serial.println(ETHERNET_ERROR_DHCP);
Ethernet.begin(ETHERNET_MAC, ETHERNET_STATIC_IP);
Ethernet.begin(g_mac, g_ethernetStaticIP);
}
if (client.connect("www.w3schools.com", 80))
{
Expand All @@ -69,7 +70,8 @@ void loop()
if (client.available())
{
char result[100];
xPath.setPath((const char*[]){ g_BreakfastMenu, g_Food, g_Name }, 3);
const char *namePath[] = { g_BreakfastMenu, g_Food, g_Name };
xPath.setPath(namePath, 3);
while (client.available())
{
if (xPath.getValue(client.read(), result, sizeof(result)))
Expand All @@ -80,7 +82,8 @@ void loop()
break;
}
}
xPath.setPath((const char*[]){ g_BreakfastMenu, g_Food, g_Description }, 3);
const char *descriptionPath[] = { g_BreakfastMenu, g_Food, g_Description };
xPath.setPath(descriptionPath, 3);
while (client.available())
{
if (xPath.getValue(client.read(), result, sizeof(result)))
Expand Down
9 changes: 9 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=MicroXPath
version=1.1
author=Thomas Mittet
maintainer=Thomas Mittet <code@lookout.no>
sentence=Allows you to do XPath like queries in XML steams while only consuming a few bytes of memory. For all Arduino boards.
paragraph=MicroXPath is a state machine which purpose is to enable XML navigation on the Arduino platform while keeping the memory footprint as small as possible. The PROGMEM version of MicroXPath uses no more than 9 bytes of RAM.
category=Communication
url=http://blog.lookout.no/2015/01/xpath-like-xml-navigator-for-arduino.html
architectures=*
2 changes: 1 addition & 1 deletion MicroXPath.cpp → src/MicroXPath.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/************************************************************************/
/* MicroXPath lib, an XML navigator with a tiny memory footprint, v1.0. */
/* MicroXPath lib, an XML navigator with a tiny memory footprint, v1.1. */
/* */
/* This library is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
Expand Down
2 changes: 1 addition & 1 deletion MicroXPath.h → src/MicroXPath.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/************************************************************************/
/* MicroXPath lib, an XML navigator with a tiny memory footprint, v1.0. */
/* MicroXPath lib, an XML navigator with a tiny memory footprint, v1.1. */
/* */
/* This library is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
Expand Down
10 changes: 5 additions & 5 deletions MicroXPath_P.cpp → src/MicroXPath_P.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/************************************************************************/
/* MicroXPath lib, an XML navigator with a tiny memory footprint, v1.0. */
/* MicroXPath lib, an XML navigator with a tiny memory footprint, v1.1. */
/* */
/* This library is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
Expand Down Expand Up @@ -56,14 +56,14 @@ void MicroXPath_P::setPath(PGM_P *path, size_t pathSize)
for (uint8_t i = 0; i < pathSize && i < this->pathSize && i < matchLevel && i == newMatchLevel; i++)
{
uint8_t len = strlen_P(path[i]);
if (strlen_P(this->path[i]) == len)
{
if (strlen_P(this->path[i]) == len)
{
for (uint8_t j = 0; j < len; j++)
{
{
if (pgm_read_byte(path[i] + j) != pgm_read_byte(this->path[i] + j)) break;
if (j == len - 1) newMatchLevel++;
}
}
}
}
this->matchCount = 0;
this->matchLevel = newMatchLevel;
Expand Down
2 changes: 1 addition & 1 deletion MicroXPath_P.h → src/MicroXPath_P.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/************************************************************************/
/* MicroXPath lib, an XML navigator with a tiny memory footprint, v1.0. */
/* MicroXPath lib, an XML navigator with a tiny memory footprint, v1.1. */
/* */
/* This library is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
Expand Down

0 comments on commit 48291ea

Please sign in to comment.