versadac  1
versadac - Scalable Recorder Firmware
uhh_msgiface.h
1 /*****************************************************************************
2 FILE : U H H _ M S G I F A C E . H
3 VERSION : $Id: uhh_msgiface.h 4938 2006-10-10 14:20:18Z martinto $
4 AUTHOR : Dave Storey
5 SYSTEM : Gnu C++
6 DESCRIPTION : UHH message interface
7  NB This is a C header, not C++.
8 *****************************************************************************/
9 
10 #if !defined __UHH_MSGIFACE_H
11 #define __UHH_MSGIFACE_H
12 
13 #include "stdtypes.h"
14 
15 
16 /* Communication layer types */
17 #include "ENUM_UhhMsg_Com.h"
18 
19 /* Message categories, request types, response errors */
20 #include "ENUM_UhhMsg_Cat.h"
21 #include "ENUM_UhhMsg_Type.h"
22 #include "ENUM_UhhMsg_Err.h"
23 
24 /* Request & response header structures */
25 #include "ENUM_UhhMsg_Req.h"
26 #include "ENUM_UhhMsg_Res.h"
27 
28 /* Integer extraction macros */
29 
30 #define UHH_MSG_GET_U8_M(_p,_o) ( (_p)[(_o)] )
31 
32 #define UHH_MSG_GET_U16_M(_p,_o) ( (((uint16)(_p)[(_o)])<<8) + (_p)[(_o)+1])
33 
34 #define UHH_MSG_GET_U24_M(_p,_o) ( (((uint32)(_p)[(_o)])<<16) + (((uint32)(_p)[(_o)+1])<<8) +\
35  (_p)[(_o)+2] )
36 
37 #define UHH_MSG_GET_I32_M(_p,_o) ( (((sint32)(_p)[(_o)])<<24) + (((sint32)(_p)[(_o)+1])<<16) + \
38  (((sint32)(_p)[(_o)+2])<<8) + (_p)[(_o)+3] )
39 
40 /* Integer insertion macros */
41 
42 #define UHH_MSG_SET_U8_M(_p,_o,_u) { (_p)[(_o)] = (uint8)(_u); }
43 
44 #define UHH_MSG_SET_U16_M(_p,_o,_u) { (_p)[(_o)] = (uint8)((_u)>> 8); \
45  (_p)[(_o)+1] = (uint8) (_u); }
46 
47 #define UHH_MSG_SET_U24_M(_p,_o,_u) { (_p)[(_o)] = (uint8)((_u)>>16); \
48  (_p)[(_o)+1] = (uint8)((_u)>>8); \
49  (_p)[(_o)+2] = (uint8) (_u); }
50 
51 #define UHH_MSG_SET_I32_M(_p,_o,_n) { (_p)[(_o)] = (uint8)((_n)>>24); \
52  (_p)[(_o)+1] = (uint8)((_n)>>16); \
53  (_p)[(_o)+2] = (uint8)((_n)>> 8); \
54  (_p)[(_o)+3] = (uint8) (_n); }
55 
56 #define UHH_MSG_SET_I56_M(_p,_o,_n) { (_p)[(_o)] = (uint8)((_n)>>48); \
57  (_p)[(_o)+1] = (uint8)((_n)>>40); \
58  (_p)[(_o)+2] = (uint8)((_n)>>32); \
59  (_p)[(_o)+3] = (uint8)((_n)>>24); \
60  (_p)[(_o)+4] = (uint8)((_n)>>16); \
61  (_p)[(_o)+5] = (uint8)((_n)>> 8); \
62  (_p)[(_o)+6] = (uint8) (_n); }
63 
64 /* The (one and only) C interface routine */
65 void uhhMsg(uint8 *z_pRequest, uint8 *z_pResponse, sint32 z_nMaxRes);
66 
67 /* Utilities for clearing (to zero) or copying request/response prior to use */
68 void uhhMsgReqClear(uint8 *z_pRequest, sint32 z_nExtra);
69 void uhhMsgResClear(uint8 *z_pResponse, sint32 z_nExtra);
70 
71 /* Mapping between internal scale types and UHH values */
72 extern const uint8 uhhScaleTypeMap[][2];
73 
74 /* Utility for finding default number of scale divisions on this product */
75 uint8 uhhGetDefaultScaleDivs( void );
76 
77 #endif