Simplified print commands

This commit is contained in:
Kristian Sloth Lauszus 2013-04-08 00:25:01 +02:00
parent 35ce9c7ab3
commit b88de72826

56
SPP.cpp
View file

@ -726,61 +726,17 @@ uint8_t SPP::calcFcs(uint8_t *data) {
/* Serial commands */ /* Serial commands */
void SPP::print(const String &str) { void SPP::print(const String &str) {
if (!connected) uint8_t length = str.length(); // Get the length of the string
return; uint8_t buf[length];
uint8_t stringLength = str.length(); // This will be used to store the characters that still needs to be sent
uint8_t length; // This is the length of the string we are sending
uint8_t offset = 0; // This is used to keep track of where we are in the string
l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress; // RFCOMM Address for(uint8_t i = 0; i < length; i++)
l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control buf[i] = str[i];
while (stringLength) { // We will run this while loop until this variable is 0 print(buf,length);
if (stringLength > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger that the outgoing buffer
length = sizeof (l2capoutbuf) - 4;
else
length = stringLength;
l2capoutbuf[2] = length << 1 | 1; // Length
uint8_t i = 0;
for (; i < length; i++)
l2capoutbuf[i + 3] = str[i + offset];
l2capoutbuf[i + 3] = calcFcs(l2capoutbuf); // Calculate checksum
RFCOMM_Command(l2capoutbuf, length + 4);
stringLength -= length;
offset += length; // Increment the offset
}
} }
void SPP::print(const char* str) { void SPP::print(const char* str) {
if (!connected) print((uint8_t*) str, strlen(str));
return;
uint8_t stringLength = strlen(str); // This will be used to store the characters that still needs to be sent
uint8_t length; // This is the length of the string we are sending
uint8_t offset = 0; // This is used to keep track of where we are in the string
l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress; // RFCOMM Address
l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control
while (stringLength) { // We will run this while loop until this variable is 0
if (stringLength > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger that the outgoing buffer
length = sizeof (l2capoutbuf) - 4;
else
length = stringLength;
l2capoutbuf[2] = length << 1 | 1; // Length
uint8_t i = 0;
for (; i < length; i++)
l2capoutbuf[i + 3] = str[i + offset];
l2capoutbuf[i + 3] = calcFcs(l2capoutbuf); // Calculate checksum
RFCOMM_Command(l2capoutbuf, length + 4);
stringLength -= length;
offset += length; // Increment the offset
}
} }
void SPP::print(uint8_t* array, uint8_t stringLength) { void SPP::print(uint8_t* array, uint8_t stringLength) {