Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of M2XStreamClient by
Revision 8:bd39886d72fb, committed 2014-01-03
- Comitter:
- citrusbyte
- Date:
- Fri Jan 03 11:55:17 2014 +0000
- Parent:
- 7:e64d9e1a800a
- Child:
- 9:48b088e317aa
- Commit message:
- Update mbed library
Changed in this revision
| M2XStreamClient.cpp | Show annotated file Show diff for this revision Revisions of this file |
| M2XStreamClient.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/M2XStreamClient.cpp Thu Nov 14 15:14:54 2013 +0000
+++ b/M2XStreamClient.cpp Fri Jan 03 11:55:17 2014 +0000
@@ -6,15 +6,31 @@
#include "LocationParseFunctions.h"
const char* M2XStreamClient::kDefaultM2XHost = "api-m2x.att.com";
-const char* kUserAgentLine = "User-Agent: M2X Arduino Client/0.1";
int print_encoded_string(Print* print, const char* str);
+int tolower(int ch);
+
+#if defined(ARDUINO_PLATFORM) || defined(MBED_PLATFORM)
+int tolower(int ch)
+{
+ // Arduino and mbed use ASCII table, so we can simplify the implementation
+ if ((ch >= 'A') && (ch <= 'Z')) {
+ return (ch + 32);
+ }
+ return ch;
+}
+#else
+// For other platform, we use libc's tolower by default
+#include <ctype.h>
+#endif
M2XStreamClient::M2XStreamClient(Client* client,
const char* key,
+ int case_insensitive,
const char* host,
int port) : _client(client),
_key(key),
+ _case_insensitive(case_insensitive),
_host(host),
_port(port),
_null_print() {
@@ -123,7 +139,7 @@
}
void M2XStreamClient::writeHttpHeader(int contentLength) {
- _client->println(kUserAgentLine);
+ _client->println(USER_AGENT);
_client->print("X-M2X-KEY: ");
_client->println(_key);
@@ -156,8 +172,14 @@
char c = _client->read();
DBG("%c", c);
- if ((str[currentIndex] == '*') ||
- (c == str[currentIndex])) {
+ int cmp;
+ if (_case_insensitive) {
+ cmp = tolower(c) - tolower(str[currentIndex]);
+ } else {
+ cmp = c - str[currentIndex];
+ }
+
+ if ((str[currentIndex] == '*') || (cmp == 0)) {
currentIndex++;
if (str[currentIndex] == '\0') {
return E_OK;
--- a/M2XStreamClient.h Thu Nov 14 15:14:54 2013 +0000
+++ b/M2XStreamClient.h Fri Jan 03 11:55:17 2014 +0000
@@ -7,10 +7,14 @@
#ifdef ARDUINO_PLATFORM
#include "Arduino.h"
+
+#define USER_AGENT "User-Agent: M2X Arduino Client/0.1"
#endif
#ifdef MBED_PLATFORM
#include "mbed.h"
+
+#define USER_AGENT "User-Agent: M2X Mbed Client/0.1"
#endif
#include "Client.h"
@@ -64,6 +68,7 @@
M2XStreamClient(Client* client,
const char* key,
+ int case_insensitive = 1,
const char* host = kDefaultM2XHost,
int port = kDefaultM2XPort);
@@ -138,6 +143,7 @@
private:
Client* _client;
const char* _key;
+ int _case_insensitive;
const char* _host;
int _port;
NullPrint _null_print;
