yhash.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * $Id: yhash.h 24575 2016-05-26 06:28:03Z seb $
4  *
5  * Simple hash tables and device/function information store
6  *
7  * - - - - - - - - - License information: - - - - - - - - -
8  *
9  * Copyright (C) 2011 and beyond by Yoctopuce Sarl, Switzerland.
10  *
11  * Yoctopuce Sarl (hereafter Licensor) grants to you a perpetual
12  * non-exclusive license to use, modify, copy and integrate this
13  * file into your software for the sole purpose of interfacing
14  * with Yoctopuce products.
15  *
16  * You may reproduce and distribute copies of this file in
17  * source or object form, as long as the sole purpose of this
18  * code is to interface with Yoctopuce products. You must retain
19  * this notice in the distributed source file.
20  *
21  * You should refer to Yoctopuce General Terms and Conditions
22  * for additional information regarding your rights and
23  * obligations.
24  *
25  * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
26  * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
27  * WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS
28  * FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO
29  * EVENT SHALL LICENSOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
30  * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
31  * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR
32  * SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
33  * LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR
34  * CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON THE
35  * BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF
36  * WARRANTY, OR OTHERWISE.
37  *
38  *********************************************************************/
39 
40 #ifndef YHASH_H
41 #define YHASH_H
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #include "ydef.h"
48 
49 //#define DEBUG_WP_LOCK
50 //#define DEBUG_WP
51 
52 #define HASH_BUF_SIZE 28
53 #define HASH_BUF_POW 5 /* HASH_BUF_POW = log_2(HASH_BUF_SIZE+2+2) */
54 #ifdef MICROCHIP_API
55 #define NB_MAX_HASH_ENTRIES 1023 /* keep hash table size <32KB on Yocto-Hub */
56 #define NB_MAX_DEVICES 80 /* base hub + up to 15 shields (up to 4 slave ports) */
57 #else
58 #define NB_MAX_HASH_ENTRIES 8192
59 #define NB_MAX_DEVICES 256
60 #endif
61 
62 #define YSTRREF_EMPTY_STRING 0x00ff /* yStrRef value for the empty string */
63 #define YSTRREF_MODULE_STRING 0x0020 /* yStrRef value for the string 'Module' */
64 #define YSTRREF_mODULE_STRING 0x00a3 /* yStrRef value for the string 'module' */
65 #define YSTRREF_HUBPORT_STRING 0x00d6 /* yStrRef value for the string 'HubPort' */
66 #define YSTRREF_SENSOR_STRING 0x0001 /* yStrRef value for the string 'Sensor' */
67 
68 #ifndef CPU_BIG_ENDIAN
69 #define WORD_TEXT_PR 0x5250
70 #define WORD_TEXT_OG 0x474f
71 #else
72 #define WORD_TEXT_PR 0x5052
73 #define WORD_TEXT_OG 0x4f47
74 #endif
75 
76 typedef enum {
84 } yWPAttribute;
85 
86 #define YBLKID_WPENTRY 0xf0
87 #define YBLKID_YPCATEG 0xf1
88 #define YBLKID_YPARRAY 0xf2
89 #define YBLKID_YPENTRY 0xf3
90 #define YBLKID_YPENTRYEND (YBLKID_YPENTRY+YOCTO_N_BASECLASSES-1)
91 
92 typedef struct {
93  u8 devYdx;
94  u8 blkId;
99  u16 devid;
101  u16 flags;
103 
104 // WP entry flags
105 #define YWP_MARK_FOR_UNREGISTER 0x02
106 #define YWP_BEACON_ON 0x01
107 
108 typedef struct {
109  u8 posYdx;
110  u8 blkId;
112  yBlkHdl entries[6];
114 
115 typedef struct {
117  u8 blkId;
119  union {
120  struct {
121 #ifndef CPU_BIG_ENDIAN
124 #else
125  yStrRef funcId;
126  yStrRef serialNum;
127 #endif
128  };
130  };
132  union {
133  char funcVal[YOCTO_PUBVAL_SIZE];
134  u16 funcValWords[YOCTO_PUBVAL_SIZE/2];
135  };
137 
138 typedef struct {
139  u8 catYdx;
140  u8 blkId;
145 
146 typedef union{
147  struct {
148  u16 hash;
150  u8 buff[HASH_BUF_SIZE];
151  };
152  union {
153  struct {
154  u8 ydx;
155  u8 blkId;
157  };
162  } blk[2];
163 } YHashSlot;
164 
165 extern char SerialNumberStr[YOCTO_SERIAL_LEN];
166 extern yStrRef SerialRef;
167 extern yBlkHdl yWpListHead;
168 extern yBlkHdl yYpListHead;
169 
170 #define YMAX_HUB_URL_DEEP 8
171 #define YOCTO_HOSTNAME_NAME (HASH_BUF_SIZE*2+2)
172 
173 typedef enum {
177 } yAsbUrlType;
178 
179 typedef enum {
183 } yAsbUrlProto;
184 
185 
186 
187 typedef struct{
188  union{
189  struct{
192  u16 port;
193  } byname;
194  struct{
197  u16 port;
198  } byip;
199  struct{
203  } byusb;
204  };
205  u16 proto;
209 } yAbsUrl;
210 
211 void yHashInit(void);
212 yHash yHashPutBuf(const u8 *buf, u16 len);
213 yHash yHashPutStr(const char *str);
214 yHash yHashTestBuf(const u8 *buf, u16 len);
215 yHash yHashTestStr(const char *str);
216 void yHashGetBuf(yHash yhash, u8 *destbuf, u16 bufsize);
217 void yHashGetStr(yHash yhash, char *destbuf, u16 bufsize);
218 u16 yHashGetStrLen(yHash yhash);
219 char *yHashGetStrPtr(yHash yhash);
220 #ifndef MICROCHIP_API
221 yUrlRef yHashUrlFromRef(yUrlRef urlref, const char *rootUrl);
222 yUrlRef yHashUrl(const char *host, const char *rootUrl, u8 testonly, char *errmsg);
223 yAsbUrlType yHashGetUrlPort(yUrlRef urlref, char *url, u16 *port, yAsbUrlProto *proto, yStrRef *user, yStrRef *password);
224 int yHashSameHub(yUrlRef url_a, yUrlRef url_b);
225 void yHashFree(void);
226 #endif
227 yUrlRef yHashUrlUSB(yHash serial);
228 yUrlRef yHashUrlAPI(void);
229 u16 yBlkListLength(yBlkHdl hdl);
230 yBlkHdl yBlkListSeek(yBlkHdl hdl, u16 pos);
231 int wpRegister(int devYdx, yStrRef serial, yStrRef logicalName, yStrRef productName, u16 productId, yUrlRef devUrl, s8 beacon);
232 yStrRef wpGetAttribute(yBlkHdl hdl, yWPAttribute attridx);
233 void wpGetSerial(yBlkHdl hdl, char *serial);
234 void wpGetLogicalName(yBlkHdl hdl, char *logicalName);
235 #ifdef DEBUG_WP_LOCK
236 void wpPreventUnregisterDbg(const char *file, u32 line);
237 void wpAllowUnregisterDbg(const char *file, u32 line);
238 #define wpPreventUnregister() wpPreventUnregisterDbg(__FILE__,__LINE__)
239 #define wpAllowUnregister() wpAllowUnregisterDbg(__FILE__,__LINE__)
240 #else
241 void wpPreventUnregisterEx(void);
242 void wpAllowUnregisterEx(void);
243 #define wpPreventUnregister() wpPreventUnregisterEx()
244 #define wpAllowUnregister() wpAllowUnregisterEx()
245 #endif
246 int wpMarkForUnregister(yStrRef serial);
247 int wpGetDevYdx(yStrRef serial);
249 #ifndef MICROCHIP_API
250 u16 wpEntryCount(void);
252 YAPI_DEVICE wpSearch(const char *device_str);
253 YAPI_DEVICE wpSearchByUrl(const char *host, const char *rootUrl);
254 int wpGetAllDevUsingHubUrl( yUrlRef hubUrl, yStrRef *buffer,int sizeInStrRef);
255 
257 int wpGetDeviceUrl(YAPI_DEVICE devdesc, char *roothubserial, char *request, int requestsize, int *neededsize);
258 YAPI_FUNCTION ypSearch(const char *class_str, const char *func_str);
259 int ypGetFunctions(const char *class_str, YAPI_DEVICE devdesc, YAPI_FUNCTION prevfundesc,
260  YAPI_FUNCTION *buffer,int maxsize,int *neededsize);
261 int ypGetFunctionInfo(YAPI_FUNCTION fundesc, char *serial, char *funcId, char *baseType, char *funcName, char *funcVal);
262 #endif
263 int ypGetFunctionsEx(yStrRef categref, YAPI_DEVICE devdesc, YAPI_FUNCTION prevfundesc, YAPI_FUNCTION *buffer, int maxsize, int *neededsize);
264 int wpGetDeviceInfo(YAPI_DEVICE devdesc, u16 *deviceid, char *productname, char *serial, char *logicalname, u8 *beacon);
265 int ypRegister(yStrRef categ, yStrRef serial, yStrRef funcId, yStrRef funcName, int funClass, int funYdx, const char *funcVal);
266 // WARNING: funcVal MUST BE WORD-ALIGNED
267 int ypRegisterByYdx(u8 devYdx, Notification_funydx funInfo, const char *funcVal, YAPI_FUNCTION *fundesc);
268 // WARNING: funcVal MUST BE WORD-ALIGNED
269 int ypGetAttributesByYdx(u8 devYdx, u8 funYdx, yStrRef *serial, yStrRef *logicalName, yStrRef *funcId, yStrRef *funcName, Notification_funydx *funcInfo, char *funcVal);
270 void ypGetCategory(yBlkHdl hdl, char *name, yBlkHdl *entries);
271 int ypGetAttributes(yBlkHdl hdl, yStrRef *serial, yStrRef *funcId, yStrRef *funcName, Notification_funydx *funcInfo, char *funcVal);
272 int ypGetType(yBlkHdl hdl);
273 int ypGetBootDevHdl(const char *serial);
274 s16 ypFindBootloaders(yStrRef *serials, u16 maxSerials);
275 int decodeNetFuncValV2(const u8 *p, Notification_funydx *funInfo, char *funcVal);
276 
277 #ifdef __cplusplus
278 }
279 #endif
280 #endif
281 
282 
int ypGetFunctionInfo(YAPI_FUNCTION fundesc, char *serial, char *funcId, char *baseType, char *funcName, char *funcVal)
Definition: yhash.c:1866
yBlkHdl yWpListHead
Definition: yhash.c:84
int ypGetAttributes(yBlkHdl hdl, yStrRef *serial, yStrRef *funcId, yStrRef *funcName, Notification_funydx *funcInfo, char *funcVal)
Definition: yhash.c:1515
u16 port
Definition: yhash.h:192
yStrRef funcName
Definition: yhash.h:131
int wpMarkForUnregister(yStrRef serial)
Definition: yhash.c:919
int wpGetDeviceUrl(YAPI_DEVICE devdesc, char *roothubserial, char *request, int requestsize, int *neededsize)
Definition: yhash.c:1124
void yHashGetBuf(yHash yhash, u8 *destbuf, u16 bufsize)
Definition: yhash.c:342
void wpPreventUnregisterEx(void)
Definition: yhash.c:733
yBlkHdl entries
Definition: yhash.h:143
yHash invalid2
Definition: yhash.h:201
yUrlRef yHashUrlFromRef(yUrlRef urlref, const char *rootUrl)
Definition: yhash.c:454
int wpGetAllDevUsingHubUrl(yUrlRef hubUrl, yStrRef *buffer, int sizeInStrRef)
Definition: yhash.c:1072
Definition: yhash.h:175
yStrRef serialNum
Definition: yhash.h:122
int ypGetAttributesByYdx(u8 devYdx, u8 funYdx, yStrRef *serial, yStrRef *logicalName, yStrRef *funcId, yStrRef *funcName, Notification_funydx *funcInfo, char *funcVal)
Definition: yhash.c:1450
s16 yHash
Definition: ydef.h:212
int wpGetDevYdx(yStrRef serial)
Definition: yhash.c:968
yHash yHashPutBuf(const u8 *buf, u16 len)
Definition: yhash.c:312
s32 YAPI_FUNCTION
Definition: ydef.h:217
yHash yStrRef
Definition: ydef.h:214
yBlkHdl nextPtr
Definition: yhash.h:118
yHash yUrlRef
Definition: ydef.h:215
YAPI_DEVICE wpSearchEx(yStrRef strref)
Definition: yhash.c:988
int wpGetDeviceInfo(YAPI_DEVICE devdesc, u16 *deviceid, char *productname, char *serial, char *logicalname, u8 *beacon)
Definition: yhash.c:1220
yAsbUrlType
Definition: yhash.h:173
void wpAllowUnregisterEx(void)
Definition: yhash.c:741
yUrlRef yHashUrl(const char *host, const char *rootUrl, u8 testonly, char *errmsg)
Definition: yhash.c:474
yYellowPageArray ypArray
Definition: yhash.h:161
u16 hash
Definition: yhash.h:148
s16 ypFindBootloaders(yStrRef *serials, u16 maxSerials)
Definition: yhash.c:1964
yUrlRef wpGetDeviceUrlRef(YAPI_DEVICE devdesc)
Definition: yhash.c:1102
yUrlRef yHashUrlUSB(yHash serial)
Definition: yhash.c:637
#define HASH_BUF_SIZE
Definition: yhash.h:52
u16 yHashGetStrLen(yHash yhash)
Definition: yhash.c:377
void ypGetCategory(yBlkHdl hdl, char *name, yBlkHdl *entries)
Definition: yhash.c:1508
yStrRef name
Definition: yhash.h:142
int ypGetFunctionsEx(yStrRef categref, YAPI_DEVICE devdesc, YAPI_FUNCTION prevfundesc, YAPI_FUNCTION *buffer, int maxsize, int *neededsize)
Definition: yhash.c:1906
yHash yHashTestBuf(const u8 *buf, u16 len)
Definition: yhash.c:327
#define YOCTO_SERIAL_LEN
Definition: ydef.h:420
yBlkHdl nextPtr
Definition: yhash.h:156
yYellowPageCateg ypCateg
Definition: yhash.h:160
yStrRef serial
Definition: yhash.h:96
int ypGetBootDevHdl(const char *serial)
void yHashGetStr(yHash yhash, char *destbuf, u16 bufsize)
Definition: yhash.c:365
yBlkHdl yBlkListSeek(yBlkHdl hdl, u16 pos)
Definition: yhash.c:147
int ypRegisterByYdx(u8 devYdx, Notification_funydx funInfo, const char *funcVal, YAPI_FUNCTION *fundesc)
Definition: yhash.c:1395
u8 ydx
Definition: yhash.h:154
yStrRef serial
Definition: yhash.h:202
void wpGetLogicalName(yBlkHdl hdl, char *logicalName)
Definition: yhash.c:910
int ypRegister(yStrRef categ, yStrRef serial, yStrRef funcId, yStrRef funcName, int funClass, int funYdx, const char *funcVal)
Definition: yhash.c:1253
YAPI_DEVICE wpSearch(const char *device_str)
Definition: yhash.c:1014
yStrRef user
Definition: yhash.h:206
#define YOCTO_PUBVAL_SIZE
Definition: ydef.h:427
int ypGetFunctions(const char *class_str, YAPI_DEVICE devdesc, YAPI_FUNCTION prevfundesc, YAPI_FUNCTION *buffer, int maxsize, int *neededsize)
Definition: yhash.c:1763
int yHashSameHub(yUrlRef url_a, yUrlRef url_b)
Definition: yhash.c:619
#define YMAX_HUB_URL_DEEP
Definition: yhash.h:170
u16 yBlkHdl
Definition: ydef.h:213
yStrRef product
Definition: yhash.h:98
yBlkHdl yYpListHead
Definition: yhash.c:85
yAsbUrlType yHashGetUrlPort(yUrlRef urlref, char *url, u16 *port, yAsbUrlProto *proto, yStrRef *user, yStrRef *password)
Definition: yhash.c:579
int wpRegister(int devYdx, yStrRef serial, yStrRef logicalName, yStrRef productName, u16 productId, yUrlRef devUrl, s8 beacon)
Definition: yhash.c:783
Definition: yhash.h:187
yYellowPageEntry ypEntry
Definition: yhash.h:159
char * yHashGetStrPtr(yHash yhash)
Definition: yhash.c:401
YAPI_DEVICE wpSearchByNameHash(yStrRef strref)
Definition: yhash.c:1023
yStrRef wpGetAttribute(yBlkHdl hdl, yWPAttribute attridx)
Definition: yhash.c:880
yStrRef host
Definition: yhash.h:190
yHash yHashTestStr(const char *str)
Definition: yhash.c:333
yHash next
Definition: yhash.h:149
u8 blkId
Definition: yhash.h:155
yAsbUrlProto
Definition: yhash.h:179
Definition: yhash.h:174
yWPAttribute
Definition: yhash.h:76
u16 proto
Definition: yhash.h:205
yStrRef password
Definition: yhash.h:207
yBlkHdl nextPtr
Definition: yhash.h:95
yStrRef ip
Definition: yhash.h:195
yStrRef funcId
Definition: yhash.h:123
yBlkHdl nextPtr
Definition: yhash.h:111
yStrRef SerialRef
Definition: yhash.c:82
int decodeNetFuncValV2(const u8 *p, Notification_funydx *funInfo, char *funcVal)
Definition: yhash.c:2056
YAPI_FUNCTION ypSearch(const char *class_str, const char *func_str)
Definition: yhash.c:1603
yStrRef domaine
Definition: yhash.h:191
int ypGetType(yBlkHdl hdl)
Definition: yhash.c:1551
yUrlRef url
Definition: yhash.h:100
s32 YAPI_DEVICE
Definition: ydef.h:216
yBlkHdl nextPtr
Definition: yhash.h:141
void yHashInit(void)
Definition: yhash.c:189
yHash invalid
Definition: yhash.h:196
yUrlRef yHashUrlAPI(void)
Definition: yhash.c:650
yWhitePageEntry wpEntry
Definition: yhash.h:158
u16 yBlkListLength(yBlkHdl hdl)
Definition: yhash.c:136
void yHashFree(void)
Definition: yhash.c:240
yStrRef name
Definition: yhash.h:97
u16 wpEntryCount(void)
Definition: yhash.c:963
YAPI_DEVICE wpSearchByUrl(const char *host, const char *rootUrl)
Definition: yhash.c:1048
YAPI_FUNCTION hwId
Definition: yhash.h:129
yHash yHashPutStr(const char *str)
Definition: yhash.c:318
Notification_funydx funInfo
Definition: yhash.h:116
char SerialNumberStr[YOCTO_SERIAL_LEN]
Definition: yhash.c:80
void wpGetSerial(yBlkHdl hdl, char *serial)
Definition: yhash.c:901
yHash invalid1
Definition: yhash.h:200


yoctopuce_altimeter
Author(s): Anja Sheppard
autogenerated on Mon Jun 10 2019 15:49:10