add PICli to pift
fix relative path in PIFileTransfer git-svn-id: svn://db.shs.com.ru/pip@67 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -3,10 +3,13 @@
|
||||
#include "pidatatransfer.h"
|
||||
|
||||
|
||||
using namespace PICoutManipulators;
|
||||
|
||||
class UDPFileTransfer: public PITimer {
|
||||
PIOBJECT_SUBCLASS(UDPFileTransfer, PITimer)
|
||||
public:
|
||||
UDPFileTransfer(const PIString &src_ip_port, const PIString &dst_ip_port) {
|
||||
quet_ = false;
|
||||
eth.setReadAddress(src_ip_port);
|
||||
eth.setSendAddress(dst_ip_port);
|
||||
//ft.setPacketSize(65000);
|
||||
@@ -21,7 +24,9 @@ public:
|
||||
eth.startThreadedRead();
|
||||
}
|
||||
|
||||
void startSend(const PIString &file) {
|
||||
void setQuet(bool quet) {quet_ = quet;}
|
||||
|
||||
void startSend(const PIStringList &file) {
|
||||
ft.send(file);
|
||||
}
|
||||
|
||||
@@ -29,16 +34,27 @@ public:
|
||||
|
||||
private:
|
||||
PIEthernet eth;
|
||||
bool quet_;
|
||||
|
||||
void tick(void *, int) {
|
||||
if (ft.isSending() || ft.isReceiving()) ftevent();
|
||||
if (ft.isSending() || ft.isReceiving()) {
|
||||
ftevent();
|
||||
// piCout << (int)ft.diagnostic().quality();
|
||||
}
|
||||
}
|
||||
|
||||
EVENT_HANDLER(void, ftevent) {
|
||||
PICout(PICoutManipulators::AddSpaces) << PICoutManipulators::ClearLine << ft.stateString() << PIString::readableSize(ft.diagnostic().receiveBytesPerSec()) + "/s"
|
||||
<< PIString::readableSize(ft.diagnostic().sendBytesPerSec()) + "/s"
|
||||
<< "(" << PIString::readableSize(ft.bytesFileCur()) << "/" << PIString::readableSize(ft.bytesFileAll()) << ", "
|
||||
<< PIString::readableSize(ft.bytesCur()) << "/" << PIString::readableSize(ft.bytesAll()) << ")" << PICoutManipulators::Flush;
|
||||
if (quet_) return;
|
||||
PICout(AddSpaces) << ClearLine << ft.stateString()
|
||||
<< PIString::readableSize(ft.diagnostic().receiveBytesPerSec()) + "/s"
|
||||
<< PIString::readableSize(ft.diagnostic().sendBytesPerSec()) + "/s"
|
||||
<< "(" << PIString::readableSize(ft.bytesFileCur()) << "/" << PIString::readableSize(ft.bytesFileAll()) << ", "
|
||||
<< PIString::readableSize(ft.bytesCur()) << "/" << PIString::readableSize(ft.bytesAll()) << ")"
|
||||
<< "ETA" << (ft.diagnostic().receiveBytesPerSec() > 0 ?
|
||||
PIString::fromNumber(PISystemTime::fromSeconds((ft.bytesAll() - ft.bytesCur()) /
|
||||
ft.diagnostic().receiveBytesPerSec()).toSeconds())
|
||||
: PIString("unknown"))
|
||||
<< Flush;
|
||||
}
|
||||
|
||||
EVENT_HANDLER1(void, ftsend, PIByteArray &, data) {
|
||||
@@ -51,22 +67,52 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void usage() {
|
||||
piCout << Bold << "PIP UDP file transfer";
|
||||
piCout << Cyan << "Version" << Bold << PIPVersion() << NewLine;
|
||||
piCout << Green << Bold << "Usage:" << Default << "\"pift [-hq] -r <receive_ip> -s <send_ip> [-d <work_dir>] [-p port] [<path1>] [<path2>] [<path3>] [...]\"" << NewLine;
|
||||
piCout << Green << Bold << "Details:";
|
||||
piCout << "-h " << Green << "- display this message and exit";
|
||||
piCout << "-q " << Green << "- quiet, no debug output to console";
|
||||
piCout << "-r " << Green << "- set receive ip address, must be ip address of this computer";
|
||||
piCout << "-s " << Green << "- set send ip address, address of computer which communicate with you";
|
||||
piCout << "-p " << Green << "- UDP port for transfer, by default 50005";
|
||||
piCout << "-d <work_dir> " << Green << "- directory, where place received files";
|
||||
piCout << "<path> " << Green << "- add path to send, if no path, then \"pift\" working in receive mode";
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char * argv[]) {
|
||||
if (!(argc == 3 || argc == 4)) {
|
||||
piCout << "UDP File Transfer";
|
||||
piCout << "USE: pift src_ip:port dst_ip:port [filename]";
|
||||
PICLI cli(argc, argv);
|
||||
cli.setOptionalArgumentsCount(-1);
|
||||
cli.addArgument("send", true);
|
||||
cli.addArgument("receive", true);
|
||||
cli.addArgument("dir", true);
|
||||
cli.addArgument("port", true);
|
||||
cli.addArgument("help");
|
||||
cli.addArgument("quet");
|
||||
if (!cli.hasArgument("send") || !cli.hasArgument("receive") || cli.hasArgument("help")) {
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
PIString src = cli.argumentValue("receive");
|
||||
PIString dst = cli.argumentValue("send");
|
||||
int port = -1;
|
||||
if (cli.hasArgument("port")) port = cli.argumentValue("port").toInt();
|
||||
if (port <=0) port = 50005;
|
||||
PIKbdListener kbd;
|
||||
kbd.enableExitCapture();
|
||||
PIString src = argv[1];
|
||||
PIString dst = argv[2];
|
||||
src += ":"+PIString::fromNumber(port);
|
||||
dst += ":"+PIString::fromNumber(port);
|
||||
UDPFileTransfer f(src, dst);
|
||||
if (cli.hasArgument("dir")) f.ft.setDirectory(cli.argumentValue("dir"));
|
||||
if (cli.hasArgument("quet")) f.setQuet(true);
|
||||
piCout << "work directory" << f.ft.directory().absolutePath() << ", listen on" << src << ", send to" << dst;
|
||||
if (argc == 4) {
|
||||
PIString file = argv[3];
|
||||
piCout << "send file" << file;
|
||||
f.startSend(file);
|
||||
PIStringList fls = cli.optionalArguments();
|
||||
if (fls.size() > 0) {
|
||||
piCout << "send files" << fls;
|
||||
f.startSend(fls);
|
||||
return 0;
|
||||
} else {
|
||||
piCout << "wait for receiving";
|
||||
|
||||
Reference in New Issue
Block a user