Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added backwards compatibility hopefully

  • Loading branch information...
commit 3d9629362a9377426b934297b0010a44264520d8 1 parent 931ea4f
@bmcdorman bmcdorman authored
View
53 cbcui/src/Serial/SerialServer.cpp
@@ -93,6 +93,7 @@ bool SerialServer::sendCommand(quint16 command, const QByteArray& data)
void SerialServer::processTransfer(QByteArray& header)
{
QDataStream headerStream(&header, QIODevice::ReadOnly);
+ bool old = false;
quint16 startWord;
quint16 packetCount;
@@ -100,7 +101,8 @@ void SerialServer::processTransfer(QByteArray& header)
headerStream >> startWord;
headerStream >> packetCount;
- headerStream >> command;
+ if(headerStream.atEnd()) old = true;
+ else headerStream >> command;
if(startWord != SERIAL_START) return;
@@ -116,7 +118,7 @@ void SerialServer::processTransfer(QByteArray& header)
compressedData.clear();
compressedData.squeeze();
- processData(command, data);
+ if(!old) processData(command, data); else processDataOld(data);
}
void SerialServer::processData(quint16 command, QByteArray& data)
@@ -150,6 +152,53 @@ void SerialServer::processData(quint16 command, QByteArray& data)
}
}
+void SerialServer::processDataOld(QByteArray& data)
+{
+
+ qWarning() << "RECV OLD" << data;
+
+ QDataStream dataStream(&data, QIODevice::ReadOnly);
+
+ QString fileName;
+ QByteArray fileData;
+
+ dataStream >> fileName;
+ dataStream >> fileData;
+
+ if(fileName.isEmpty()) return;
+
+ QFileInfo fileInfo(fileName);
+
+ QString projectPath = createProject(fileInfo.baseName());
+ writeFile(projectPath + "/" + fileName, fileData);
+
+ QString mainFilePath = projectPath + "/" + fileName;
+
+ while(dataStream.status() == QDataStream::Ok) {
+ fileName.clear();
+ fileData.clear();
+
+ dataStream >> fileName;
+ dataStream >> fileData;
+
+ if(!fileName.isEmpty()) {
+ writeFile(projectPath + "/" + fileName, fileData);
+ }
+ }
+
+ emit downloadFinished(mainFilePath);
+}
+
+QString SerialServer::createProject(const QString& projectName)
+{
+ const QString& projectPath = "/mnt/user/code/" + projectName;
+
+ system(("rm -rf \"" + projectPath + "\"").toLocal8Bit());
+ system(("mkdir -p \"" + projectPath + "\"").toLocal8Bit());
+
+ return projectPath;
+}
+
void SerialServer::writeFile(QString fileName, QByteArray& fileData)
{
QFile fout(fileName);
View
2  cbcui/src/Serial/SerialServer.h
@@ -108,6 +108,8 @@ private slots:
bool readPacket(QByteArray *packetData);
void processTransfer(QByteArray& header);
+ void processDataOld(QByteArray& data);
+ QString createProject(const QString& projectName);
void processData(quint16 command, QByteArray& data);
void writeFile(QString fileName, QByteArray& fileData);
void sendOk();
Please sign in to comment.
Something went wrong with that request. Please try again.