Форум программистов, компьютерный форум CyberForum.ru

Не могу собрать программу для Raspbian - C++

Восстановить пароль Регистрация
 
DimNsk
0 / 0 / 0
Регистрация: 28.12.2013
Сообщений: 6
28.12.2013, 23:23     Не могу собрать программу для Raspbian #1
Помогите собрать программу для Debian (Raspbian)

Есть исходники

main.c
Кликните здесь для просмотра всего текста
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
/*Windows
#include <cstdlib>
#include <iostream>
#include <usb.h>
*/
/*
Linux*/
/* #include "usb.h"  */
#include </usr/include/libusb-1.0/libusb.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <string.h>
 
#define VERSION "0.1.0"
#define VENDOR_ID 0x16c0
#define PRODUCT_ID 0x05df 
 
#define INTFACE 0
#define ONEWIRE_REPEAT       5
#define USB_REPEAT           5
#define USB_PAUSE_CONST      50000
unsigned char USB_BUFI[8];
unsigned char USB_BUFO[8];
unsigned long long ONEWIRE_ROM[40];
float ONEWIRE_TEMP[40];
int ONEWIRE_COUNT;
float T;
    
const static int timeout=5000; /* timeout in ms */
 
 
usb_dev_handle *find_lvr_winusb();
usb_dev_handle* setup_libusb_access() {
     usb_dev_handle *lvr_winusb;
     usb_set_debug(0);
     usb_init();
     usb_find_busses();
     usb_find_devices();
 
     if(!(lvr_winusb = find_lvr_winusb())) {
                return NULL;
        }
 
 
/* Linux */
usb_detach_kernel_driver_np(lvr_winusb,0);
        if (usb_set_configuration(lvr_winusb, 1) < 0) {
                printf("Could not set configuration 1 : \n");
                return NULL;
        }
 
        if (usb_claim_interface(lvr_winusb, INTFACE) < 0) {
                printf("Could not claim interface: \n");
                return NULL;
        }
        return lvr_winusb;
 }
 
 usb_dev_handle *find_lvr_winusb() 
 {
      struct usb_bus *bus;
         struct usb_device *dev;
         for (bus = usb_busses; bus; bus = bus->next) {
         for (dev = bus->devices; dev; dev = dev->next) {
                        if (dev->descriptor.idVendor == VENDOR_ID && 
                                dev->descriptor.idProduct == PRODUCT_ID ) {
                                usb_dev_handle *handle;
                                if (!(handle = usb_open(dev))) {
                                        printf("Could not open USB device\n");
                                        return NULL;
                                }
                                return handle;
                        }
                }
        }
        return NULL;
 }
 
usb_dev_handle *lvr_winusb = NULL;
 
void USB_PAUSE(unsigned long long MS)
{   //  MS - задержка в милисекундах
    //  блокирует всё
    for (unsigned long long i=0; i<MS*USB_PAUSE_CONST; i++);
}
 
void USB_BUF_CLEAR()
{   //  очистка буферов приёма и передачи
    for (int i=0; i<9; i++) { USB_BUFI[i]=0; USB_BUFO[i]=0; }
}
 
bool USB_GET_FEATURE()
{   //  чтение в буфер из устройства
 
    bool RESULT=false;
    int i=USB_REPEAT;   //  число попыток
    while (!RESULT & ((i--)>0))
        try { 
            RESULT = usb_control_msg(lvr_winusb, 0xA1, 0x01, 0x300, 0, (char *)USB_BUFI, 0x8, timeout);
        }
            catch (...) { RESULT=false; };
    if (!RESULT) printf("Error reading from device\n");
/*
    printf("read ");
    for(int i=0;i<8;i++) printf("%x ",USB_BUFI[i]);
    printf("\n");
*/
    return RESULT;
} 
 
bool USB_SET_FEATURE()
{   //  запись из буфера в устройство
    bool RESULT=false;
    try { 
            RESULT = usb_control_msg(lvr_winusb, 0x21, 0x09, 0x300, 0, (char *)USB_BUFO, 0x8, timeout);
    }
        catch (...) { RESULT=false;  };
    if (!RESULT) printf("Error writing to device\n");
/*
    printf("write ");
    for(int i=0;i<8;i++) printf("%x ",USB_BUFO[i]);
    printf("\n");
*/
    return RESULT;
}
 
bool USB_GET_PORT(unsigned char &PS)
{   //  чтение состояния порта, 2ms
    USB_BUF_CLEAR();
    bool RESULT=false;
    USB_BUFO[0]=0x7E;
    int i=USB_REPEAT;   //  число попыток
    while (!RESULT & ((i--)>0))
        if (USB_SET_FEATURE())
            if (USB_GET_FEATURE())
                if (USB_BUFI[0]==0x7E) { PS=USB_BUFI[1]; RESULT=USB_BUFI[2]==PS; }
                    else RESULT=false;
    if (!RESULT) printf("Error reading PORT\n");
    return RESULT;
}
 
bool USB_SET_PORT(unsigned char PS)
{   //  запись состояния порта, 2ms
    USB_BUF_CLEAR();
    bool RESULT=false;
    USB_BUFO[0]=0xE7;
    USB_BUFO[1]=PS;
    int i=USB_REPEAT;   //  число попыток
    while (!RESULT & ((i--)>0))
        if (USB_SET_FEATURE())
            if (USB_GET_FEATURE())
                 { RESULT=(USB_BUFI[0]==0xE7)&(USB_BUFI[1]==PS)&(USB_BUFI[2]==PS); }
    if (!RESULT) printf("Error writing PORT\n");
    return RESULT;
}
 
bool USB_GET_FAMILY(unsigned char &FAMILY)
{   //  чтение группового кода устройства, 2ms
    USB_BUF_CLEAR();
    bool RESULT=false;
    USB_BUFO[0]=0x1D;
    int i=USB_REPEAT;   //  число попыток
    while (!RESULT & ((i--)>0))
        if (USB_SET_FEATURE())
            if (USB_GET_FEATURE())
                if (USB_BUFI[0]==0x1D) { RESULT=true; FAMILY=USB_BUFI[1]; }
                    else RESULT=false;
    if (!RESULT) printf("Error reading FAMILY\n");
    return RESULT;
}
 
bool USB_GET_SOFTV(unsigned int &SV)
{   //  чтение номера версии прошивки, 2ms
    USB_BUF_CLEAR();
    bool RESULT=false;
    USB_BUFO[0]=0x1D;
    int i=USB_REPEAT;   //  число попыток
    while (!RESULT & ((i--)>0))
        if (USB_SET_FEATURE())
            if (USB_GET_FEATURE())
                if (USB_BUFI[0]==0x1D) { RESULT=true; SV=USB_BUFI[2]+(USB_BUFI[3]>>8); }
                    else RESULT=false;
    if (!RESULT) printf("Error reading firmware version\n");
    return RESULT;
}
 
bool USB_GET_ID(unsigned int &ID)
{   //  чтение ID устройства, 2ms
    USB_BUF_CLEAR();
    bool RESULT=false;
    USB_BUFO[0]=0x1D;
    int i=USB_REPEAT;   //  число попыток
    while (!RESULT & ((i--)>0))
        if (USB_SET_FEATURE())
            if (USB_GET_FEATURE())
                if (USB_BUFI[0]==0x1D) { RESULT=true; ID=(USB_BUFI[4]<<24)+(USB_BUFI[5]<<16)+(USB_BUFI[6]<<8)+USB_BUFI[7]; }
                    else RESULT=false;
    if (!RESULT) printf("Error reading device ID\n");
    return RESULT;
}
 
bool USB_EE_RD(unsigned char ADR,unsigned  char &DATA)
{   //  чтение EEPROM
    USB_BUF_CLEAR();
    bool RESULT=false;
    USB_BUFO[0]=0xE0;
    USB_BUFO[1]=ADR;
    int i=USB_REPEAT;   //  число попыток
    while (!RESULT & ((i--)>0))
        if (USB_SET_FEATURE())
            if (USB_GET_FEATURE()) { RESULT=(USB_BUFI[0]==0xE0)&(USB_BUFI[1]==ADR); DATA=USB_BUFI[2]; }
    if (!RESULT) printf("Error reading EEPROM\n");
    return RESULT;
}
 
bool USB_EE_WR(unsigned char ADR,unsigned  char DATA)
{   //  запись EEPROM, 17ms
    USB_BUF_CLEAR();
    bool RESULT=false;
    USB_BUFO[0]=0x0E;
    USB_BUFO[1]=ADR;    USB_BUFO[2]=DATA;
    int i=USB_REPEAT;   //  число попыток
    while (!RESULT & ((i--)>0))
        if (USB_SET_FEATURE())
            {
            USB_PAUSE(15);   //  на запись в EEPROM
            if (USB_GET_FEATURE()) RESULT=(USB_BUFI[0]==0x0E)&(USB_BUFI[1]==ADR)&(USB_BUFI[2]==DATA);
            } else RESULT=false;
    if (!RESULT) printf("Error writing EEPROM\n");
    return RESULT;
}
 
bool OW_RESET()
{   //  RESET, ~3ms
    bool RESULT=false;
    int i;
    USB_BUF_CLEAR();
    USB_BUFO[0]=0x18;    USB_BUFO[1]=0x48;
        
    unsigned char N=ONEWIRE_REPEAT;
 
    while (!RESULT &((N--)>0))
        if (USB_SET_FEATURE())
            {
            USB_PAUSE(1);
            if (USB_GET_FEATURE()) {
               RESULT=(USB_BUFI[0]==0x18)&(USB_BUFI[1]==0x48)&(USB_BUFI[2]==0x00);
            }
                else RESULT=false;
            }
    if (!RESULT) printf("Error OW_RESET\n");
    return RESULT;
}
 
bool OW_READ_BIT(unsigned char &B)
{   //  чтение бита, 3ms
    bool RESULT=false;
    USB_BUF_CLEAR();
    USB_BUFO[0]=0x18;    USB_BUFO[1]=0x81;    USB_BUFO[2]=0x01;
    if (USB_SET_FEATURE())
        {
        USB_PAUSE(1);
        if (USB_GET_FEATURE())
            { RESULT=(USB_BUFI[0]==0x18)&(USB_BUFI[1]==0x81); B=USB_BUFI[2]&0x01; }
        }
    if (!RESULT) printf("Error OW_READ_BIT\n");
    return RESULT;
}
 
bool OW_READ_2BIT(unsigned char &B)
{   //  чтение 2-x бит, 3ms
    bool RESULT=false;
    USB_BUF_CLEAR();
    USB_BUFO[0]=0x18;    USB_BUFO[1]=0x82;
    USB_BUFO[2]=0x01;    USB_BUFO[3]=0x01;
    if (USB_SET_FEATURE())
        {
        USB_PAUSE(1);
        if (USB_GET_FEATURE())
            { RESULT=(USB_BUFI[0]==0x18)&(USB_BUFI[1]==0x82); B=(USB_BUFI[2]&0x01)+((USB_BUFI[3]<<1)&0x02); }
        }
    if (!RESULT) printf("Error OW_READ_2BIT\n");
    return RESULT;
}
 
bool OW_READ_BYTE(unsigned char &B)
{   //  чтение байта, 3ms
    bool RESULT=false;
    USB_BUF_CLEAR();
    USB_BUFO[0]=0x18;    USB_BUFO[1]=0x88;    USB_BUFO[2]=0xFF;
    if (USB_SET_FEATURE())
        {
        USB_PAUSE(1);
        if (USB_GET_FEATURE())
            { RESULT=(USB_BUFI[0]==0x18)&(USB_BUFI[1]==0x88); B=USB_BUFI[2]; }
        }
    if (!RESULT) printf("Error OW_READ_BYTE\n");
    return RESULT;
}
 
bool OW_READ_4BYTE(unsigned long &B)
{   //  чтение 4 байта, 4ms
    bool RESULT=false;
    USB_BUF_CLEAR();
    USB_BUFO[0]=0x18;    USB_BUFO[1]=0x84;    USB_BUFO[2]=0xFF;
    USB_BUFO[3]=0xFF;    USB_BUFO[4]=0xFF;    USB_BUFO[5]=0xFF;
    if (USB_SET_FEATURE())
        {
        USB_PAUSE(2);
        if (USB_GET_FEATURE())
            { RESULT=(USB_BUFI[0]==0x18)&(USB_BUFI[1]==0x84); B=USB_BUFI[2]+(USB_BUFI[3]<<8)+(USB_BUFI[4]<<16)+(USB_BUFI[5]<<24); }
        }
    if (!RESULT) printf("Error OW_READ_4BYTE\n");
    return RESULT;
}
 
bool OW_WRITE_BIT(unsigned char B)
{   //  запись бита, 3ms
    bool RESULT=false;
    USB_BUF_CLEAR();
    USB_BUFO[0]=0x18;    USB_BUFO[1]=0x81;    USB_BUFO[2]=B&0x01;
    if (USB_SET_FEATURE())
        {
        USB_PAUSE(1);
        if (USB_GET_FEATURE())
            RESULT=(USB_BUFI[0]==0x18)&(USB_BUFI[1]==0x81)&((USB_BUFI[2]&0x01)==(B&0x01));
        }
    if (!RESULT) printf("Error OW_WRITE_BIT\n");
    return RESULT;
}
 
bool OW_WRITE_BYTE(unsigned char B)
{   //  запись байта, 3ms
    bool RESULT=false;
    USB_BUF_CLEAR();
    USB_BUFO[0]=0x18;    USB_BUFO[1]=0x88;    USB_BUFO[2]=B;
    if (USB_SET_FEATURE())
        {
        USB_PAUSE(1);
        if (USB_GET_FEATURE())
            RESULT=(USB_BUFI[0]==0x18)&(USB_BUFI[1]==0x88)&(USB_BUFI[2]==B);
        }
    if (!RESULT) printf("Error OW_WRITE_BYTE\n");
    return RESULT;
}
 
bool OW_WRITE_4BYTE(unsigned long B)
{   //  запись 4 байта, 4ms
    bool RESULT=false;
    unsigned char D0, D1, D2, D3;
    D0=B&0xFF;
    D1=(B>>8) &0xFF;
    D2=(B>>16)&0xFF;
    D3=(B>>24)&0xFF;
    USB_BUF_CLEAR();
    USB_BUFO[0]=0x18;    USB_BUFO[1]=0x84;    USB_BUFO[2]=B&0xFF;
    USB_BUFO[3]=(B>>8)&0xFF;
    USB_BUFO[4]=(B>>16)&0xFF;
    USB_BUFO[5]=(B>>24)&0xFF;
    if (USB_SET_FEATURE())
        {
        USB_PAUSE(2);
        if (USB_GET_FEATURE())
            RESULT=(USB_BUFI[0]==0x18)&(USB_BUFI[1]==0x84)&(USB_BUFI[2]==D0&(USB_BUFI[3]==D1)&(USB_BUFI[4]==D2)&(USB_BUFI[5]==D3));
        }
    if (!RESULT) printf("Error OW_WRITE_4BYTE\n");
    return RESULT;
}
 
unsigned char CRC8(unsigned char CRC, unsigned char D)
{   //  подчсёт CRC для DALLAS
    unsigned char R=CRC;
    for (int i=0; i<8; i++)
        if ((R^(D>>i))&0x01==0x01) R=((R^0x18)>>1)|0x80;
            else R=(R>>1)&0x7F;
    return R;
}
 
bool READ_ROM(unsigned long long &ROM64)
{   //  чтение ROM, 14ms
    bool RESULT=false;
    unsigned long B;
    unsigned char N=ONEWIRE_REPEAT;
    unsigned long long T, CRC;
    while (!RESULT&((N--)>0))
        if (OW_RESET())
            if (OW_WRITE_BYTE(0x33))
                {   //  чтение 64 бит
                ROM64=0;    CRC=0;
                if (OW_READ_4BYTE(B))
                    {
                    T=B;
                    ROM64=ROM64+T;
                    if (OW_READ_4BYTE(B)) { T=B; ROM64=ROM64+(T<<32); RESULT=true; }
                        else RESULT=false;
                    }
                    else RESULT=false;
                //   проверка CRC
                if (RESULT)
                    {
                    T=ROM64;
                    for (int i=0; i<8; i++) CRC=CRC8(CRC, (T>>(i*8))&0xFF);
                    RESULT=CRC==0;
                    }
                }
    if (!RESULT) printf("Error READ_ROM\n");
    return RESULT;
}
 
bool MATCH_ROM(unsigned long long ROM)
{   //  выбор прибора по ROM, 14ms
    bool RESULT=false;
    unsigned long long T=ROM;
    unsigned char N=ONEWIRE_REPEAT;
    while (!RESULT&((N--)>0))
        if (OW_RESET())
            if (OW_WRITE_BYTE(0x55))
                if (OW_WRITE_4BYTE(T&0xFFFFFFFF))
                    RESULT=OW_WRITE_4BYTE((T>>32)&0xFFFFFFFF);
    if (!RESULT) printf("Error MATCH_ROM\n");
    return RESULT;
}
 
bool SKIP_ROM()
{   //  пропуск ROM-команд, 6ms
    bool RESULT=false;
    unsigned char N=ONEWIRE_REPEAT;
    while (!RESULT&((N--)>0))
        if (OW_RESET()) RESULT=OW_WRITE_BYTE(0xCC);
    if (!RESULT) printf("Error SKIP_ROM\n");
    return RESULT;
}
 
bool SEARCH_ROM(unsigned long long ROM_NEXT, int PL)
{   //  поиск ROM, 1 dev - 410ms, 5 dev - 2.26s, 20 dev - 8.89s
    bool RESULT=false;
    unsigned char N=ONEWIRE_REPEAT;
    unsigned char BIT;
    bool CL[64]; for (int i=0; i<64; i++) CL[i]=false;
    unsigned long long RL[64];
    unsigned long long B1=1, CRC, ROM;
    while (!RESULT&((N--)>0))
        {
        ROM=0;
        if (OW_RESET()) RESULT=OW_WRITE_BYTE(0xF0);
        if (RESULT)
            for (int i=0; i<64; i++)
                if (RESULT)
                    if (OW_READ_2BIT(BIT))
                        switch (BIT&0x03)
                            {
                            case 0 :
                                {   //  коллизия есть
                                if (PL<i) {CL[i]=true; RL[i]=ROM;}
                                if (PL>=i) BIT=(ROM_NEXT>>i)&0x01; else BIT=0;
                                if(!OW_WRITE_BIT(BIT)) { RESULT=false; i=64; }
                                if (BIT==1) ROM=ROM+(B1<<i);
                                break;
                                }
                            case 1 : { if (!OW_WRITE_BIT(0x01)) { RESULT=false; i=64; } else ROM=ROM+(B1<<i); break;}
                            case 2 : { if (!OW_WRITE_BIT(0x00)) { RESULT=false; i=64; } break;}
                            case 3 : { RESULT=false; i=64; break;}   //  нет на линии
                            }
                        else { RESULT=false; i=64; }
        if (ROM==0) RESULT=false;
        if (RESULT) { CRC=0; for (int j=0; j<8; j++) CRC=CRC8(CRC, (ROM>>(j*8))&0xFF); RESULT=CRC==0; }
        }
    if (!RESULT) printf("Error SEARCH_ROM\n");
        else ONEWIRE_ROM[ONEWIRE_COUNT++]=ROM;
    //  рекурентный вызов поиска
    for (int i=0; i<64; i++)
        if (CL[i]) SEARCH_ROM(RL[i]|(B1<<i), i);
    return RESULT;
}
 
bool SKIP_ROM_CONVERT()
{   //  пропуск ROM-команд, старт измерения температуры, 9ms
    bool RESULT=false;
    unsigned char N=ONEWIRE_REPEAT;
    while (!RESULT&((N--)>0))
        if (OW_RESET())
            if (OW_WRITE_BYTE(0xCC))
                RESULT=OW_WRITE_BYTE(0x44);
    if (!RESULT) printf("Error SKIP_ROM_CONVERT\n");
    return RESULT;
}
 
bool GET_TEMPERATURE(unsigned long long ROM, float &T)
{   //  чтение температуры, 28ms
    unsigned long long CRC;
    unsigned long L1, L2;
    unsigned char L3;
    unsigned char FAMILY=ROM&0xFF;
    bool RESULT=false;
    unsigned char N=ONEWIRE_REPEAT;
    while (!RESULT&((N--)>0))
        if (MATCH_ROM(ROM))
            if (OW_WRITE_BYTE(0xBE))
                    if (OW_READ_4BYTE(L1))
                        if (OW_READ_4BYTE(L2))
                            if (OW_READ_BYTE(L3))
                                {
                                CRC=0;
                                for (int i=0; i<4; i++) CRC=CRC8(CRC, (L1>>(i*8))&0xFF);
                                for (int i=0; i<4; i++) CRC=CRC8(CRC, (L2>>(i*8))&0xFF);
                                CRC=CRC8(CRC, L3);
                                RESULT=CRC==0;
 
                                short K=L1&0xFFFF;
                                //  DS18B20 +10.125=00A2h, -10.125=FF5Eh
                                //  DS18S20 +25.0=0032h, -25.0=FFCEh
                                //  K=0x0032;
                                T=1000;     //  для неопознанной FAMILY датчик отсутствует
                                if ((FAMILY==0x28)|(FAMILY==0x22)) T=K*0.0625;  //  DS18B20 | DS1822
                                if (FAMILY==0x10) T=K*0.5;                      //  DS18S20 | DS1820
                                }
    if (!RESULT) printf("Error GET_TEMPERATURE\n");
    return RESULT;
}
 
 
int read_ports()
 {
    int ret=0;
    unsigned char PS;
    if(USB_GET_PORT(PS)) {
        if((PS==8)|(PS==24)) printf("Port1 is on\n");
        else printf("Port1 is off\n");
        if(PS>=16) printf("Port2 is on\n");
        else printf("Port2 is off\n");
        return 1;
    }
    return 0;
 }
 
int set_port(int num, bool stat)
 {
    unsigned char PS, PS_OLD;
    bool ret;
 
    if (USB_GET_PORT(PS))
        {   //  удалость прочитать
        PS_OLD=PS;
        } else { printf("Error USB_GET_PORT\n"); return 0; }
    //  включение / выключение
    if ((num==1)&(stat==1))  { PS=PS|0x08; ret = USB_SET_PORT(PS); }
    else if ((num==1)&(stat==0)) { PS=PS&0x10; ret = USB_SET_PORT(PS); }
    else if ((num==2)&(stat==1))  { PS=PS|0x10; ret = USB_SET_PORT(PS); }
    else if ((num==2)&(stat==0)) { PS=PS&0x08; ret = USB_SET_PORT(PS); }             
    if(!ret) return 0;
    printf("Status port changed\n");
    return 1;
}
 
int device_info() {
    int ret=0;
    unsigned int SV,ID;
    unsigned char FAMILY;
    ret = USB_GET_SOFTV(SV);
    if(ret) printf("Firmware: %xh\n", SV);
    ret = USB_GET_FAMILY(FAMILY);
    if(ret) printf("USB series: %xh\n", FAMILY);
    ret = USB_GET_ID(ID);
    if(ret) printf("USB identifier: %xh\n", ID);
    return 1;
}
 
 
int scan() {
    int ret;
    ret = SEARCH_ROM(0, 0);
    for(int i=1;i<=ONEWIRE_COUNT;i++) {
            printf("temp_id%d = %x",i, (ONEWIRE_ROM[i-1]>>32)&0xFFFFFFFF);
            printf("%x\n",ONEWIRE_ROM[i-1]&0xFFFFFFFF);
    }
    return 1;    
}
 
int temp(unsigned long long ROM) {
    int ret;
    ONEWIRE_COUNT = 1;
    ONEWIRE_ROM[0] = ROM;
    SKIP_ROM_CONVERT();
    ret = GET_TEMPERATURE(ONEWIRE_ROM[0], T);
    if(ret) printf("%f\n",T);
}
 
int ports_save() {
    unsigned char PS;
    if (USB_GET_PORT(PS)) {
        if (USB_EE_WR(0x04, PS)) {printf("Status ports saved\n");return 1;}
    }
    printf("Error saving ports status\n");
    return 0;
}
 
int delay_get() {
    unsigned char B;
    USB_EE_RD(0x05, B);
    printf("%d\n", B);
    return 1;
}
 
int delay_set(int B) {
    if((B<5)|(B>255)) {
        printf("Wrong num %d\n",B);
        return 0;
    }
    if (USB_EE_WR(0x05, B)) {printf("Delay changed\n");return 1;}
    return 0;
}
 
 
long long unsigned int HexStringToUInt(char* s)
{
long long unsigned int v = 0;
while (char c = *s++)
{
if (c < '0') return 0; //invalid character
if (c > '9') //shift alphabetic characters down
{
if (c >= 'a') c -= 'a' - 'A'; //upper-case 'a' or higher
if (c > 'Z') return 0; //invalid character
if (c > '9') c -= 'A'-1-'9'; //make consecutive with digits
if (c < '9' + 1) return 0; //invalid character
}
c -= '0'; //convert char to hex digit value
v = v << 4; //shift left by a hex digit
v += c; //add the current digit
}
 
return v;
}
 
int main( int argc, char **argv)
{
    lvr_winusb = setup_libusb_access();
 
        char buf;
   
        if(argc==1) {
            printf("Temperature sensor BM1707 control v1.0\n");
            if(lvr_winusb!=NULL) {
                printf("Device has been plugged\n");
            }
            else printf("Device unplugged\n");
            printf("\nUsage: bmcontrol [options]\n\n");
            printf("   info                          Show device information\n");
            printf("   scan                          Scaning temperature sensors\n");
            printf("   temp <id>                     Show temperature sensor <id> \n");
            printf("   ports                         Show ports status\n");
            printf("   pset <port> <status>          Set off/on port status.\n");
            printf("                                 Correct value: port [1, 2] status [0, 1]. \n");
            printf("   psave                         Save ports status in EEPROM\n");
            printf("   delay                         Get delay time of device before power save\n");
            printf("   delay <5-255>                 Set delay time of device before power save\n");
        }
        else if(lvr_winusb!=NULL){
             if(strcmp(argv[1],"ports") == 0) buf = read_ports();
             else if(strcmp(argv[1],"info") == 0) device_info();
             else if(strcmp(argv[1],"scan") == 0) scan();
             else if(strcmp(argv[1],"psave") == 0) ports_save();
             else if((strcmp(argv[1],"temp") == 0)&&(argv[2])) {
                  long unsigned rom1=0, rom2=0;
                  long long unsigned rom=0;
                  rom = HexStringToUInt(argv[2]);
                  temp(rom);
             }
             else if((strcmp(argv[1],"pset") == 0)&(argc==4)) buf = set_port(atoi((const char*) argv[2]), (bool) atoi((const char*) argv[3]));
             else if((strcmp(argv[1],"delay") == 0)&(argc==2)) delay_get();
             else if((strcmp(argv[1],"delay") == 0)&(argc==3)) delay_set( atoi(argv[2]));
             else printf("Wrong command %s.\n", argv[1]);
        }
        else {
             printf("Device not plugged\n");
             exit(-1);
        }
        if(lvr_winusb!=NULL) {
            usb_release_interface(lvr_winusb, 0);
            usb_close(lvr_winusb);
        }
        return 0;
}


и

makefile
Кликните здесь для просмотра всего текста
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
CC = g++
 
all: bmcontrol
 
%.o: %.c
    $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -I. -I/usr/include -lusb -o $@ $^
 
 
bmcontrol: main.o
    $(CC) -I/usr/include -L/usr/lib -lusb -o $@ $^
 
 
clean: 
    rm -f *.o bmcontrol


При сборке командой make
вываливаются ошибки

Код
g++   -c -I. -I/usr/include -lusb -o main.o main.c
main.c:32:1: error: ‘usb_dev_handle’ does not name a type
main.c:33:1: error: ‘usb_dev_handle’ does not name a type
main.c:59:2: error: ‘usb_dev_handle’ does not name a type
main.c:79:1: error: ‘usb_dev_handle’ does not name a type
main.c: In function ‘bool USB_GET_FEATURE()’:
main.c:99:38: error: ‘lvr_winusb’ was not declared in this scope
main.c:99:102: error: ‘usb_control_msg’ was not declared in this scope
main.c: In function ‘bool USB_SET_FEATURE()’:
main.c:115:38: error: ‘lvr_winusb’ was not declared in this scope
main.c:115:102: error: ‘usb_control_msg’ was not declared in this scope
main.c: In function ‘int main(int, char**)’:
main.c:637:5: error: ‘lvr_winusb’ was not declared in this scope
main.c:637:38: error: ‘setup_libusb_access’ was not declared in this scope
main.c:669:104: error: ‘atoi’ was not declared in this scope
main.c:671:87: error: ‘atoi’ was not declared in this scope
main.c:676:21: error: ‘exit’ was not declared in this scope
main.c:679:48: error: ‘usb_release_interface’ was not declared in this scope
main.c:680:33: error: ‘usb_close’ was not declared in this scope
make: *** [main.o] Error 1
Что я делаю не так?
После регистрации реклама в сообщениях будет скрыта и будут доступны все возможности форума.
Tulosba
:)
Эксперт C++
4378 / 3221 / 297
Регистрация: 19.02.2013
Сообщений: 9,044
28.12.2013, 23:36     Не могу собрать программу для Raspbian #2
Насколько я понимаю usb_dev_handle определен в usb.h, который в 8 строке почему-то закомменчен. Вопрос: почему? С остальными ошибками, скорее всего, подобная проблема.
KOPOJI
28.12.2013, 23:39
  #3

Не по теме:

Цитата Сообщение от Tulosba Посмотреть сообщение
почему-то закомменчен
как я понимаю, это мини-инструкция в виде "если вы на windows, раскомментируйте это, если вы на linux, то раскомментируйте то..

DimNsk
0 / 0 / 0
Регистрация: 28.12.2013
Сообщений: 6
28.12.2013, 23:46  [ТС]     Не могу собрать программу для Raspbian #4
Цитата Сообщение от Tulosba Посмотреть сообщение
Насколько я понимаю usb_dev_handle определен в usb.h, который в 8 строке почему-то закомменчен. Вопрос: почему? С остальными ошибками, скорее всего, подобная проблема.
прописал прямой путь иначе вываливается ошибка , что не находит usb.h

Код
g++   -c -I. -I/usr/include -lusb -o main.o main.c
main.c:8:18: fatal error: usb.h: No such file or directory
compilation terminated.
make: *** [main.o] Error 1
Tulosba
:)
Эксперт C++
4378 / 3221 / 297
Регистрация: 19.02.2013
Сообщений: 9,044
28.12.2013, 23:48     Не могу собрать программу для Raspbian #5
Цитата Сообщение от DimNsk Посмотреть сообщение
прописал прямой путь
А по этому "прямому" пути есть определение usb_dev_handle?
DimNsk
0 / 0 / 0
Регистрация: 28.12.2013
Сообщений: 6
28.12.2013, 23:49  [ТС]     Не могу собрать программу для Raspbian #6
Библиотека libusb.h

Кликните здесь для просмотра всего текста
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
/*
 * Public libusbx header file
 * Copyright © 2007-2008 Daniel Drake <dsd@gentoo.org>
 * Copyright © 2001 Johannes Erdfelt <johannes@erdfelt.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */
 
#ifndef LIBUSB_H
#define LIBUSB_H
 
#ifdef _MSC_VER
/* on MS environments, the inline keyword is available in C++ only */
#define inline __inline
/* ssize_t is also not available (copy/paste from MinGW) */
#ifndef _SSIZE_T_DEFINED
#define _SSIZE_T_DEFINED
#undef ssize_t
#ifdef _WIN64
  typedef __int64 ssize_t;
#else
  typedef int ssize_t;
#endif /* _WIN64 */
#endif /* _SSIZE_T_DEFINED */
#endif /* _MSC_VER */
 
/* stdint.h is also not usually available on MS */
#if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H))
typedef unsigned __int8   uint8_t;
typedef unsigned __int16  uint16_t;
typedef unsigned __int32  uint32_t;
#else
#include <stdint.h>
#endif
 
#include <sys/types.h>
#include <time.h>
#include <limits.h>
 
#if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__)
#include <sys/time.h>
#endif
 
/* 'interface' might be defined as a macro on Windows, so we need to
 * undefine it so as not to break the current libusbx API, because
 * libusb_config_descriptor has an 'interface' member
 * As this can be problematic if you include windows.h after libusb.h
 * in your sources, we force windows.h to be included first. */
#if defined(_WIN32) || defined(__CYGWIN__)
#include <windows.h>
#if defined(interface)
#undef interface
#endif
#endif
 
/** \def LIBUSB_CALL
 * \ingroup misc
 * libusbx's Windows calling convention.
 *
 * Under Windows, the selection of available compilers and configurations
 * means that, unlike other platforms, there is not <em>one true calling
 * convention</em> (calling convention: the manner in which parameters are
 * passed to funcions in the generated assembly code).
 *
 * Matching the Windows API itself, libusbx uses the WINAPI convention (which
 * translates to the <tt>stdcall</tt> convention) and guarantees that the
 * library is compiled in this way. The public header file also includes
 * appropriate annotations so that your own software will use the right
 * convention, even if another convention is being used by default within
 * your codebase.
 *
 * The one consideration that you must apply in your software is to mark
 * all functions which you use as libusbx callbacks with this LIBUSB_CALL
 * annotation, so that they too get compiled for the correct calling
 * convention.
 *
 * On non-Windows operating systems, this macro is defined as nothing. This
 * means that you can apply it to your code without worrying about
 * cross-platform compatibility.
 */
/* LIBUSB_CALL must be defined on both definition and declaration of libusbx
 * functions. You'd think that declaration would be enough, but cygwin will
 * complain about conflicting types unless both are marked this way.
 * The placement of this macro is important too; it must appear after the
 * return type, before the function name. See internal documentation for
 * API_EXPORTED.
 */
#if defined(_WIN32) || defined(__CYGWIN__)
#define LIBUSB_CALL WINAPI
#else
#define LIBUSB_CALL
#endif
 
#ifdef __cplusplus
extern "C" {
#endif
 
/** \def libusb_cpu_to_le16
 * \ingroup misc
 * Convert a 16-bit value from host-endian to little-endian format. On
 * little endian systems, this function does nothing. On big endian systems,
 * the bytes are swapped.
 * \param x the host-endian value to convert
 * \returns the value in little-endian byte order
 */
static inline uint16_t libusb_cpu_to_le16(const uint16_t x)
{
    union {
        uint8_t  b8[2];
        uint16_t b16;
    } _tmp;
    _tmp.b8[1] = x >> 8;
    _tmp.b8[0] = x & 0xff;
    return _tmp.b16;
}
 
/** \def libusb_le16_to_cpu
 * \ingroup misc
 * Convert a 16-bit value from little-endian to host-endian format. On
 * little endian systems, this function does nothing. On big endian systems,
 * the bytes are swapped.
 * \param x the little-endian value to convert
 * \returns the value in host-endian byte order
 */
#define libusb_le16_to_cpu libusb_cpu_to_le16
 
/* standard USB stuff */
 
/** \ingroup desc
 * Device and/or Interface Class codes */
enum libusb_class_code {
    /** In the context of a \ref libusb_device_descriptor "device descriptor",
     * this bDeviceClass value indicates that each interface specifies its
     * own class information and all interfaces operate independently.
     */
    LIBUSB_CLASS_PER_INTERFACE = 0,
 
    /** Audio class */
    LIBUSB_CLASS_AUDIO = 1,
 
    /** Communications class */
    LIBUSB_CLASS_COMM = 2,
 
    /** Human Interface Device class */
    LIBUSB_CLASS_HID = 3,
 
    /** Physical */
    LIBUSB_CLASS_PHYSICAL = 5,
 
    /** Printer class */
    LIBUSB_CLASS_PRINTER = 7,
 
    /** Image class */
    LIBUSB_CLASS_PTP = 6, /* legacy name from libusb-0.1 usb.h */
    LIBUSB_CLASS_IMAGE = 6,
 
    /** Mass storage class */
    LIBUSB_CLASS_MASS_STORAGE = 8,
 
    /** Hub class */
    LIBUSB_CLASS_HUB = 9,
 
    /** Data class */
    LIBUSB_CLASS_DATA = 10,
 
    /** Smart Card */
    LIBUSB_CLASS_SMART_CARD = 0x0b,
 
    /** Content Security */
    LIBUSB_CLASS_CONTENT_SECURITY = 0x0d,
 
    /** Video */
    LIBUSB_CLASS_VIDEO = 0x0e,
 
    /** Personal Healthcare */
    LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f,
 
    /** Diagnostic Device */
    LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
 
    /** Wireless class */
    LIBUSB_CLASS_WIRELESS = 0xe0,
 
    /** Application class */
    LIBUSB_CLASS_APPLICATION = 0xfe,
 
    /** Class is vendor-specific */
    LIBUSB_CLASS_VENDOR_SPEC = 0xff
};
 
/** \ingroup desc
 * Descriptor types as defined by the USB specification. */
enum libusb_descriptor_type {
    /** Device descriptor. See libusb_device_descriptor. */
    LIBUSB_DT_DEVICE = 0x01,
 
    /** Configuration descriptor. See libusb_config_descriptor. */
    LIBUSB_DT_CONFIG = 0x02,
 
    /** String descriptor */
    LIBUSB_DT_STRING = 0x03,
 
    /** Interface descriptor. See libusb_interface_descriptor. */
    LIBUSB_DT_INTERFACE = 0x04,
 
    /** Endpoint descriptor. See libusb_endpoint_descriptor. */
    LIBUSB_DT_ENDPOINT = 0x05,
 
    /** HID descriptor */
    LIBUSB_DT_HID = 0x21,
 
    /** HID report descriptor */
    LIBUSB_DT_REPORT = 0x22,
 
    /** Physical descriptor */
    LIBUSB_DT_PHYSICAL = 0x23,
 
    /** Hub descriptor */
    LIBUSB_DT_HUB = 0x29,
};
 
/* Descriptor sizes per descriptor type */
#define LIBUSB_DT_DEVICE_SIZE           18
#define LIBUSB_DT_CONFIG_SIZE           9
#define LIBUSB_DT_INTERFACE_SIZE        9
#define LIBUSB_DT_ENDPOINT_SIZE     7
#define LIBUSB_DT_ENDPOINT_AUDIO_SIZE   9   /* Audio extension */
#define LIBUSB_DT_HUB_NONVAR_SIZE       7
 
#define LIBUSB_ENDPOINT_ADDRESS_MASK    0x0f    /* in bEndpointAddress */
#define LIBUSB_ENDPOINT_DIR_MASK        0x80
 
/** \ingroup desc
 * Endpoint direction. Values for bit 7 of the
 * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme.
 */
enum libusb_endpoint_direction {
    /** In: device-to-host */
    LIBUSB_ENDPOINT_IN = 0x80,
 
    /** Out: host-to-device */
    LIBUSB_ENDPOINT_OUT = 0x00
};
 
#define LIBUSB_TRANSFER_TYPE_MASK           0x03    /* in bmAttributes */
 
/** \ingroup desc
 * Endpoint transfer type. Values for bits 0:1 of the
 * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field.
 */
enum libusb_transfer_type {
    /** Control endpoint */
    LIBUSB_TRANSFER_TYPE_CONTROL = 0,
 
    /** Isochronous endpoint */
    LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
 
    /** Bulk endpoint */
    LIBUSB_TRANSFER_TYPE_BULK = 2,
 
    /** Interrupt endpoint */
    LIBUSB_TRANSFER_TYPE_INTERRUPT = 3
};
 
/** \ingroup misc
 * Standard requests, as defined in table 9-3 of the USB2 specifications */
enum libusb_standard_request {
    /** Request status of the specific recipient */
    LIBUSB_REQUEST_GET_STATUS = 0x00,
 
    /** Clear or disable a specific feature */
    LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
 
    /* 0x02 is reserved */
 
    /** Set or enable a specific feature */
    LIBUSB_REQUEST_SET_FEATURE = 0x03,
 
    /* 0x04 is reserved */
 
    /** Set device address for all future accesses */
    LIBUSB_REQUEST_SET_ADDRESS = 0x05,
 
    /** Get the specified descriptor */
    LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
 
    /** Used to update existing descriptors or add new descriptors */
    LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
 
    /** Get the current device configuration value */
    LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
 
    /** Set device configuration */
    LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
 
    /** Return the selected alternate setting for the specified interface */
    LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
 
    /** Select an alternate interface for the specified interface */
    LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
 
    /** Set then report an endpoint's synchronization frame */
    LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
};
 
/** \ingroup misc
 * Request type bits of the
 * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
 * transfers. */
enum libusb_request_type {
    /** Standard */
    LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
 
    /** Class */
    LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
 
    /** Vendor */
    LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
 
    /** Reserved */
    LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5)
};
 
/** \ingroup misc
 * Recipient bits of the
 * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
 * transfers. Values 4 through 31 are reserved. */
enum libusb_request_recipient {
    /** Device */
    LIBUSB_RECIPIENT_DEVICE = 0x00,
 
    /** Interface */
    LIBUSB_RECIPIENT_INTERFACE = 0x01,
 
    /** Endpoint */
    LIBUSB_RECIPIENT_ENDPOINT = 0x02,
 
    /** Other */
    LIBUSB_RECIPIENT_OTHER = 0x03,
};
 
#define LIBUSB_ISO_SYNC_TYPE_MASK       0x0C
 
/** \ingroup desc
 * Synchronization type for isochronous endpoints. Values for bits 2:3 of the
 * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
 * libusb_endpoint_descriptor.
 */
enum libusb_iso_sync_type {
    /** No synchronization */
    LIBUSB_ISO_SYNC_TYPE_NONE = 0,
 
    /** Asynchronous */
    LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
 
    /** Adaptive */
    LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
 
    /** Synchronous */
    LIBUSB_ISO_SYNC_TYPE_SYNC = 3
};
 
#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
 
/** \ingroup desc
 * Usage type for isochronous endpoints. Values for bits 4:5 of the
 * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
 * libusb_endpoint_descriptor.
 */
enum libusb_iso_usage_type {
    /** Data endpoint */
    LIBUSB_ISO_USAGE_TYPE_DATA = 0,
 
    /** Feedback endpoint */
    LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
 
    /** Implicit feedback Data endpoint */
    LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
};
 
/** \ingroup desc
 * A structure representing the standard USB device descriptor. This
 * descriptor is documented in section 9.6.1 of the USB 2.0 specification.
 * All multiple-byte fields are represented in host-endian format.
 */
struct libusb_device_descriptor {
    /** Size of this descriptor (in bytes) */
    uint8_t  bLength;
 
    /** Descriptor type. Will have value
     * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this
     * context. */
    uint8_t  bDescriptorType;
 
    /** USB specification release number in binary-coded decimal. A value of
     * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */
    uint16_t bcdUSB;
 
    /** USB-IF class code for the device. See \ref libusb_class_code. */
    uint8_t  bDeviceClass;
 
    /** USB-IF subclass code for the device, qualified by the bDeviceClass
     * value */
    uint8_t  bDeviceSubClass;
 
    /** USB-IF protocol code for the device, qualified by the bDeviceClass and
     * bDeviceSubClass values */
    uint8_t  bDeviceProtocol;
 
    /** Maximum packet size for endpoint 0 */
    uint8_t  bMaxPacketSize0;
 
    /** USB-IF vendor ID */
    uint16_t idVendor;
 
    /** USB-IF product ID */
    uint16_t idProduct;
 
    /** Device release number in binary-coded decimal */
    uint16_t bcdDevice;
 
    /** Index of string descriptor describing manufacturer */
    uint8_t  iManufacturer;
 
    /** Index of string descriptor describing product */
    uint8_t  iProduct;
 
    /** Index of string descriptor containing device serial number */
    uint8_t  iSerialNumber;
 
    /** Number of possible configurations */
    uint8_t  bNumConfigurations;
};
 
/** \ingroup desc
 * A structure representing the standard USB endpoint descriptor. This
 * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
 * All multiple-byte fields are represented in host-endian format.
 */
struct libusb_endpoint_descriptor {
    /** Size of this descriptor (in bytes) */
    uint8_t  bLength;
 
    /** Descriptor type. Will have value
     * \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in
     * this context. */
    uint8_t  bDescriptorType;
 
    /** The address of the endpoint described by this descriptor. Bits 0:3 are
     * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction,
     * see \ref libusb_endpoint_direction.
     */
    uint8_t  bEndpointAddress;
 
    /** Attributes which apply to the endpoint when it is configured using
     * the bConfigurationValue. Bits 0:1 determine the transfer type and
     * correspond to \ref libusb_transfer_type. Bits 2:3 are only used for
     * isochronous endpoints and correspond to \ref libusb_iso_sync_type.
     * Bits 4:5 are also only used for isochronous endpoints and correspond to
     * \ref libusb_iso_usage_type. Bits 6:7 are reserved.
     */
    uint8_t  bmAttributes;
 
    /** Maximum packet size this endpoint is capable of sending/receiving. */
    uint16_t wMaxPacketSize;
 
    /** Interval for polling endpoint for data transfers. */
    uint8_t  bInterval;
 
    /** For audio devices only: the rate at which synchronization feedback
     * is provided. */
    uint8_t  bRefresh;
 
    /** For audio devices only: the address if the synch endpoint */
    uint8_t  bSynchAddress;
 
    /** Extra descriptors. If libusbx encounters unknown endpoint descriptors,
     * it will store them here, should you wish to parse them. */
    const unsigned char *extra;
 
    /** Length of the extra descriptors, in bytes. */
    int extra_length;
};
 
/** \ingroup desc
 * A structure representing the standard USB interface descriptor. This
 * descriptor is documented in section 9.6.5 of the USB 2.0 specification.
 * All multiple-byte fields are represented in host-endian format.
 */
struct libusb_interface_descriptor {
    /** Size of this descriptor (in bytes) */
    uint8_t  bLength;
 
    /** Descriptor type. Will have value
     * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE
     * in this context. */
    uint8_t  bDescriptorType;
 
    /** Number of this interface */
    uint8_t  bInterfaceNumber;
 
    /** Value used to select this alternate setting for this interface */
    uint8_t  bAlternateSetting;
 
    /** Number of endpoints used by this interface (excluding the control
     * endpoint). */
    uint8_t  bNumEndpoints;
 
    /** USB-IF class code for this interface. See \ref libusb_class_code. */
    uint8_t  bInterfaceClass;
 
    /** USB-IF subclass code for this interface, qualified by the
     * bInterfaceClass value */
    uint8_t  bInterfaceSubClass;
 
    /** USB-IF protocol code for this interface, qualified by the
     * bInterfaceClass and bInterfaceSubClass values */
    uint8_t  bInterfaceProtocol;
 
    /** Index of string descriptor describing this interface */
    uint8_t  iInterface;
 
    /** Array of endpoint descriptors. This length of this array is determined
     * by the bNumEndpoints field. */
    const struct libusb_endpoint_descriptor *endpoint;
 
    /** Extra descriptors. If libusbx encounters unknown interface descriptors,
     * it will store them here, should you wish to parse them. */
    const unsigned char *extra;
 
    /** Length of the extra descriptors, in bytes. */
    int extra_length;
};
 
/** \ingroup desc
 * A collection of alternate settings for a particular USB interface.
 */
struct libusb_interface {
    /** Array of interface descriptors. The length of this array is determined
     * by the num_altsetting field. */
    const struct libusb_interface_descriptor *altsetting;
 
    /** The number of alternate settings that belong to this interface */
    int num_altsetting;
};
 
/** \ingroup desc
 * A structure representing the standard USB configuration descriptor. This
 * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
 * All multiple-byte fields are represented in host-endian format.
 */
struct libusb_config_descriptor {
    /** Size of this descriptor (in bytes) */
    uint8_t  bLength;
 
    /** Descriptor type. Will have value
     * \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG
     * in this context. */
    uint8_t  bDescriptorType;
 
    /** Total length of data returned for this configuration */
    uint16_t wTotalLength;
 
    /** Number of interfaces supported by this configuration */
    uint8_t  bNumInterfaces;
 
    /** Identifier value for this configuration */
    uint8_t  bConfigurationValue;
 
    /** Index of string descriptor describing this configuration */
    uint8_t  iConfiguration;
 
    /** Configuration characteristics */
    uint8_t  bmAttributes;
 
    /** Maximum power consumption of the USB device from this bus in this
     * configuration when the device is fully opreation. Expressed in units
     * of 2 mA. */
    uint8_t  MaxPower;
 
    /** Array of interfaces supported by this configuration. The length of
     * this array is determined by the bNumInterfaces field. */
    const struct libusb_interface *interface;
 
    /** Extra descriptors. If libusbx encounters unknown configuration
     * descriptors, it will store them here, should you wish to parse them. */
    const unsigned char *extra;
 
    /** Length of the extra descriptors, in bytes. */
    int extra_length;
};
 
/** \ingroup asyncio
 * Setup packet for control transfers. */
struct libusb_control_setup {
    /** Request type. Bits 0:4 determine recipient, see
     * \ref libusb_request_recipient. Bits 5:6 determine type, see
     * \ref libusb_request_type. Bit 7 determines data transfer direction, see
     * \ref libusb_endpoint_direction.
     */
    uint8_t  bmRequestType;
 
    /** Request. If the type bits of bmRequestType are equal to
     * \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD
     * "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to
     * \ref libusb_standard_request. For other cases, use of this field is
     * application-specific. */
    uint8_t  bRequest;
 
    /** Value. Varies according to request */
    uint16_t wValue;
 
    /** Index. Varies according to request, typically used to pass an index
     * or offset */
    uint16_t wIndex;
 
    /** Number of bytes to transfer */
    uint16_t wLength;
};
 
#define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
 
/* libusbx */
 
struct libusb_context;
struct libusb_device;
struct libusb_device_handle;
 
/** \ingroup lib
 * Structure providing the version of the libusbx runtime
 */
struct libusb_version {
    /** Library major version. */
    const uint16_t major;
 
    /** Library minor version. */
    const uint16_t minor;
 
    /** Library micro version. */
    const uint16_t micro;
 
    /** Library nano version. */
    const uint16_t nano;
 
    /** Library release candidate suffix string, e.g. "-rc4". */
    const char *rc;
 
    /** For ABI compatibility only. */
    const char* describe;
};
 
/** \ingroup lib
 * Structure representing a libusbx session. The concept of individual libusbx
 * sessions allows for your program to use two libraries (or dynamically
 * load two modules) which both independently use libusb. This will prevent
 * interference between the individual libusbx users - for example
 * libusb_set_debug() will not affect the other user of the library, and
 * libusb_exit() will not destroy resources that the other user is still
 * using.
 *
 * Sessions are created by libusb_init() and destroyed through libusb_exit().
 * If your application is guaranteed to only ever include a single libusbx
 * user (i.e. you), you do not have to worry about contexts: pass NULL in
 * every function call where a context is required. The default context
 * will be used.
 *
 * For more information, see \ref contexts.
 */
typedef struct libusb_context libusb_context;
 
/** \ingroup dev
 * Structure representing a USB device detected on the system. This is an
 * opaque type for which you are only ever provided with a pointer, usually
 * originating from libusb_get_device_list().
 *
 * Certain operations can be performed on a device, but in order to do any
 * I/O you will have to first obtain a device handle using libusb_open().
 *
 * Devices are reference counted with libusb_device_ref() and
 * libusb_device_unref(), and are freed when the reference count reaches 0.
 * New devices presented by libusb_get_device_list() have a reference count of
 * 1, and libusb_free_device_list() can optionally decrease the reference count
 * on all devices in the list. libusb_open() adds another reference which is
 * later destroyed by libusb_close().
 */
typedef struct libusb_device libusb_device;
 
 
/** \ingroup dev
 * Structure representing a handle on a USB device. This is an opaque type for
 * which you are only ever provided with a pointer, usually originating from
 * libusb_open().
 *
 * A device handle is used to perform I/O and other operations. When finished
 * with a device handle, you should call libusb_close().
 */
typedef struct libusb_device_handle libusb_device_handle;
 
/** \ingroup dev
 * Speed codes. Indicates the speed at which the device is operating.
 */
enum libusb_speed {
    /** The OS doesn't report or know the device speed. */
    LIBUSB_SPEED_UNKNOWN = 0,
 
    /** The device is operating at low speed (1.5MBit/s). */
    LIBUSB_SPEED_LOW = 1,
 
    /** The device is operating at full speed (12MBit/s). */
    LIBUSB_SPEED_FULL = 2,
 
    /** The device is operating at high speed (480MBit/s). */
    LIBUSB_SPEED_HIGH = 3,
 
    /** The device is operating at super speed (5000MBit/s). */
    LIBUSB_SPEED_SUPER = 4,
};
 
/** \ingroup misc
 * Error codes. Most libusbx functions return 0 on success or one of these
 * codes on failure.
 * You can call \ref libusb_error_name() to retrieve a string representation
 * of an error code.
 */
enum libusb_error {
    /** Success (no error) */
    LIBUSB_SUCCESS = 0,
 
    /** Input/output error */
    LIBUSB_ERROR_IO = -1,
 
    /** Invalid parameter */
    LIBUSB_ERROR_INVALID_PARAM = -2,
 
    /** Access denied (insufficient permissions) */
    LIBUSB_ERROR_ACCESS = -3,
 
    /** No such device (it may have been disconnected) */
    LIBUSB_ERROR_NO_DEVICE = -4,
 
    /** Entity not found */
    LIBUSB_ERROR_NOT_FOUND = -5,
 
    /** Resource busy */
    LIBUSB_ERROR_BUSY = -6,
 
    /** Operation timed out */
    LIBUSB_ERROR_TIMEOUT = -7,
 
    /** Overflow */
    LIBUSB_ERROR_OVERFLOW = -8,
 
    /** Pipe error */
    LIBUSB_ERROR_PIPE = -9,
 
    /** System call interrupted (perhaps due to signal) */
    LIBUSB_ERROR_INTERRUPTED = -10,
 
    /** Insufficient memory */
    LIBUSB_ERROR_NO_MEM = -11,
 
    /** Operation not supported or unimplemented on this platform */
    LIBUSB_ERROR_NOT_SUPPORTED = -12,
 
    /* NB! Remember to update libusb_error_name()
       when adding new error codes here. */
 
    /** Other error */
    LIBUSB_ERROR_OTHER = -99,
};
 
/** \ingroup asyncio
 * Transfer status codes */
enum libusb_transfer_status {
    /** Transfer completed without error. Note that this does not indicate
     * that the entire amount of requested data was transferred. */
    LIBUSB_TRANSFER_COMPLETED,
 
    /** Transfer failed */
    LIBUSB_TRANSFER_ERROR,
 
    /** Transfer timed out */
    LIBUSB_TRANSFER_TIMED_OUT,
 
    /** Transfer was cancelled */
    LIBUSB_TRANSFER_CANCELLED,
 
    /** For bulk/interrupt endpoints: halt condition detected (endpoint
     * stalled). For control endpoints: control request not supported. */
    LIBUSB_TRANSFER_STALL,
 
    /** Device was disconnected */
    LIBUSB_TRANSFER_NO_DEVICE,
 
    /** Device sent more data than requested */
    LIBUSB_TRANSFER_OVERFLOW,
};
 
/** \ingroup asyncio
 * libusb_transfer.flags values */
enum libusb_transfer_flags {
    /** Report short frames as errors */
    LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,
 
    /** Automatically free() transfer buffer during libusb_free_transfer() */
    LIBUSB_TRANSFER_FREE_BUFFER = 1<<1,
 
    /** Automatically call libusb_free_transfer() after callback returns.
     * If this flag is set, it is illegal to call libusb_free_transfer()
     * from your transfer callback, as this will result in a double-free
     * when this flag is acted upon. */
    LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2,
 
    /** Terminate transfers that are a multiple of the endpoint's
     * wMaxPacketSize with an extra zero length packet. This is useful
     * when a device protocol mandates that each logical request is
     * terminated by an incomplete packet (i.e. the logical requests are
     * not separated by other means).
     *
     * This flag only affects host-to-device transfers to bulk and interrupt
     * endpoints. In other situations, it is ignored.
     *
     * This flag only affects transfers with a length that is a multiple of
     * the endpoint's wMaxPacketSize. On transfers of other lengths, this
     * flag has no effect. Therefore, if you are working with a device that
     * needs a ZLP whenever the end of the logical request falls on a packet
     * boundary, then it is sensible to set this flag on <em>every</em>
     * transfer (you do not have to worry about only setting it on transfers
     * that end on the boundary).
     *
     * This flag is currently only supported on Linux.
     * On other systems, libusb_submit_transfer() will return
     * LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this flag is set.
     *
     * Available since libusb-1.0.9.
     */
    LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 << 3,
};
 
/** \ingroup asyncio
 * Isochronous packet descriptor. */
struct libusb_iso_packet_descriptor {
    /** Length of data to request in this packet */
    unsigned int length;
 
    /** Amount of data that was actually transferred */
    unsigned int actual_length;
 
    /** Status code for this packet */
    enum libusb_transfer_status status;
};
 
struct libusb_transfer;
 
/** \ingroup asyncio
 * Asynchronous transfer callback function type. When submitting asynchronous
 * transfers, you pass a pointer to a callback function of this type via the
 * \ref libusb_transfer::callback "callback" member of the libusb_transfer
 * structure. libusbx will call this function later, when the transfer has
 * completed or failed. See \ref asyncio for more information.
 * \param transfer The libusb_transfer struct the callback function is being
 * notified about.
 */
typedef void (LIBUSB_CALL *libusb_transfer_cb_fn)(struct libusb_transfer *transfer);
 
/** \ingroup asyncio
 * The generic USB transfer structure. The user populates this structure and
 * then submits it in order to request a transfer. After the transfer has
 * completed, the library populates the transfer with the results and passes
 * it back to the user.
 */
struct libusb_transfer {
    /** Handle of the device that this transfer will be submitted to */
    libusb_device_handle *dev_handle;
 
    /** A bitwise OR combination of \ref libusb_transfer_flags. */
    uint8_t flags;
 
    /** Address of the endpoint where this transfer will be sent. */
    unsigned char endpoint;
 
    /** Type of the endpoint from \ref libusb_transfer_type */
    unsigned char type;
 
    /** Timeout for this transfer in millseconds. A value of 0 indicates no
     * timeout. */
    unsigned int timeout;
 
    /** The status of the transfer. Read-only, and only for use within
     * transfer callback function.
     *
     * If this is an isochronous transfer, this field may read COMPLETED even
     * if there were errors in the frames. Use the
     * \ref libusb_iso_packet_descriptor::status "status" field in each packet
     * to determine if errors occurred. */
    enum libusb_transfer_status status;
 
    /** Length of the data buffer */
    int length;
 
    /** Actual length of data that was transferred. Read-only, and only for
     * use within transfer callback function. Not valid for isochronous
     * endpoint transfers. */
    int actual_length;
 
    /** Callback function. This will be invoked when the transfer completes,
     * fails, or is cancelled. */
    libusb_transfer_cb_fn callback;
 
    /** User context data to pass to the callback function. */
    void *user_data;
 
    /** Data buffer */
    unsigned char *buffer;
 
    /** Number of isochronous packets. Only used for I/O with isochronous
     * endpoints. */
    int num_iso_packets;
 
    /** Isochronous packet descriptors, for isochronous transfers only. */
    struct libusb_iso_packet_descriptor iso_packet_desc
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
    [] /* valid C99 code */
#else
    [0] /* non-standard, but usually working code */
#endif
    ;
};
 
/** \ingroup misc
 * Capabilities supported by this instance of libusb. Test if the loaded
 * library supports a given capability by calling
 * \ref libusb_has_capability().
 */
enum libusb_capability {
    /** The libusb_has_capability() API is available. */
    LIBUSB_CAP_HAS_CAPABILITY = 0,
};
 
int LIBUSB_CALL libusb_init(libusb_context **ctx);
void LIBUSB_CALL libusb_exit(libusb_context *ctx);
void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);
const struct libusb_version * LIBUSB_CALL libusb_get_version(void);
int LIBUSB_CALL libusb_has_capability(uint32_t capability);
const char * LIBUSB_CALL libusb_error_name(int errcode);
 
ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,
    libusb_device ***list);
void LIBUSB_CALL libusb_free_device_list(libusb_device **list,
    int unref_devices);
libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev);
void LIBUSB_CALL libusb_unref_device(libusb_device *dev);
 
int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev,
    int *config);
int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev,
    struct libusb_device_descriptor *desc);
int LIBUSB_CALL libusb_get_active_config_descriptor(libusb_device *dev,
    struct libusb_config_descriptor **config);
int LIBUSB_CALL libusb_get_config_descriptor(libusb_device *dev,
    uint8_t config_index, struct libusb_config_descriptor **config);
int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev,
    uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
void LIBUSB_CALL libusb_free_config_descriptor(
    struct libusb_config_descriptor *config);
uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev);
int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
    unsigned char endpoint);
int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev,
    unsigned char endpoint);
 
int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **handle);
void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle);
libusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle);
 
int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev,
    int configuration);
int LIBUSB_CALL libusb_claim_interface(libusb_device_handle *dev,
    int interface_number);
int LIBUSB_CALL libusb_release_interface(libusb_device_handle *dev,
    int interface_number);
 
libusb_device_handle * LIBUSB_CALL libusb_open_device_with_vid_pid(
    libusb_context *ctx, uint16_t vendor_id, uint16_t product_id);
 
int LIBUSB_CALL libusb_set_interface_alt_setting(libusb_device_handle *dev,
    int interface_number, int alternate_setting);
int LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev,
    unsigned char endpoint);
int LIBUSB_CALL libusb_reset_device(libusb_device_handle *dev);
 
int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *dev,
    int interface_number);
int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev,
    int interface_number);
int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev,
    int interface_number);
 
/* async I/O */
 
/** \ingroup asyncio
 * Get the data section of a control transfer. This convenience function is here
 * to remind you that the data does not start until 8 bytes into the actual
 * buffer, as the setup packet comes first.
 *
 * Calling this function only makes sense from a transfer callback function,
 * or situations where you have already allocated a suitably sized buffer at
 * transfer->buffer.
 *
 * \param transfer a transfer
 * \returns pointer to the first byte of the data section
 */
static inline unsigned char *libusb_control_transfer_get_data(
    struct libusb_transfer *transfer)
{
    return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;
}
 
/** \ingroup asyncio
 * Get the control setup packet of a control transfer. This convenience
 * function is here to remind you that the control setup occupies the first
 * 8 bytes of the transfer data buffer.
 *
 * Calling this function only makes sense from a transfer callback function,
 * or situations where you have already allocated a suitably sized buffer at
 * transfer->buffer.
 *
 * \param transfer a transfer
 * \returns a casted pointer to the start of the transfer data buffer
 */
static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
    struct libusb_transfer *transfer)
{
    return (struct libusb_control_setup *) transfer->buffer;
}
 
/** \ingroup asyncio
 * Helper function to populate the setup packet (first 8 bytes of the data
 * buffer) for a control transfer. The wIndex, wValue and wLength values should
 * be given in host-endian byte order.
 *
 * \param buffer buffer to output the setup packet into
 * \param bmRequestType see the
 * \ref libusb_control_setup::bmRequestType "bmRequestType" field of
 * \ref libusb_control_setup
 * \param bRequest see the
 * \ref libusb_control_setup::bRequest "bRequest" field of
 * \ref libusb_control_setup
 * \param wValue see the
 * \ref libusb_control_setup::wValue "wValue" field of
 * \ref libusb_control_setup
 * \param wIndex see the
 * \ref libusb_control_setup::wIndex "wIndex" field of
 * \ref libusb_control_setup
 * \param wLength see the
 * \ref libusb_control_setup::wLength "wLength" field of
 * \ref libusb_control_setup
 */
static inline void libusb_fill_control_setup(unsigned char *buffer,
    uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
    uint16_t wLength)
{
    struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
    setup->bmRequestType = bmRequestType;
    setup->bRequest = bRequest;
    setup->wValue = libusb_cpu_to_le16(wValue);
    setup->wIndex = libusb_cpu_to_le16(wIndex);
    setup->wLength = libusb_cpu_to_le16(wLength);
}
 
struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(int iso_packets);
int LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer);
int LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer);
void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer);
 
/** \ingroup asyncio
 * Helper function to populate the required \ref libusb_transfer fields
 * for a control transfer.
 *
 * If you pass a transfer buffer to this function, the first 8 bytes will
 * be interpreted as a control setup packet, and the wLength field will be
 * used to automatically populate the \ref libusb_transfer::length "length"
 * field of the transfer. Therefore the recommended approach is:
 * -# Allocate a suitably sized data buffer (including space for control setup)
 * -# Call libusb_fill_control_setup()
 * -# If this is a host-to-device transfer with a data stage, put the data
 *    in place after the setup packet
 * -# Call this function
 * -# Call libusb_submit_transfer()
 *
 * It is also legal to pass a NULL buffer to this function, in which case this
 * function will not attempt to populate the length field. Remember that you
 * must then populate the buffer and length fields later.
 *
 * \param transfer the transfer to populate
 * \param dev_handle handle of the device that will handle the transfer
 * \param buffer data buffer. If provided, this function will interpret the
 * first 8 bytes as a setup packet and infer the transfer length from that.
 * \param callback callback function to be invoked on transfer completion
 * \param user_data user data to pass to callback function
 * \param timeout timeout for the transfer in milliseconds
 */
static inline void libusb_fill_control_transfer(
    struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
    unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,
    unsigned int timeout)
{
    struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
    transfer->dev_handle = dev_handle;
    transfer->endpoint = 0;
    transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL;
    transfer->timeout = timeout;
    transfer->buffer = buffer;
    if (setup)
        transfer->length = LIBUSB_CONTROL_SETUP_SIZE
            + libusb_le16_to_cpu(setup->wLength);
    transfer->user_data = user_data;
    transfer->callback = callback;
}
 
/** \ingroup asyncio
 * Helper function to populate the required \ref libusb_transfer fields
 * for a bulk transfer.
 *
 * \param transfer the transfer to populate
 * \param dev_handle handle of the device that will handle the transfer
 * \param endpoint address of the endpoint where this transfer will be sent
 * \param buffer data buffer
 * \param length length of data buffer
 * \param callback callback function to be invoked on transfer completion
 * \param user_data user data to pass to callback function
 * \param timeout timeout for the transfer in milliseconds
 */
static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,
    libusb_device_handle *dev_handle, unsigned char endpoint,
    unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
    void *user_data, unsigned int timeout)
{
    transfer->dev_handle = dev_handle;
    transfer->endpoint = endpoint;
    transfer->type = LIBUSB_TRANSFER_TYPE_BULK;
    transfer->timeout = timeout;
    transfer->buffer = buffer;
    transfer->length = length;
    transfer->user_data = user_data;
    transfer->callback = callback;
}
 
/** \ingroup asyncio
 * Helper function to populate the required \ref libusb_transfer fields
 * for an interrupt transfer.
 *
 * \param transfer the transfer to populate
 * \param dev_handle handle of the device that will handle the transfer
 * \param endpoint address of the endpoint where this transfer will be sent
 * \param buffer data buffer
 * \param length length of data buffer
 * \param callback callback function to be invoked on transfer completion
 * \param user_data user data to pass to callback function
 * \param timeout timeout for the transfer in milliseconds
 */
static inline void libusb_fill_interrupt_transfer(
    struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
    unsigned char endpoint, unsigned char *buffer, int length,
    libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
{
    transfer->dev_handle = dev_handle;
    transfer->endpoint = endpoint;
    transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT;
    transfer->timeout = timeout;
    transfer->buffer = buffer;
    transfer->length = length;
    transfer->user_data = user_data;
    transfer->callback = callback;
}
 
/** \ingroup asyncio
 * Helper function to populate the required \ref libusb_transfer fields
 * for an isochronous transfer.
 *
 * \param transfer the transfer to populate
 * \param dev_handle handle of the device that will handle the transfer
 * \param endpoint address of the endpoint where this transfer will be sent
 * \param buffer data buffer
 * \param length length of data buffer
 * \param num_iso_packets the number of isochronous packets
 * \param callback callback function to be invoked on transfer completion
 * \param user_data user data to pass to callback function
 * \param timeout timeout for the transfer in milliseconds
 */
static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer,
    libusb_device_handle *dev_handle, unsigned char endpoint,
    unsigned char *buffer, int length, int num_iso_packets,
    libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
{
    transfer->dev_handle = dev_handle;
    transfer->endpoint = endpoint;
    transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;
    transfer->timeout = timeout;
    transfer->buffer = buffer;
    transfer->length = length;
    transfer->num_iso_packets = num_iso_packets;
    transfer->user_data = user_data;
    transfer->callback = callback;
}
 
/** \ingroup asyncio
 * Convenience function to set the length of all packets in an isochronous
 * transfer, based on the num_iso_packets field in the transfer structure.
 *
 * \param transfer a transfer
 * \param length the length to set in each isochronous packet descriptor
 * \see libusb_get_max_packet_size()
 */
static inline void libusb_set_iso_packet_lengths(
    struct libusb_transfer *transfer, unsigned int length)
{
    int i;
    for (i = 0; i < transfer->num_iso_packets; i++)
        transfer->iso_packet_desc[i].length = length;
}
 
/** \ingroup asyncio
 * Convenience function to locate the position of an isochronous packet
 * within the buffer of an isochronous transfer.
 *
 * This is a thorough function which loops through all preceding packets,
 * accumulating their lengths to find the position of the specified packet.
 * Typically you will assign equal lengths to each packet in the transfer,
 * and hence the above method is sub-optimal. You may wish to use
 * libusb_get_iso_packet_buffer_simple() instead.
 *
 * \param transfer a transfer
 * \param packet the packet to return the address of
 * \returns the base address of the packet buffer inside the transfer buffer,
 * or NULL if the packet does not exist.
 * \see libusb_get_iso_packet_buffer_simple()
 */
static inline unsigned char *libusb_get_iso_packet_buffer(
    struct libusb_transfer *transfer, unsigned int packet)
{
    int i;
    size_t offset = 0;
    int _packet;
 
    /* oops..slight bug in the API. packet is an unsigned int, but we use
     * signed integers almost everywhere else. range-check and convert to
     * signed to avoid compiler warnings. FIXME for libusb-2. */
    if (packet > INT_MAX)
        return NULL;
    _packet = packet;
 
    if (_packet >= transfer->num_iso_packets)
        return NULL;
 
    for (i = 0; i < _packet; i++)
        offset += transfer->iso_packet_desc[i].length;
 
    return transfer->buffer + offset;
}
 
/** \ingroup asyncio
 * Convenience function to locate the position of an isochronous packet
 * within the buffer of an isochronous transfer, for transfers where each
 * packet is of identical size.
 *
 * This function relies on the assumption that every packet within the transfer
 * is of identical size to the first packet. Calculating the location of
 * the packet buffer is then just a simple calculation:
 * <tt>buffer + (packet_size * packet)</tt>
 *
 * Do not use this function on transfers other than those that have identical
 * packet lengths for each packet.
 *
 * \param transfer a transfer
 * \param packet the packet to return the address of
 * \returns the base address of the packet buffer inside the transfer buffer,
 * or NULL if the packet does not exist.
 * \see libusb_get_iso_packet_buffer()
 */
static inline unsigned char *libusb_get_iso_packet_buffer_simple(
    struct libusb_transfer *transfer, unsigned int packet)
{
    int _packet;
 
    /* oops..slight bug in the API. packet is an unsigned int, but we use
     * signed integers almost everywhere else. range-check and convert to
     * signed to avoid compiler warnings. FIXME for libusb-2. */
    if (packet > INT_MAX)
        return NULL;
    _packet = packet;
 
    if (_packet >= transfer->num_iso_packets)
        return NULL;
 
    return transfer->buffer + (transfer->iso_packet_desc[0].length * _packet);
}
 
/* sync I/O */
 
int LIBUSB_CALL libusb_control_transfer(libusb_device_handle *dev_handle,
    uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
    unsigned char *data, uint16_t wLength, unsigned int timeout);
 
int LIBUSB_CALL libusb_bulk_transfer(libusb_device_handle *dev_handle,
    unsigned char endpoint, unsigned char *data, int length,
    int *actual_length, unsigned int timeout);
 
int LIBUSB_CALL libusb_interrupt_transfer(libusb_device_handle *dev_handle,
    unsigned char endpoint, unsigned char *data, int length,
    int *actual_length, unsigned int timeout);
 
/** \ingroup desc
 * Retrieve a descriptor from the default control pipe.
 * This is a convenience function which formulates the appropriate control
 * message to retrieve the descriptor.
 *
 * \param dev a device handle
 * \param desc_type the descriptor type, see \ref libusb_descriptor_type
 * \param desc_index the index of the descriptor to retrieve
 * \param data output buffer for descriptor
 * \param length size of data buffer
 * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
 */
static inline int libusb_get_descriptor(libusb_device_handle *dev,
    uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length)
{
    return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
        LIBUSB_REQUEST_GET_DESCRIPTOR, (desc_type << 8) | desc_index, 0, data,
        (uint16_t) length, 1000);
}
 
/** \ingroup desc
 * Retrieve a descriptor from a device.
 * This is a convenience function which formulates the appropriate control
 * message to retrieve the descriptor. The string returned is Unicode, as
 * detailed in the USB specifications.
 *
 * \param dev a device handle
 * \param desc_index the index of the descriptor to retrieve
 * \param langid the language ID for the string descriptor
 * \param data output buffer for descriptor
 * \param length size of data buffer
 * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
 * \see libusb_get_string_descriptor_ascii()
 */
static inline int libusb_get_string_descriptor(libusb_device_handle *dev,
    uint8_t desc_index, uint16_t langid, unsigned char *data, int length)
{
    return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
        LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t)((LIBUSB_DT_STRING << 8) | desc_index),
        langid, data, (uint16_t) length, 1000);
}
 
int LIBUSB_CALL libusb_get_string_descriptor_ascii(libusb_device_handle *dev,
    uint8_t desc_index, unsigned char *data, int length);
 
/* polling and timeouts */
 
int LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx);
void LIBUSB_CALL libusb_lock_events(libusb_context *ctx);
void LIBUSB_CALL libusb_unlock_events(libusb_context *ctx);
int LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx);
int LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx);
void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx);
void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx);
int LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv);
 
int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx,
    struct timeval *tv);
int LIBUSB_CALL libusb_handle_events_timeout_completed(libusb_context *ctx,
    struct timeval *tv, int *completed);
int LIBUSB_CALL libusb_handle_events(libusb_context *ctx);
int LIBUSB_CALL libusb_handle_events_completed(libusb_context *ctx, int *completed);
int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,
    struct timeval *tv);
int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx);
int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx,
    struct timeval *tv);
 
/** \ingroup poll
 * File descriptor for polling
 */
struct libusb_pollfd {
    /** Numeric file descriptor */
    int fd;
 
    /** Event flags to poll for from <poll.h>. POLLIN indicates that you
     * should monitor this file descriptor for becoming ready to read from,
     * and POLLOUT indicates that you should monitor this file descriptor for
     * nonblocking write readiness. */
    short events;
};
 
/** \ingroup poll
 * Callback function, invoked when a new file descriptor should be added
 * to the set of file descriptors monitored for events.
 * \param fd the new file descriptor
 * \param events events to monitor for, see \ref libusb_pollfd for a
 * description
 * \param user_data User data pointer specified in
 * libusb_set_pollfd_notifiers() call
 * \see libusb_set_pollfd_notifiers()
 */
typedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(int fd, short events,
    void *user_data);
 
/** \ingroup poll
 * Callback function, invoked when a file descriptor should be removed from
 * the set of file descriptors being monitored for events. After returning
 * from this callback, do not use that file descriptor again.
 * \param fd the file descriptor to stop monitoring
 * \param user_data User data pointer specified in
 * libusb_set_pollfd_notifiers() call
 * \see libusb_set_pollfd_notifiers()
 */
typedef void (LIBUSB_CALL *libusb_pollfd_removed_cb)(int fd, void *user_data);
 
const struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds(
    libusb_context *ctx);
void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,
    libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,
    void *user_data);
 
#ifdef __cplusplus
}
#endif
 
#endif
KOPOJI
Модератор
 Аватар для KOPOJI
16239 / 6450 / 389
Регистрация: 12.06.2012
Сообщений: 19,330
28.12.2013, 23:49     Не могу собрать программу для Raspbian #7
Цитата Сообщение от DimNsk Посмотреть сообщение
иначе вываливается ошибка , что не находит usb.h
насколько помню, путь, указанный с помощью кавычек не от корня считается от текущей директории..
Цитата Сообщение от DimNsk Посмотреть сообщение
прописал прямой путь
ну а с прописанным полным путем работает?
DimNsk
0 / 0 / 0
Регистрация: 28.12.2013
Сообщений: 6
28.12.2013, 23:50  [ТС]     Не могу собрать программу для Raspbian #8
Цитата Сообщение от Tulosba Посмотреть сообщение
А по этому "прямому" пути есть определение usb_dev_handle?
нет.
Tulosba
:)
Эксперт C++
4378 / 3221 / 297
Регистрация: 19.02.2013
Сообщений: 9,044
28.12.2013, 23:52     Не могу собрать программу для Raspbian #9
Цитата Сообщение от DimNsk Посмотреть сообщение
нет.
Ну так и что же Вы хотите? Ищите файл с реализацией.
DimNsk
0 / 0 / 0
Регистрация: 28.12.2013
Сообщений: 6
29.12.2013, 20:38  [ТС]     Не могу собрать программу для Raspbian #10
Цитата Сообщение от KOPOJI Посмотреть сообщение
насколько помню, путь, указанный с помощью кавычек не от корня считается от текущей директории..

ну а с прописанным полным путем работает?
нет не работает а вываливаются ошибки

прописал в кавычках
#include "/usr/include/libusb-1.0/libusb.h"

теже ошибки
Код
g++   -c -I. -I/usr/include -lusb -o main.o main.c
main.c:32:1: error: ‘usb_dev_handle’ does not name a type
main.c:33:1: error: ‘usb_dev_handle’ does not name a type
main.c:59:2: error: ‘usb_dev_handle’ does not name a type
main.c:79:1: error: ‘usb_dev_handle’ does not name a type
main.c: In function ‘bool USB_GET_FEATURE()’:
main.c:99:38: error: ‘lvr_winusb’ was not declared in this scope
main.c:99:102: error: ‘usb_control_msg’ was not declared in this scope
main.c: In function ‘bool USB_SET_FEATURE()’:
main.c:115:38: error: ‘lvr_winusb’ was not declared in this scope
main.c:115:102: error: ‘usb_control_msg’ was not declared in this scope
main.c: In function ‘int main(int, char**)’:
main.c:637:5: error: ‘lvr_winusb’ was not declared in this scope
main.c:637:38: error: ‘setup_libusb_access’ was not declared in this scope
main.c:669:104: error: ‘atoi’ was not declared in this scope
main.c:671:87: error: ‘atoi’ was not declared in this scope
main.c:676:21: error: ‘exit’ was not declared in this scope
main.c:679:48: error: ‘usb_release_interface’ was not declared in this scope
main.c:680:33: error: ‘usb_close’ was not declared in this scope
make: *** [main.o] Error 1
Добавлено через 13 минут
Цитата Сообщение от Tulosba Посмотреть сообщение
Ну так и что же Вы хотите? Ищите файл с реализацией.
нашел файл usb.h с другой реализацией в нем есть переменная usb_dev_handle

после сборки ошибок меньше но все равно
Код
g++ -I/usr/include -L/usr/lib -lusb -o bmcontrol main.o
/usr/bin/ld: cannot find -lusb
collect2: ld returned 1 exit status
make: *** [bmcontrol] Error 1
Добавлено через 20 часов 31 минуту
Все решилось сборкой и установкой библиотеки libusb-0.1-12
после этого файл bmcontrol собрался без ошибок
Все спасибо
MoreAnswers
Эксперт
37091 / 29110 / 5898
Регистрация: 17.06.2006
Сообщений: 43,301
31.12.2013, 07:48     Не могу собрать программу для Raspbian
Еще ссылки по теме:

не могу изменить программу для немного другого условия C++
Не могу собрать модульную программу C++
Не могу в цикле собрать из строк идентификатор переменной C++

Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
DimNsk
0 / 0 / 0
Регистрация: 28.12.2013
Сообщений: 6
31.12.2013, 07:48  [ТС]     Не могу собрать программу для Raspbian #11
Продолжаем...

Функция GET_TEMPERATURE выдает ошибку:

Вот код функции

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
bool GET_TEMPERATURE(unsigned long long ROM, float &T)
{
    if ( DEBUG ) printf("[D] enter GET_TEMPERATURE\n");
    unsigned long long CRC;
    unsigned long L1, L2;
    unsigned char L3;
    unsigned char FAMILY=ROM&0xFF;
    bool RESULT=false;
    unsigned char N=3;
    while (!RESULT&((N--)>0))
        if (MATCH_ROM(ROM))
            if (OW_WRITE_BYTE(0xBE))
                    if (OW_READ_4BYTE(L1))
                        if (OW_READ_4BYTE(L2))
                            if (OW_READ_BYTE(L3))
                            {
                                if ( DEBUG ) printf("[D] L1=%lx\tL2=%lx\tL3=%hhx\n", L1, L2, L3);
                                CRC=0;
                                for (int i=0; i<4; i++) CRC=CRC8(CRC, (L1>>(i*8))&0xFF);
                                if ( DEBUG ) printf("[D] CRC=%llx\n", CRC);
                                for (int i=0; i<4; i++) CRC=CRC8(CRC, (L2>>(i*8))&0xFF);
                                if ( DEBUG ) printf("[D] CRC=%llx\n", CRC);
                                CRC=CRC8(CRC, L3);
                                if ( DEBUG ) printf("[D] CRC=%llx\n", CRC);
                                RESULT=CRC==0;
                                short K=L1&0xFFFF;
                                //  DS18B20 +10.125=00A2h, -10.125=FF5Eh
                                //  DS18S20 +25.0=0032h, -25.0=FFCEh
                                //  K=0x0032;
                                T=1000;     //  for unknow FAMILY - no sensor exists
                                if ((FAMILY==0x28)|(FAMILY==0x22)) T=K*0.0625;  //  DS18B20 | DS1822
                                if (FAMILY==0x10) T=K*0.5;                      //  DS18S20 | DS1820
                                if ( DEBUG ) printf("[D] ~T=%f\n", T);
                            } else printf("[!] !OW_READ_BYTE(L3) \n");
                        else printf("[!] !OW_READ_4BYTE(L2) \n");
                    else printf("[!] !OW_READ_4BYTE(L1) \n");
                else printf("[!] !OW_WRITE_BYTE(0xBE) \n");
        else printf("[!] !MATCH_ROM(ROM) \n");
    if (!RESULT) printf("[!] Error GET_TEMPERATURE\n");
    return RESULT;
}
вот вывод DEBUG

Bash
1
#  /root/mp707/bmcontrol scan
temp_id1 = 8300000483000004
temp_id2 = 40000034000003


Bash
1
# /root/mp707/bmcontrol temp 40000034000003
Код
[D] enter GET_TEMPERATURE
[D] L1=ffffffff L2=ffffffff     L3=ff
[D] CRC=8d
[D] CRC=c9
[D] CRC=63
[D] ~T=1000.000000
[D] L1=ffffffff L2=ffffffff     L3=ff
[D] CRC=8d
[D] CRC=c9
[D] CRC=63
[D] ~T=1000.000000
[D] L1=ffffffff L2=ffffffff     L3=ff
[D] CRC=8d
[D] CRC=c9
[D] CRC=63
[D] ~T=1000.000000
[!] Error GET_TEMPERATURE

Что не так?
Yandex
Объявления
31.12.2013, 07:48     Не могу собрать программу для Raspbian
Ответ Создать тему
Опции темы

Текущее время: 08:56. Часовой пояс GMT +3.
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Рейтинг@Mail.ru