2017-04-24 13:22:55 +02:00
|
|
|
/** Websocket message related functions.
|
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
|
|
|
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
2017-04-27 12:56:43 +02:00
|
|
|
* @license GNU General Public License (version 3)
|
|
|
|
*
|
|
|
|
* VILLASnode
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
2017-05-05 19:24:16 +00:00
|
|
|
*
|
2017-04-27 12:56:43 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2017-05-05 19:24:16 +00:00
|
|
|
*
|
2017-04-27 12:56:43 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-04-24 13:22:55 +02:00
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
#include <endian.h>
|
|
|
|
|
|
|
|
#include "webmsg.h"
|
2017-04-24 14:19:12 +02:00
|
|
|
#include "webmsg_format.h"
|
2017-04-24 13:22:55 +02:00
|
|
|
|
|
|
|
void webmsg_ntoh(struct webmsg *m)
|
|
|
|
{
|
2017-04-24 14:19:12 +02:00
|
|
|
webmsg_hdr_ntoh(m);
|
2017-04-24 13:22:55 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < m->length; i++)
|
2017-04-24 14:19:12 +02:00
|
|
|
m->data[i].i = le32toh(m->data[i].i);
|
2017-04-24 13:22:55 +02:00
|
|
|
}
|
|
|
|
|
2017-04-24 14:19:12 +02:00
|
|
|
void webmsg_hton(struct webmsg *m)
|
2017-04-24 13:22:55 +02:00
|
|
|
{
|
|
|
|
for (int i = 0; i < m->length; i++)
|
2017-04-24 14:19:12 +02:00
|
|
|
m->data[i].i = htole32(m->data[i].i);
|
2017-04-24 13:22:55 +02:00
|
|
|
|
|
|
|
webmsg_hdr_hton(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void webmsg_hdr_hton(struct webmsg *m)
|
|
|
|
{
|
|
|
|
m->length = htole16(m->length);
|
2017-04-24 14:19:12 +02:00
|
|
|
m->sequence = htole32(m->sequence);
|
|
|
|
m->ts.sec = htole32(m->ts.sec);
|
|
|
|
m->ts.nsec = htole32(m->ts.nsec);
|
2017-04-24 13:22:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void webmsg_hdr_ntoh(struct webmsg *m)
|
|
|
|
{
|
2017-04-24 14:19:12 +02:00
|
|
|
m->length = le16toh(m->length);
|
|
|
|
m->sequence = le32toh(m->sequence);
|
|
|
|
m->ts.sec = le32toh(m->ts.sec);
|
|
|
|
m->ts.nsec = le32toh(m->ts.nsec);
|
2017-04-24 13:22:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int webmsg_verify(struct webmsg *m)
|
|
|
|
{
|
|
|
|
if (m->version != WEBMSG_VERSION)
|
|
|
|
return -1;
|
|
|
|
else if (m->type != WEBMSG_TYPE_DATA)
|
|
|
|
return -2;
|
2017-04-24 14:19:12 +02:00
|
|
|
else if (m->rsvd1 != 0)
|
2017-04-24 13:22:55 +02:00
|
|
|
return -3;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|