Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
skylivex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
astronomy
skylivex
Commits
b6ff20d0
Commit
b6ff20d0
authored
Feb 19, 2013
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Skylive Message parser is coming...
parent
8be07439
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
123 additions
and
10 deletions
+123
-10
skproto.cpp
plugins/skproto.cpp
+109
-5
skproto.h
plugins/skproto.h
+14
-5
No files found.
plugins/skproto.cpp
View file @
b6ff20d0
...
@@ -45,18 +45,115 @@ void SkyliveProtocol::startPlugin()
...
@@ -45,18 +45,115 @@ void SkyliveProtocol::startPlugin()
SM_TCPCLIENT
=
HOME
;
SM_TCPCLIENT
=
HOME
;
std
::
cout
<<
"SkyliveProtocol initialized in thread "
<<
thread
()
<<
std
::
endl
;
std
::
cout
<<
"SkyliveProtocol initialized in thread "
<<
thread
()
<<
std
::
endl
;
registerHandler
((
QString
)
"connectTelescopes"
,
&
SkyliveProtocol
::
handle_connect
);
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
()
void
SkyliveProtocol
::
readFromNetwork
()
{
{
char
buffer
[
1024
];
char
c
;
int
ba
=
tcpSocket
->
bytesAvailable
();
int
readidx
=
0
;
std
::
cout
<<
"Bytes: "
<<
ba
<<
std
::
endl
;
while
(
tcpSocket
->
bytesAvailable
())
while
(
tcpSocket
->
bytesAvailable
())
{
{
tcpSocket
->
read
(
buffer
,
1024
);
if
(
readidx
>
MAX_PACKETREAD
)
std
::
cout
<<
"Received From Skylive Server: "
<<
buffer
<<
std
::
endl
;
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)
...
@@ -65,12 +162,18 @@ void SkyliveProtocol::handle_connect(SKMessage::SKMessage msg)
authenticated
=
false
;
authenticated
=
false
;
std
::
cout
<<
"SkyliveProtocol connect: "
<<
msg
.
handle
.
toStdString
()
<<
std
::
endl
;
std
::
cout
<<
"SkyliveProtocol connect: "
<<
msg
.
handle
.
toStdString
()
<<
std
::
endl
;
tcpSocket
=
new
QTcpSocket
(
this
);
tcpSocket
=
new
QTcpSocket
(
this
);
connect
(
tcpSocket
,
SIGNAL
(
connected
()),
this
,
SLOT
(
clientConnected
()));
connect
(
tcpSocket
,
SIGNAL
(
readyRead
()),
this
,
SLOT
(
readFromNetwork
()));
connect
(
tcpSocket
,
SIGNAL
(
readyRead
()),
this
,
SLOT
(
readFromNetwork
()));
connect
(
tcpSocket
,
SIGNAL
(
error
(
QAbstractSocket
::
SocketError
)),
this
,
SLOT
(
displayError
(
QAbstractSocket
::
SocketError
)));
connect
(
tcpSocket
,
SIGNAL
(
error
(
QAbstractSocket
::
SocketError
)),
this
,
SLOT
(
displayError
(
QAbstractSocket
::
SocketError
)));
tcpSocket
->
abort
();
tcpSocket
->
abort
();
tcpSocket
->
connectToHost
(
SERVERHOST
,
SERVERPORT
);
tcpSocket
->
connectToHost
(
SERVERHOST
,
SERVERPORT
);
}
}
void
SkyliveProtocol
::
clientConnected
()
{
SM_TCPCLIENT
=
CONNECTED
;
}
void
SkyliveProtocol
::
receiveMessage
(
SKMessage
::
SKMessage
msg
)
void
SkyliveProtocol
::
receiveMessage
(
SKMessage
::
SKMessage
msg
)
{
{
std
::
cout
<<
"SkyliveProtocol msg received: "
<<
msg
.
handle
.
toStdString
()
<<
std
::
endl
;
std
::
cout
<<
"SkyliveProtocol msg received: "
<<
msg
.
handle
.
toStdString
()
<<
std
::
endl
;
...
@@ -108,5 +211,6 @@ void SkyliveProtocol::displayError(QAbstractSocket::SocketError socketError)
...
@@ -108,5 +211,6 @@ void SkyliveProtocol::displayError(QAbstractSocket::SocketError socketError)
default
:
default
:
std
::
cout
<<
"networ error: "
<<
std
::
endl
;
std
::
cout
<<
"networ error: "
<<
std
::
endl
;
}
}
SM_TCPCLIENT
=
HOME
;
}
}
plugins/skproto.h
View file @
b6ff20d0
...
@@ -42,18 +42,21 @@
...
@@ -42,18 +42,21 @@
#include <QTcpSocket>
#include <QTcpSocket>
//#include <QNetworkSession>
//#include <QNetworkSession>
#include <QByteArray>
#include <QByteArray>
#include <QQueue>
#include "pluginsinterfaces.h"
#include "pluginsinterfaces.h"
#include "ipcmsg.h"
#include "ipcmsg.h"
#define SERVERHOST "www.skylive.name"
#define SERVERHOST "www.skylive.name"
#define SERVERPORT 8080
#define SERVERPORT 8080
#define MAX_PACKETREAD 2048
struct
SKProtoMsg
struct
SKProtoMsg
{
{
QByteArray
cmd
;
QByteArray
cmd
;
QByteArray
params
;
QByteArray
params
;
QByteArray
crc
;
QByteArray
crc
;
int
computed_crc
;
};
};
enum
_SM_TCPCLIENT
enum
_SM_TCPCLIENT
...
@@ -66,11 +69,11 @@ enum _SM_TCPCLIENT
...
@@ -66,11 +69,11 @@ enum _SM_TCPCLIENT
};
//SM_TCPCLIENT = HOME;
};
//SM_TCPCLIENT = HOME;
#define PROTO_START
"["
#define PROTO_START
0x5b // [
#define PROTO_END
"]"
#define PROTO_END
0x5d // ]
#define CMD_END
">"
#define CMD_END
0x3e // >
#define PARAM_SEPARATOR
"|"
#define PARAM_SEPARATOR
0x7c // |
#define PARAM_END
":"
#define PARAM_END
0x3a // :
class
SkyliveProtocol
;
class
SkyliveProtocol
;
...
@@ -88,6 +91,8 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface
...
@@ -88,6 +91,8 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface
//QNetworkSession *networkSession;
//QNetworkSession *networkSession;
bool
authenticated
;
bool
authenticated
;
_SM_TCPCLIENT
SM_TCPCLIENT
;
_SM_TCPCLIENT
SM_TCPCLIENT
;
SKProtoMsg
protoMsg
;
QQueue
<
SKProtoMsg
>
protoQueue
;
public
:
public
:
...
@@ -98,10 +103,14 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface
...
@@ -98,10 +103,14 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface
private
slots
:
private
slots
:
void
sessionOpened
();
void
sessionOpened
();
void
readFromNetwork
();
void
readFromNetwork
();
void
clientConnected
();
void
displayError
(
QAbstractSocket
::
SocketError
);
void
displayError
(
QAbstractSocket
::
SocketError
);
public
slots
:
public
slots
:
void
receiveMessage
(
SKMessage
::
SKMessage
msg
);
void
receiveMessage
(
SKMessage
::
SKMessage
msg
);
private
slots
:
void
processPackets
();
signals
:
signals
:
void
putMessage
(
SKMessage
::
SKMessage
msg
);
void
putMessage
(
SKMessage
::
SKMessage
msg
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment