From 0cfe91a044e06ef05a3a9403cdef77dcc0a47004 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sat, 4 Aug 2012 20:57:37 +0200 Subject: [PATCH] Added support to send Strings --- SPP.cpp | 15 +++++++++++++++ SPP.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/SPP.cpp b/SPP.cpp index 9a6011a2..4f12f4e6 100644 --- a/SPP.cpp +++ b/SPP.cpp @@ -670,6 +670,17 @@ uint8_t SPP::calcFcs(uint8_t *data) { } /* Serial commands */ +void SPP::print(const String &str) { + l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress;; // RFCOMM Address + l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control + l2capoutbuf[2] = str.length() << 1 | 1; // Length + uint8_t i = 0; + for(; i < str.length(); i++) + l2capoutbuf[i+3] = str[i]; + l2capoutbuf[i+3] = calcFcs(l2capoutbuf); + + RFCOMM_Command(l2capoutbuf,str.length()+4); +} void SPP::print(const char* data) { l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress;; // RFCOMM Address l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control @@ -712,6 +723,10 @@ void SPP::print(const __FlashStringHelper *ifsh) { print(buf,size); } +void SPP::println(const String &str) { + str + "\r\n"; + print(str); +} void SPP::println(const char* data) { char output[strlen(data)+2]; strcpy(output,data); diff --git a/SPP.h b/SPP.h index 8b12fd5a..a6b736a1 100644 --- a/SPP.h +++ b/SPP.h @@ -106,11 +106,13 @@ public: bool connected;// Variable used to indicate if the connection is established /* Serial port profile (SPP) commands */ + void print(const String &); // Used to send strings void print(const char* data); // Used to send strings void print(uint8_t data); // Used to send single bytes void print(uint8_t* array, uint8_t length); // Used to send arrays void print(const __FlashStringHelper *); // Used to print strings stored in flash + void println(const String &); // Used to send strings void println(const char* data); // Include newline and carriage return void println(uint8_t data); // Include newline and carriage return void println(uint8_t* array, uint8_t length); // Include newline and carriage return