ydef.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * $Id: ydef.h 29064 2017-11-02 16:13:37Z seb $
4  *
5  * Standard definitions common to all yoctopuce projects
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 YOCTO_DEF_H
41 #define YOCTO_DEF_H
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 
47 #if defined(_WIN32)
48 // Windows C compiler
49 #define WINDOWS_API
50 
51 #ifdef _WIN64
52 #define __64BITS__
53 #define __WIN64__
54 #else
55 #define __32BITS__
56 #endif
57 
58 #ifdef _MSC_VER
59 typedef unsigned char u8;
60 typedef signed char s8;
61 typedef unsigned short int u16;
62 typedef signed short int s16;
63 typedef unsigned long int u32;
64 typedef signed long int s32;
65 typedef unsigned long long u64;
66 typedef signed long long s64;
67 #define VARIABLE_SIZE
68 #define FMTs64 "lld"
69 #define FMTu64 "llu"
70 #define FMTx64 "llx"
71 
72 #else
73 
74 #ifdef __BORLANDC__
75 typedef unsigned __int8 u8;
76 typedef __int8 s8;
77 typedef unsigned __int16 u16;
78 typedef __int16 s16;
79 typedef unsigned __int32 u32;
80 typedef __int32 s32;
81 typedef unsigned __int64 u64;
82 typedef __int64 s64;
83 #else
84 typedef unsigned char u8;
85 typedef signed char s8;
86 typedef unsigned short int u16;
87 typedef signed short int s16;
88 typedef unsigned int u32;
89 typedef signed int s32;
90 typedef unsigned long long u64;
91 typedef signed long long s64;
92 #endif
93 
94 #define VARIABLE_SIZE 0
95 #define FMTs64 "lld"
96 #define FMTu64 "llu"
97 #define FMTx64 "llx"
98 
99 #endif
100 // end of WINDOWS_API
101 
102 
103 #elif defined(__C30__)
104 // Microchip C30
105 #define MICROCHIP_API
106 #define __16BITS__
107 
108 typedef unsigned char u8;
109 typedef signed char s8;
110 typedef unsigned short int u16;
111 typedef signed short int s16;
112 typedef unsigned long int u32;
113 typedef signed long int s32;
114 typedef unsigned long long u64;
115 typedef signed long long s64;
116 #define VARIABLE_SIZE 0
117 #define FMTs64 "lld"
118 #define FMTu64 "llu"
119 #define FMTx64 "llx"
120 // end of MICROCHIP_API
121 
122 #elif defined(__APPLE__)
123 #include <TargetConditionals.h>
124 
125 #if TARGET_IPHONE_SIMULATOR
126 //#warning IOS simulatore platform
127 #define IOS_API
128 #elif TARGET_OS_IPHONE
129 //#warning IOS platform
130 #define IOS_API
131 #elif TARGET_OS_MAC
132 #define OSX_API
133 
134 #if defined(__i386__)
135 #define __32BITS__
136 #elif defined(__x86_64__)
137 #define OSX_API
138 #define __64BITS__
139 #else
140 #error Unsupported MAC OS X architecture
141 #endif
142 
143 #else
144 #error Unsupported Apple target
145 #endif
146 
147 // Mac OS X C compiler
148 typedef unsigned char u8;
149 typedef signed char s8;
150 typedef unsigned short int u16;
151 typedef signed short int s16;
152 typedef unsigned int u32;
153 typedef signed int s32;
154 #ifdef __LP64__
155 typedef unsigned long u64;
156 typedef signed long s64;
157 #else
158 typedef unsigned long long u64;
159 typedef signed long long s64;
160 #endif
161 #define VARIABLE_SIZE 0
162 #define FMTs64 "ld"
163 #define FMTu64 "lu"
164 #define FMTx64 "lx"
165 #include <pthread.h>
166 #include <errno.h>
167 // end of OSX_API OR IOS_API
168 
169 
170 #elif defined(__linux__)
171 // gcc compiler on linux
172 #define LINUX_API
173 
174 #if defined(__i386__)
175 #define __32BITS__
176 #define FMTs64 "lld"
177 #define FMTu64 "llu"
178 #define FMTx64 "llx"
179 #elif defined(__x86_64__)
180 #define __64BITS__
181 #define FMTs64 "ld"
182 #define FMTu64 "lu"
183 #define FMTx64 "lx"
184 #else
185 #define __32BITS__
186 #define FMTs64 "lld"
187 #define FMTu64 "llu"
188 #define FMTx64 "llx"
189 #endif
190 
191 #include <stdint.h>
192 typedef uint8_t u8;
193 typedef int8_t s8;
194 typedef uint16_t u16;
195 typedef int16_t s16;
196 typedef uint32_t u32;
197 typedef int32_t s32;
198 typedef uint64_t u64;
199 typedef int64_t s64;
200 #define VARIABLE_SIZE 0
201 #include <pthread.h>
202 #include <errno.h>
203 
204 #else
205 #warning UNSUPPORTED ARCHITECTURE, please edit yocto_def.h !
206 #endif
207 // end of LINUX_API
208 
209 
210 typedef u32 yTime; /* measured in milliseconds */
211 typedef u32 u31; /* shorter unsigned integers */
212 typedef s16 yHash;
213 typedef u16 yBlkHdl; /* (yHash << 1) + [0,1] */
214 typedef yHash yStrRef;
215 typedef yHash yUrlRef;
216 typedef s32 YAPI_DEVICE; /* yStrRef of serial number */
217 typedef s32 YAPI_FUNCTION; /* yStrRef of serial + (ystrRef of funcId << 16) */
218 
219 #define INVALID_HASH_IDX -1 /* To use for yHash, yStrRef, yApiRef types */
220 #define INVALID_BLK_HDL 0 /* To use for yBlkHdl type */
221 
222 #ifdef MICROCHIP_API
223 typedef u8 YSOCKET;
224 typedef s8 YYSBIO;
225 typedef s8 YTRNKIO;
226 #else
227 // we have hardcoded the type of SOCKET to
228 // prevent to mess up with user own code
229 #if defined(WINDOWS_API)
230 #if defined(__64BITS__)
231 typedef u64 YSOCKET;
232 #else
233 typedef u32 YSOCKET;
234 #endif
235 #else
236 typedef int YSOCKET;
237 #endif
238 typedef s32 YUSBIO;
239 typedef s32 YUSBDEV;
240 #endif
241 
242 #define YIO_INVALID 0
243 #define YIO_USB 1
244 #define YIO_TCP 2
245 #define YIO_YSB 3
246 #define YIO_TRUNK 4
247 #define YIO_WS 5
248 
249 #define YIO_DEFAULT_USB_TIMEOUT 2000u
250 #define YIO_DEFAULT_TCP_TIMEOUT 20000u
251 #define YIO_1_MINUTE_TCP_TIMEOUT 60000u
252 #define YIO_10_MINUTES_TCP_TIMEOUT 600000u
253 #define YIO_IDLE_TCP_TIMEOUT 5000u
254 
255 #ifdef MICROCHIP_API
256 // same as yhub devhdl
257 typedef s16 YIOHDL;
258 #else
259 // make sure this union is no more than 8 bytes, YIOHDL is allocated used in all foreign APIs
260 typedef void *YIOHDL;
261 #endif
262 
263 #define YIOHDL_SIZE (sizeof(YIOHDL))
264 
265 #define INVALID_YHANDLE (-1)
266 
267 #define S8(x) ((s8)(x))
268 #define S16(x) ((s16)(x))
269 #define S32(x) ((s32)(x))
270 #define S64(x) ((s64)(x))
271 #define U8(x) ((u8)(x))
272 #define U16(x) ((u16)(x))
273 #define U32(x) ((u32)(x))
274 #define U64(x) ((u64)(x))
275 
276 #define U8ADDR(x) ((u8 *)&(x))
277 #define U16ADDR(x) ((u16 *)&(x))
278 
279 #define ADDRESSOF(x) (&(x))
280 #define PTRVAL(x) (*(x))
281 
282 #if defined(__PIC24FJ256DA206__)
283 #define _FAR __eds__
284 #else
285 #define _FAR
286 #endif
287 
288 #if defined(MICROCHIP_API) || defined(VIRTUAL_HUB)
289 #define YAPI_IN_YDEVICE
290 #define YSTATIC
291 #else
292 #define YSTATIC static
293 #endif
294 
295 
296 //#define DEBUG_CRITICAL_SECTION
297 
298 #ifdef DEBUG_CRITICAL_SECTION
299 
300 #include <winsock2.h>
301 #include <ws2tcpip.h>
302 #include <WinBase.h>
303 
304 typedef enum {
305  YCS_UNALLOCATED=0,
306  YCS_ALLOCATED=1,
307  YCS_DELETED=2
308 } YCS_STATE;
309 
310 typedef enum {
311  YCS_NONE=0,
312  YCS_INIT=1,
313  YCS_LOCK=2,
314  YCS_LOCKTRY=3,
315  YCS_RELEASE=4,
316  YCS_DELETE=5
317 } YCS_ACTION;
318 
319 typedef struct {
320  int thread;
321  const char* fileid;
322  int lineno;
323  YCS_ACTION action;
324 } YCS_LOC;
325 
326 #define YCS_NB_TRACE 5
327 
328 typedef struct {
329  volatile u32 no;
330  volatile YCS_STATE state;
331  volatile int lock;
332 #if defined(WINDOWS_API)
333  CRITICAL_SECTION cs;
334 #else
335  pthread_mutex_t cs;
336 #endif
337  YCS_LOC last_actions[YCS_NB_TRACE];
339 
341 
342 void yInitDebugCS();
343 void yFreeDebugCS();
344 void yDbgInitializeCriticalSection(const char* fileid, int lineno, yCRITICAL_SECTION *cs);
345 void yDbgEnterCriticalSection(const char* fileid, int lineno, yCRITICAL_SECTION *cs);
346 int yDbgTryEnterCriticalSection(const char* fileid, int lineno, yCRITICAL_SECTION *cs);
347 void yDbgLeaveCriticalSection(const char* fileid, int lineno, yCRITICAL_SECTION *cs);
348 void yDbgDeleteCriticalSection(const char* fileid, int lineno, yCRITICAL_SECTION *cs);
349 
350 #define yInitializeCriticalSection(cs) yDbgInitializeCriticalSection(__FILE_ID__,__LINE__,cs)
351 #define yEnterCriticalSection(cs) yDbgEnterCriticalSection(__FILE_ID__,__LINE__,cs)
352 #define yTryEnterCriticalSection(cs) yDbgTryEnterCriticalSection(__FILE_ID__,__LINE__,cs)
353 #define yLeaveCriticalSection(cs) yDbgLeaveCriticalSection(__FILE_ID__,__LINE__,cs)
354 #define yDeleteCriticalSection(cs) yDbgDeleteCriticalSection(__FILE_ID__,__LINE__,cs)
355 
356 #else
357 #if defined(MICROCHIP_API)
358 #define yCRITICAL_SECTION u8
359 #define yInitializeCriticalSection(cs)
360 #define yEnterCriticalSection(cs)
361 #define yTryEnterCriticalSection(cs) 1
362 #define yLeaveCriticalSection(cs)
363 #define yDeleteCriticalSection(cs)
364 #else
365 
366 typedef void* yCRITICAL_SECTION;
367 void yInitializeCriticalSection(yCRITICAL_SECTION *cs);
368 void yEnterCriticalSection(yCRITICAL_SECTION *cs);
369 int yTryEnterCriticalSection(yCRITICAL_SECTION *cs);
370 void yLeaveCriticalSection(yCRITICAL_SECTION *cs);
371 void yDeleteCriticalSection(yCRITICAL_SECTION *cs);
372 #endif
373 #endif
374 
375 
376 typedef enum {
377  YAPI_SUCCESS = 0, // everything worked all right
378  YAPI_NOT_INITIALIZED = -1, // call yInitAPI() first !
379  YAPI_INVALID_ARGUMENT = -2, // one of the arguments passed to the function is invalid
380  YAPI_NOT_SUPPORTED = -3, // the operation attempted is (currently) not supported
381  YAPI_DEVICE_NOT_FOUND = -4, // the requested device is not reachable
382  YAPI_VERSION_MISMATCH = -5, // the device firmware is incompatible with this API version
383  YAPI_DEVICE_BUSY = -6, // the device is busy with another task and cannot answer
384  YAPI_TIMEOUT = -7, // the device took too long to provide an answer
385  YAPI_IO_ERROR = -8, // there was an I/O problem while talking to the device
386  YAPI_NO_MORE_DATA = -9, // there is no more data to read from
387  YAPI_EXHAUSTED = -10, // you have run out of a limited resource, check the documentation
388  YAPI_DOUBLE_ACCES = -11, // you have two process that try to access to the same device
389  YAPI_UNAUTHORIZED = -12, // unauthorized access to password-protected device
390  YAPI_RTC_NOT_READY = -13, // real-time clock has not been initialized (or time was lost)
391  YAPI_FILE_NOT_FOUND = -14 // the file is not found
392 } YRETCODE;
393 
394 #define YISERR(retcode) ((retcode) < 0)
395 
396 // Yoctopuce arbitrary constants
397 #define YOCTO_API_VERSION_STR "1.10"
398 #define YOCTO_API_VERSION_BCD 0x0110
399 #include "yversion.h"
400 #define YOCTO_DEFAULT_PORT 4444
401 #define YOCTO_VXI_PORT 4445
402 #define YOCTO_VENDORID 0x24e0
403 #define YOCTO_DEVID_FACTORYBOOT 1
404 #define YOCTO_DEVID_BOOTLOADER 2
405 #define YOCTO_DEVID_HIGHEST 0xfefe
406 #define YAPI_HASH_BUF_SIZE 28
407 #define YOCTO_CALIB_TYPE_OFS 30
408 
409 // Other special ports
410 #define PORTMAPPER_PORT 111
411 
412 // Known baseclases
413 #define YOCTO_AKA_YFUNCTION 0
414 #define YOCTO_AKA_YSENSOR 1
415 #define YOCTO_N_BASECLASSES 2
416 
417 // Standard buffer sizes
418 #define YOCTO_ERRMSG_LEN 256
419 #define YOCTO_MANUFACTURER_LEN 20
420 #define YOCTO_SERIAL_LEN 20
421 #define YOCTO_BASE_SERIAL_LEN 8
422 #define YOCTO_PRODUCTNAME_LEN 28
423 #define YOCTO_FIRMWARE_LEN 22
424 #define YOCTO_LOGICAL_LEN 20
425 #define YOCTO_FUNCTION_LEN 20
426 #define YOCTO_UNIT_LEN 10
427 #define YOCTO_PUBVAL_SIZE 6 // Size of the data (can be non null terminated)
428 #define YOCTO_PUBVAL_LEN 16 // Temporary storage, >= YOCTO_PUBVAL_SIZE+2
429 #define YOCTO_REPORT_LEN 9 // Max size of a timed report, including isAvg flag
430 #define YOCTO_SERIAL_SEED_SIZE (YOCTO_SERIAL_LEN - YOCTO_BASE_SERIAL_LEN - 1)
431 
432 // websocket key from specification v13
433 #define YOCTO_WEBSOCKET_MAGIC "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
434 #define YOCTO_WEBSOCKET_MAGIC_LEN 36
435 
436 
437 // firmware description
438 typedef union {
439  u8 asBytes[YOCTO_FIRMWARE_LEN];
440  struct {
441  char buildVersion[YOCTO_FIRMWARE_LEN-2];
443  } data;
444 } yFirmwareSt;
445 
446 // device description
447 typedef struct {
448  u16 vendorid;
449  u16 deviceid;
452  char manufacturer[YOCTO_MANUFACTURER_LEN];
453  char productname[YOCTO_PRODUCTNAME_LEN];
454  char serial[YOCTO_SERIAL_LEN];
455  char logicalname[YOCTO_LOGICAL_LEN];
456  char firmware[YOCTO_FIRMWARE_LEN];
457  u8 beacon;
458 } yDeviceSt;
459 
460 // definitions for USB protocl
461 
462 #ifndef C30
463 #define Nop()
464 #pragma pack(push,1)
465 #endif
466 
467 #define USB_PKT_SIZE 64
468 #define YPKT_USB_VERSION_NO_RETRY_BCD 0x0207
469 #define YPKT_USB_VERSION_BCD 0x0208
470 #define TO_SAFE_U16(safe,unsafe) {(safe).low = (unsafe)&0xff; (safe).high=(unsafe)>>8;}
471 #define FROM_SAFE_U16(safe,unsafe) {(unsafe) = (safe).low |((u16)((safe).high)<<8);}
472 
473 typedef struct {
474  u8 low;
475  u8 high;
476 } SAFE_U16;
477 
478 #ifndef CPU_BIG_ENDIAN
479 
480 #define YPKTNOMSK (0x7)
481 typedef struct {
482  u8 pktno : 3;
483  u8 stream : 5;
484  u8 pkt : 2;
485  u8 size : 6;
486 } YSTREAM_Head;
487 #else
488 #define YPKTNOMSK (0x7)
489 typedef struct {
490  u8 stream : 5;
491  u8 pktno : 3;
492  u8 size : 6;
493  u8 pkt : 2;
494 } YSTREAM_Head;
495 #endif
496 #define YPKT_STREAM 0
497 #define YPKT_CONF 1
498 
499 //
500 // YPKT_CONF packets format
501 //
502 
503 #define USB_CONF_RESET 0
504 #define USB_CONF_START 1
505 
506 typedef union{
507  struct{
509  u8 ok;
512  } reset;
513  struct{
514  u8 nbifaces;
516  } start;
517 } USB_Conf_Pkt;
518 
519 //
520 // YPKT_STREAM packets can encompass multiple streams
521 //
522 
523 #define YSTREAM_EMPTY 0
524 #define YSTREAM_TCP 1
525 #define YSTREAM_TCP_CLOSE 2
526 #define YSTREAM_NOTICE 3
527 #define YSTREAM_REPORT 4
528 #define YSTREAM_META 5
529 #define YSTREAM_REPORT_V2 6
530 #define YSTREAM_NOTICE_V2 7
531 #define YSTREAM_TCP_NOTIF 8
532 #define YSTREAM_TCP_ASYNCCLOSE 9
533 
534 // Data in YSTREAM_NOTICE stream
535 
536 #define NOTIFY_1STBYTE_MAXTINY 63
537 #define NOTIFY_1STBYTE_MINSMALL 128
538 
539 #define NOTIFY_PKT_NAME 0
540 #define NOTIFY_PKT_PRODNAME 1
541 #define NOTIFY_PKT_CHILD 2
542 #define NOTIFY_PKT_FIRMWARE 3
543 #define NOTIFY_PKT_FUNCNAME 4
544 #define NOTIFY_PKT_FUNCVAL 5
545 #define NOTIFY_PKT_STREAMREADY 6
546 #define NOTIFY_PKT_LOG 7
547 #define NOTIFY_PKT_FUNCNAMEYDX 8
548 #define NOTIFY_PKT_PRODINFO 9
549 
550 #define NOTIFY_V2_LEGACY 0 // unused (reserved for compatibility with legacy notifications)
551 #define NOTIFY_V2_6RAWBYTES 1 // largest type: data is always 6 bytes
552 #define NOTIFY_V2_TYPEDDATA 2 // other types: first data byte holds the decoding format
553 #define NOTIFY_V2_FLUSHGROUP 3 // no data associated
554 // Higher values not allowed (Notification_funydx.raw must stay <= 63)
555 
556 // New types of generic notifications
557 #define PUBVAL_LEGACY 0 // 0-6 ASCII characters (normally sent as YSTREAM_NOTICE)
558 #define PUBVAL_1RAWBYTE 1 // 1 raw byte (=2 characters)
559 #define PUBVAL_2RAWBYTES 2 // 2 raw bytes (=4 characters)
560 #define PUBVAL_3RAWBYTES 3 // 3 raw bytes (=6 characters)
561 #define PUBVAL_4RAWBYTES 4 // 4 raw bytes (=8 characters)
562 #define PUBVAL_5RAWBYTES 5 // 5 raw bytes (=10 characters)
563 #define PUBVAL_6RAWBYTES 6 // 6 hex bytes (=12 characters) (sent as V2_6RAWBYTES)
564 #define PUBVAL_C_LONG 7 // 32-bit C signed integer
565 #define PUBVAL_C_FLOAT 8 // 32-bit C float
566 #define PUBVAL_YOCTO_FLOAT_E3 9 // 32-bit Yocto fixed-point format (e-3)
567 
568 typedef struct{
569  char serial[YOCTO_SERIAL_LEN];
570  u8 type;
572 
573 #ifdef _MSC_VER
574 #pragma warning( push )
575 #pragma warning( disable : 4200 )
576 #endif
577 
578 typedef union {
579  // This definition must match packet generated in yoctoPacket.c
580  u8 raw; // originally shifted by NOTIFY_1STBYTE_MINSMALL for smallnot
581  struct {
582 #ifndef CPU_BIG_ENDIAN
583  u8 funydx:4;
584  u8 typeV2:3; // note: high bit MUST stay zero to ensure raw value <= 63 for tiny notifications
585  u8 isSmall:1;
586 #else
587  u8 isSmall:1;
588  u8 typeV2:3;
589  u8 funydx:4;
590 #endif
591  } v2;
593 
594 typedef struct{
595  // This definition must match packet generated in yoctoPacket.c
597  char pubval[VARIABLE_SIZE]; // deduce actual size from YSTREAM_head
599 
600 typedef struct{
601  // This definition must match packet generated in yoctoPacket.c
603  u8 devydx;
604  char pubval[VARIABLE_SIZE]; // deduce actual size from YSTREAM_head
606 
607 #ifdef _MSC_VER
608 #pragma warning( pop )
609 #endif
610 
611 typedef struct{
612  char name[YOCTO_LOGICAL_LEN];
613  u8 beacon;
615 
617 
618 typedef struct {
622 
623 typedef struct {
624  char childserial[YOCTO_SERIAL_LEN];
625  u8 onoff;
626  u8 devydx;
628 
629 typedef struct {
630  char firmware[YOCTO_FIRMWARE_LEN];
634 
635 typedef struct {
636  char funcid[YOCTO_FUNCTION_LEN];
637  char funcname[YOCTO_LOGICAL_LEN];
639 
640 typedef struct {
641  char funcid[YOCTO_FUNCTION_LEN];
642  char pubval[YOCTO_PUBVAL_SIZE];
644 
645 typedef struct {
646  char funcidshort[YOCTO_FUNCTION_LEN-1];
647  u8 funclass; // 0..YOCTO_N_BASECLASSES-1
648  char funcname[YOCTO_LOGICAL_LEN];
649  u8 funydx;
651 
652 typedef union {
656  struct {
658  union {
660  Notification_product productname;
667  u8 raw;
668  };
669  };
671 
672 #define NOTIFY_NETPKT_NAME '0'
673 #define NOTIFY_NETPKT_PRODNAME '1'
674 #define NOTIFY_NETPKT_CHILD '2'
675 #define NOTIFY_NETPKT_FIRMWARE '3'
676 #define NOTIFY_NETPKT_FUNCNAME '4'
677 #define NOTIFY_NETPKT_FUNCVAL '5'
678 #define NOTIFY_NETPKT_STREAMREADY '6'
679 #define NOTIFY_NETPKT_LOG '7'
680 #define NOTIFY_NETPKT_FUNCNAMEYDX '8'
681 #define NOTIFY_NETPKT_PRODINFO '9'
682 #define NOTIFY_NETPKT_FLUSHV2YDX 't'
683 #define NOTIFY_NETPKT_FUNCV2YDX 'u'
684 #define NOTIFY_NETPKT_TIMEV2YDX 'v'
685 #define NOTIFY_NETPKT_DEVLOGYDX 'w'
686 #define NOTIFY_NETPKT_TIMEVALYDX 'x'
687 #define NOTIFY_NETPKT_FUNCVALYDX 'y'
688 #define NOTIFY_NETPKT_TIMEAVGYDX 'z'
689 #define NOTIFY_NETPKT_NOT_SYNC '@'
690 
691 #define NOTIFY_NETPKT_VERSION "01"
692 #define NOTIFY_NETPKT_START "YN01"
693 #define NOTIFY_NETPKT_START_LEN 4
694 #define NOTIFY_NETPKT_STOP '\n'
695 #define NOTIFY_NETPKT_SEP ','
696 #define NOTIFY_NETPKT_MAX_LEN (NOTIFY_NETPKT_START_LEN+1+YOCTO_SERIAL_LEN+1+YOCTO_FUNCTION_LEN+1+YOCTO_LOGICAL_LEN+1+1)
697 
698 #define NOTIFY_PKT_NAME_LEN (sizeof(Notification_header) + sizeof(Notification_name))
699 #define NOTIFY_PKT_PRODNAME_LEN (sizeof(Notification_header) + sizeof(Notification_product))
700 #define NOTIFY_PKT_PRODINFO_LEN (sizeof(Notification_header) + sizeof(Notification_prodinfo))
701 #define NOTIFY_PKT_CHILD_LEN (sizeof(Notification_header) + sizeof(Notification_child))
702 #define NOTIFY_PKT_FIRMWARE_LEN (sizeof(Notification_header) + sizeof(Notification_firmware))
703 #define NOTIFY_PKT_STREAMREADY_LEN (sizeof(Notification_header) + sizeof(u8))
704 #define NOTIFY_PKT_LOG_LEN (sizeof(Notification_header) + sizeof(u8))
705 #define NOTIFY_PKT_FUNCNAME_LEN (sizeof(Notification_header) + sizeof(Notification_funcname))
706 #define NOTIFY_PKT_FUNCVAL_LEN (sizeof(Notification_header) + sizeof(Notification_funcval))
707 #define NOTIFY_PKT_FUNCNAMEYDX_LEN (sizeof(Notification_header) + sizeof(Notification_funcnameydx))
708 #define NOTIFY_PKT_TINYVAL_MAXLEN (sizeof(Notification_tiny) + YOCTO_PUBVAL_SIZE)
709 
710 // Data in YSTREAM_REPORT stream
711 //
712 // Reports are always first in a packet, which
713 // makes it easy to filter packets that contain
714 // reports only, and interpret them as fixed offsets
715 
716 typedef struct {
717  union {
718  struct {
719 #ifndef CPU_BIG_ENDIAN
720  u8 funYdx:4; // (LOWEST NIBBLE) function index on device, 0xf==timestamp
721  u8 extraLen:3; // Number of extra data bytes in addition to first one
722  u8 isAvg:1; // (HIGHEST BIT) 0:one immediate value (1-4 bytes), 1:min/avg/max (2+4+2 bytes)
723 #else
724  u8 isAvg:1; // (HIGHEST BIT) 0:one immediate value (1-4 bytes), 1:min/avg/max (2+4+2 bytes)
725  u8 extraLen:3; // Number of extra data bytes in addition to first one
726  u8 funYdx:4; // (LOWEST NIBBLE) function index on device, 0xf==timestamp
727 #endif
728  };
729  u8 head;
730  };
731  u8 data[1]; // Payload itself (numbers in little-endian format)
733 
734 typedef struct {
735  union {
736  struct {
737 #ifndef CPU_BIG_ENDIAN
738  u8 funYdx:4; // (LOWEST NIBBLE) function index on device, 0xf==timestamp
739  u8 extraLen:4; // Number of extra data bytes in addition to data[0]
740 #else
741  u8 extraLen:4; // Number of extra data bytes in addition to data[0]
742  u8 funYdx:4; // (LOWEST NIBBLE) function index on device, 0xf==timestamp
743 #endif
744  };
745  u8 head;
746  };
747  union {
748  // When extraLen >= 4 && funYdx != 0xf : first data byte describes the payload
749  struct {
750 #ifndef CPU_BIG_ENDIAN
751  u8 avgExtraLen:2; // Number of extra bytes in the first value (average value, signed MeasureVal)
752  u8 minDiffExtraLen:2; // Number of extra bytes to encode the 2nd value (avg - min, always > 0)
753  u8 maxDiffExtraLen:2; // Number of extra bytes to encode the 3rd value (max - avg, always > 0)
754  u8 reserved:2; // unused, currently set to 0
755 #else
756  u8 reserved:2; // unused, currently set to 0
757  u8 maxDiffExtraLen:2; // Number of extra bytes to encode the 3rd value (max - avg)
758  u8 minDiffExtraLen:2; // Number of extra bytes to encode the 2nd value (avg - min)
759  u8 avgExtraLen:2; // Number of extra bytes in the first value (average)
760 #endif
761  };
762  // When extraLen <= 3 (up to 4 bytes of data): live report value (1-4 bytes)
763  u8 data[1]; // Payload itself (numbers in little-endian format)
764  };
766 
767 // data format in USB_Report_Pkt_V2:
768 //
769 
770 
771 #define MAX_ASYNC_TCPCHAN 4
772 
773 
774 // Data in YSTREAM_META stream
775 
776 #define USB_META_UTCTIME 1
777 #define USB_META_DLFLUSH 2
778 #define USB_META_ACK_D2H_PACKET 3
779 #define USB_META_WS_ANNOUNCE 4
780 #define USB_META_WS_AUTHENTICATION 5
781 #define USB_META_WS_ERROR 6
782 #define USB_META_ACK_UPLOAD 7
783 
784 #define USB_META_UTCTIME_SIZE 5u
785 #define USB_META_DLFLUSH_SIZE 1u
786 #define USB_META_ACK_D2H_PACKET_SIZE 2u
787 #define USB_META_WS_ANNOUNCE_SIZE (8 + YOCTO_SERIAL_LEN)
788 #define USB_META_WS_AUTHENTICATION_SIZE 28u
789 #define USB_META_WS_ERROR_SIZE 4u
790 #define USB_META_ACK_UPLOAD_SIZE 6u
791 
792 #define USB_META_WS_PROTO_V1 1 // adding authentication support
793 #define USB_META_WS_PROTO_V2 2 // adding API packets throttling
794 
795 #define USB_META_WS_AUTH_FLAGS_VALID 1 // set it if the sha1 and nonce are pertinent
796 #define USB_META_WS_AUTH_FLAGS_RW 2 // set it if RW acces are granted
797 
798 typedef union {
799  struct {
800  u8 metaType; // =USB_META_UTCTIME
801  u8 unixTime[4]; // actually a DWORD in little-endian format
802  } utcTime;
803  struct {
804  u8 metaType; // =USB_META_DLFLUSH (flush datalogger)
805  } dlFlush;
806  struct {
807  u8 metaType; // =USB_META_ACK_D2H_PACKET (ack last device to host packet)
808  u8 pktno; // = last pktno that the host has received
809  } pktAck;
810  struct {
811  u8 metaType; // =USB_META_WS_ANNOUNCE (ack last device to host packet)
812  u8 version; // the version of the authentication
813  u16 maxtcpws; // maximum TCP window size, in multiples of 16 bytes
814  u32 nonce; // nonce append to password (in capital hex)
815  char serial[YOCTO_SERIAL_LEN];
816  } announce;
817  struct {
818  u8 metaType; // =USB_META_WS_AUTHENTICATION (authenticate trafic)
819  u8 version; // the version of the authentication
820  u16 flags; // reserved bits
821  u32 nonce; // nonce append to password (in capital hex)
822  u8 sha1[20]; // sha1 signature
823  } auth;
824  struct {
825  u8 metaType; // =USB_META_WS_ANNOUNCE (ack last device to host packet)
826  u8 reserved; // reserved (must be 0)
827  u16 htmlcode; // HTML error code
828  } error;
829  struct {
830  u8 metaType; // =USB_META_ACK_UPLOAD (ack upload progress every KB)
831  u8 tcpchan; // TCP channel index (as of proto v2, only available on tcpchan 0)
832  u8 totalBytes[4]; // actually a DWORD in little-endian format, number of bytes received so far
833  } uploadAck;
834 } USB_Meta_Pkt;
835 
836 
837 
838 typedef union {
839  struct {
840 #ifdef CPU_BIG_ENDIAN
841  u8 stream : 5; // Encapsulated protocol
842  u8 tcpchan : 3; // Encapsulated TCP subchannel
843 #else
844  u8 tcpchan : 3; // Encapsulated TCP subchannel
845  u8 stream : 5; // Encapsulated protocol
846 #endif
847  };
848  u8 encaps;
849 } WSStreamHead;
850 
851 
852 
853 
854 //
855 // SSDP global definitions for hubs
856 //
857 
858 #define YSSDP_PORT 1900
859 #define YSSDP_MCAST_ADDR_STR "239.255.255.250"
860 #define YSSDP_MCAST_ADDR (0xFAFFFFEF)
861 #define YSSDP_URN_YOCTOPUCE "urn:yoctopuce-com:device:hub:1"
862 
863 // prototype of the async request completion callback
864 typedef void (*yapiRequestAsyncCallback)(void *context, const u8 *result, u32 resultlen, int retcode, const char *errmsg);
865 // prototype of the request progress callback
866 typedef void (*yapiRequestProgressCallback)(void *context, u32 acked, u32 totalbytes);
867 
868 
869 
870 //
871 // PROG packets are only used in bootloader (USB DeviceID=0001/0002)
872 //
873 
874 #define PROG_NOP 0 // nothing to do
875 #define PROG_REBOOT 1 // reset the device
876 #define PROG_ERASE 2 // erase completely the device
877 #define PROG_PROG 3 // program the device
878 #define PROG_VERIF 4 // program the device
879 #define PROG_INFO 5 // get device info
880 #define PROG_INFO_EXT 6 // get extended device info (flash bootloader only)
881 
882 #define MAX_BYTE_IN_PACKET (60)
883 #define MAX_INSTR_IN_PACKET (MAX_BYTE_IN_PACKET/3)
884 
885 #define ERASE_BLOCK_SIZE_INSTR 512 // the minimal erase size in nb instr
886 #define PROGRAM_BLOCK_SIZE_INSTR 64 // the minimal program size in nb instr
887 //define some addresses in bytes too
888 #define ERASE_BLOCK_SIZE_BADDR (ERASE_BLOCK_SIZE_INSTR*2)
889 #define PROGRAM_BLOCK_SIZE_BADDR (PROGRAM_BLOCK_SIZE_INSTR*2)
890 
891 
892 typedef union {
893  u8 raw[64];
894  u16 words[32];
895  struct {
896 #ifndef CPU_BIG_ENDIAN
897  u8 size : 5;
898  u8 type : 3;
899 #else
900  u8 type : 3;
901  u8 size : 5;
902 #endif
906  } pkt;
907  struct {
908 #ifndef CPU_BIG_ENDIAN
909  u8 size : 5;
910  u8 type : 3;
911 #else
912  u8 type : 3;
913  u8 size : 5;
914 #endif
915  u8 pad;
917  u16 devidl;
918  u16 devidh;
924  } pktinfo;
925  struct {
926 #ifndef CPU_BIG_ENDIAN
927  u8 size : 5;
928  u8 type : 3;
929 #else
930  u8 type : 3;
931  u8 size : 5;
932 #endif
934 #ifndef CPU_BIG_ENDIAN
935  u16 pageno : 14;
936  u16 dwordpos_hi : 2;
937 #else
938  u8 pageno_lo;
939  u8 misc_hi;
940 #endif
941  union {
942  u16 npages; // for PROG_ERASE
943  u16 btsign; // for PROG_REBOOT
944  u8 data[MAX_BYTE_IN_PACKET]; // for PROG_PROG
945  } opt;
946  } pkt_ext;
947  struct {
948 #ifndef CPU_BIG_ENDIAN
949  u8 size : 5;
950  u8 type : 3;
951 #else
952  u8 type : 3;
953  u8 size : 5;
954 #endif
956  u16 pr_blk_size;
957  u16 devidl;
958  u16 devidh;
959  u32 settings_addr;
960  u32 last_addr;
961  u32 config_start;
962  u32 config_stop;
963  u16 er_blk_size;
969  } pktinfo_ext;
971 
972 #ifndef CPU_BIG_ENDIAN
973 #define SET_PROG_POS_PAGENO(PKT_EXT, PAGENO, POS) {\
974  (PKT_EXT).dwordpos_lo = (POS) & 0xff;\
975  (PKT_EXT).dwordpos_hi = ((POS) >> 8) & 3;\
976  (PKT_EXT).pageno = (PAGENO) & 0x3fff;}
977 #define GET_PROG_POS_PAGENO(PKT_EXT, PAGENO, POS) {\
978  POS = (PKT_EXT).dwordpos_lo + ((u32)(PKT_EXT).dwordpos_hi <<8);\
979  PAGENO = (PKT_EXT).pageno;}
980 
981 #define INTEL_U16(NUM) (NUM)
982 #define INTEL_U32(NUM) (NUM)
983 #else
984 #define SET_PROG_POS_PAGENO(PKT_EXT, PAGENO, POS) {\
985  (PKT_EXT).dwordpos_lo = (POS) & 0xff;\
986  (PKT_EXT).pageno_lo = (PAGENO) & 0xff;\
987  (PKT_EXT).misc_hi = (((PAGENO) >>8) & 0x3f)+ (((POS) & 0x300) >>2) ;}
988 #define GET_PROG_POS_PAGENO(PKT_EXT, PAGENO, POS) {\
989  POS = (PKT_EXT).dwordpos_lo + (((u16)(PKT_EXT).misc_hi << 2) & 0x300);\
990  PAGENO = (PKT_EXT).pageno_lo + (((u16)(PKT_EXT).misc_hi & 0x3f) << 8);}
991 #define INTEL_U16(NUM) ((((NUM) & 0xff00) >> 8) | (((NUM)&0xff) << 8))
992 #define INTEL_U32(NUM) ((((NUM) >> 24) & 0xff) | (((NUM) << 8) & 0xff0000) | (((NUM) >> 8) & 0xff00) | (((NUM) << 24) & 0xff000000 ))
993 
994 #endif
995 
996 
997 
998 #define START_APPLICATION_SIGN 0
999 #define START_BOOTLOADER_SIGN ('b'| ('T'<<8))
1000 #define START_AUTOFLASHER_SIGN ('b'| ('F'<<8))
1001 
1002 
1003 typedef union {
1004  u8 data[USB_PKT_SIZE];
1005  u16 data16[USB_PKT_SIZE/2];
1006  u32 data32[USB_PKT_SIZE/4];
1009  struct{
1012  } confpkt;
1013 } USB_Packet;
1014 
1015 #ifndef C30
1016 #pragma pack(pop)
1017 #endif
1018 
1019 //device indentifications PIC24FJ256DA210 family
1020 #define FAMILY_PIC24FJ256DA210 0X41
1021 #define PIC24FJ128DA206 0x08
1022 #define PIC24FJ128DA106 0x09
1023 #define PIC24FJ128DA210 0x0A
1024 #define PIC24FJ128DA110 0x0B
1025 #define PIC24FJ256DA206 0x0C
1026 #define PIC24FJ256DA106 0x0D
1027 #define PIC24FJ256DA210 0x0E
1028 #define PIC24FJ256DA110 0x0F
1029 
1030 //device indentifications PIC24FJ64GB004 family
1031 #define FAMILY_PIC24FJ64GB004 0x42
1032 #define PIC24FJ32GB002 0x03
1033 #define PIC24FJ64GB002 0x07
1034 #define PIC24FJ32GB004 0x0B
1035 #define PIC24FJ64GB004 0x0F
1036 
1037 // Spansion Flash JEDEC id
1038 #define JEDEC_SPANSION_4MB 0x16
1039 #define JEDEC_SPANSION_8MB 0x17
1040 
1041 #define YESC (27u)
1042 
1043 #ifdef __cplusplus
1044 }
1045 #endif
1046 
1047 #endif
SAFE_U16 deviceid
Definition: ydef.h:620
u8 ifaceno
Definition: ydef.h:510
u32 u31
Definition: ydef.h:211
void * yCRITICAL_SECTION
Definition: ydef.h:366
Notification_child childserial
Definition: ydef.h:662
s16 yHash
Definition: ydef.h:212
ROSCPP_DECL void start()
void * YIOHDL
Definition: ydef.h:260
void yInitializeCriticalSection(yCRITICAL_SECTION *cs)
Definition: ythread.c:629
s32 YAPI_FUNCTION
Definition: ydef.h:217
yHash yStrRef
Definition: ydef.h:214
u16 first_code_page
Definition: ydef.h:967
#define YOCTO_PRODUCTNAME_LEN
Definition: ydef.h:422
yHash yUrlRef
Definition: ydef.h:215
SAFE_U16 api
Definition: ydef.h:508
u8 ack_delay
Definition: ydef.h:515
u16 first_yfs3_page
Definition: ydef.h:968
void(* yapiRequestProgressCallback)(void *context, u32 acked, u32 totalbytes)
Definition: ydef.h:866
u16 devidl
Definition: ydef.h:917
u32 settings_addr
Definition: ydef.h:919
#define YOCTO_FIRMWARE_LEN
Definition: ydef.h:423
SAFE_U16 vendorid
Definition: ydef.h:631
Notification_prodinfo productinfo
Definition: ydef.h:661
u16 npages
Definition: ydef.h:942
#define YOCTO_SERIAL_LEN
Definition: ydef.h:420
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
Definition: ythread.c:672
#define MAX_BYTE_IN_PACKET
Definition: ydef.h:882
u8 nbifaces
Definition: ydef.h:511
u16 maxtcpws
Definition: ydef.h:813
u16 pr_blk_size
Definition: ydef.h:916
u8 firstByte
Definition: ydef.h:653
u8 tcpchan
Definition: ydef.h:831
u32 yTime
Definition: ydef.h:210
YRETCODE
Definition: ydef.h:376
Definition: ydef.h:473
Notification_product productname
Definition: ydef.h:660
YSTREAM_Head first_stream
Definition: ydef.h:1007
u8 metaType
Definition: ydef.h:800
u8 dwordpos_lo
Definition: ydef.h:933
u16 vendorid
Definition: ydef.h:448
USB_Conf_Pkt conf
Definition: ydef.h:1011
u16 deviceid
Definition: ydef.h:449
Notification_funydx funInfo
Definition: ydef.h:596
#define USB_PKT_SIZE
Definition: ydef.h:467
YSTREAM_Head head
Definition: ydef.h:1010
u8 low
Definition: ydef.h:474
#define YOCTO_PUBVAL_SIZE
Definition: ydef.h:427
u16 ext_jedec_id
Definition: ydef.h:964
s32 YUSBIO
Definition: ydef.h:238
u16 yBlkHdl
Definition: ydef.h:213
u32 last_addr
Definition: ydef.h:920
#define YOCTO_FUNCTION_LEN
Definition: ydef.h:425
Notification_funcname funcnamenot
Definition: ydef.h:664
int YSOCKET
Definition: ydef.h:236
u32 config_start
Definition: ydef.h:921
#define YOCTO_MANUFACTURER_LEN
Definition: ydef.h:419
Notification_funcnameydx funcnameydxnot
Definition: ydef.h:666
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
Definition: ythread.c:647
Notification_firmware firmwarenot
Definition: ydef.h:663
void(* yapiRequestAsyncCallback)(void *context, const u8 *result, u32 resultlen, int retcode, const char *errmsg)
Definition: ydef.h:864
Notification_small smallpubvalnot
Definition: ydef.h:655
void yDeleteCriticalSection(yCRITICAL_SECTION *cs)
Definition: ythread.c:682
int yTryEnterCriticalSection(yCRITICAL_SECTION *cs)
Definition: ythread.c:657
u8 beacon
Definition: ydef.h:457
u16 devidh
Definition: ydef.h:918
u16 devrelease
Definition: ydef.h:450
u16 ext_total_pages
Definition: ydef.h:966
Notification_name namenot
Definition: ydef.h:659
u8 reserved
Definition: ydef.h:826
u16 yfsSignature
Definition: ydef.h:442
Notification_tiny tinypubvalnot
Definition: ydef.h:654
SAFE_U16 deviceid
Definition: ydef.h:632
u8 pktno
Definition: ydef.h:808
u16 nbinbterfaces
Definition: ydef.h:451
u8 high
Definition: ydef.h:475
u8 encaps
Definition: ydef.h:848
u16 flags
Definition: ydef.h:820
USB_Prog_Packet prog
Definition: ydef.h:1008
Notification_funcval pubvalnot
Definition: ydef.h:665
u8 version
Definition: ydef.h:812
char Notification_product[YOCTO_PRODUCTNAME_LEN]
Definition: ydef.h:616
u16 adress_low
Definition: ydef.h:904
u32 nonce
Definition: ydef.h:814
Notification_header head
Definition: ydef.h:657
s32 YAPI_DEVICE
Definition: ydef.h:216
u16 htmlcode
Definition: ydef.h:827
u8 addres_high
Definition: ydef.h:903
u16 ext_page_size
Definition: ydef.h:965
u16 er_blk_size
Definition: ydef.h:923
s32 YUSBDEV
Definition: ydef.h:239
u16 btsign
Definition: ydef.h:943
u32 config_stop
Definition: ydef.h:922
#define YOCTO_LOGICAL_LEN
Definition: ydef.h:424
Notification_funydx funInfo
Definition: ydef.h:602


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