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