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>
|
2016-02-09 05:33:19 +01:00
|
|
|
* @copyright 2014-2016, Institute for Automation of Complex Power Systems, EONERC
|
2016-06-08 23:21:42 +02:00
|
|
|
* This file is part of VILLASnode. All Rights Reserved. Proprietary and confidential.
|
2015-08-07 01:11:43 +02:00
|
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
2015-06-02 21:53:04 +02:00
|
|
|
*********************************************************************************/
|
2014-06-05 09:34:29 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-09-07 16:29:05 +00:00
|
|
|
#include <ctype.h>
|
2014-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
#ifdef __linux__
|
2015-08-21 10:19:32 +02:00
|
|
|
#include <byteswap.h>
|
2014-09-04 13:25:21 +00:00
|
|
|
#elif defined(__PPC__) /* Xilinx toolchain */
|
2015-08-21 10:19:32 +02:00
|
|
|
#include <xil_io.h>
|
2015-10-08 10:51:48 +02:00
|
|
|
#define bswap_16(x) Xil_EndianSwap16(x)
|
2015-08-21 10:19:32 +02:00
|
|
|
#define bswap_32(x) Xil_EndianSwap32(x)
|
2014-08-31 16:15:54 +00:00
|
|
|
#endif
|
2014-06-05 09:34:29 +00:00
|
|
|
|
|
|
|
#include "msg.h"
|
2014-07-07 07:53:42 +00:00
|
|
|
#include "node.h"
|
2014-06-05 09:34:55 +00:00
|
|
|
#include "utils.h"
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2016-10-30 17:11:12 -04:00
|
|
|
void msg_hdr_swap(struct msg *m)
|
2014-06-05 09:34:29 +00:00
|
|
|
{
|
2016-07-11 18:19:23 +02:00
|
|
|
m->length = bswap_16(m->length);
|
2015-10-08 10:51:48 +02:00
|
|
|
m->sequence = bswap_32(m->sequence);
|
|
|
|
m->ts.sec = bswap_32(m->ts.sec);
|
|
|
|
m->ts.nsec = bswap_32(m->ts.nsec);
|
2014-07-18 16:05:49 +00:00
|
|
|
|
|
|
|
m->endian ^= 1;
|
|
|
|
}
|
|
|
|
|
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;
|
2016-06-08 22:31:24 +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;
|
2015-04-01 13:25:03 +02:00
|
|
|
}
|