Add Ymodem transmit translated to boosts
This commit is contained in:
141
xymodem.h
Normal file
141
xymodem.h
Normal file
@@ -0,0 +1,141 @@
|
||||
#ifndef modem_HH
|
||||
#define modem_HH
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include "Thread.h"
|
||||
#include "TimeoutSerial.h"
|
||||
|
||||
using std::fstream;
|
||||
using std::string;
|
||||
|
||||
class __tools;
|
||||
|
||||
struct y_modem_data
|
||||
{
|
||||
y_modem_data() : first_ack(false) {}
|
||||
|
||||
bool first_ack;
|
||||
bool first_pkt;
|
||||
};
|
||||
|
||||
class Operator: public Thread< Operator >
|
||||
{
|
||||
public:
|
||||
Operator (TimeoutSerial &c);
|
||||
private:
|
||||
int Entry(); //Strting point
|
||||
|
||||
void SetupInfoBlock (string &block);
|
||||
void UpdateProgress (int = 0);
|
||||
|
||||
bool GetChar();
|
||||
bool IsChar ();
|
||||
bool IsAck ();
|
||||
bool IsSync ();
|
||||
bool IsNack ();
|
||||
bool IsCan ();
|
||||
|
||||
protected:
|
||||
void SendBlock(char *p, int size);
|
||||
void SendEot ();
|
||||
|
||||
virtual int GetBlockSize () = 0;
|
||||
virtual int SetupBlockHdr () = 0;
|
||||
virtual int SetupCheckSum (char *data, char *dest) = 0;
|
||||
virtual char GetSync () = 0;
|
||||
virtual char GetAck () = 0;
|
||||
virtual char GetCan () = 0;
|
||||
virtual char GetNack () = 0;
|
||||
virtual char GetEot () = 0;
|
||||
virtual char GetProto() = 0;
|
||||
|
||||
virtual void SetSize (int) {}
|
||||
virtual void SetMode (int) {}
|
||||
virtual int GetMode () { return 0; }
|
||||
|
||||
|
||||
public:
|
||||
void SessionStartup (const string &);
|
||||
void StartTransfert ();
|
||||
|
||||
protected:
|
||||
TimeoutSerial *com, *q;
|
||||
fstream f;
|
||||
int pkt;
|
||||
int fsize,psize;
|
||||
int count;
|
||||
string fname;
|
||||
string ibuff;
|
||||
string obuff;
|
||||
};
|
||||
|
||||
|
||||
static const int LEN_B_XMODEM = 128;
|
||||
|
||||
// bitmask
|
||||
enum {
|
||||
XMODEM1K=0x01,
|
||||
XMODEMCRC=0x02,
|
||||
};
|
||||
|
||||
class XModem : public Operator {
|
||||
public:
|
||||
XModem (TimeoutSerial &c);
|
||||
|
||||
private:
|
||||
int GetBlockSize () { return psize; }
|
||||
int SetupBlockHdr ();
|
||||
int SetupCheckSum (char *data, char *dest);
|
||||
|
||||
char GetSync ();
|
||||
char GetAck ();
|
||||
char GetNack ();
|
||||
char GetCan ();
|
||||
char GetProto();
|
||||
char GetEot ();
|
||||
int GetMode () {return xmodem_mode;}
|
||||
|
||||
void SetSize (int size);
|
||||
void SetMode (int mode) {
|
||||
xmodem_mode|=mode;
|
||||
if (mode&XMODEM1K) psize=1024;
|
||||
}
|
||||
|
||||
public:
|
||||
int xmodem_mode;
|
||||
|
||||
private:
|
||||
__tools &t;
|
||||
int psize;
|
||||
};
|
||||
|
||||
/* we don't use the standard 128 block but 1024 only
|
||||
*/
|
||||
static const int LEN_B_YMODEM = 1024;
|
||||
|
||||
class YModem : public Operator {
|
||||
public:
|
||||
YModem (TimeoutSerial &c);
|
||||
|
||||
private:
|
||||
int GetBlockSize () { return psize; }
|
||||
int SetupBlockHdr ();
|
||||
int SetupCheckSum (char *data, char *dest);
|
||||
|
||||
char GetSync ();
|
||||
char GetAck ();
|
||||
char GetNack ();
|
||||
char GetCan ();
|
||||
char GetProto();
|
||||
char GetEot ();
|
||||
|
||||
void SetSize (int size);
|
||||
|
||||
private:
|
||||
__tools &t;
|
||||
int psize;
|
||||
};
|
||||
|
||||
|
||||
#endif // modem_HH
|
||||
Reference in New Issue
Block a user