Skip to content

Commit a1c8e13

Browse files
sveljkovveljko
authored andcommitted
Support Arduino CI (#31)
Also fix a few minor bugs.
1 parent 2c82ad8 commit a1c8e13

File tree

20 files changed

+935
-229
lines changed

20 files changed

+935
-229
lines changed

.arduino-ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
platforms:
2+
zero:
3+
board: arduino:samd:arduino_zero_native
4+
package: arduino:samd
5+
gcc:
6+
features:
7+
defines:
8+
- __SAMD21G18A__
9+
- ARDUINO_SAMD_ZERO
10+
- __COMPILING_AVR_LIBC__
11+
- SPCR
12+
- DORD
13+
warnings:
14+
flags:
15+
16+
unittest:
17+
platforms:
18+
# - uno
19+
# - due
20+
# - zero
21+
- leonardo

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/.bundle/
2+
/.yardoc
3+
Gemfile.lock
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
vendor
10+
*.gem
11+
12+
# rspec failure tracking
13+
.rspec_status
14+
15+
# C++ stuff
16+
*.bin
17+
*.bin.dSYM
18+
119
# Object files
220
*.o
321

.travis.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
sudo: false
2+
language: ruby
3+
4+
os:
5+
- linux
6+
- osx
7+
8+
env:
9+
- BADGE=linux
10+
- BADGE=osx
11+
12+
# hack to get some OS-specific badges
13+
matrix:
14+
exclude:
15+
- os: linux
16+
env: BADGE=osx
17+
- os: osx
18+
env: BADGE=linux
19+
20+
#before_install: gem install bundler -v 1.15.4
21+
script:
22+
- g++ -v
23+
- bundle install
24+
- bundle exec arduino_ci_remote.rb
25+

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source 'https://rubygems.org'
2+
gem 'arduino_ci'

PubNubDefs.h

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define DBGprintln(x...)
2121
#endif
2222

23+
2324
/* Under some board support libraries, like ESP8266,
2425
the (de-facto) standard library functions are missing.
2526
To use Pubnub library with those boards, you need to
@@ -34,7 +35,7 @@ inline size_t strspn(const char* cs, const char* ct)
3435
for (p = ct; *p && *p != *cs; ++p) {
3536
continue;
3637
}
37-
if (*p != '\0') {
38+
if (*p == '\0') {
3839
break;
3940
}
4041
}
@@ -118,8 +119,8 @@ class PubSubClient : public PubNub_BASE_CLIENT {
118119
public:
119120
PubSubClient()
120121
: PubNub_BASE_CLIENT()
121-
, json_enabled(false)
122122
, d_avail(0)
123+
, json_enabled(false)
123124
{
124125
strcpy(timetoken, "0");
125126
}
@@ -154,6 +155,7 @@ class PubSubClient : public PubNub_BASE_CLIENT {
154155
int read(uint8_t* buf, size_t size)
155156
{
156157
int len = PubNub_BASE_CLIENT::read(buf, size);
158+
157159
if (d_avail > len) {
158160
if (len > 0) {
159161
d_avail -= len;
@@ -254,6 +256,7 @@ class PubNub {
254256
d_auth = 0;
255257
d_last_http_status_code_class = http_scc_unknown;
256258
set_port(http_port);
259+
return true;
257260
}
258261

259262
/**
@@ -406,6 +409,12 @@ class PubNub {
406409
return d_last_http_status_code_class;
407410
}
408411

412+
#if defined(PUBNUB_UNIT_TEST)
413+
inline PubNonSubClient& publishClient() { return publish_client; }
414+
inline PubNonSubClient& historyClient() { return history_client; };
415+
inline PubSubClient& subscribeClient() { return subscribe_client; }
416+
#endif /* PUBNUB_UNIT_TEST */
417+
409418
private:
410419
enum PubNub_BH {
411420
PubNub_BH_OK,
@@ -437,7 +446,7 @@ class PubNub {
437446

438447
#if defined(__AVR)
439448
#include <avr/pgmspace.h>
440-
#else
449+
#elif !defined(strncasecmp_P) || defined(PUBNUB_DEFINE_STRSPN_AND_STRNCASECMP)
441450
#define strncasecmp_P(a, b, c) strncasecmp(a, b, c)
442451
#endif
443452

@@ -691,6 +700,7 @@ inline PubNonSubClient* PubNub::publish(const char* channel,
691700
}
692701
return 0;
693702
}
703+
return 0;
694704
}
695705

696706

@@ -778,6 +788,7 @@ inline PubSubClient* PubNub::subscribe(const char* channel, int timeout)
778788
}
779789
return 0;
780790
}
791+
return 0;
781792
}
782793

783794

@@ -820,6 +831,7 @@ inline PubNonSubClient* PubNub::history(const char* channel, int limit, int time
820831
}
821832
return 0;
822833
}
834+
return 0;
823835
}
824836

825837
/** A helper that "cracks" the messages from an array of them.
@@ -916,8 +928,10 @@ class MessageCracker {
916928
if (0 == d_bracket_level) {
917929
d_state = done;
918930
}
919-
else if (--d_bracket_level == 0) {
920-
d_state = ground_zero;
931+
else {
932+
if (--d_bracket_level == 0) {
933+
d_state = ground_zero;
934+
}
921935
msg.concat(c);
922936
}
923937
break;
@@ -926,6 +940,10 @@ class MessageCracker {
926940
break;
927941
}
928942
break;
943+
case malformed:
944+
case done:
945+
default:
946+
break;
929947
}
930948
}
931949

@@ -962,7 +980,7 @@ class SubscribeCracker {
962980
}
963981

964982
/** Low-level interface, handles one incoming/response character
965-
at a time. To see if a message has be "cracked out" of the
983+
at a time. To see if a message has been "cracked out" of the
966984
response, use `message_complete()`.
967985
*/
968986
void handle(char c, String& msg)
@@ -984,6 +1002,10 @@ class SubscribeCracker {
9841002
break;
9851003
}
9861004
break;
1005+
case malformed:
1006+
case done:
1007+
default:
1008+
break;
9871009
}
9881010
}
9891011

@@ -1206,6 +1228,9 @@ class PublishCracker {
12061228
d_state = done;
12071229
}
12081230
break;
1231+
case done:
1232+
default:
1233+
break;
12091234
}
12101235
}
12111236

@@ -1284,6 +1309,7 @@ class PublishCracker {
12841309
case done:
12851310
return "Done.";
12861311
}
1312+
return "!?!";
12871313
}
12881314
enum { MAX_DESCRIPTION = 50, MAX_TIMESTAMP = 20 };
12891315

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

1374-
char line[sizeof(chunked_str)]; /* Not NUL-terminated! */
1375-
int linelen = 0;
1376-
char ch = 0;
1400+
char line[sizeof(chunked_str)]; /* Not NUL-terminated! */
1401+
unsigned linelen = 0;
1402+
char ch = 0;
13771403
do {
13781404
WAIT();
13791405
ch = client.read();

appveyor.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
install:
2+
- set PATH=C:\Ruby22\bin;C:\cygwin\bin;C:\cygwin64\bin;%PATH%
3+
- bundle install
4+
- '%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'
5+
6+
environment:
7+
matrix:
8+
- CYG_ARCH: x86_64
9+
CYG_ROOT: C:/cygwin64
10+
11+
build: off
12+
13+
before_test:
14+
- ruby -v
15+
- gem -v
16+
- bundle -v
17+
- g++ -v
18+
19+
test_script:
20+
# https://help.appveyor.com/discussions/problems/5170-progresspreference-not-works-always-shown-preparing-modules-for-first-use-in-stderr
21+
- ps: $ProgressPreference = "SilentlyContinue"
22+
- bundle exec arduino_ci_remote.rb
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
compile:
2+
# Choosing to run compilation tests on different Arduino platforms
3+
platforms:
4+
- uno
5+
- due
6+
# - zero
7+
# - leonardo
8+
- m4
9+
# - esp32
10+
# - esp8266
11+
- mega2560
12+
13+
# Declaring Dependent Arduino Libraries (to be installed via the Arduino Library Manager)
14+
libraries:
15+
- "WiFi101"

examples/PubNubDemo/.arduino-ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
compile:
2+
# Choosing to run compilation tests on different Arduino platforms
3+
platforms:
4+
- uno
5+
- due
6+
# - zero
7+
- leonardo
8+
- m4
9+
- esp32
10+
# - esp8266
11+
- mega2560

examples/PubNubDemo/PubNubDemo.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ void loop()
8080
Serial.print("Outcome: ");
8181
Serial.print(cheez.outcome());
8282
Serial.print(' ');
83-
Serial.println(crack.to_str(cheez.outcome()));
83+
Serial.println(cheez.to_str(cheez.outcome()));
8484
Serial.print("description: ");
8585
Serial.println(cheez.description());
8686
Serial.print("timestamp: ");
8787
Serial.println(cheez.timestamp());
8888
Serial.print("state: ");
8989
Serial.print(cheez.state());
9090
Serial.print(' ');
91-
Serial.println(crack.to_str(cheez.state()));
91+
Serial.println(cheez.to_str(cheez.state()));
9292

9393
client->stop();
9494
Serial.println();
@@ -102,7 +102,7 @@ void loop()
102102
return;
103103
}
104104
String msg;
105-
SubscribeCracker ritz(sclient);
105+
SubscribeCracker ritz(subclient);
106106
while (!ritz.finished()) {
107107
ritz.get(msg);
108108
if (msg.length() > 0) {
@@ -120,7 +120,7 @@ void loop()
120120
delay(1000);
121121
return;
122122
}
123-
SubscribeCracker tuc(hisclient);
123+
HistoryCracker tuc(hisclient);
124124
while (!tuc.finished()) {
125125
tuc.get(msg);
126126
if (msg.length() > 0) {

0 commit comments

Comments
 (0)