Skylive Message parser is coming...

parent 8be07439
......@@ -45,18 +45,115 @@ void SkyliveProtocol::startPlugin()
SM_TCPCLIENT = HOME;
std::cout << "SkyliveProtocol initialized in thread " << thread() << std::endl;
registerHandler((QString)"connectTelescopes", &SkyliveProtocol::handle_connect);
QTimer *parsetimer = new QTimer();
QObject::connect(parsetimer, SIGNAL(timeout()), this, SLOT(processPackets()));
parsetimer->start();
}
void SkyliveProtocol::processPackets()
{
if(!protoQueue.isEmpty())
{
SKProtoMsg pkt;
pkt = protoQueue.dequeue();
QString cmd(pkt.cmd);
std::cout << "Packages in Queue: " << cmd.toStdString() <<std::endl;
}
}
void SkyliveProtocol::readFromNetwork()
{
char buffer[1024];
int ba = tcpSocket->bytesAvailable();
std::cout << "Bytes: " << ba << std::endl;
char c;
int readidx=0;
while(tcpSocket->bytesAvailable())
{
tcpSocket->read(buffer, 1024);
std::cout << "Received From Skylive Server: " << buffer << std::endl;
if(readidx > MAX_PACKETREAD)
return;
tcpSocket->read(&c, 1);
switch(SM_TCPCLIENT)
{
case HOME:
break;
case CONNECTED:
switch(c)
{
case PROTO_START:
{
SKProtoMsg protoMsg;
SM_TCPCLIENT=COMMAND;
break;
}
default:
break;
}
break;
case COMMAND:
protoMsg.computed_crc+=c;
switch(c)
{
case CMD_END:
SM_TCPCLIENT=PARAMS;
break;
case PROTO_START:
{
SKProtoMsg protoMsg;
break;
}
case PARAM_END:
case PROTO_END:
SM_TCPCLIENT=CONNECTED;
break;
default:
protoMsg.cmd.append(c);
}
break;
case PARAMS:
protoMsg.computed_crc+=c;
switch(c)
{
case PARAM_END:
SM_TCPCLIENT=CRC;
break;
case PROTO_START:
{
SKProtoMsg protoMsg;
SM_TCPCLIENT=COMMAND;
break;
}
case CMD_END:
case PROTO_END:
SM_TCPCLIENT=CONNECTED;
break;
default:
protoMsg.params.append(c);
}
break;
case CRC:
switch(c)
{
case PROTO_START:
{
SKProtoMsg protoMsg;
SM_TCPCLIENT=COMMAND;
break;
}
case PROTO_END:
protoQueue.enqueue(protoMsg);
case CMD_END:
case PARAM_END:
SM_TCPCLIENT=CONNECTED;
break;
default:
protoMsg.crc.append(c);
}
break;
}
readidx++;
}
}
......@@ -65,12 +162,18 @@ void SkyliveProtocol::handle_connect(SKMessage::SKMessage msg)
authenticated=false;
std::cout << "SkyliveProtocol connect: " << msg.handle.toStdString() << std::endl;
tcpSocket = new QTcpSocket(this);
connect(tcpSocket, SIGNAL(connected()), this, SLOT(clientConnected()));
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readFromNetwork()));
connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(displayError(QAbstractSocket::SocketError)));
tcpSocket->abort();
tcpSocket->connectToHost(SERVERHOST, SERVERPORT);
}
void SkyliveProtocol::clientConnected()
{
SM_TCPCLIENT = CONNECTED;
}
void SkyliveProtocol::receiveMessage(SKMessage::SKMessage msg)
{
std::cout << "SkyliveProtocol msg received: " << msg.handle.toStdString() << std::endl;
......@@ -108,5 +211,6 @@ void SkyliveProtocol::displayError(QAbstractSocket::SocketError socketError)
default:
std::cout << "networ error: " << std::endl;
}
SM_TCPCLIENT = HOME;
}
......@@ -42,18 +42,21 @@
#include <QTcpSocket>
//#include <QNetworkSession>
#include <QByteArray>
#include <QQueue>
#include "pluginsinterfaces.h"
#include "ipcmsg.h"
#define SERVERHOST "www.skylive.name"
#define SERVERPORT 8080
#define MAX_PACKETREAD 2048
struct SKProtoMsg
{
QByteArray cmd;
QByteArray params;
QByteArray crc;
int computed_crc;
};
enum _SM_TCPCLIENT
......@@ -66,11 +69,11 @@ enum _SM_TCPCLIENT
}; //SM_TCPCLIENT = HOME;
#define PROTO_START "["
#define PROTO_END "]"
#define CMD_END ">"
#define PARAM_SEPARATOR "|"
#define PARAM_END ":"
#define PROTO_START 0x5b // [
#define PROTO_END 0x5d // ]
#define CMD_END 0x3e // >
#define PARAM_SEPARATOR 0x7c // |
#define PARAM_END 0x3a // :
class SkyliveProtocol;
......@@ -88,6 +91,8 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface
//QNetworkSession *networkSession;
bool authenticated;
_SM_TCPCLIENT SM_TCPCLIENT;
SKProtoMsg protoMsg;
QQueue<SKProtoMsg> protoQueue;
public:
......@@ -98,10 +103,14 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface
private slots:
void sessionOpened();
void readFromNetwork();
void clientConnected();
void displayError(QAbstractSocket::SocketError);
public slots:
void receiveMessage(SKMessage::SKMessage msg);
private slots:
void processPackets();
signals:
void putMessage(SKMessage::SKMessage msg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment