iCub-main
Loading...
Searching...
No Matches
dc1394thread.cpp
Go to the documentation of this file.
1#include "dc1394thread.h"
2#include <QDebug>
3#include "dc1394SliderBase.h"
4#include <yarp/os/LogStream.h>
5
6DC1394Thread::DC1394Thread(char *loc, char *rem,QObject *parent) :
7 QThread(parent)
8{
9 this->rem = rem;
10 this->loc = loc;
11
12 opCounter = 0;
13}
14
15bool DC1394Thread::getCameraDescription(CameraDescriptor *camera)
16{
17 if(fgControl)
18 return fgControl->getCameraDescription(camera);
19
20 return false;
21}
22
24{
25 // create firewire thread
26
27 grabberControl = new yarp::dev::PolyDriver;
28 // create usb thread
29
30 yarp::os::Property config;
31 config.put("device", "frameGrabber_nwc_yarp");
32 config.put("remote",rem.toLatin1().data());
33 config.put("local",loc.toLatin1().data());
34
35 bool opened = grabberControl->open(config);
36 if(!opened)
37 {
38 yError() << "Cannot open frameGrabber_nwc_yarp device.";
39 // TODO: What to do here??
40 }
41
42 grabberControl->view(fgControl);
43 grabberControl->view(DC1394Control);
44
45 if(!fgControl)
46 {
47 yError() << "RemoteGrabber does not have IFrameGrabberControl interface. Cannot proceed.";
48 // TODO: What to do here??
49 }
50
51 if(!DC1394Control)
52 {
53 yWarning() << "RemoteGrabber does not have IFrameGrabberControlDC1394 interface, please update yarp.";
54 }
55
56 keepRunning = true;
57 while(keepRunning){
58
59 QVariantList list = taskList.takeFirst();
60
61 threadFunction func = (threadFunction)list.takeFirst().toInt();
62
63 switch(func){
64 case _unknown:{
65 done();
66 break;
67 }
68 case _initFormatTab:{
70 break;
71 }
72 case _init:{
73 init();
74 break;
75 }
76 case _reload:{
77 reload();
78 break;
79 }
80 case _reset:{
81 reset();
82 break;
83 }
84 case _loadDefault:{
86 break;
87 }
90 break;
91 }
92 case _setPowerDC1394:{
93 setPowerDC1394(list);
94 break;
95 }
98 break;
99 }
101 setVideoModeDC1394(list);
102 break;
103 }
106 break;
107 }
108 case _setFPSDC1394:{
109 setFPSDC1394(list);
110 break;
111 }
112 case _setISOSpeedDC1394:{
113 setISOSpeedDC1394(list);
114 break;
115 }
118 break;
119 }
122 break;
123 }
124 case _sliderRefresh:{
125 sliderRefresh(list);
126 break;
127 }
128 case _sliderWBRefresh:{
129 sliderWBRefresh(list);
130 break;
131 }
132 case _sliderPropagate:{
133 sliderPropagate(list);
134 break;
135 }
136 case _sliderWBPropagate:{
137 sliderWBPropagate(list);
138 break;
139 }
140 case _sliderSetFeature:{
142 break;
143 }
146 break;
147 }
148 case _sliderOnePush:{
149 sliderOnePush(list);
150 break;
151 }
152 case _sliderWBOnePush:{
153 sliderWBOnePush(list);
154 break;
155 }
156 case _sliderRadioAuto:{
157 sliderRadioAuto(list);
158 break;
159 }
160 case _sliderPower:{
161 sliderPower(list);
162 break;
163 }
164 case _sliderHasFeature:{
165 sliderHasFeature(list);
166 break;
167 }
168 }
169
170
171 while(keepRunning && taskList.isEmpty()){
172 mutex.lock();
173 waitCond.wait(&mutex,200);
174 mutex.unlock();
175 }
176 }
177
178 grabberControl->close();
179 delete grabberControl;
180}
181
183{
184 keepRunning = false;
185 waitCond.wakeAll();
186 while(isRunning()){
187 QThread::msleep(100);
188 }
189}
190
191void DC1394Thread::doTask(threadFunction func, QVariantList args)
192{
193 mutex1.lock();
194 QVariant vaFunc = (int)func;
195
196 if(func != _sliderSetFeature && func != _sliderWBSetFeature){
197 if(opCounter == 0){
198 startLoading();
199 }
200 opCounter++;
201 }
202
203 QVariantList list;
204 list.append(vaFunc);
205 list.append(args);
206
207 mutex.lock();
208 taskList.enqueue(list);
209 waitCond.wakeAll();
210 mutex.unlock();
211
212 mutex1.unlock();
213}
214
216{
217 mutex1.lock();
218 QVariant vaFunc = (int)func;
219
220 if(opCounter == 0){
221 startLoading();
222 }
223 opCounter++;
224
225 QVariantList list;
226 list.append(vaFunc);
227 mutex.lock();
228 taskList.enqueue(list);
229 waitCond.wakeAll();
230 mutex.unlock();
231
232 mutex1.unlock();
233}
234
236{
237 uint videoModeMaskDC1394 = DC1394Control->getVideoModeMaskDC1394();
238 uint fPSMaskDC1394 = DC1394Control->getFPSMaskDC1394();
239 uint colorCodingMaskDC1394 = DC1394Control->getColorCodingMaskDC1394(DC1394Control->getVideoModeDC1394());
240 initFormatTabDone(videoModeMaskDC1394,fPSMaskDC1394,colorCodingMaskDC1394);
241
242 opCounter--;
243 if(opCounter == 0){
244 stopLoading();
245 }
246}
247
249{
250
251 uint videoModeDC1394 = DC1394Control->getVideoModeDC1394();
252 uint fPSDC1394 = DC1394Control->getFPSDC1394();
253 uint iSOSpeedDC1394 = DC1394Control->getISOSpeedDC1394();
254 bool operationModeDC1394 = DC1394Control->getOperationModeDC1394();
255 uint colorCodingDC1394 = DC1394Control->getColorCodingDC1394();
256 unsigned int xmax,ymax,xstep,ystep,xoffstep,yoffstep;
257 DC1394Control->getFormat7MaxWindowDC1394(xmax,ymax,xstep,ystep,xoffstep,yoffstep);
258 QSize max = QSize(xmax,ymax);
259 QSize step = QSize(xstep,ystep);
260 QSize offset = QSize(xoffstep,yoffstep);
261
262 unsigned int xdim,ydim;
263 int x0,y0;
264 DC1394Control->getFormat7WindowDC1394(xdim,ydim,x0,y0);
265 QSize dim = QSize(xdim,ydim);
266 QSize pos = QSize(x0,y0);
267
268 uint bytesPerPacketDC1394 = DC1394Control->getBytesPerPacketDC1394();
269 bool transmissionDC1394 = DC1394Control->getTransmissionDC1394();
270
271 initDone(videoModeDC1394,
272 fPSDC1394,
273 iSOSpeedDC1394,
274 operationModeDC1394,
275 colorCodingDC1394,
276 max,
277 step,
278 offset,
279 dim,
280 pos,
281 bytesPerPacketDC1394,
282 transmissionDC1394
283 );
284 opCounter--;
285 if(opCounter == 0){
286 stopLoading();
287 }
288}
289
291{
292 uint videoModeDC1394 = DC1394Control->getVideoModeDC1394();
293 uint colorCodingMaskDC1394 = DC1394Control->getColorCodingMaskDC1394(videoModeDC1394);
294
295 unsigned int xmax,ymax,xstep,ystep,xoffstep,yoffstep;
296 DC1394Control->getFormat7MaxWindowDC1394(xmax,ymax,xstep,ystep,xoffstep,yoffstep);
297 QSize max = QSize(xmax,ymax);
298 QSize step = QSize(xstep,ystep);
299 QSize offset = QSize(xoffstep,yoffstep);
300
301 unsigned int xdim,ydim;
302 int x0,y0;
303 DC1394Control->getFormat7WindowDC1394(xdim,ydim,x0,y0);
304 QSize dim = QSize(xdim,ydim);
305 QSize pos = QSize(x0,y0);
306
307 uint colorCodingDC1394 = DC1394Control->getColorCodingDC1394();
308 uint bytesPerPacketDC1394 = DC1394Control->getBytesPerPacketDC1394();
309 uint fPSMaskDC1394 = DC1394Control->getFPSMaskDC1394();
310 uint fPSDC1394 = DC1394Control->getFPSDC1394();
311 uint iSOSpeedDC1394 = DC1394Control->getISOSpeedDC1394();
312
313 reloadDone(videoModeDC1394,
314 colorCodingMaskDC1394,
315 max,
316 step,
317 offset,
318 dim,
319 pos,
320 colorCodingDC1394,
321 bytesPerPacketDC1394,
322 fPSMaskDC1394,
323 fPSDC1394,
324 iSOSpeedDC1394);
325
326 opCounter--;
327 if(opCounter == 0){
328 stopLoading();
329 }
330}
331
333{
334 DC1394Control->setDefaultsDC1394();
335 opCounter++;
336 reload();
337
338 uint bytesPerPacketDC1394 = DC1394Control->getBytesPerPacketDC1394();
339 uint colorCodingMaskDC1394 = DC1394Control->getColorCodingMaskDC1394(DC1394Control->getVideoModeDC1394());
340 DC1394Control->setTransmissionDC1394(true);
341 bool transmissionDC1394 = DC1394Control->getTransmissionDC1394();
342
343 loadDefaultDone(bytesPerPacketDC1394,colorCodingMaskDC1394,transmissionDC1394);
344
345 opCounter--;
346 if(opCounter == 0){
347 stopLoading();
348 }
349}
350
352{
353 DC1394Control->setResetDC1394();
354 opCounter++;
355 reload();
356
357 uint bytesPerPacketDC1394 = DC1394Control->getBytesPerPacketDC1394();
358 uint colorCodingMaskDC1394 = DC1394Control->getColorCodingMaskDC1394(DC1394Control->getVideoModeDC1394());
359 bool transmissionDC1394 = DC1394Control->getTransmissionDC1394();
360
361 resetDone(bytesPerPacketDC1394,colorCodingMaskDC1394,transmissionDC1394);
362 opCounter--;
363 if(opCounter == 0){
364 stopLoading();
365 }
366}
367
369{
370 bool value = arg.at(0).toBool();
371 DC1394Control->setTransmissionDC1394(value);
373 opCounter--;
374 if(opCounter == 0){
375 stopLoading();
376 }
377}
378
379void DC1394Thread::setPowerDC1394(QVariantList arg)
380{
381 bool value = arg.at(0).toBool();
382 DC1394Control->setPowerDC1394(value);
384 opCounter--;
385 if(opCounter == 0){
386 stopLoading();
387 }
388}
390{
391 unsigned int xdim=arg.at(0).toUInt();
392 unsigned int ydim=arg.at(1).toUInt();
393 int x0=arg.at(2).toInt();
394 int y0=arg.at(3).toInt();
395
396 DC1394Control->setFormat7WindowDC1394(xdim,ydim,x0,y0);
398 opCounter--;
399 if(opCounter == 0){
400 stopLoading();
401 }
402}
403
405{
406 unsigned int video_mode=arg.at(0).toUInt();
407 DC1394Control->setVideoModeDC1394(video_mode);
409 opCounter--;
410 if(opCounter == 0){
411 stopLoading();
412 }
413}
414
416{
417 int value =arg.at(0).toInt();
418 DC1394Control->setColorCodingDC1394(value);
419
421 opCounter--;
422 if(opCounter == 0){
423 stopLoading();
424 }
425}
426
427void DC1394Thread::setFPSDC1394(QVariantList arg)
428{
429 int value = arg.at(0).toInt();
430 DC1394Control->setFPSDC1394(value);
431
433
434 opCounter--;
435 if(opCounter == 0){
436 stopLoading();
437 }
438}
439
441{
442 int value = arg.at(0).toInt();
443 DC1394Control->setISOSpeedDC1394(value);
444
446 opCounter--;
447 if(opCounter == 0){
448 stopLoading();
449 }
450}
451
453{
454 int value = arg.at(0).toUInt();
455 DC1394Control->setBytesPerPacketDC1394(value);
456
458 opCounter--;
459 if(opCounter == 0){
460 stopLoading();
461 }
462}
463
465{
466 int value = arg.at(0).toInt();
467 DC1394Control->setOperationModeDC1394(value);
468
470 opCounter--;
471 if(opCounter == 0){
472 stopLoading();
473 }
474}
475
476void DC1394Thread::sliderRefresh(QVariantList arg)
477{
478 cameraFeature_id_t feature;
479
480 QObject *ptr = (QObject*)arg.at(0).value<void*>();
481 int value = arg.at(1).toInt();
482 feature = (cameraFeature_id_t)value;
483
484
485 FeatureMode mode;
486 bool bON, bAuto, bHasAuto, bHasManual, bHasOnePush, bHasOnOff;
487 fgControl->getActive(feature, &bON);
488 fgControl->getMode(feature, &mode);
489 fgControl->hasOnOff(feature, &bHasOnOff);
490 fgControl->hasAuto(feature, &bHasAuto);
491 fgControl->hasManual(feature, &bHasManual);
492 fgControl->hasOnePush(feature, &bHasOnePush);
493 double val;
494 fgControl->getFeature(feature, &val);
495 mode == MODE_AUTO ? bAuto = true : bAuto = false;
496
497// bool bON=true; //DC1394Control->getActiveDC1394(feature);
498// bool bAuto=false; //DC1394Control->getModeDC1394(feature);
499// bool bHasOnOff=true; //DC1394Control->hasOnOffDC1394(feature);
500// bool bHasAuto= true; //DC1394Control->hasAutoDC1394(feature);
501// bool bHasManual=true; //DC1394Control->hasManualDC1394(feature);
502// bool bHasOnePush=true; //DC1394Control->hasOnePushDC1394(feature);
503// double val=0.5; //DC1394Control->getFeatureDC1394(feature);
504
505// fgControl->setActive(feature,bON); refresh should not send commands right?
506
507 sliderRefreshDone(ptr,bON,bAuto,bHasOnOff,bHasAuto,bHasManual,bHasOnePush,val);
508
509 opCounter--;
510 if(opCounter == 0){
511 stopLoading();
512 }
513}
514
515void DC1394Thread::sliderWBRefresh(QVariantList arg)
516{
517 cameraFeature_id_t feature;
518
519 QObject *ptr = (QObject*)arg.at(0).value<void*>();
520 int value = arg.at(1).toInt();
521 feature = (cameraFeature_id_t)value;
522
523// bool bON=DC1394Control->getActiveDC1394(feature);
524// bool bAuto=DC1394Control->getModeDC1394(feature);
525// bool bHasOnOff=DC1394Control->hasOnOffDC1394(feature);
526// bool bHasAuto=DC1394Control->hasAutoDC1394(feature);
527// bool bHasManual=DC1394Control->hasManualDC1394(feature);
528// bool bHasOnePush=DC1394Control->hasOnePushDC1394(feature);
529
530 FeatureMode mode;
531 bool bON, bAuto, bHasAuto, bHasManual, bHasOnePush, bHasOnOff;
532 fgControl->getActive(feature, &bON);
533 fgControl->getMode(feature, &mode);
534 fgControl->hasOnOff(feature, &bHasOnOff);
535 fgControl->hasAuto(feature, &bHasAuto);
536 fgControl->hasManual(feature, &bHasManual);
537 fgControl->hasOnePush(feature, &bHasOnePush);
538 mode == MODE_AUTO ? bAuto = true : bAuto = false;
539
540 double redVal;
541 double blueVal;
542 fgControl->getFeature(feature, &blueVal, &redVal);
543
544 sliderWBRefreshDone(ptr,bON,bAuto,bHasOnOff,bHasAuto,bHasManual,bHasOnePush,redVal,blueVal);
545
546 opCounter--;
547 if(opCounter == 0){
548 stopLoading();
549 }
550}
551
552void DC1394Thread::sliderPropagate(QVariantList arg)
553{
554 cameraFeature_id_t feature;
555 int value = arg.at(0).toInt();
556 feature = (cameraFeature_id_t)value;
557
558
559 double val = arg.at(1).toDouble();
560 bool bRBa = arg.at(2).toBool();
561 bool bPwr = arg.at(3).toBool();
562
563 FeatureMode mode = bRBa ? MODE_AUTO : MODE_MANUAL;
564
565 fgControl->setFeature(feature,val);
566 fgControl->setMode(feature,mode);
567 fgControl->setActive(feature,bPwr);
568
570
571 opCounter--;
572 if(opCounter == 0){
573 stopLoading();
574 }
575}
576
578{
579 cameraFeature_id_t feature;
580 int value = arg.at(0).toInt();
581 feature = (cameraFeature_id_t)value;
582
583
584 double redVal = arg.at(1).toDouble();
585 double blueVal = arg.at(2).toDouble();
586 bool bRBa = arg.at(3).toBool();
587 bool bPwr = arg.at(4).toBool();
588
589 fgControl->setFeature(feature, blueVal, redVal);
590 FeatureMode mode;
591 bRBa ? mode = MODE_AUTO : mode = MODE_MANUAL;
592
593 fgControl->setMode(feature,mode);
594 fgControl->setActive(feature,bPwr);
595
597
598 opCounter--;
599 if(opCounter == 0){
600 stopLoading();
601 }
602}
603
604
606{
607 cameraFeature_id_t feature;
608 QObject *ptr = (QObject*)arg.at(0).value<void*>();
609 int value = arg.at(1).toInt();
610 feature = (cameraFeature_id_t)value;
611
612 double val = arg.at(2).toDouble();
613
614 fgControl->setFeature(feature,val);
615
617
618// opCounter--;
619// if(opCounter == 0){
620// stopLoading();
621// }
622}
623
625{
626 cameraFeature_id_t feature;
627 QObject *ptr = (QObject*)arg.at(0).value<void*>();
628 int value = arg.at(1).toInt();
629 feature = (cameraFeature_id_t)value;
630
631 double redVal = arg.at(2).toDouble();
632 double blueVal = arg.at(3).toDouble();
633
634 fgControl->setFeature(feature, blueVal,redVal);
635
636 sliderWBSetFeatureDC1394Done(ptr,redVal,blueVal);
637
638// opCounter--;
639// if(opCounter == 0){
640// stopLoading();
641// }
642}
643
644void DC1394Thread::sliderOnePush(QVariantList arg)
645{
646 cameraFeature_id_t feature;
647 QObject *ptr = (QObject*)arg.at(0).value<void*>();
648 int value = arg.at(1).toInt();
649 feature = (cameraFeature_id_t)value;
650
651 fgControl->setOnePush(feature);
652
653 double val;
654 fgControl->getFeature(feature, &val);
655
656 sliderOnePushDone(ptr,val);
657
658 opCounter--;
659 if(opCounter == 0){
660 stopLoading();
661 }
662}
663
664void DC1394Thread::sliderWBOnePush(QVariantList arg)
665{
666 cameraFeature_id_t feature;
667 QObject *ptr = (QObject*)arg.at(0).value<void*>();
668 int value = arg.at(1).toInt();
669 feature = (cameraFeature_id_t)value;
670
671 double redVal;
672 double blueVal;
673
674 fgControl->setOnePush(feature);
675 fgControl->getFeature(feature, &blueVal, &redVal);
676
677 sliderWBOnePushDone(ptr,redVal,blueVal);
678
679 opCounter--;
680 if(opCounter == 0){
681 stopLoading();
682 }
683}
684
685
686void DC1394Thread::sliderRadioAuto(QVariantList arg)
687{
688 cameraFeature_id_t feature;
689 QObject *ptr = (QObject*)arg.at(0).value<void*>();
690 int value = arg.at(1).toInt();
691 bool bVal = arg.at(2).toBool();
692 feature = (cameraFeature_id_t)value;
693 FeatureMode mode = bVal ? MODE_AUTO : MODE_MANUAL;
694
695 bool bON;
696 fgControl->getActive(feature, &bON);
697 fgControl->setMode(feature, mode);
698
699 sliderRadioAutoDone(ptr,true, bVal);
700
701 opCounter--;
702 if(opCounter == 0){
703 stopLoading();
704 }
705}
706
707void DC1394Thread::sliderPower(QVariantList arg)
708{
709 qDebug() << "sliderPower";
710
711 cameraFeature_id_t feature;
712 QObject *ptr = (QObject*)arg.at(0).value<void*>();
713 int value = arg.at(1).toInt();
714 bool bON = arg.at(2).toBool();
715 feature = (cameraFeature_id_t)value;
716
717 fgControl->setActive(feature, bON);
718
719 bool hasAuto, hasManual, hasOnePush;
720 fgControl->hasAuto(feature, &hasAuto);
721 fgControl->hasManual(feature, &hasManual);
722 fgControl->hasOnePush(feature, &hasOnePush);
723 sliderPowerDone(ptr,bON,hasAuto,hasManual,hasOnePush);
724
725 opCounter--;
726 if(opCounter == 0){
727 stopLoading();
728 }
729}
730
731
732void DC1394Thread::sliderHasFeature(QVariantList arg)
733{
734 cameraFeature_id_t feature;
735 QObject *ptr = (QObject*)arg.at(0).value<void*>();
736 int value = arg.at(1).toInt();
737 feature = (cameraFeature_id_t)value;
738
739 bool hasFeature;
740 fgControl->hasFeature(feature, &hasFeature);
741
742 opCounter--;
743 if(opCounter == 0){
744 stopLoading();
745 }
746
747 sliderHasFeatureDone(ptr,hasFeature);
748}
void sliderPower(QVariantList arg)
void setPowerDC1394Done()
void setFormat7WindowDC1394(QVariantList arg)
void reloadDone(uint, uint, QSize, QSize, QSize, QSize, QSize, uint, uint, uint, uint, uint)
void sliderSetFeatureDC1394Done(QObject *, double)
void setTransmissionDC1394(QVariantList arg)
void sliderWBRefreshDone(QObject *, bool, bool, bool, bool, bool, bool, double, double)
void sliderOnePush(QVariantList arg)
void setFPSDC1394Done()
void startLoading()
void sliderHasFeatureDone(QObject *, bool)
void setBytesPerPacketDC1394(QVariantList arg)
void setTransmissionDC1394Done()
void setColorCodingDC1394(QVariantList arg)
void sliderWBSetFeatureDC1394Done(QObject *, double, double)
void sliderPropagate(QVariantList arg)
void sliderRefresh(QVariantList arg)
void setOperationModeDC1394(QVariantList arg)
void sliderRadioAuto(QVariantList arg)
void sliderSetFeatureDC1394(QVariantList arg)
void sliderOnePushDone(QObject *, double)
void setPowerDC1394(QVariantList arg)
void setISOSpeedDC1394(QVariantList)
void setISOSpeedDC1394Done()
void stopLoading()
void sliderRefreshDone(QObject *, bool, bool, bool, bool, bool, bool, double)
void doTask(threadFunction)
void sliderWBSetFeatureDC1394(QVariantList arg)
void setOperationModeDC1394Done()
void loadDefaultDone(uint, uint, bool)
void sliderWBOnePush(QVariantList arg)
void setColorCodingDC1394Done()
void setVideoModeDC1394Done()
void resetDone(uint, uint, bool)
void setFormat7WindowDC1394Done()
void sliderWBRefresh(QVariantList arg)
void setBytesPerPacketDC1394Done()
void initFormatTabDone(uint, uint, uint)
DC1394Thread(char *loc, char *rem, QObject *parent=0)
void sliderPowerDone(QObject *, bool, bool, bool, bool)
void sliderHasFeature(QVariantList arg)
bool getCameraDescription(CameraDescriptor *camera)
void sliderRadioAutoDone(QObject *, bool, bool)
void sliderWBOnePushDone(QObject *, double, double)
void initDone(uint, uint, uint, bool, uint, QSize, QSize, QSize, QSize, QSize, uint, bool)
void setVideoModeDC1394(QVariantList arg)
void sliderWBPropagate(QVariantList arg)
void sliderPropagateDone()
void sliderWBPropagateDone()
void setFPSDC1394(QVariantList arg)
threadFunction
@ _setOperationModeDC1394
@ _setBytesPerPacketDC1394
@ _setFPSDC1394
@ _setPowerDC1394
@ _initFormatTab
@ _setTransmissionDC1394
@ _unknown
@ _sliderOnePush
@ _sliderSetFeature
@ _init
@ _sliderPropagate
@ _sliderWBOnePush
@ _reload
@ _sliderRadioAuto
@ _sliderRefresh
@ _sliderWBPropagate
@ _setVideoModeDC1394
@ _setISOSpeedDC1394
@ _loadDefault
@ _setFormat7WindowDC1394
@ _sliderWBRefresh
@ _sliderPower
@ _reset
@ _setColorCodingDC1394
@ _sliderWBSetFeature
@ _sliderHasFeature
degrees offset
Definition sine.m:4