mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-16 00:00:02 +01:00
48 lines
1.2 KiB
C
48 lines
1.2 KiB
C
/** Message related functions.
|
|
*
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
|
* @copyright 2014-2016, Institute for Automation of Complex Power Systems, EONERC
|
|
* This file is part of VILLASnode. All Rights Reserved. Proprietary and confidential.
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
|
*********************************************************************************/
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
|
|
#ifdef __linux__
|
|
#include <byteswap.h>
|
|
#elif defined(__PPC__) /* Xilinx toolchain */
|
|
#include <xil_io.h>
|
|
#define bswap_16(x) Xil_EndianSwap16(x)
|
|
#define bswap_32(x) Xil_EndianSwap32(x)
|
|
#endif
|
|
|
|
#include "msg.h"
|
|
#include "node.h"
|
|
#include "utils.h"
|
|
|
|
void msg_swap(struct msg *m)
|
|
{
|
|
m->length = bswap_16(m->length);
|
|
m->sequence = bswap_32(m->sequence);
|
|
m->ts.sec = bswap_32(m->ts.sec);
|
|
m->ts.nsec = bswap_32(m->ts.nsec);
|
|
|
|
for (int i = 0; i < m->length; i++)
|
|
m->data[i].i = bswap_32(m->data[i].i);
|
|
|
|
m->endian ^= 1;
|
|
}
|
|
|
|
int msg_verify(struct msg *m)
|
|
{
|
|
if (m->version != MSG_VERSION)
|
|
return -1;
|
|
else if (m->type != MSG_TYPE_DATA)
|
|
return -2;
|
|
else if ((m->rsvd1 != 0) || (m->rsvd2 != 0))
|
|
return -3;
|
|
else
|
|
return 0;
|
|
}
|