Qt is complete framework for software development built on top of C++ with abstractions for GUI, Networking, Multimedia and all sorts of other nice stuff. A Qt way of handling OutGauge could look like this
<?php
#include <QtCore/QByteArray>
#include <QtCore/QDataStream>
#include <QtCore/QDebug>
#include <QtCore/QString>
#include <QtNetwork/QHostAddress>
#include <QtNetwork/QUdpSocket>
const QHostAddress ADDR ("127.0.0.1");
const quint16 PORT = 30000;
QUdpSocket* ogSocket = new QUdpSocket();
if (ogSocket.bind(ADDR, PORT)) {
connect(ogSocket, SIGNAL(readyRead()), this, SLOT(getPacket()));
else
qDebug() << "Cannot bind socket.";
--------------------------------------------
void getPacket() {
QByteArray buffer;
qint64 length = ogSocket->PendingDatagramSize();
if (length == 92 || length == 96) {
/* This is an OutGauge packet */
buffer.resize(length);
ogSocket->readDatagram(buffer.data(), length, NULL, NULL);
} else {
/* Not an OutGauge packet, skip it */
ogSocket->readDatagram(buffer.data(), 0, NULL, NULL);
return;
}
/* Extract data from the packet */
deserialize(buffer, length);
}
void deserialize(const QByteArray& ar, qint64 len)
{
qint32 m_Time;
quint8 m_rawCar[4];
quint32 m_Flags;
quint8 m_Gear;
quint8 m_PLID;
float m_Speed;
float m_RPM;
float m_Turbo;
float m_EngTemp;
float m_Fuel;
float m_OilPressure;
float m_OilTemp;
quint32 m_DashLights;
quint32 m_ShowLights;
float m_Throttle;
float m_Brake;
float m_Clutch;
quint8 m_rawDisplay1[16];
quint8 m_rawDisplay2[16];
qint32 m_ID;
QDataStream stream(ar);
stream.setByteOrder(QDataStream::LittleEndian);
stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
stream >> m_Time;
for (int i = 0; i < 4; i++)
stream >> m_rawCar[i];
stream >> m_Flags >> m_Gear >> m_PLID >> m_Speed >> m_RPM >> m_Turbo >> m_EngTemp >> m_Fuel >> m_OilPressure >> m_OilTemp >> m_DashLights >> m_ShowLights >> m_Throttle >> m_Brake >> m_Clutch;
for (int i = 0; i < 16; i++)
stream >> m_rawDisplay1[i];
for (int i = 0; i < 16; i++)
stream >> m_rawDisplay2[i];
if (len == 96)
stream >> m_ID;
QString m_Car = QString::fromLatin1((const char*)m_rawCar);
QString m_Display1 = QString::fromLatin1((const char*)m_rawDisplay1);
QString m_Display2 = QString::fromLatin1((const char*)m_rawDisplay2);
}
?>