Rename some commandID enums to be closer their ASCII value

GlobalDiscover -> QueryAll
TableData      -> ReadTable
WriteTableData -> TableModify
This commit is contained in:
Andrius Štikonas 2015-05-27 00:03:33 +01:00
parent ba52a9862e
commit 32cf746ace
3 changed files with 28 additions and 17 deletions

View File

@ -156,7 +156,7 @@ void Server::readPendingDatagrams()
if ( reply != discover && reply.left ( 2 ) == magicKey ) // check for Magic Key if ( reply != discover && reply.left ( 2 ) == magicKey ) // check for Magic Key
{ {
if ( reply.mid ( 4, 2 ) == QByteArray::fromHex ( "71 61" ) || reply.mid ( 4, 2 ) == QByteArray::fromHex ( "71 67" )) // Reply to discover packet if ( reply.mid ( 4, 2 ) == QStringLiteral("qa").toLatin1() || reply.mid ( 4, 2 ) == QStringLiteral("qg").toLatin1()) // Reply to discover packet
{ {
bool duplicate = false; bool duplicate = false;
for ( std::vector<Socket*>::const_iterator i = sockets->begin() ; i != sockets->end(); ++i ) for ( std::vector<Socket*>::const_iterator i = sockets->begin() ; i != sockets->end(); ++i )

View File

@ -32,15 +32,15 @@ Socket::Socket ( QHostAddress IPaddress, QByteArray reply )
std::reverse ( rmac.begin(), rmac.end() ); std::reverse ( rmac.begin(), rmac.end() );
powered = reply.right ( 1 ) == one; powered = reply.right ( 1 ) == one;
commandID[GlobalDiscover] = QStringLiteral( "qa" ).toLatin1(); // Query All commandID[QueryAll] = QStringLiteral( "qa" ).toLatin1();
commandID[Discover] = QStringLiteral( "qg" ).toLatin1(); // qg commandID[Discover] = QStringLiteral( "qg" ).toLatin1(); // qg
commandID[Subscribe] = QStringLiteral( "cl" ).toLatin1(); // Login Command commandID[Subscribe] = QStringLiteral( "cl" ).toLatin1(); // Login Command
commandID[PowerOn] = QStringLiteral( "sf" ).toLatin1(); // sf (change of power state) commandID[PowerOn] = QStringLiteral( "sf" ).toLatin1(); // State Flip (change of power state)
commandID[PowerOff] = commandID[PowerOn]; commandID[PowerOff] = commandID[PowerOn];
commandID[TableData] = QStringLiteral( "rt" ).toLatin1(); // Read Table commandID[ReadTable] = QStringLiteral( "rt" ).toLatin1();
commandID[SocketData] = commandID[TableData]; commandID[SocketData] = commandID[ReadTable];
commandID[TimingData] = commandID[TableData]; commandID[TimingData] = commandID[ReadTable];
commandID[WriteSocketData] = QStringLiteral( "tm" ).toLatin1(); // Table Modify commandID[TableModify] = QStringLiteral( "tm" ).toLatin1();
QByteArray commandIDPower = QStringLiteral( "dc" ).toLatin1(); // Socket change responce QByteArray commandIDPower = QStringLiteral( "dc" ).toLatin1(); // Socket change responce
// 2 hex bytes are the total length of the message // 2 hex bytes are the total length of the message
@ -48,7 +48,7 @@ Socket::Socket ( QHostAddress IPaddress, QByteArray reply )
datagram[Subscribe] = commandID[Subscribe] + mac + twenties + rmac + twenties; datagram[Subscribe] = commandID[Subscribe] + mac + twenties + rmac + twenties;
datagram[PowerOn] = commandIDPower + mac + twenties + zeros + one; datagram[PowerOn] = commandIDPower + mac + twenties + zeros + one;
datagram[PowerOff] = commandIDPower + mac + twenties + zeros + zero; datagram[PowerOff] = commandIDPower + mac + twenties + zeros + zero;
datagram[TableData] = commandID[TableData] + mac + twenties + /*zeros*/QByteArray::fromHex ( "72 00 00 00" ) + QByteArray::fromHex ( "01 00 00" ) + zeros; datagram[ReadTable] = commandID[ReadTable] + mac + twenties + /*zeros*/QByteArray::fromHex ( "72 00 00 00" ) + QByteArray::fromHex ( "01 00 00" ) + zeros;
udpSocket = new QUdpSocket(); udpSocket = new QUdpSocket();
udpSocket->connectToHost ( ip, 10000 ); udpSocket->connectToHost ( ip, 10000 );
@ -170,13 +170,13 @@ void Socket::writeSocketData(QByteArray name, QByteArray password, QByteArray ti
uint16_t length = record.length(); uint16_t length = record.length();
stream << length; stream << length;
datagram[WriteSocketData] = commandID[WriteSocketData] + mac + twenties + zeros + QByteArray::fromHex ( "04:00:01" ) /*table number and unknown*/ + recordLength + record; datagram[TableModify] = commandID[TableModify] + mac + twenties + zeros + QByteArray::fromHex ( "04:00:01" ) /*table number and unknown*/ + recordLength + record;
sendDatagram ( WriteSocketData ); sendDatagram ( TableModify );
} }
void Socket::tableData() void Socket::tableData()
{ {
sendDatagram ( TableData ); sendDatagram ( ReadTable );
datagram[SocketData] = commandID[SocketData] + mac + twenties + zeros + QByteArray::fromHex ( "04 00 00" ) + zeros; datagram[SocketData] = commandID[SocketData] + mac + twenties + zeros + QByteArray::fromHex ( "04 00 00" ) + zeros;
datagram[TimingData] = commandID[TimingData] + mac + twenties + zeros + QByteArray::fromHex ( "03 00 00" ) + zeros; datagram[TimingData] = commandID[TimingData] + mac + twenties + zeros + QByteArray::fromHex ( "03 00 00" ) + zeros;
// table number + 00 + version number // table number + 00 + version number
@ -193,7 +193,7 @@ bool Socket::parseReply ( QByteArray reply )
QByteArray id = reply.mid ( 4, 2 ); QByteArray id = reply.mid ( 4, 2 );
unsigned int datagram = std::distance ( commandID, std::find ( commandID, commandID + MaxCommands, id ) ); // match commandID with enum unsigned int datagram = std::distance ( commandID, std::find ( commandID, commandID + MaxCommands, id ) ); // match commandID with enum
if ( datagram == TableData ) // determine the table number if ( datagram == ReadTable ) // determine the table number
{ {
unsigned int table = reply[reply.indexOf ( twenties ) + 11]; unsigned int table = reply[reply.indexOf ( twenties ) + 11];
switch ( table ) switch ( table )
@ -210,13 +210,13 @@ bool Socket::parseReply ( QByteArray reply )
qWarning() << "No table"; // FIXME: initial data query qWarning() << "No table"; // FIXME: initial data query
default: default:
qWarning() << "Failed to identify data table."; qWarning() << "Failed to identify data table.";
datagram = TableData; datagram = ReadTable;
return false; return false;
} }
} }
switch ( datagram ) switch ( datagram )
{ {
case GlobalDiscover: case QueryAll:
case Discover: case Discover:
{ {
QByteArray timeArray = reply.right(5).left(4); QByteArray timeArray = reply.right(5).left(4);
@ -244,7 +244,7 @@ bool Socket::parseReply ( QByteArray reply )
} }
break; break;
} }
case TableData: case ReadTable:
// FIXME: order might be swapped; // FIXME: order might be swapped;
socketTableVersion = reply.mid ( reply.indexOf ( QByteArray::fromHex ( "000100000600" ) ) + 6, 2 ); socketTableVersion = reply.mid ( reply.indexOf ( QByteArray::fromHex ( "000100000600" ) ) + 6, 2 );
// 000100000600 // 000100000600
@ -292,7 +292,7 @@ bool Socket::parseReply ( QByteArray reply )
case TimingData: case TimingData:
// std::cout << reply.toHex().toStdString() << " " << datagram << std::endl; // for debugging purposes only // std::cout << reply.toHex().toStdString() << " " << datagram << std::endl; // for debugging purposes only
break; break;
case WriteSocketData: case TableModify:
sendDatagram ( SocketData ); sendDatagram ( SocketData );
break; break;
default: default:

View File

@ -59,7 +59,18 @@ public:
QDateTime socketDateTime; QDateTime socketDateTime;
private: private:
enum Datagram {GlobalDiscover, Discover, Subscribe, PowerOff, PowerOn, TableData, SocketData, TimingData, WriteSocketData, MaxCommands}; enum Datagram {
QueryAll,
Discover,
Subscribe,
PowerOff,
PowerOn,
ReadTable,
SocketData,
TimingData,
TableModify,
MaxCommands
};
void sendDatagram ( Datagram ); void sendDatagram ( Datagram );
void subscribe(); void subscribe();