QXRD  0.11.16
qxrddetectorpilatusremote.cpp
Go to the documentation of this file.
2 #include "qxrddebug.h"
3 #include <QCryptographicHash>
4 
6  : QcepObject("pilatusRemote", owner),
8 {
9  printMessage("Constructed Pilatus Remote Object");
10 
11  connect(&m_Process, &QProcess::readyRead, this, &QxrdDetectorPilatusRemote::onReadyRead);
12 }
13 
15 {
16  printMessage(tr("Connect to %1").arg(sshCmd));
17 
18  m_Process.setProcessChannelMode(QProcess::MergedChannels);
19  m_Process.start(sshCmd);
20 }
21 
23 {
24  printMessage(tr("Exceute %1").arg(cmd));
25 
26  m_Process.write(qPrintable(cmd+"\n"));
27 }
28 
30 {
31  printMessage(tr("Remote On ready read (%1 bytes available)").arg(m_Process.bytesAvailable()));
32 
33  m_Buffer.append(m_Process.readAll());
34 
35  while (1) {
36  if (m_FileTransferSize > 0) { // Doing a file transfer
37  if (m_Buffer.count() >= m_FileTransferSize) {
39 
40  QByteArray hash = QCryptographicHash::hash(m_TransferredFile, QCryptographicHash::Md5);
41 
42  printMessage(tr("%1 byte file transferred, md5sum %2")
43  .arg(m_FileTransferSize)
44  .arg(QString(hash.toHex())));
45 
46  m_Buffer.remove(0, m_FileTransferSize);
47 
49  } else {
50  return;
51  }
52  } else {
53  int ind = m_Buffer.indexOf('\n');
54 
55  if (ind >= 0) {
56  QString line = m_Buffer.left(ind); // Don't include newline
57  m_Buffer.remove(0, ind+1);
58 
59  if (qcepDebug(DEBUG_PILATUS)) {
60  printMessage(tr("(%1) : \"%2\"").arg(line.count()).arg(QString(line)));
61  }
62 
63  interpretLine(line);
64  } else { // No new lines when expected
65  return;
66  }
67  }
68  }
69 }
70 
72 {
73  printMessage(tr("QxrdDetectorPilatusRemote::interpretLine(\"%1\")").arg(line));
74 
75  if (line.startsWith("transfer:")) {
76  QStringList fields = line.split(QRegExp("\\s+"));
77 
78  printMessage(tr("transfer: %1 args").arg(fields.count()));
79 
80  foreach(QString f, fields) {
81  printMessage(tr("Arg:%1").arg(f));
82  }
83 
84  m_FileTransferSize = fields.value(4).toInt();
85 
86  printMessage(tr("Transfer %1 bytes").arg(m_FileTransferSize));
87  }
88 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
QxrdDetectorPilatusRemote(QcepObject *owner)
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime()) const
Definition: qcepobject.cpp:84