dsm-api-v2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ds.h
Go to the documentation of this file.
1 /*
2  This file is part of the digitalSTROM ds485-core library.
3 
4  Copyright (C) 2010 digitalSTROM.org, Schlieren, Switzerland
5 
6  digitalSTROM ds485-core library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation version 2
9  of the License.
10 
11  digitalSTROM ds485-core library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with digitalSTROM ds485-core library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef _dsid_h
22 #define _dsid_h
23 
24 #if defined(__GNUC__)
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdint.h>
28 #include <sys/types.h>
29 #include <unistd.h>
30 #include <sys/time.h>
31 #elif defined(__MSVC__)
32 #endif
33 
37 typedef struct dsid {
38  unsigned char id[12];
39 } dsid_t;
40 
41 #define IsBroadcastId(id) \
42  (memcmp("\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", &(id), sizeof(dsid_t)) == 0)
43 
44 #define IsEqualId(id1, id2) \
45  (memcmp(&(id1), &(id2), sizeof(dsid_t)) == 0)
46 
47 #define SetBroadcastId(id) \
48  memcpy(&(id), "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", sizeof(dsid_t))
49 
50 #define SetNullId(id) \
51  memcpy(&(id), "\0\0\0\0\0\0\0\0\0\0\0\0", sizeof(dsid_t))
52 
53 #define IsNullId(id) \
54  (memcmp("\0\0\0\0\0\0\0\0\0\0\0\0", &(id), sizeof(dsid_t)) == 0)
55 
56 #if defined(__linux__)
57 # define BSP_MS_PER_TICKS 10
58 #elif defined(__APPLE__)
59 # define BSP_MS_PER_TICKS 10
60 #elif defined(__CYGWIN__)
61 # define BSP_MS_PER_TICKS 10
62 #endif
63 
64 #endif