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.
Dependents: AutonomousDAQ AutonomousDAQ
SnCommPeripheral.cpp
- Committer:
- uci1
- Date:
- 2013-09-05
- Revision:
- 3:a7f72492f19e
- Parent:
- 0:26c9189e5924
- Child:
- 4:8328c2972290
File content as of revision 3:a7f72492f19e:
#include "SnCommPeripheral.h"
#include <string>
#include "SnHeaderFrame.h"
bool SnCommPeripheral::IsTimedOut(const uint32_t timeout_clock) const {
if (timeout_clock==0) {
// for not obeying timeout option
return false;
} else {
const uint32_t ct = time(0);
if ( (ct==0) ||
(fabs(static_cast<double>(timeout_clock-ct))>kSecsPerDay) ) {
// clock problems!
// timeout now. hope the clock problems
// get fixed in the next comm window
return true;
} else {
return (ct>timeout_clock);
}
}
}
bool SnCommPeripheral::SendString(const char* str,
const uint32_t timeout) {
#ifdef DEBUG
printf("SnCommPeripheral::SendString %s\r\n",str);
#endif
const size_t rlen = strlen(str);
const size_t slen = rlen > kMaxStrLen ? kMaxStrLen : rlen;
const int msiz = slen+SnHeaderFrame::SizeOf();
char* const ts = new char[msiz];
char* t = ts;
SnHeaderFrame::WriteTo(t, SnHeaderFrame::kStringCode, slen);
strncpy(t, str, slen);
int32_t mlen = SendAll(ts, msiz, timeout);
delete[] ts;
mlen += FinishSending(timeout);
return (msiz==mlen);
}
void SnCommPeripheral::CapitalizeInPlace(std::string::iterator s,
const std::string::const_iterator send) {
static const char upd = 'a' - 'A'; // a>A
for (; s!=send; ++s) {
if ( ((*s)>='a') && ((*s)<='z') ) {
(*s) -= upd;
}
}
}