-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDevice.cpp
1023 lines (781 loc) · 23.9 KB
/
Device.cpp
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
// *****************************************************************************
//
// Copyright (c) 2013, Pleora Technologies Inc., All rights reserved.
//
// *****************************************************************************
#include "eBUSPlayerShared.h"
#include "Device.h"
#include "DeviceGEV.h"
#include "DeviceU3V.h"
#include <PvDeviceSerialPort.h>
#include <PvGenFile.h>
#include <PvDeviceInfoGEV.h>
#include <assert.h>
#include <sstream>
#define SOURCE_SELECTOR ( "SourceSelector" )
#define GEV_DEVICE_CLASS ( "GevDeviceClass" )
#define TRANSMITTER ( "Transmitter" )
#define PIXEL_FORMAT ( "PixelFormat" )
#define WIDTH ( "Width" )
#define HEIGHT ( "Height" )
#define PAYLOAD_SIZE ( "PayloadSize" )
#define ACQUISITION_START ( "AcquisitionStart" )
#define ACQUISITION_STOP ( "AcquisitionStop" )
#define ACQUISITION_MODE ( "AcquisitionMode" )
#define DATA_LENGTH ( "DataLength" )
#define SOURCE_STREAM_CHANNEL ( "SourceStreamChannel" )
#ifdef _AFXDLL
IMPLEMENT_DYNAMIC( Device, CObject )
#endif // _AFXDLL
///
/// \brief Constructor
///
Device::Device( IMessageSink *aSink, LogBuffer *aLogBuffer )
: mMessageSink( aSink )
, mDevice( NULL )
, mAcquisitionStateManager( NULL )
, mUpdatingAcquisitionMode( false )
, mUpdatingSources( false )
, mLogBuffer( aLogBuffer )
, mRecovery( false )
, mSerialSupported( false )
, mClass( PvDeviceClassUnknown )
, mIsMultiSourceTransmitter( false )
{
assert( mMessageSink != NULL );
assert( mLogBuffer != NULL );
}
///
/// \brief Destructor
///
Device::~Device()
{
Disconnect();
assert( mAcquisitionStateManager == NULL );
assert( mDeviceAdapter != NULL );
if ( mDeviceAdapter != NULL )
{
delete mDeviceAdapter;
mDeviceAdapter = NULL;
}
assert( mDevice != NULL );
if ( mDevice != NULL )
{
delete mDevice;
mDevice = NULL;
}
}
///
/// \brief Creates the right type of device object based on aDeviceInfo
///
Device *Device::Create( const PvDeviceInfo *aDeviceInfo, IMessageSink *aSink, LogBuffer *aLogBuffer )
{
assert( aDeviceInfo != NULL );
assert( aSink != NULL );
assert( aLogBuffer != NULL );
Device *lDevice = NULL;
switch ( aDeviceInfo->GetType() )
{
case PvDeviceInfoTypeGEV:
lDevice = new DeviceGEV( aSink, aLogBuffer );
break;
case PvDeviceInfoTypeU3V:
lDevice = new DeviceU3V( aSink, aLogBuffer );
break;
default:
break;
}
return lDevice;
}
///
/// \brief Completes the connection process (shared GEV, U3V)
///
void Device::CompleteConnect( PvStream *aStream )
{
// Call early, needed to complete this method
SetIsMultiSourceTransmitter();
int64_t lSource = 0;
if ( IsMultiSourceTransmitter() )
{
mDevice->GetParameters()->GetIntegerValue( SOURCE_SELECTOR, lSource );
}
// Register for device callbacks
mDevice->RegisterEventSink( this );
mAcquisitionStateManagerMutex.Lock();
///////////////////////////////////////////////////////////////////////////
// Regardless of whether a corresponding stream is open or not, we can still pass it to the acquisition state manager
assert( mAcquisitionStateManager == NULL );
if ( IsTransmitter() )
{
mAcquisitionStateManager = new PvAcquisitionStateManager( mDevice, aStream, static_cast<uint32_t>( lSource ) );
mAcquisitionStateManager->RegisterEventSink( this );
}
///////////////////////////////////////////////////////////////////////////
mAcquisitionStateManagerMutex.Unlock();
// Create the event monitor *before* registering the device event sink
mLogBuffer->SetParameters( mDevice->GetParameters() );
// Check whether video interface serial communication is supported or not
mSerialSupported = PvDeviceSerialPort::IsSupported( mDeviceAdapter, PvDeviceSerial0 );
mSerialSupported |= PvDeviceSerialPort::IsSupported( mDeviceAdapter, PvDeviceSerialBulk0 );
// Fill available sources
GetSources( mAvailableSources );
// Register for parameters callbacks
uint32_t lParametersCount = GetParameters()->GetCount();
for ( uint32_t i = 0; i < lParametersCount; i++ )
{
PvGenParameter *lParameter = GetParameters()->Get( i );
lParameter->RegisterEventSink( this );
}
}
///
/// \brief Change the source
///
bool Device::ChangeSource( int64_t aSource )
{
// Select the new source if needed
PvGenEnum *lSourceSelector = GetParameters()->GetEnum( SOURCE_SELECTOR );
int64_t lCurrent = 0;
lSourceSelector->GetValue( lCurrent );
if ( lCurrent != aSource )
{
PvResult lResult = lSourceSelector->SetValue( aSource );
return lResult.IsOK();
}
return false;
}
///
/// \brief Change the source
///
void Device::CompleteChangeSource( PvStream *aStream, int64_t aSource )
{
mAcquisitionStateManagerMutex.Lock();
///////////////////////////////////////////////////////////////////////////
// Reset acquisition state manager
FreeAcquisitionStateManager( false );
// Regardless of whether a corresponding stream is open or not, we can still pass it to the acquisition state manager
mAcquisitionStateManager = new PvAcquisitionStateManager( GetDevice(), aStream, static_cast<uint32_t>( aSource ) );
mAcquisitionStateManager->RegisterEventSink( this );
///////////////////////////////////////////////////////////////////////////
mAcquisitionStateManagerMutex.Unlock();
}
///
/// \brief Disconnects the device
///
PvResult Device::Disconnect()
{
if ( !IsConnected() )
{
return PvResult::Code::NOT_CONNECTED;
}
mLogBuffer->SetParameters( NULL );
uint32_t lParametersCount = GetParameters()->GetCount();
for ( uint32_t i = 0; i < lParametersCount; i++ )
{
PvGenParameter *lParameter = GetParameters()->Get( i );
lParameter->UnregisterEventSink( this );
}
mDevice->UnregisterEventSink( this );
mDevice->Disconnect();
mUpdatingAcquisitionMode = false;
mUpdatingSources = false;
mRecovery = false;
mSerialSupported = false;
mAvailableSources.clear();
FreeAcquisitionStateManager();
return PvResult::Code::OK;
}
///
/// \brief True if the device is connected
///
bool Device::IsConnected()
{
return ( mDevice != NULL ) && mDevice->IsConnected();
}
///
/// \brief Returns the enabled state of various controls
///
void Device::GetControlsEnabled( ControlsState &aState )
{
aState.Reset();
// Used to temporarily select the source in use
PvGenStateStack lStack( GetParameters() );
PvAcquisitionState lAcquisitionState = GetAcquisitionState();
PushSource( &lStack );
PvGenCommand *lStart = GetParameters()->GetCommand( ACQUISITION_START );
PvGenCommand *lStop = GetParameters()->GetCommand( ACQUISITION_STOP );
PvGenEnum *lMode = GetParameters()->GetEnum( ACQUISITION_MODE );
PvGenEnum *lSource = GetParameters()->GetEnum( SOURCE_SELECTOR );
if ( IsMultiSourceTransmitter() )
{
aState.mSource =
( lSource != NULL ) &&
( lSource->IsWritable() ) &&
( lAcquisitionState != PvAcquisitionStateLocked );
}
if ( lMode != NULL )
{
aState.mAcquisitionMode =
( lMode->IsWritable() ) &&
( lAcquisitionState != PvAcquisitionStateLocked );
}
if ( lStart != NULL )
{
aState.mStart = ( lAcquisitionState != PvAcquisitionStateLocked );
}
if ( lStop != NULL )
{
aState.mStop = ( lAcquisitionState != PvAcquisitionStateUnlocked );
}
}
///
/// \brief Returns true if the device is a multi source transmitter
///
void Device::SetIsMultiSourceTransmitter()
{
mIsMultiSourceTransmitter = false;
PvGenEnum *lEnum = mDevice->GetParameters()->GetEnum( SOURCE_SELECTOR );
PvGenEnum *lDeviceClass = mDevice->GetParameters()->GetEnum( GEV_DEVICE_CLASS );
if ( ( lEnum != NULL ) && ( lDeviceClass != NULL ) )
{
PvString lClass;
if ( lDeviceClass->GetValue( lClass ).IsOK() )
{
mIsMultiSourceTransmitter = ( lClass == TRANSMITTER );
}
}
}
///
/// \brief Returns the communication parameters for the device
///
PvGenParameterArray *Device::GetCommunicationParameters()
{
if ( mDevice != NULL )
{
return mDevice->GetCommunicationParameters();
}
return NULL;
}
///
/// \brief Returns the parameters of the device
///
PvGenParameterArray *Device::GetParameters()
{
if ( mDevice != NULL )
{
return mDevice->GetParameters();
}
return NULL;
}
///
/// \brief Instructs the device controller to start streaming and opens socket
///
PvResult Device::StartAcquisition()
{
// Used to temporarily select the source in use
PvGenStateStack lStack( GetParameters() );
PushSource( &lStack );
return mAcquisitionStateManager->Start();
}
///
/// \brief Instructs the device controller to stop streaming
///
PvResult Device::StopAcquisition()
{
// Used to temporarily select the source in use
PvGenStateStack lStack( GetParameters() );
PushSource( &lStack );
return mAcquisitionStateManager->Stop();
}
///
/// \brief Sets a new acquisition mode
///
PvResult Device::SetAcquisitionMode( int64_t aNewMode )
{
// Set source selector if needed
PvGenStateStack lStack( GetParameters() );
PushSource( &lStack );
// Get acquisition mode parameter
PvGenEnum *lMode = GetParameters()->GetEnum( ACQUISITION_MODE );
if ( lMode == NULL )
{
return PvResult::Code::NOT_FOUND;
}
// Change mode
return lMode->SetValue( aNewMode );
}
///
/// \brief Returns the default name to use when saving the GenICam XML file of the device
///
PvString Device::GetDeviceXMLDefaultName()
{
PvString lFilename;
if ( !mDevice->GetDefaultGenICamXMLFilename( lFilename ).IsOK() )
{
lFilename = "Default.xml";
}
return lFilename;
}
///
/// \brief Saves the GenICam XML file of the device to a file on the host
///
PvResult Device::SaveDeviceXML( const PvString &aFileName )
{
if ( !IsConnected() )
{
return PvResult::Code::NOT_CONNECTED;
}
return mDevice->DumpGenICamXML( aFileName );
}
///
/// \brief Saves the device controller configuration
///
PvResult Device::Save( PvConfigurationWriter *aWriter )
{
assert( aWriter != NULL );
return aWriter->Store( mDevice );
}
///
/// \brief Loads the device controller configuration
///
PvResult Device::Load( PvConfigurationReader *aReader )
{
assert( aReader != NULL );
return aReader->Restore( 0, mDevice );
}
///
/// \brief Pushes the current source on the GenICam state stack (if the device is multi-source)
///
void Device::PushSource( PvGenStateStack *aStack )
{
assert( aStack != NULL );
// If multi source, push the active source on the stack
if ( IsMultiSourceTransmitter() )
{
int64_t lSource1 = 0;
GetParameters()->GetEnumValue( SOURCE_SELECTOR, lSource1 );
int64_t lSource2 = GetCurrentSource();
if ( lSource1 != lSource2 )
{
// Select source (will be reset when lStack goes out of scope)
aStack->SetEnumValue( SOURCE_SELECTOR, mAcquisitionStateManager->GetSource() );
}
}
}
///
/// \brief Returns the numerical value of the currently selected source on the device
///
int64_t Device::GetSelectedSource()
{
if ( !IsConnected() )
{
return -1;
}
int64_t lValue = -1;
PvGenEnum *lEnum = GetParameters()->GetEnum( SOURCE_SELECTOR );
if ( lEnum != NULL )
{
lEnum->GetValue( lValue );
}
return lValue;
}
///
/// \brief Returns true if the device is streaming
///
bool Device::IsStreaming()
{
return GetAcquisitionState() == PvAcquisitionStateLocked;
}
///
/// \brief Return the current acquisition mode
///
void Device::GetCurrentAcquisitionMode( ComboItem &aMode, bool &aWritable )
{
ComboItemVector lModes;
GetAcquisitionModes( lModes, aWritable, true );
assert ( lModes.size() == 1 );
if ( lModes.size() != 1 )
{
return;
}
aMode = *lModes.begin();
}
///
/// \brief Returns all acquisition modes
///
void Device::GetAcquisitionModes( ComboItemVector &aModes, bool &aEnabled )
{
GetAcquisitionModes( aModes, aEnabled, false );
}
///
/// \brief Returns all possible acquisition modes for the device
///
void Device::GetAcquisitionModes( ComboItemVector &aModes, bool &aEnabled, bool aOnlyCurrent )
{
aModes.clear();
aEnabled = false;
if ( !IsConnected() )
{
return;
}
PvGenEnum *lEnum = GetParameters()->GetEnum( "AcquisitionMode" );
if ( lEnum != NULL )
{
PvGenStateStack lStack( GetParameters() );
PushSource( &lStack );
int64_t lCurrentValue = 0;
lEnum->GetValue( lCurrentValue );
int64_t lCount = 0;
lEnum->GetEntriesCount( lCount );
for ( int64_t i = 0; i < lCount; i++ )
{
const PvGenEnumEntry *lEE = NULL;
lEnum->GetEntryByIndex( i, &lEE );
PvString lName;
lEE->GetName( lName );
int64_t lValue;
lEE->GetValue( lValue );
if ( aOnlyCurrent && ( lCurrentValue != lValue ) )
{
continue;
}
ComboItem lMode;
lMode.mName = lName;
lMode.mValue = lValue;
lMode.mSelected = ( lCurrentValue == lValue );
aModes.push_back( lMode );
}
aEnabled = lEnum->IsWritable() && ( GetAcquisitionState() != PvAcquisitionStateLocked );
}
}
///
/// \brief Returns all sources for the device.
///
void Device::GetSources( ComboItemVector &aSources )
{
aSources.clear();
PvGenEnum *lSourceSelector = GetParameters()->GetEnum( "SourceSelector" );
if ( lSourceSelector == NULL )
{
return;
}
int64_t lSourceCount = 0;
lSourceSelector->GetEntriesCount( lSourceCount );
uint64_t lActiveSource = GetCurrentSource();
// Fill source selector combo box
for ( int64_t i = 0; i < lSourceCount; i++ )
{
const PvGenEnumEntry *lEE = NULL;
lSourceSelector->GetEntryByIndex( i, &lEE );
if ( lEE->IsAvailable() )
{
PvString lDisplayName;
lEE->GetDisplayName( lDisplayName );
int64_t lValue = 0;
lEE->GetValue( lValue );
ComboItem lComboItem;
lComboItem.mName = lDisplayName.GetUnicode();
lComboItem.mValue = lValue;
if ( lActiveSource == static_cast<uint32_t>( lValue ) )
{
lComboItem.mSelected = true;
}
aSources.push_back( lComboItem );
}
}
}
///
/// \brief Returns the current acquisition state
///
PvAcquisitionState Device::GetAcquisitionState()
{
if ( !IsConnected() )
{
return PvAcquisitionStateUnknown;
}
mAcquisitionStateManagerMutex.Lock();
///////////////////////////////////////////////////////////////////////////
PvAcquisitionState lAcquisitionState = PvAcquisitionStateUnknown;
if ( mAcquisitionStateManager != NULL )
{
lAcquisitionState = mAcquisitionStateManager->GetState();
}
///////////////////////////////////////////////////////////////////////////
mAcquisitionStateManagerMutex.Unlock();
return lAcquisitionState;
}
///
/// \brief Returns the current source. -1 if the source cannot be retrieve (ie: not mutli-source)
///
int64_t Device::GetCurrentSource()
{
if ( !IsConnected() || !IsMultiSourceTransmitter() )
{
return -1;
}
mAcquisitionStateManagerMutex.Lock();
///////////////////////////////////////////////////////////////////////////
int64_t lRetVal = 0;
if ( mAcquisitionStateManager != NULL )
{
lRetVal = mAcquisitionStateManager->GetSource();
}
///////////////////////////////////////////////////////////////////////////
mAcquisitionStateManagerMutex.Unlock();
return lRetVal;
}
///
/// \brief Returns
///
uint16_t Device::GetCurrentSourceChannel()
{
if ( !IsConnected() || !IsMultiSourceTransmitter() )
{
return 0;
}
PvGenInteger *lSourceChannel = GetParameters()->GetInteger( SOURCE_STREAM_CHANNEL );
if ( lSourceChannel == NULL )
{
return 0;
}
int64_t lValue = 0;
lSourceChannel->GetValue( lValue );
return static_cast<uint16_t>( lValue );
}
///
/// \brief Returns true if acquisition is currently locked
///
bool Device::IsAcquisitionLocked()
{
return GetAcquisitionState() == PvAcquisitionStateLocked;
}
///
/// \brief Sets the device pointer
///
void Device::SetDevice( PvDevice *aDevice )
{
mDevice = aDevice;
// Create device adapter
mDeviceAdapter = new PvDeviceAdapter( aDevice );
}
///
/// \brief PvGenEventSink
///
void Device::OnParameterUpdate( PvGenParameter *aParameter )
{
if ( mAcquisitionStateManager == NULL )
{
return;
}
PvString lName = aParameter->GetName();
if ( lName == ACQUISITION_MODE )
{
// Prevent re-entry
if ( !mUpdatingAcquisitionMode )
{
if ( IsMultiSourceTransmitter() )
{
int64_t lSource1 = 0;
GetParameters()->GetEnumValue( SOURCE_SELECTOR, lSource1 );
int64_t lSource2 = mAcquisitionStateManager->GetSource();
if ( lSource1 == lSource2 )
{
// Only refresh if the source selector is that same as the source used by eBUSPlayer
mUpdatingAcquisitionMode = true;
mMessageSink->SendMsgIfPossible( WM_UPDATEACQUISITIONMODE, 1 );
}
}
else
{
// No source selector, always refresh
mUpdatingAcquisitionMode = true;
mMessageSink->SendMsgIfPossible( WM_UPDATEACQUISITIONMODE, 1 );
}
}
}
if ( lName == SOURCE_SELECTOR )
{
if ( !mUpdatingSources && IsMultiSourceTransmitter() )
{
PvGenEnum *lSourceSelector = dynamic_cast<PvGenEnum *>( aParameter );
if ( lSourceSelector == NULL )
{
return;
}
// Retrieve enum entry count from source selector
int64_t lSourceCount = 0;
lSourceSelector->GetEntriesCount( lSourceCount );
// Build list of available sources
Int64Vector lSources;
for ( int64_t i = 0; i < lSourceCount; i++ )
{
const PvGenEnumEntry *lEE = NULL;
lSourceSelector->GetEntryByIndex( i, &lEE );
if ( lEE->IsAvailable() )
{
int64_t lValue = 0;
lEE->GetValue( lValue );
lSources.push_back( lValue );
}
}
// Compare available sources vs. cached combo box content
bool lIsTheSame = false;
if ( lSources.size() == mAvailableSources.size() )
{
lIsTheSame = true;
Int64Vector::const_iterator lIt1 = lSources.begin();
ComboItemVector::const_iterator lIt2 = mAvailableSources.begin();
while ( ( lIt1 != lSources.end() ) && ( lIt2 != mAvailableSources.end() ) )
{
if ( *lIt1 != lIt2->mValue )
{
lIsTheSame = false;
break;
}
lIt1++;
lIt2++;
}
}
if ( !lIsTheSame )
{
mUpdatingSources = true;
mMessageSink->PostMsg( WM_UPDATESOURCES, 0, -1 );
}
}
}
}
///
/// PvDeviceEventSink
///
void Device::OnLinkDisconnected( PvDevice *aDevice )
{
mRecovery = true;
mMessageSink->PostMsg( WM_LINKDISCONNECTED );
}
///
/// PvDeviceEventSink
///
void Device::OnLinkReconnected( PvDevice *aDevice )
{
mMessageSink->PostMsg( WM_LINKRECONNECTED );
}
///
/// PvDeviceEventSink
///
void Device::OnEvent( PvDevice *aDevice, uint16_t aEventID, uint16_t aChannel, uint64_t aBlockID, uint64_t aTimestamp, const void *aData, uint32_t aDataLength )
{
if ( ( aEventID == 0x9009 ) &&
( aData != NULL ) &&
( aDataLength > 0 ) )
{
if ( mLogBuffer->IsSerialComLogEnabled() )
{
mLogBuffer->CamHeadSerialComLog( (const unsigned char*)aData, aDataLength, aTimestamp );
}
}
}
///
/// PvDeviceEventSink
///
void Device::OnEventGenICam( PvDevice *aDevice, uint16_t aEventID, uint16_t aChannel, uint64_t aBlockID, uint64_t aTimestamp, PvGenParameterList *aData )
{
if ( !mLogBuffer->IsEventsEnabled() )
{
return;
}
// Basic event log
std::stringstream lLog;
lLog << "Event ID: 0x" << std::hex << aEventID << " ";
lLog << "Channel: 0x" << std::hex << aBlockID << " ";
lLog << "Timestamp: 0x" << std::hex << aTimestamp;
// Add parameters
if ( aData != NULL )
{
// Is there a parameter containing "DataLength"? Get its value to query only subset of defined IRegister
int64_t lDataLength = 0;
PvGenParameter *lP = aData->GetFirst();
while ( lP != NULL )
{
std::string lName = lP->GetName().GetAscii();
if ( lName.find( DATA_LENGTH ) != std::string::npos )
{
PvGenInteger *lPI = dynamic_cast<PvGenInteger *>( lP );
if ( lPI != NULL )
{
lPI->GetValue( lDataLength );
}
break;
}
lP = aData->GetNext();
}
PvGenParameter *lParameter = aData->GetFirst();
while ( lParameter != NULL )
{
lLog << "\r\n ";
lLog << lParameter->GetName().GetAscii();
lLog << ": ";
PvGenRegister *lRegister = dynamic_cast<PvGenRegister *>( lParameter );
if ( lRegister == NULL )
{
lLog << lParameter->ToString().GetAscii();
}
else
{
lLog << "\r\n";
if ( lDataLength <= 0 )
{
lRegister->GetLength( lDataLength );
}
uint8_t *lData = new uint8_t[ static_cast<uint32_t>( lDataLength ) ];
PvResult lResult = lRegister->Get( lData, static_cast<uint32_t>( lDataLength ) );
lLog << LogBuffer::Unpack( " ", lData, static_cast<uint32_t>( lDataLength ), 0 );
delete []lData;
lData = NULL;
}
lParameter = aData->GetNext();
}
}
mLogBuffer->Log( lLog.str() );
}
///
/// \brief PvDeviceEventSink
///
void Device::OnCmdLinkRead( const void *aBuffer, int64_t aAddress, int64_t aLength )
{
}
///
/// \brief PvDeviceEventSink
///
void Device::OnCmdLinkWrite( const void *aBuffer, int64_t aAddress, int64_t aLength )
{
}
///
/// \brief PvAcquisitionStateEventSink
///
void Device::OnAcquisitionStateChanged( PvDevice* aDevice, PvStream* aStream, uint32_t aSource, PvAcquisitionState aState )
{
mMessageSink->SendMsgIfPossible( WM_ACQUISITIONSTATECHANGED );
}
///
/// \brief Loads communication parameters from a string
///
void Device::LoadCommunicationParameters( const PvString &aParameters )
{
PvConfigurationReader lReader;
lReader.LoadFromString( aParameters );
lReader.Restore( 0, mDevice->GetCommunicationParameters() );