2014-07-14 11:49:44 +00:00
|
|
|
/** Message related functions.
|
2014-06-05 09:34:29 +00:00
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2017-03-03 20:20:13 -04:00
|
|
|
* @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/>.
|
2015-06-02 21:53:04 +02:00
|
|
|
*********************************************************************************/
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2017-04-23 22:12:10 +02:00
|
|
|
#include <arpa/inet.h>
|
2014-06-05 09:34:29 +00:00
|
|
|
|
|
|
|
#include "msg.h"
|
2017-04-23 22:12:10 +02:00
|
|
|
#include "msg_format.h"
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2017-04-23 22:12:10 +02:00
|
|
|
void msg_ntoh(struct msg *m)
|
2014-06-05 09:34:29 +00:00
|
|
|
{
|
2017-04-23 22:12:10 +02:00
|
|
|
msg_hdr_ntoh(m);
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-04-23 22:12:10 +02:00
|
|
|
for (int i = 0; i < m->length; i++)
|
|
|
|
m->data[i].i = ntohl(m->data[i].i);
|
|
|
|
}
|
|
|
|
|
|
|
|
void msg_hton(struct msg *m)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < m->length; i++)
|
|
|
|
m->data[i].i = htonl(m->data[i].i);
|
|
|
|
|
|
|
|
msg_hdr_hton(m);
|
|
|
|
}
|
2014-07-18 16:05:49 +00:00
|
|
|
|
2017-04-23 22:12:10 +02:00
|
|
|
void msg_hdr_hton(struct msg *m)
|
|
|
|
{
|
|
|
|
m->length = htons(m->length);
|
|
|
|
m->sequence = htonl(m->sequence);
|
|
|
|
m->ts.sec = htonl(m->ts.sec);
|
|
|
|
m->ts.nsec = htonl(m->ts.nsec);
|
|
|
|
}
|
|
|
|
|
|
|
|
void msg_hdr_ntoh(struct msg *m)
|
|
|
|
{
|
|
|
|
m->length = ntohs(m->length);
|
|
|
|
m->sequence = ntohl(m->sequence);
|
|
|
|
m->ts.sec = ntohl(m->ts.sec);
|
|
|
|
m->ts.nsec = ntohl(m->ts.nsec);
|
2014-07-18 16:05:49 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 13:25:03 +02:00
|
|
|
int msg_verify(struct msg *m)
|
|
|
|
{
|
2015-06-02 22:39:15 +02:00
|
|
|
if (m->version != MSG_VERSION)
|
|
|
|
return -1;
|
|
|
|
else if (m->type != MSG_TYPE_DATA)
|
|
|
|
return -2;
|
2017-04-23 22:12:10 +02:00
|
|
|
else if ((m->rsvd1 != 0) || (m->rsvd2 != 0))
|
2016-01-14 22:59:57 +01:00
|
|
|
return -3;
|
2015-06-02 22:39:15 +02:00
|
|
|
else
|
|
|
|
return 0;
|
2017-04-23 22:12:10 +02:00
|
|
|
}
|