Random
This commit is contained in:
@@ -134,6 +134,19 @@ void TimeoutSerial::read(char *data, size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
int TimeoutSerial::readChar(int delay)
|
||||
{
|
||||
vector<char> result(1,'\0');
|
||||
|
||||
timeout = posix_time::seconds(delay);
|
||||
try {
|
||||
result = read(1);
|
||||
return static_cast<int>(result[0]);
|
||||
} catch (boost::system::system_error& e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<char> TimeoutSerial::read(size_t size)
|
||||
{
|
||||
vector<char> result(size,'\0');//Allocate a vector with the desired size
|
||||
|
||||
@@ -161,6 +161,7 @@ public:
|
||||
* \throws timeout_exception in case of timeout
|
||||
*/
|
||||
std::string readStringUntil(const std::string& delim="\n");
|
||||
int readChar(int delay);
|
||||
|
||||
void setRTS(bool enabled);
|
||||
void setDTR(bool enabled);
|
||||
|
||||
18
XModem.cpp
18
XModem.cpp
@@ -21,6 +21,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "XModem.h"
|
||||
#include "TimeoutSerial.h"
|
||||
#ifdef UTEST
|
||||
#include "CppUTestExt/MockSupport.h"
|
||||
#endif
|
||||
@@ -35,24 +36,17 @@ const int XModem::receiveDelay=7000;
|
||||
const int XModem::rcvRetryLimit = 10;
|
||||
|
||||
|
||||
|
||||
|
||||
XModem::XModem(int (*recvChar)(int msDelay),
|
||||
void (*sendData)(const char *data, int len))
|
||||
XModem::XModem(TimeoutSerial *serial)
|
||||
{
|
||||
this->sendData = sendData;
|
||||
this->recvChar = recvChar;
|
||||
this->serial = serial;
|
||||
this->dataHandler = NULL;
|
||||
|
||||
}
|
||||
XModem::XModem(int (*recvChar)(int msDelay),
|
||||
void (*sendData)(const char *data, int len),
|
||||
|
||||
XModem::XModem(TimeoutSerial *serial,
|
||||
bool (*dataHandler)(unsigned long number, char *buffer, int len))
|
||||
{
|
||||
this->sendData = sendData;
|
||||
this->recvChar = recvChar;
|
||||
this->serial = serial;
|
||||
this->dataHandler = dataHandler;
|
||||
|
||||
}
|
||||
|
||||
bool XModem::dataAvail(int delay)
|
||||
|
||||
8
XModem.h
8
XModem.h
@@ -41,6 +41,7 @@ class XModem {
|
||||
char buffer[133];
|
||||
//repeated block flag
|
||||
bool repeatedBlock;
|
||||
TimeoutSerial *serial;
|
||||
|
||||
int (*recvChar)(int);
|
||||
void (*sendData)(const char *data, int len);
|
||||
@@ -56,6 +57,8 @@ class XModem {
|
||||
bool receiveFrames(transfer_t transfer);
|
||||
bool sendNack(void);
|
||||
void init(void);
|
||||
void sendSerialData(const char *data, int len);
|
||||
int recvSerialChar(int);
|
||||
|
||||
bool transmitFrames(transfer_t);
|
||||
unsigned char generateChkSum(const char *buffer, int len);
|
||||
@@ -67,9 +70,8 @@ class XModem {
|
||||
static const unsigned char EOT;
|
||||
static const unsigned char CAN;
|
||||
|
||||
XModem(int (*recvChar)(int), void (*sendData)(const char *data, int len));
|
||||
XModem(int (*recvChar)(int), void (*sendData)(const char *data, int len),
|
||||
bool (*dataHandler)(unsigned long, char*, int));
|
||||
XModem(TimeoutSerial *serial);
|
||||
XModem(TimeoutSerial *serial,bool (*dataHandler)(unsigned long, char*, int));
|
||||
bool receive();
|
||||
bool transmit();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user