Added support to send Strings

This commit is contained in:
Kristian Lauszus 2012-08-04 20:57:37 +02:00
parent 6dc2b6e09d
commit 0cfe91a044
2 changed files with 17 additions and 0 deletions

15
SPP.cpp
View file

@ -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);

2
SPP.h
View file

@ -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