CHAILink SDK  Version 1.3
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
CLC_Utils.h
Go to the documentation of this file.
1 //*********************************************************
2 // File: CLC_Utils.h
3 // Project: CopperLan CHAILink Client SDK
4 // Version: 1.3
5 // Release Date: 2014/04/15
6 //*********************************************************
7 
8 /********************************************************************
9 Software License Agreement: CHAILink Client source code
10 
11 The software supplied herewith by Klavis Technology (the “Company”) is intended and
12 supplied to you, the Company’s customer, for use solely and exclusively on embedded
13 CopperLan products needing a CHAILink Client.
14  The software is owned by the Company and/or its supplier, and is protected
15  under applicable copyright laws. All rights are reserved. Any use in violation of the
16  foregoing restrictions may subject the user to criminal sanctions under applicable laws,
17 as well as to civil liability for the breach of the terms and conditions of this license.
18 
19 THIS SOFTWARE MUST REMAIN UNMODIFIED. NO WARRANTIES, WHETHER EXPRESS,
20  IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
21  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE
22 IN CASE OF SOURCE CODE CHANGE BY THE CUSTOMER. IN CASE OF SUCH CHANGE, THE
23 COMPANY SHALL NOT BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
24 OF ANY KIND.
25 ********************************************************************/
26 
27 #ifndef _CLC_UTILS_H_
28 #define _CLC_UTILS_H_
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
35 
36 
38 // definition of various serialization/deserialization macro for CP types
40 // Align d
41 #define SERIALIZE_ALIGN4(d) ((d+3) & ~3)
42 #define SERIALIZE_ALIGN2(d) ((d+1) & ~1)
43 // align ptr to a 32 bit boundary (ptr MUST be CPUINT8*)
44 #define SERIALIZE_ALIGN4_PTR(p) p = ((CPUINT8*)0 + ((((CPUINT8*)(p) - (CPUINT8*)0) + 3) & ~3))
45 #define SERIALIZE_ALIGN2_PTR(p) p = ((CPUINT8*)0 + ((((CPUINT8*)(p) - (CPUINT8*)0) + 1) & ~1))
46 
47 #define CLCDESERIALIZE_DEVICEID(deviceID, p) DESERIALIZE_UINT16((deviceID).wBrandID, p); \
48  DESERIALIZE_UINT16((deviceID).wModelID, p); \
49  { \
50  CPUINT16 wTmp1, wTmp2; \
51  DESERIALIZE_UINT16(wTmp1, p); \
52  DESERIALIZE_UINT16(wTmp2, p); \
53  (deviceID).dwDuplicateNumber = ((CPUINT32) wTmp2 << 16) | wTmp1; \
54  } \
55  DESERIALIZE_UINT16((deviceID).wModuleID, p);
56 
57 #define CLCSERIALIZE_DEVICEID(p, deviceID) SERIALIZE_UINT16(p, (deviceID).wBrandID); \
58  SERIALIZE_UINT16(p, (deviceID).wModelID); \
59  SERIALIZE_UINT16(p, ((CPUINT16) (deviceID).dwDuplicateNumber)); \
60  SERIALIZE_UINT16(p, ((CPUINT16) ((deviceID).dwDuplicateNumber >> 16))); \
61  SERIALIZE_UINT16(p, (deviceID).wModuleID);
62 
63 #define CLCDESERIALIZE_SECTIONID(sectionID, p) { \
64  CPUINT16 w1, w2, w3, w4; \
65  DESERIALIZE_UINT16(w1, p); \
66  DESERIALIZE_UINT16(w2, p); \
67  DESERIALIZE_UINT16(w3, p); \
68  DESERIALIZE_UINT16(w4, p); \
69  (sectionID).qwSectionType = ((CPUINT64) w1) << 48 | ((CPUINT64) w2) << 32 | ((CPUINT32) w3) << 16 | w4; \
70  DESERIALIZE_UINT16((sectionID).wInstance, p); \
71  }
72 
73 #define CLCSERIALIZE_SECTIONID(p, sectionID) SERIALIZE_UINT16(p, ((CPUINT16) ((sectionID).qwSectionType >> 48))); \
74  SERIALIZE_UINT16(p, ((CPUINT16) ((sectionID).qwSectionType >> 32))); \
75  SERIALIZE_UINT16(p, ((CPUINT16) ((sectionID).qwSectionType >> 16))); \
76  SERIALIZE_UINT16(p, ((CPUINT16) (sectionID).qwSectionType)); \
77  SERIALIZE_UINT16(p, (sectionID).wInstance);
78 
79 #define CLCDESERIALIZE_PARAMETERID(paramID, p) DESERIALIZE_UINT16((paramID).wInputID, p); \
80  DESERIALIZE_UINT16((paramID).wMsgType, p); \
81  DESERIALIZE_UINT16((paramID).wMsgNum, p); \
82  DESERIALIZE_UINT16((paramID).wMsgIndex, p);
83 
84 #define CLCSERIALIZE_PARAMETERID(p, paramID) SERIALIZE_UINT16(p, (paramID).wInputID); \
85  SERIALIZE_UINT16(p, (paramID).wMsgType); \
86  SERIALIZE_UINT16(p, (paramID).wMsgNum); \
87  SERIALIZE_UINT16(p, (paramID).wMsgIndex);
88 
89 #define CLCDESERIALIZE_CONTROLLERID(ctrlID, p) DESERIALIZE_UINT16((ctrlID).wOutputID, p); \
90  DESERIALIZE_UINT16((ctrlID).wCtrlType, p); \
91  DESERIALIZE_UINT16((ctrlID).wCtrlInstance, p);
92 
93 #define CLCSERIALIZE_CONTROLLERID(p, ctrlID) SERIALIZE_UINT16(p, (ctrlID).wOutputID); \
94  SERIALIZE_UINT16(p, (ctrlID).wCtrlType); \
95  SERIALIZE_UINT16(p, (ctrlID).wCtrlInstance);
96 
97 #define CLCDESERIALIZE_CONTROLLERASSIGNMENT(ctrlAssignment, p) \
98  CLCDESERIALIZE_ENDPOINT((ctrlAssignment).target, p); \
99  DESERIALIZE_UINT16((ctrlAssignment).wMsgType, p); \
100  DESERIALIZE_UINT16((ctrlAssignment).wMsgNum, p); \
101  DESERIALIZE_UINT16((ctrlAssignment).wMsgIndex, p); \
102  DESERIALIZE_UINT16((ctrlAssignment).wInformationProfile, p); \
103  DESERIALIZE_UINT16((ctrlAssignment).wValueDown, p); \
104  DESERIALIZE_UINT16((ctrlAssignment).wValueUp, p); \
105  DESERIALIZE_UINT8((ctrlAssignment).bAvailableValues, p); \
106  p += sizeof(CPUINT8); // for 2 bytes alignment
107 
108 #define CLCSERIALIZE_CONTROLLERASSIGNMENT(p, ctrlAssignment) \
109  CLCSERIALIZE_ENDPOINT(p, (ctrlAssignment).target); \
110  SERIALIZE_UINT16(p, (ctrlAssignment).wMsgType); \
111  SERIALIZE_UINT16(p, (ctrlAssignment).wMsgNum); \
112  SERIALIZE_UINT16(p, (ctrlAssignment).wMsgIndex); \
113  SERIALIZE_UINT16(p, (ctrlAssignment).wInformationProfile); \
114  SERIALIZE_UINT16(p, (ctrlAssignment).wValueDown); \
115  SERIALIZE_UINT16(p, (ctrlAssignment).wValueUp); \
116  SERIALIZE_UINT8(p, (ctrlAssignment).bAvailableValues); \
117  SERIALIZE_UINT8(p, 0); // for 2 bytes alignment
118 
119 #define CLCDESERIALIZE_SMARTCONNECTSECTIONITEM(scSectionItem, p) \
120  DESERIALIZE_UINT64((scSectionItem).qwSectionType, p); \
121  CLCDESERIALIZE_DEVICEID((scSectionItem).DevID, p); \
122  DESERIALIZE_UINT16((scSectionItem).wInstanceCount, p);
123 
124 #define CLCSERIALIZE_SMARTCONNECTSECTIONITEM(p, ctrlAssignment) \
125  SERIALIZE_UINT64(p, (scSectionItem).qwSectionType); \
126  CLCSERIALIZE_DEVICEID(p, (scSectionItem).DevID); \
127  SERIALIZE_UINT16(p, (scSectionItem).wInstanceCount);
128 
129 #define CLCDESERIALIZE_SMARTCONNECTCONTROLLERITEM(scControllerItem, p) \
130  DESERIALIZE_UINT16((scControllerItem).wControllerID, p); \
131  DESERIALIZE_UINT16((scControllerItem).wControllerTypes, p); \
132  DESERIALIZE_UINT16((scControllerItem).wPreferredMsgType, p); \
133  DESERIALIZE_UINT16((scControllerItem).wPreferredMsgNum, p); \
134  DESERIALIZE_UINT16((scControllerItem).wGroup, p);
135 
136 #define CLCSERIALIZE_SMARTCONNECTCONTROLLERITEM(p, scControllerItem) \
137  SERIALIZE_UINT16(p, (scControllerItem).wControllerID); \
138  SERIALIZE_UINT16(p, (scControllerItem).wControllerTypes); \
139  SERIALIZE_UINT16(p, (scControllerItem).wPreferredMsgType); \
140  SERIALIZE_UINT16(p, (scControllerItem).wPreferredMsgNum); \
141  SERIALIZE_UINT16(p, (scControllerItem).wGroup);
142 
143 #define CLCDESERIALIZE_INTERNALVALUE(val, p) DESERIALIZE_UINT16((val).wRawValue, p); \
144  DESERIALIZE_UINT16((val).wDataType, p); \
145  switch((val).wDataType & _DT_LengthMask_) \
146  { \
147  case DTL_16: \
148  DESERIALIZE_UINT16((val).value.u16, p); \
149  p += 6; \
150  break; \
151  case DTL_32: \
152  DESERIALIZE_UINT32((val).value.u32, p); \
153  p += 4; \
154  break; \
155  case DTL_64: \
156  DESERIALIZE_UINT64((val).value.u64, p); \
157  default: \
158  break; \
159  }
160 
161 #define CLCSERIALIZE_INTERNALVALUE(p, val) SERIALIZE_UINT16(p, (val).wRawValue); \
162  SERIALIZE_UINT16(p, (val).wDataType); \
163  switch((val).wDataType & _DT_LengthMask_) \
164  { \
165  case DTL_16: \
166  SERIALIZE_UINT16(p, (val).value.u16); \
167  p += 6; \
168  break; \
169  case DTL_32: \
170  SERIALIZE_UINT32(p, (val).value.u32); \
171  p += 4; \
172  break; \
173  case DTL_64: \
174  SERIALIZE_UINT64(p, (val).value.u64); \
175  default: \
176  break; \
177  }
178 
179 #define CLCDESERIALIZE_ENDPOINT(ep, p) DESERIALIZE_UINT16((ep).deviceID.wBrandID, p); \
180  DESERIALIZE_UINT16((ep).deviceID.wModelID, p); \
181  { \
182  CPUINT16 wTmp1, wTmp2; \
183  DESERIALIZE_UINT16(wTmp1, p); \
184  DESERIALIZE_UINT16(wTmp2, p); \
185  (ep).deviceID.dwDuplicateNumber = (((CPUINT32) wTmp2) << 16) | wTmp1; \
186  } \
187  DESERIALIZE_UINT16((ep).deviceID.wModuleID, p); \
188  DESERIALIZE_UINT16((ep).wInOutID, p);
189 
190 
191 #define CLCSERIALIZE_ENDPOINT(p, ep) SERIALIZE_UINT16(p, (ep).deviceID.wBrandID); \
192  SERIALIZE_UINT16(p, (ep).deviceID.wModelID); \
193  SERIALIZE_UINT16(p, ((CPUINT16) (ep).deviceID.dwDuplicateNumber)); \
194  SERIALIZE_UINT16(p, ((CPUINT16) ((ep).deviceID.dwDuplicateNumber >> 16))); \
195  SERIALIZE_UINT16(p, (ep).deviceID.wModuleID); \
196  SERIALIZE_UINT16(p, (ep).wInOutID);
197 
198 #define CLCSERIALIZE_APPEVENTMSG(p, msg) SERIALIZE_UINT16(p, (msg).wProfiles); \
199  SERIALIZE_UINT16(p, (msg).Profile.DataArray[0]); \
200  SERIALIZE_UINT16(p, (msg).Profile.DataArray[1]); \
201  SERIALIZE_UINT16(p, (msg).Profile.DataArray[2]); \
202  SERIALIZE_UINT16(p, (msg).Profile.DataArray[3]); \
203  SERIALIZE_UINT16(p, (msg).Profile.DataArray[4]); \
204  SERIALIZE_UINT16(p, (msg).Profile.DataArray[5]); \
205  SERIALIZE_UINT16(p, (msg).Profile.DataArray[6]); \
206  SERIALIZE_UINT16(p, (msg).Profile.DataArray[7]);
207 
208 #define CLCDESERIALIZE_APPEVENTMSG(msg, p) DESERIALIZE_UINT16((msg).wProfiles, p); \
209  DESERIALIZE_UINT16((msg).Profile.DataArray[0], p); \
210  DESERIALIZE_UINT16((msg).Profile.DataArray[1], p); \
211  DESERIALIZE_UINT16((msg).Profile.DataArray[2], p); \
212  DESERIALIZE_UINT16((msg).Profile.DataArray[3], p); \
213  DESERIALIZE_UINT16((msg).Profile.DataArray[4], p); \
214  DESERIALIZE_UINT16((msg).Profile.DataArray[5], p); \
215  DESERIALIZE_UINT16((msg).Profile.DataArray[6], p); \
216  DESERIALIZE_UINT16((msg).Profile.DataArray[7], p);
217 
218 #define CLCSERIALIZE_APPMODIFIERMSG(p, msg) SERIALIZE_UINT16(p, (msg).wProfiles); \
219  SERIALIZE_UINT16(p, (msg).wNumber); \
220  SERIALIZE_UINT16(p, (msg).Profile.DataArray[0]); \
221  SERIALIZE_UINT16(p, (msg).Profile.DataArray[1]); \
222  SERIALIZE_UINT16(p, (msg).Profile.DataArray[2]); \
223  SERIALIZE_UINT16(p, (msg).Profile.DataArray[3]); \
224  SERIALIZE_UINT16(p, (msg).Profile.DataArray[4]); \
225  SERIALIZE_UINT16(p, (msg).Profile.DataArray[5]); \
226  SERIALIZE_UINT16(p, (msg).Profile.DataArray[6]); \
227  SERIALIZE_UINT16(p, (msg).Profile.DataArray[7]); \
228  CLCSERIALIZE_INTERNALVALUE(p, (msg).Value);
229 
230 #define CLCDESERIALIZE_APPMODIFIERMSG(msg, p) DESERIALIZE_UINT16((msg).wProfiles, p); \
231  DESERIALIZE_UINT16((msg).wNumber, p); \
232  DESERIALIZE_UINT16((msg).Profile.DataArray[0], p); \
233  DESERIALIZE_UINT16((msg).Profile.DataArray[1], p); \
234  DESERIALIZE_UINT16((msg).Profile.DataArray[2], p); \
235  DESERIALIZE_UINT16((msg).Profile.DataArray[3], p); \
236  DESERIALIZE_UINT16((msg).Profile.DataArray[4], p); \
237  DESERIALIZE_UINT16((msg).Profile.DataArray[5], p); \
238  DESERIALIZE_UINT16((msg).Profile.DataArray[6], p); \
239  DESERIALIZE_UINT16((msg).Profile.DataArray[7], p); \
240  CLCDESERIALIZE_INTERNALVALUE((msg).Value, p);
241 
242 #define CLCSERIALIZE_APPSELECTORMSG(p, msg) SERIALIZE_UINT16(p, (msg).wProfiles); \
243  SERIALIZE_UINT16(p, (msg).wNumber); \
244  SERIALIZE_UINT16(p, (msg).Profile.DataArray[0]); \
245  SERIALIZE_UINT16(p, (msg).Profile.DataArray[1]); \
246  SERIALIZE_UINT16(p, (msg).Profile.DataArray[2]); \
247  SERIALIZE_UINT16(p, (msg).Profile.DataArray[3]); \
248  SERIALIZE_UINT16(p, (msg).Profile.DataArray[4]); \
249  SERIALIZE_UINT16(p, (msg).Profile.DataArray[5]); \
250  SERIALIZE_UINT16(p, (msg).Profile.DataArray[6]); \
251  SERIALIZE_UINT16(p, (msg).Profile.DataArray[7]); \
252  SERIALIZE_UINT16(p, (msg).wValue);
253 
254 #define CLCDESERIALIZE_APPSELECTORMSG(msg, p) DESERIALIZE_UINT16((msg).wProfiles, p); \
255  DESERIALIZE_UINT16((msg).wNumber, p); \
256  DESERIALIZE_UINT16((msg).Profile.DataArray[0], p); \
257  DESERIALIZE_UINT16((msg).Profile.DataArray[1], p); \
258  DESERIALIZE_UINT16((msg).Profile.DataArray[2], p); \
259  DESERIALIZE_UINT16((msg).Profile.DataArray[3], p); \
260  DESERIALIZE_UINT16((msg).Profile.DataArray[4], p); \
261  DESERIALIZE_UINT16((msg).Profile.DataArray[5], p); \
262  DESERIALIZE_UINT16((msg).Profile.DataArray[6], p); \
263  DESERIALIZE_UINT16((msg).Profile.DataArray[7], p); \
264  DESERIALIZE_UINT16((msg).wValue, p);
265 
266 #define CLCSERIALIZE_APPTEXTMSG_BASE(p, msg) SERIALIZE_UINT16(p, (msg).wProfiles); \
267  SERIALIZE_UINT16(p, (msg).wNumber); \
268  SERIALIZE_UINT16(p, (msg).Profile.DataArray[0]); \
269  SERIALIZE_UINT16(p, (msg).Profile.DataArray[1]); \
270  SERIALIZE_UINT16(p, (msg).Profile.DataArray[2]); \
271  SERIALIZE_UINT16(p, (msg).Profile.DataArray[3]); \
272  SERIALIZE_UINT16(p, (msg).Profile.DataArray[4]); \
273  SERIALIZE_UINT16(p, (msg).Profile.DataArray[5]); \
274  SERIALIZE_UINT16(p, (msg).Profile.DataArray[6]); \
275  SERIALIZE_UINT16(p, (msg).Profile.DataArray[7]);
276 
277 #define CLCDESERIALIZE_APPTEXTMSG_BASE(msg, p) DESERIALIZE_UINT16((msg).wProfiles, p); \
278  DESERIALIZE_UINT16((msg).wNumber, p); \
279  DESERIALIZE_UINT16((msg).Profile.DataArray[0], p); \
280  DESERIALIZE_UINT16((msg).Profile.DataArray[1], p); \
281  DESERIALIZE_UINT16((msg).Profile.DataArray[2], p); \
282  DESERIALIZE_UINT16((msg).Profile.DataArray[3], p); \
283  DESERIALIZE_UINT16((msg).Profile.DataArray[4], p); \
284  DESERIALIZE_UINT16((msg).Profile.DataArray[5], p); \
285  DESERIALIZE_UINT16((msg).Profile.DataArray[6], p); \
286  DESERIALIZE_UINT16((msg).Profile.DataArray[7], p);
287 
288 #define CLCDESERIALIZE_TIMESTAMPINFO(ts, p) DESERIALIZE_UINT64((ts).systemTime, p); \
289  DESERIALIZE_UINT32((ts).songPosition, p); \
290  DESERIALIZE_UINT16((ts).wTimeStampFlags, p);
291 
293 // Internal helper functions
295 CLC_ErrorCode Generic_RegisterNotificationHandler(CPHOBJECT const hObject, CPUINT16 const wMehodID, CPUINT32 const dwEnableNotificationFlags);
296 
298 
303 
306 CLC_SDK_API void SectionID_Init(CPSECTIONID * const pSectionID);
307 
311 CLC_SDK_API void SectionID_SetAnyInstanceOf(CPSECTIONID * const pSectionID, CPUINT64 const sectionType);
312 
316 CLC_SDK_API CPBOOLEAN SectionID_IsEmpty(CPSECTIONID const * const pSectionID);
317 
322 CLC_SDK_API CPBOOLEAN SectionID_Match(CPSECTIONID const * const pSectionID1, CPSECTIONID const * const pSectionID2);
323 
325 
326 #ifdef __cplusplus
327 }
328 #endif
329 
330 #endif // _CLC_UTILS_H_
#define CLC_SDK_API
Definition: CLCm_Platform.h:37
CPBOOLEAN SectionID_Match(CPSECTIONID const *const pSectionID1, CPSECTIONID const *const pSectionID2)
Checks if two Section IDs match taking care of wildcards.
Container structure for Section ID Each Input is associated to a SectionID giving information about i...
Definition: CLC_Types.h:67
CLC_ErrorCode
Error code Enumeration. Error codes from 0x01 to 0xFF are related to a CopperLan functions return cod...
Definition: CLCm_Defines.h:469
void SectionID_Init(CPSECTIONID *const pSectionID)
Initialize a Section ID to NullSectionID.
unsigned short CPUINT16
Word Integer (16 bit unsigned)
Definition: PlatformTypes.h:45
unsigned long CPUINT32
Double Word Integer (32 bit unsigned)
Definition: PlatformTypes.h:48
void SectionID_SetAnyInstanceOf(CPSECTIONID *const pSectionID, CPUINT64 const sectionType)
Set a Section ID to an AnyInstanceOf wildcard Section ID.
CPUINT32 CPHOBJECT
Handle on Object.
Definition: CLCm_Types.h:57
unsigned long long CPUINT64
Quad Word Integer (64 bit unsigned)
Definition: PlatformTypes.h:51
CPBOOLEAN SectionID_IsEmpty(CPSECTIONID const *const pSectionID)
Empty checks a Section ID.