Debian Codegraph @

interfaces/artnet/misc.c

raw symbols SCIP
1 /*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 *
16 * misc.c
17 * Misc code for libartnet (almost nothing these days)
18 * Copyright (C) 2004-2005 Simon Newton
19 */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include "private.h"
24
25 // static buffer for the error strings
26 char artnet_errstr[256];
27
28 /*
29 * Libartnet error function
30 * This writes the error string to artnet_errstr, which can be accessed
31 * using artnet_strerror();
32 */
33 void artnet_error(const char *fmt, ...) {
34 va_list ap;
35 va_start(ap, fmt);
36 vsnprintf(artnet_errstr, sizeof(artnet_errstr), fmt, ap);
37 va_end(ap);
38 }
39
40
41 /*
42 * Converts 4 bytes in big endian order to a 32 bit int
43 */
44 int32_t artnet_misc_nbytes_to_32(uint8_t bytes[4]) {
45 return (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3];
46 }
47
48 /*
49 * Converts an int to an arrany of 4 bytes in big endian format
50 */
51 void artnet_misc_int_to_bytes(int data, uint8_t *bytes) {
52 bytes[3] = (data & 0x000000FF);
53 bytes[2] = (data & 0x0000FF00) >> 8;
54 bytes[1] = (data & 0x00FF0000) >> 16;
55 bytes[0] = (data & 0xFF000000) >> 24;
56 }