Skip to content

Commit

Permalink
Support Arduino CI (#31)
Browse files Browse the repository at this point in the history
Also fix a few minor bugs.
  • Loading branch information
sveljko authored and vveljko committed Apr 7, 2019
1 parent 2c82ad8 commit a1c8e13
Show file tree
Hide file tree
Showing 20 changed files with 935 additions and 229 deletions.
21 changes: 21 additions & 0 deletions .arduino-ci.yml
@@ -0,0 +1,21 @@
platforms:
zero:
board: arduino:samd:arduino_zero_native
package: arduino:samd
gcc:
features:
defines:
- __SAMD21G18A__
- ARDUINO_SAMD_ZERO
- __COMPILING_AVR_LIBC__
- SPCR
- DORD
warnings:
flags:

unittest:
platforms:
# - uno
# - due
# - zero
- leonardo
18 changes: 18 additions & 0 deletions .gitignore
@@ -1,3 +1,21 @@
/.bundle/
/.yardoc
Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
vendor
*.gem

# rspec failure tracking
.rspec_status

# C++ stuff
*.bin
*.bin.dSYM

# Object files
*.o

Expand Down
25 changes: 25 additions & 0 deletions .travis.yml
@@ -0,0 +1,25 @@
sudo: false
language: ruby

os:
- linux
- osx

env:
- BADGE=linux
- BADGE=osx

# hack to get some OS-specific badges
matrix:
exclude:
- os: linux
env: BADGE=osx
- os: osx
env: BADGE=linux

#before_install: gem install bundler -v 1.15.4
script:
- g++ -v
- bundle install
- bundle exec arduino_ci_remote.rb

2 changes: 2 additions & 0 deletions Gemfile
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'arduino_ci'
44 changes: 35 additions & 9 deletions PubNubDefs.h
Expand Up @@ -20,6 +20,7 @@
#define DBGprintln(x...)
#endif


/* Under some board support libraries, like ESP8266,
the (de-facto) standard library functions are missing.
To use Pubnub library with those boards, you need to
Expand All @@ -34,7 +35,7 @@ inline size_t strspn(const char* cs, const char* ct)
for (p = ct; *p && *p != *cs; ++p) {
continue;
}
if (*p != '\0') {
if (*p == '\0') {
break;
}
}
Expand Down Expand Up @@ -118,8 +119,8 @@ class PubSubClient : public PubNub_BASE_CLIENT {
public:
PubSubClient()
: PubNub_BASE_CLIENT()
, json_enabled(false)
, d_avail(0)
, json_enabled(false)
{
strcpy(timetoken, "0");
}
Expand Down Expand Up @@ -154,6 +155,7 @@ class PubSubClient : public PubNub_BASE_CLIENT {
int read(uint8_t* buf, size_t size)
{
int len = PubNub_BASE_CLIENT::read(buf, size);

if (d_avail > len) {
if (len > 0) {
d_avail -= len;
Expand Down Expand Up @@ -254,6 +256,7 @@ class PubNub {
d_auth = 0;
d_last_http_status_code_class = http_scc_unknown;
set_port(http_port);
return true;
}

/**
Expand Down Expand Up @@ -406,6 +409,12 @@ class PubNub {
return d_last_http_status_code_class;
}

#if defined(PUBNUB_UNIT_TEST)
inline PubNonSubClient& publishClient() { return publish_client; }
inline PubNonSubClient& historyClient() { return history_client; };
inline PubSubClient& subscribeClient() { return subscribe_client; }
#endif /* PUBNUB_UNIT_TEST */

private:
enum PubNub_BH {
PubNub_BH_OK,
Expand Down Expand Up @@ -437,7 +446,7 @@ class PubNub {

#if defined(__AVR)
#include <avr/pgmspace.h>
#else
#elif !defined(strncasecmp_P) || defined(PUBNUB_DEFINE_STRSPN_AND_STRNCASECMP)
#define strncasecmp_P(a, b, c) strncasecmp(a, b, c)
#endif

Expand Down Expand Up @@ -691,6 +700,7 @@ inline PubNonSubClient* PubNub::publish(const char* channel,
}
return 0;
}
return 0;
}


Expand Down Expand Up @@ -778,6 +788,7 @@ inline PubSubClient* PubNub::subscribe(const char* channel, int timeout)
}
return 0;
}
return 0;
}


Expand Down Expand Up @@ -820,6 +831,7 @@ inline PubNonSubClient* PubNub::history(const char* channel, int limit, int time
}
return 0;
}
return 0;
}

/** A helper that "cracks" the messages from an array of them.
Expand Down Expand Up @@ -916,8 +928,10 @@ class MessageCracker {
if (0 == d_bracket_level) {
d_state = done;
}
else if (--d_bracket_level == 0) {
d_state = ground_zero;
else {
if (--d_bracket_level == 0) {
d_state = ground_zero;
}
msg.concat(c);
}
break;
Expand All @@ -926,6 +940,10 @@ class MessageCracker {
break;
}
break;
case malformed:
case done:
default:
break;
}
}

Expand Down Expand Up @@ -962,7 +980,7 @@ class SubscribeCracker {
}

/** Low-level interface, handles one incoming/response character
at a time. To see if a message has be "cracked out" of the
at a time. To see if a message has been "cracked out" of the
response, use `message_complete()`.
*/
void handle(char c, String& msg)
Expand All @@ -984,6 +1002,10 @@ class SubscribeCracker {
break;
}
break;
case malformed:
case done:
default:
break;
}
}

Expand Down Expand Up @@ -1206,6 +1228,9 @@ class PublishCracker {
d_state = done;
}
break;
case done:
default:
break;
}
}

Expand Down Expand Up @@ -1284,6 +1309,7 @@ class PublishCracker {
case done:
return "Done.";
}
return "!?!";
}
enum { MAX_DESCRIPTION = 50, MAX_TIMESTAMP = 20 };

Expand Down Expand Up @@ -1371,9 +1397,9 @@ inline enum PubNub::PubNub_BH PubNub::_request_bh(PubNub_BASE_CLIENT& client,
* Transfer-Encoding: chunked (or \r\n) */
const static char chunked_str[] = "Transfer-Encoding: chunked\r\n";

char line[sizeof(chunked_str)]; /* Not NUL-terminated! */
int linelen = 0;
char ch = 0;
char line[sizeof(chunked_str)]; /* Not NUL-terminated! */
unsigned linelen = 0;
char ch = 0;
do {
WAIT();
ch = client.read();
Expand Down
22 changes: 22 additions & 0 deletions appveyor.yml
@@ -0,0 +1,22 @@
install:
- set PATH=C:\Ruby22\bin;C:\cygwin\bin;C:\cygwin64\bin;%PATH%
- bundle install
- '%CYG_ROOT%\setup-%CYG_ARCH%.exe -qnNdO -R %CYG_ROOT% -s http://cygwin.mirror.constant.com -l %CYG_ROOT%/var/cache/setup -P autoconf -P automake -P bison -P libgmp-devel -P gcc-core -P gcc-g++ -P mingw-runtime -P mingw-binutils -P mingw-gcc-core -P mingw-gcc-g++ -P mingw-pthreads -P mingw-w32api -P libtool -P make -P gettext-devel -P gettext -P intltool -P libiconv -P pkg-config -P git -P wget -P curl'

environment:
matrix:
- CYG_ARCH: x86_64
CYG_ROOT: C:/cygwin64

build: off

before_test:
- ruby -v
- gem -v
- bundle -v
- g++ -v

test_script:
# https://help.appveyor.com/discussions/problems/5170-progresspreference-not-works-always-shown-preparing-modules-for-first-use-in-stderr
- ps: $ProgressPreference = "SilentlyContinue"
- bundle exec arduino_ci_remote.rb
15 changes: 15 additions & 0 deletions examples/AdafruitFeatherM0WINC1500/.arduino-ci.yml
@@ -0,0 +1,15 @@
compile:
# Choosing to run compilation tests on different Arduino platforms
platforms:
- uno
- due
# - zero
# - leonardo
- m4
# - esp32
# - esp8266
- mega2560

# Declaring Dependent Arduino Libraries (to be installed via the Arduino Library Manager)
libraries:
- "WiFi101"
11 changes: 11 additions & 0 deletions examples/PubNubDemo/.arduino-ci.yml
@@ -0,0 +1,11 @@
compile:
# Choosing to run compilation tests on different Arduino platforms
platforms:
- uno
- due
# - zero
- leonardo
- m4
- esp32
# - esp8266
- mega2560
8 changes: 4 additions & 4 deletions examples/PubNubDemo/PubNubDemo.ino
Expand Up @@ -80,15 +80,15 @@ void loop()
Serial.print("Outcome: ");
Serial.print(cheez.outcome());
Serial.print(' ');
Serial.println(crack.to_str(cheez.outcome()));
Serial.println(cheez.to_str(cheez.outcome()));
Serial.print("description: ");
Serial.println(cheez.description());
Serial.print("timestamp: ");
Serial.println(cheez.timestamp());
Serial.print("state: ");
Serial.print(cheez.state());
Serial.print(' ');
Serial.println(crack.to_str(cheez.state()));
Serial.println(cheez.to_str(cheez.state()));

client->stop();
Serial.println();
Expand All @@ -102,7 +102,7 @@ void loop()
return;
}
String msg;
SubscribeCracker ritz(sclient);
SubscribeCracker ritz(subclient);
while (!ritz.finished()) {
ritz.get(msg);
if (msg.length() > 0) {
Expand All @@ -120,7 +120,7 @@ void loop()
delay(1000);
return;
}
SubscribeCracker tuc(hisclient);
HistoryCracker tuc(hisclient);
while (!tuc.finished()) {
tuc.get(msg);
if (msg.length() > 0) {
Expand Down

0 comments on commit a1c8e13

Please sign in to comment.