-
Notifications
You must be signed in to change notification settings - Fork 2
/
orlaco.c
2541 lines (2097 loc) · 98.9 KB
/
orlaco.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
/****************************************************************************
*
* Copyright 2021 Lee Mitchell <lee@indigopepper.com>
* This file is part of OCC (Orlaco Camera Configurator)
*
* OCC (Orlaco Camera Configurator) is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OCC (Orlaco Camera Configurator) 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OCC (Orlaco Camera Configurator). If not,
* see <http://www.gnu.org/licenses/>.
*
****************************************************************************/
/****************************************************************************/
/*** Include files ***/
/****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "orlaco.h"
#include "sys/time.h"
/****************************************************************************/
/*** Macro Definitions ***/
/****************************************************************************/
#define ORLACO_SOCKET_READ_TIMEOUT_MS (100)
/****************************************************************************/
/*** Type Definitions ***/
/****************************************************************************/
// SOME/IP Methods
typedef enum {
E_ORLACO_METHOD_ID_GET_DATA_SHEET = 0x0001,
E_ORLACO_METHOD_ID_GET_CAM_STATUS = 0x0002,
E_ORLACO_METHOD_ID_SET_CAM_MODE = 0x0003, // Start, Stop, Restart the camera application
E_ORLACO_METHOD_ID_SET_CAM_EXCLUSIVE = 0x0011,
E_ORLACO_METHOD_ID_ERASE_CAM_EXCLUSIVE = 0x0019,
E_ORLACO_METHOD_ID_SET_HOST_PARAMETERS = 0x0022,
E_ORLACO_METHOD_ID_GET_HOST_PARAMETERS = 0x0024,
E_ORLACO_METHOD_ID_ERASE_HOST_PARAMETERS = 0x0029,
E_ORLACO_METHOD_ID_SET_REGION_OF_INTEREST = 0x0101,
E_ORLACO_METHOD_ID_SET_REGIONS_OF_INTEREST = 0x0102,
E_ORLACO_METHOD_ID_GET_REGION_OF_INTEREST = 0x0103,
E_ORLACO_METHOD_ID_GET_REGIONS_OF_INTEREST = 0x0104,
E_ORLACO_METHOD_ID_ERASE_REGION_OF_INTEREST = 0x0109,
E_ORLACO_METHOD_ID_SET_VIDEO_FORMAT = 0x0111,
E_ORLACO_METHOD_ID_GET_VIDEO_FORMAT = 0x0113,
E_ORLACO_METHOD_ID_ERASE_VIDEO_FORMAT = 0x0119,
E_ORLACO_METHOD_ID_SET_HISTOGRAMM_FORMAT = 0x0121,
E_ORLACO_METHOD_ID_GET_HISTOGRAMM_FORMAT = 0x0123,
E_ORLACO_METHOD_ID_ERASE_HISTOGRAMM_FORMAT = 0x0129,
E_ORLACO_METHOD_ID_SUBSCRIBE_ROI_VIDEO = 0x0131,
E_ORLACO_METHOD_ID_UNSUBSCRIBE_ROI_VIDEO = 0x0132,
E_ORLACO_METHOD_ID_SUBSCRIBE_ROI_HISTOGRAMM = 0x0133,
E_ORLACO_METHOD_ID_UNSUBSCRIBE_ROI_HISTOGRAMM = 0x0134,
E_ORLACO_METHOD_ID_SET_CAM_CONTROL = 0x0201,
E_ORLACO_METHOD_ID_SET_CAM_CONTROLS = 0x0202,
E_ORLACO_METHOD_ID_GET_CAM_CONTROL = 0x0203,
E_ORLACO_METHOD_ID_GET_CAM_CONTROLS = 0x0204,
E_ORLACO_METHOD_ID_SET_CAM_REGISTER = 0x0301,
E_ORLACO_METHOD_ID_SET_CAM_REGISTERS = 0x0302,
E_ORLACO_METHOD_ID_GET_CAM_REGISTER = 0x0303,
E_ORLACO_METHOD_ID_GET_CAM_REGISTERS = 0x0304,
E_ORLACO_METHOD_ID_SET_USED_REGISTER_SET = 0x0305,
E_ORLACO_METHOD_ID_SERVICE_DISCOVERY = 0x8100,
} ORLACO_teMethodID;
// SOME/IP Message Type
typedef enum {
E_ORLACO_MESSAGE_TYPE_REQUEST = 0x00,
E_ORLACO_MESSAGE_TYPE_REQUEST_NO_RETURN = 0x01,
E_ORLACO_MESSAGE_TYPE_NOTIFICATION = 0x02,
E_ORLACO_MESSAGE_TYPE_RESPONSE = 0x80,
E_ORLACO_MESSAGE_TYPE_ERROR = 0x81,
E_ORLACO_MESSAGE_TYPE_TP_REQUEST = 0x20,
E_ORLACO_MESSAGE_TYPE_TP_REQUEST_NO_RETURN = 0x21,
E_ORLACO_MESSAGE_TYPE_TP_NOTIFICATION = 0x22,
E_ORLACO_MESSAGE_TYPE_TP_RESPONSE = 0x23,
E_ORLACO_MESSAGE_TYPE_TP_ERROR = 0x24,
} ORLACO_teMessageType;
// Make sure these remain in the same order as the register indexes
typedef enum {
E_ORLACO_REGISTER_ADDRESS_LED_MODE = 0xb00c,
E_ORLACO_REGISTER_ADDRESS_STREAM_PROTOCOL = 0xb041,
E_ORLACO_REGISTER_ADDRESS_STATIC_IP_ADDRESS_0 = 0xb042,
E_ORLACO_REGISTER_ADDRESS_STATIC_IP_ADDRESS_1 = 0xb043,
E_ORLACO_REGISTER_ADDRESS_STATIC_IP_ADDRESS_2 = 0xb044,
E_ORLACO_REGISTER_ADDRESS_STATIC_IP_ADDRESS_3 = 0xb045,
E_ORLACO_REGISTER_ADDRESS_STATIC_NETWORK_MASK_0 = 0xb046,
E_ORLACO_REGISTER_ADDRESS_STATIC_NETWORK_MASK_1 = 0xb047,
E_ORLACO_REGISTER_ADDRESS_STATIC_NETWORK_MASK_2 = 0xb048,
E_ORLACO_REGISTER_ADDRESS_STATIC_NETWORK_MASK_3 = 0xb049,
E_ORLACO_REGISTER_ADDRESS_MAC_ADDRESS_0 = 0xb04a,
E_ORLACO_REGISTER_ADDRESS_MAC_ADDRESS_1 = 0xb04b,
E_ORLACO_REGISTER_ADDRESS_MAC_ADDRESS_2 = 0xb04c,
E_ORLACO_REGISTER_ADDRESS_MAC_ADDRESS_3 = 0xb04d,
E_ORLACO_REGISTER_ADDRESS_MAC_ADDRESS_4 = 0xb04e,
E_ORLACO_REGISTER_ADDRESS_MAC_ADDRESS_5 = 0xb04f,
E_ORLACO_REGISTER_ADDRESS_VLAN_ID_0 = 0xb055,
E_ORLACO_REGISTER_ADDRESS_VLAN_ID_1 = 0xb056,
E_ORLACO_REGISTER_ADDRESS_STREAM_ID_0 = 0xb057, // 0xb057 - 0xb05e inclusive
E_ORLACO_REGISTER_ADDRESS_STREAM_ID_1 = 0xb058, // 0xb057 - 0xb05e inclusive
E_ORLACO_REGISTER_ADDRESS_STREAM_ID_2 = 0xb059, // 0xb057 - 0xb05e inclusive
E_ORLACO_REGISTER_ADDRESS_STREAM_ID_3 = 0xb05a, // 0xb057 - 0xb05e inclusive
E_ORLACO_REGISTER_ADDRESS_STREAM_ID_4 = 0xb05b, // 0xb057 - 0xb05e inclusive
E_ORLACO_REGISTER_ADDRESS_STREAM_ID_5 = 0xb05c, // 0xb057 - 0xb05e inclusive
E_ORLACO_REGISTER_ADDRESS_STREAM_ID_6 = 0xb05d, // 0xb057 - 0xb05e inclusive
E_ORLACO_REGISTER_ADDRESS_STREAM_ID_7 = 0xb05e, // 0xb057 - 0xb05e inclusive
E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_IP_ADDRESS_0 = 0xb05f,
E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_IP_ADDRESS_1 = 0xb060,
E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_IP_ADDRESS_2 = 0xb061,
E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_IP_ADDRESS_3 = 0xb062,
E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_MAC_ADDRESS_0 = 0xb063,
E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_MAC_ADDRESS_1 = 0xb064,
E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_MAC_ADDRESS_2 = 0xb065,
E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_MAC_ADDRESS_3 = 0xb066,
E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_MAC_ADDRESS_4 = 0xb067,
E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_MAC_ADDRESS_5 = 0xb068,
E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_PORT_0 = 0xb069,
E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_PORT_1 = 0xb06a,
E_ORLACO_REGISTER_ADDRESS_SELECTED_ROI = 0xb06b,
E_ORLACO_REGISTER_ADDRESS_NO_STREAM_AT_BOOT = 0xb06c,
E_ORLACO_REGISTER_ADDRESS_UDP_COMMUNICATION_PORT_0 = 0xb06d,
E_ORLACO_REGISTER_ADDRESS_UDP_COMMUNICATION_PORT_1 = 0xb06e,
E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_SOURCE_PORT_0 = 0xb06f,
E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_SOURCE_PORT_1 = 0xb070,
E_ORLACO_REGISTER_ADDRESS_HDR = 0xb071,
E_ORLACO_REGISTER_ADDRESS_OVERLAY = 0xb072,
E_ORLACO_REGISTER_ADDRESS_DHCP = 0xb073,
E_ORLACO_REGISTER_ADDRESS_WAIT_FOR_MAC = 0xb078,
E_ORLACO_REGISTER_ADDRESS_WAIT_FOR_PTP_SYNC = 0xb079,
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_0 = 0xb171, // 0xb171 - 0xb180 inclusive
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_1 = 0xb172, // 0xb171 - 0xb180 inclusive
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_2 = 0xb173, // 0xb171 - 0xb180 inclusive
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_3 = 0xb174, // 0xb171 - 0xb180 inclusive
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_4 = 0xb175, // 0xb171 - 0xb180 inclusive
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_5 = 0xb176, // 0xb171 - 0xb180 inclusive
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_6 = 0xb177, // 0xb171 - 0xb180 inclusive
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_7 = 0xb178, // 0xb171 - 0xb180 inclusive
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_8 = 0xb179, // 0xb171 - 0xb180 inclusive
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_9 = 0xb17a, // 0xb171 - 0xb180 inclusive
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_10 = 0xb17b, // 0xb171 - 0xb180 inclusive
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_11 = 0xb17c, // 0xb171 - 0xb180 inclusive
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_12 = 0xb17d, // 0xb171 - 0xb180 inclusive
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_13 = 0xb17e, // 0xb171 - 0xb180 inclusive
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_14 = 0xb17f, // 0xb171 - 0xb180 inclusive
E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_15 = 0xb180, // 0xb171 - 0xb180 inclusive
} ORLACO_teRegisterAddress;
typedef struct {
uint16_t u16Address;
char *pcDescription;
char *pcHelp;
} ORLACO_tsRegisterDefinition;
typedef struct {
uint16_t u16Qtty;
uint16_t au16RegisterAddress[ORLACO_MAX_REGISTERS];
} ORLACO_tsRegisterRequestsPayload;
typedef struct {
uint16_t u16Qtty;
ORLACO_tsRegisterValue asRegisterValues[ORLACO_MAX_REGISTERS];
} ORLACO_tsGetRegistersResponsePayload;
typedef struct {
uint16_t u16Qtty;
ORLACO_tsRegisterValue asRegisterValues[ORLACO_MAX_REGISTERS];
} ORLACO_tsSetRegistersRequestPayload;
typedef struct {
uint32_t u32ExclusiveTime;
} ORLACO_tsSetCamExclusivePayload;
typedef struct {
uint32_t u32Mode;
} ORLACO_tsSetCamModePayload;
typedef struct {
uint32_t u32RegionOfInterestIndex;
uint16_t u16P1X;
uint16_t u16P1Y;
uint16_t u16P2X;
uint16_t u16P2Y;
uint8_t u8Unknown1SetTo0x01;
uint8_t u8Unknown2SetTo0x00;
uint16_t u16Unknown3SetTo0x0000;
uint16_t u16OutputWidth;
uint16_t u16OutputHeight;
uint8_t u8Unknown4SetTo0x00;
uint8_t u8FrameRate;
uint16_t u16Unknown4bSetTo0x0000;
uint8_t u8Unknown5SetTo0x00;
uint8_t u8Unknown6SetTo0x02;
uint32_t u32MaxBitrate; // set to 0x00000032 = 50Mb/s
uint8_t u8VideoCompressionMode; // 0x00 = none, 0x01 = JPEG, 0x02 = H.264
uint8_t u8Unknown7SetTo0x00;
uint8_t u8Unknown8SetTo0x00;
uint8_t u8Unknown9SetTo0x00;
uint8_t u8Unknown10SetTo0x04;
uint8_t u8Unknown11SetTo0x01;
uint16_t u16Unknown12SetTo0x00ff;
} ORLACO_tsSetRegionOfInterestPayload;
// New camera, payload from get roi 0 request
// 0000 00 00 00 00 05 00 03 c0 01 00 00 00 05 00 03 c0
// 0010 00 1e 00 00 00 02 00 00 00 32 01 00 00 00 04 01
// 0020 00 ff
typedef struct {
uint32_t u32RegionOfInterest;
} ORLACO_tsGetRegionOfInterestRequestPayload;
typedef struct {
uint32_t u32RegionOfInterest;
uint16_t u16P1X;
uint16_t u16P1Y;
uint16_t u16P2X;
uint16_t u16P2Y;
uint8_t u8Unknown1SetTo0x01;
uint8_t u8Unknown2SetTo0x00;
uint16_t u16Unknown3SetTo0x0000;
uint16_t u16OutputWidth;
uint16_t u16OutputHeight;
uint8_t u8Unknown4SetTo0x00;
uint8_t u8FrameRate;
uint16_t u16Unknown4bSetTo0x0000;
uint8_t u8Unknown5SetTo0x00;
uint8_t u8Unknown6SetTo0x02;
uint32_t u32MaxBitrate; // set to 0x00000032 = 50Mb/s
uint8_t u8VideoCompressionMode; // 0x00 = none, 0x01 = MJPEG, 0x02 = H.264
uint8_t u8Unknown7SetTo0x00;
uint8_t u8Unknown8SetTo0x00;
uint8_t u8Unknown9SetTo0x00;
uint8_t u8Unknown10SetTo0x04;
uint8_t u8Unknown11SetTo0x01;
uint16_t u16Unknown12SetTo0x00ff;
} ORLACO_tsGetRegionOfInterestResponsePayload;
typedef struct {
uint32_t u32RegionOfInterest;
} ORLACO_tsSubscribeRegionOfInterestPayload;
typedef struct {
uint16_t u16Length;
uint8_t u8Type;
uint8_t u8Reserved;
union {
uint32_t au32Data[2];
} uData;
} ORLACO_tsServiceDiscoveryServiceOptions;
typedef struct {
uint8_t u8Flags;
uint32_t u24Reserved;
uint32_t u32LengthOfEntriesArrayInBytes;
ORLACO_tsServiceDiscoveryServiceEntry asServiceEntry[ORLACO_MAX_SD_SERVICES];
uint32_t u32LengthOfOptionsArrayInBytes;
ORLACO_tsServiceDiscoveryServiceOptions asServiceOptions[ORLACO_MAX_SD_OPTIONS];
} ORLACO_tsServiceDiscoveryPayload;
typedef struct {
ORLACO_tuIP uSrcAddr;
uint16_t u16ServiceID;
uint16_t u16MethodID;
uint32_t u32Length;
uint16_t u16ClientID;
uint16_t u16SessionID;
uint8_t u8SomeIPVersion;
uint8_t u8InterfaceVersion;
uint8_t u8MessageType;
uint8_t u8ReturnCode;
union {
ORLACO_tsSetCamExclusivePayload sSetCamExclusivePayload;
ORLACO_tsSetCamModePayload sSetCamModePayload;
ORLACO_tsRegisterRequestsPayload sRegisterRequestsPayload;
ORLACO_tsGetRegistersResponsePayload sGetRegistersResponsePayload;
ORLACO_tsSetRegistersRequestPayload sSetRegistersRequestPayload;
ORLACO_tsGetRegionOfInterestRequestPayload sGetRegionOfInterestRequestPayload;
ORLACO_tsGetRegionOfInterestResponsePayload sGetRegionOfInterestResponsePayload;
ORLACO_tsSetRegionOfInterestPayload sSetRegionOfInterestPayload;
ORLACO_tsSubscribeRegionOfInterestPayload sSubscribeRegionOfInterestPayload;
ORLACO_tsServiceDiscoveryPayload sServiceDiscoveryPayload;
} uPayload;
} ORLACO_tsMsg ;
typedef struct {
uint32_t u32Length;
uint32_t u32Offset;
uint8_t *pu8Data;
} ORLACO_tsBuffer;
/****************************************************************************/
/*** Local Function Prototypes ***/
/****************************************************************************/
static uint16_t ORLACO_u16GetSessionID(ORLACO_tsInstance *psInstance);
static ORLACO_tsBuffer *ORLACO_psBufferCreate(uint32_t u32DataLength);
static void ORLACO_vBufferDestroy(ORLACO_tsBuffer *psBuffer);
static bool_t ORLACO_bWriteU8(ORLACO_tsBuffer *psBuffer, uint8_t u8Data);
static bool_t ORLACO_bWriteU16(ORLACO_tsBuffer *psBuffer, uint16_t u16Data);
static bool_t ORLACO_bWriteU24(ORLACO_tsBuffer *psBuffer, uint32_t u24Data);
static bool_t ORLACO_bWriteU32(ORLACO_tsBuffer *psBuffer, uint32_t u32Data);
static bool_t ORLACO_bReadU8(ORLACO_tsBuffer *psBuffer, uint8_t *pu8Data);
static bool_t ORLACO_bReadU16(ORLACO_tsBuffer *psBuffer, uint16_t *pu16Data);
static bool_t ORLACO_bReadU24(ORLACO_tsBuffer *psBuffer, uint32_t *pu24Data);
static bool_t ORLACO_bReadU32(ORLACO_tsBuffer *psBuffer, uint32_t *pu32Data);
static bool_t ORLACO_bWriteMessageHeaderIntoBuffer(ORLACO_tsBuffer *psBuffer, ORLACO_tsMsg *psMsg);
static bool_t ORLACO_bReadMessageHeaderFromBuffer(ORLACO_tsBuffer *psBuffer, ORLACO_tsMsg *psMsg);
static void ORLACO_vPrintBuffer(ORLACO_tsBuffer *psBuffer);
static bool_t ORLACO_bWriteServiceDiscoveryServiceEntryIntoBuffer(ORLACO_tsBuffer *psBuffer, ORLACO_tsServiceDiscoveryServiceEntry *psServiceEntry);
static bool_t ORLACO_bReadServiceDiscoveryServiceEntryFromBuffer(ORLACO_tsBuffer *psBuffer, ORLACO_tsServiceDiscoveryServiceEntry *psServiceEntry);
static bool_t ORLACO_bSendDatagram(UDPSOCKET sktTx, struct sockaddr_in *psDstAddr, ORLACO_tsBuffer *psBuffer);
static bool_t ORLACO_bReceiveDatagram(ORLACO_tsInstance *psInstance, ORLACO_tsMsg *psRxMsg, uint16_t u16MethodID);
static char *ORLACO_pcGetReturnCodeAsString(ORLACO_teReturnCode eReturnCode);
bool_t ORLACO_bIPAlreadyInArray(ORLACO_tsInstance *psInstance, ORLACO_tuIP IP);
/****************************************************************************/
/*** Exported Variables ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Variables ***/
/****************************************************************************/
// A list of all the registers known so far in the Orlaco camera
// Make sure these stay in the same order that they are defined in, otherwise the indexes will be useless.
const ORLACO_tsRegisterDefinition ORLACO_asRegisterDefinitions[] = {
{E_ORLACO_REGISTER_ADDRESS_LED_MODE, "LED Mode", "0=Off, 1=Auto, 2=On"},
{E_ORLACO_REGISTER_ADDRESS_STREAM_PROTOCOL, "Stream Protocol", "0=RTP, 1=AVB"},
{E_ORLACO_REGISTER_ADDRESS_STATIC_IP_ADDRESS_0, "IP Address 0", ""},
{E_ORLACO_REGISTER_ADDRESS_STATIC_IP_ADDRESS_1, "IP Address 1", ""},
{E_ORLACO_REGISTER_ADDRESS_STATIC_IP_ADDRESS_2, "IP Address 2", ""},
{E_ORLACO_REGISTER_ADDRESS_STATIC_IP_ADDRESS_3, "IP Address 3", ""},
{E_ORLACO_REGISTER_ADDRESS_STATIC_NETWORK_MASK_0, "Network Mask 0", ""},
{E_ORLACO_REGISTER_ADDRESS_STATIC_NETWORK_MASK_1, "Network Mask 1", ""},
{E_ORLACO_REGISTER_ADDRESS_STATIC_NETWORK_MASK_2, "Network Mask 2", ""},
{E_ORLACO_REGISTER_ADDRESS_STATIC_NETWORK_MASK_3, "Network Mask 3", ""},
{E_ORLACO_REGISTER_ADDRESS_MAC_ADDRESS_0 , "MAC Address 0", ""},
{E_ORLACO_REGISTER_ADDRESS_MAC_ADDRESS_1 , "MAC Address 1", ""},
{E_ORLACO_REGISTER_ADDRESS_MAC_ADDRESS_2 , "MAC Address 2", ""},
{E_ORLACO_REGISTER_ADDRESS_MAC_ADDRESS_3 , "MAC Address 3", ""},
{E_ORLACO_REGISTER_ADDRESS_MAC_ADDRESS_4 , "MAC Address 4", ""},
{E_ORLACO_REGISTER_ADDRESS_MAC_ADDRESS_5 , "MAC Address 5", ""},
{E_ORLACO_REGISTER_ADDRESS_VLAN_ID_0, "VLAN ID 0", ""},
{E_ORLACO_REGISTER_ADDRESS_VLAN_ID_1, "VLAN ID 1", ""},
{E_ORLACO_REGISTER_ADDRESS_STREAM_ID_0, "Stream ID 0", ""},
{E_ORLACO_REGISTER_ADDRESS_STREAM_ID_1, "Stream ID 1", ""},
{E_ORLACO_REGISTER_ADDRESS_STREAM_ID_2, "Stream ID 2", ""},
{E_ORLACO_REGISTER_ADDRESS_STREAM_ID_3, "Stream ID 3", ""},
{E_ORLACO_REGISTER_ADDRESS_STREAM_ID_4, "Stream ID 4", ""},
{E_ORLACO_REGISTER_ADDRESS_STREAM_ID_5, "Stream ID 5", ""},
{E_ORLACO_REGISTER_ADDRESS_STREAM_ID_6, "Stream ID 6", ""},
{E_ORLACO_REGISTER_ADDRESS_STREAM_ID_7, "Stream ID 7", ""},
{E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_IP_ADDRESS_0, "Destination IP Address 0", ""},
{E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_IP_ADDRESS_1, "Destination IP Address 1", ""},
{E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_IP_ADDRESS_2, "Destination IP Address 2", ""},
{E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_IP_ADDRESS_3, "Destination IP Address 3", ""},
{E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_MAC_ADDRESS_0,"Destination MAC Address 0", ""},
{E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_MAC_ADDRESS_1,"Destination MAC Address 1", ""},
{E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_MAC_ADDRESS_2,"Destination MAC Address 2", ""},
{E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_MAC_ADDRESS_3,"Destination MAC Address 3", ""},
{E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_MAC_ADDRESS_4,"Destination MAC Address 4", ""},
{E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_MAC_ADDRESS_5,"Destination MAC Address 5", ""},
{E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_PORT_0, "Destination Port 0", ""},
{E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_DESTINATION_PORT_1, "Destination Port 1", ""},
{E_ORLACO_REGISTER_ADDRESS_SELECTED_ROI, "Selected ROI", "1 to 10"},
{E_ORLACO_REGISTER_ADDRESS_NO_STREAM_AT_BOOT, "No Stream At Boot ?", "0=Stream, 1=No stream"},
{E_ORLACO_REGISTER_ADDRESS_UDP_COMMUNICATION_PORT_0, "UDP Communication Port 0", ""},
{E_ORLACO_REGISTER_ADDRESS_UDP_COMMUNICATION_PORT_1, "UDP Communication Port 1", ""},
{E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_SOURCE_PORT_0, "RTP Stream Source Port 0", ""},
{E_ORLACO_REGISTER_ADDRESS_RTP_STREAM_SOURCE_PORT_1, "RTP Stream Source Port 1", ""},
{E_ORLACO_REGISTER_ADDRESS_HDR, "HDR ?", "0=Disabled, 1=Enabled"},
{E_ORLACO_REGISTER_ADDRESS_OVERLAY, "Overlay ?", "0=Disabled, 1=Enabled"},
{E_ORLACO_REGISTER_ADDRESS_DHCP, "DHCP Enabled ?", "0=Disabled, 1=Enabled"},
{E_ORLACO_REGISTER_ADDRESS_WAIT_FOR_MAC, "Wait For MAC ?", "0=Don't wait, 1=Wait"},
{E_ORLACO_REGISTER_ADDRESS_WAIT_FOR_PTP_SYNC, "Wait For PTP Sync ?", "0=Don't wait, 1=Wait"},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_0, "DHCP Hostname 0", ""},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_1, "DHCP Hostname 1", ""},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_2, "DHCP Hostname 2", ""},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_3, "DHCP Hostname 3", ""},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_4, "DHCP Hostname 4", ""},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_5, "DHCP Hostname 5", ""},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_6, "DHCP Hostname 6", ""},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_7, "DHCP Hostname 7", ""},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_8, "DHCP Hostname 8", ""},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_9, "DHCP Hostname 9", ""},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_10, "DHCP Hostname 10", ""},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_11, "DHCP Hostname 11", ""},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_12, "DHCP Hostname 12", ""},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_13, "DHCP Hostname 13", ""},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_14, "DHCP Hostname 14", ""},
{E_ORLACO_REGISTER_ADDRESS_DHCP_HOSTNAME_15, "DHCP Hostname 15", ""},
};
/****************************************************************************/
/*** Exported Functions ***/
/****************************************************************************/
/****************************************************************************
*
* NAME: ORLACO_bInit
*
* DESCRIPTION:
* Initialises the Orlaco functions
*
* RETURNS:
* bool_t TRUE if successful, FALSE otherwise
*
****************************************************************************/
bool_t ORLACO_bInit(ORLACO_tsInstance *psInstance, char *pcUnicastIP, char *pcBroadcastIP, uint16_t u16DstPort)
{
int n;
int iEnable;
psInstance->u16DstPort = u16DstPort;
psInstance->u16NumCameras = 0;
psInstance->psCameras = NULL;
// Initialise the socket
psInstance->Socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
#ifdef _WIN32
if (psInstance->Socket == INVALID_SOCKET)
#else
if (psInstance->Socket < 0)
#endif
{
printf("Error: Can't create UDP socket in %s\n", __FUNCTION__);
return FALSE;
}
// Make sure socket supports broadcasts
iEnable = 1;
if(setsockopt(psInstance->Socket, SOL_SOCKET, SO_BROADCAST, (const char*)&iEnable, sizeof(iEnable)) != 0)
{
printf("Error: Can't set socket options in %s\n", __FUNCTION__);
return FALSE;
}
// Make sure socket doesn't receive its own broadcasts
// iEnable = 0;
// if(setsockopt(psInstance->Socket, IPPROTO_IP, IP_MULTICAST_LOOP, &iEnable, sizeof(iEnable)) != 0)
// {
// printf("Error: Can't set socket options\n");
// return FALSE;
// }
#ifdef _WIN32
DWORD timeout = ORLACO_SOCKET_READ_TIMEOUT_MS;
if(setsockopt(psInstance->Socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) != 0)
{
printf("Error: Can't set socket options in %s\n", __FUNCTION__);
return FALSE;
}
#else
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = ORLACO_SOCKET_READ_TIMEOUT_MS * 1000;
if(setsockopt(psInstance->Socket, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) != 0)
{
printf("Error: Can't set socket options in %s\n", __FUNCTION__);
return FALSE;
}
#endif
/* Set the socket address for the server */
memset((char *) &psInstance->fdServer, 0, sizeof(psInstance->fdServer));
psInstance->fdServer.sin_family = AF_INET;
psInstance->fdServer.sin_port = htons(u16DstPort);
psInstance->fdServer.sin_addr.s_addr = INADDR_ANY;
/* Set the socket address for unicast packets */
memset((char *) &psInstance->fdUnicast, 0, sizeof(psInstance->fdUnicast));
psInstance->fdUnicast.sin_family = AF_INET;
psInstance->fdUnicast.sin_port = htons(u16DstPort);
psInstance->fdUnicast.sin_addr.s_addr = inet_addr(pcUnicastIP);
/* Set the socket address for broadcast packets */
memset((char *) &psInstance->fdBroadcast, 0, sizeof(psInstance->fdBroadcast));
psInstance->fdBroadcast.sin_family = AF_INET;
psInstance->fdBroadcast.sin_port = htons(u16DstPort);
psInstance->fdBroadcast.sin_addr.s_addr = inet_addr(pcBroadcastIP);
if(bind(psInstance->Socket, (const struct sockaddr*)&psInstance->fdServer, sizeof(psInstance->fdServer)) < 0)
{
printf("Error: Bind failed in %s\n", __FUNCTION__);
return FALSE;
}
// Set how many registers we have
psInstance->u16NumRegisters = sizeof(ORLACO_asRegisterDefinitions) / sizeof(ORLACO_tsRegisterDefinition);
// Allocate the memory for the registers
psInstance->psRegisters = (ORLACO_tsRegisterValue*)malloc(psInstance->u16NumRegisters * sizeof(ORLACO_tsRegisterValue));
if(psInstance->psRegisters == NULL)
{
printf("Error: Failed to allocate memory for registers in %s\n", __FUNCTION__);
return FALSE;
}
// Initialise the registers with the correct addresses etc
memset(psInstance->psRegisters, 0, psInstance->u16NumRegisters * sizeof(ORLACO_tsRegisterValue));
for(n = 0; n < psInstance->u16NumRegisters; n++)
{
psInstance->psRegisters[n].u16Address = ORLACO_asRegisterDefinitions[n].u16Address;
psInstance->psRegisters[n].pcDescription = ORLACO_asRegisterDefinitions[n].pcDescription;
psInstance->psRegisters[n].pcHelp = ORLACO_asRegisterDefinitions[n].pcHelp;
}
// Set how many regions of interest there are
psInstance->u16NumRegionsOfInterest = ORLACO_NUM_REGIONS_OF_INTEREST;
// Allocate the memory for the regions of interest
psInstance->psRegionsOfInterest = (ORLACO_tsRegionOfInterest*)malloc(psInstance->u16NumRegionsOfInterest * sizeof(ORLACO_tsRegionOfInterest));
if(psInstance->psRegionsOfInterest == NULL)
{
printf("Error: Failed to allocate memory for regions of interest in %s\n", __FUNCTION__);
return FALSE;
}
// Initialise the regions of interest
memset(psInstance->psRegionsOfInterest, 0, psInstance->u16NumRegionsOfInterest * sizeof(ORLACO_tsRegionOfInterest));
return TRUE;
}
/****************************************************************************
*
* NAME: ORLACO_vDeInit
*
* DESCRIPTION:
* De-initialises the Orlaco functions
*
* RETURNS:
* void
*
****************************************************************************/
void ORLACO_vDeInit(ORLACO_tsInstance *psInstance)
{
#ifdef _WIN32
closesocket(psInstance->Socket);
#else
close(psInstance->Socket);
#endif
// Free memory allocated for the registers
if(psInstance->psRegisters != NULL)
{
free(psInstance->psRegisters);
}
// Free memory allocated for the regions of interest
if(psInstance->psRegionsOfInterest != NULL)
{
free(psInstance->psRegionsOfInterest);
}
// Free memory allocated for discovered cameras
if(psInstance->psCameras != NULL)
{
free(psInstance->psCameras);
}
}
/****************************************************************************
*
* NAME: ORLACO_vSetVerbosity
*
* DESCRIPTION:
* Set the logging verbosity level
*
* RETURNS:
* void
*
****************************************************************************/
void ORLACO_vSetVerbosity(ORLACO_tsInstance *psInstance, ORLACO_eVerbosityLevel eVerbosityLevel)
{
psInstance->eVerbosity = eVerbosityLevel;
}
/****************************************************************************
*
* NAME: ORLACO_bSetBroadcastIP
*
* DESCRIPTION:
* Sets the broadcast IP address
*
* RETURNS:
* bool_t TRUE if successful, FALSE otherwise
*
****************************************************************************/
bool_t ORLACO_bSetBroadcastIP(ORLACO_tsInstance *psInstance, char *pcIpAddress, uint16_t u16DstPort)
{
/* Set the socket address for broadcast packets */
memset((char *) &psInstance->fdBroadcast, 0, sizeof(psInstance->fdBroadcast));
psInstance->fdBroadcast.sin_family = AF_INET;
psInstance->fdBroadcast.sin_port = htons(u16DstPort);
psInstance->fdBroadcast.sin_addr.s_addr = inet_addr(pcIpAddress);
return TRUE;
}
/****************************************************************************
*
* NAME: ORLACO_bSetUnicastIP
*
* DESCRIPTION:
* Sets the unicast IP address
*
* RETURNS:
* bool_t TRUE if successful, FALSE otherwise
*
****************************************************************************/
bool_t ORLACO_bSetUnicastIP(ORLACO_tsInstance *psInstance, char *pcIpAddress, uint16_t u16DstPort)
{
/* Set the socket address for unicast packets */
memset((char *) &psInstance->fdUnicast, 0, sizeof(psInstance->fdUnicast));
psInstance->fdUnicast.sin_family = AF_INET;
psInstance->fdUnicast.sin_port = htons(u16DstPort);
psInstance->fdUnicast.sin_addr.s_addr = inet_addr(pcIpAddress);
return TRUE;
}
/****************************************************************************
*
* NAME: ORLACO_bBufferTest
*
* DESCRIPTION:
* Function for testing the buffer read/write functions
*
* RETURNS:
* bool_t TRUE if successful, FALSE otherwise
*
****************************************************************************/
bool_t ORLACO_bBufferTest(ORLACO_tsInstance *psInstance)
{
uint8_t u8;
uint16_t u16;
uint32_t u24;
uint32_t u32;
bool_t bOk = TRUE;
// Allocate a buffer
ORLACO_tsBuffer *psBuffer = ORLACO_psBufferCreate(ORLACO_BUFFER_LENGTH);
if(psBuffer == NULL)
{
printf("Buffer allocation failed in %s\n", __FUNCTION__);
return FALSE;
}
bOk &= ORLACO_bWriteU8(psBuffer, 0x11);
bOk &= ORLACO_bWriteU16(psBuffer, 0x2233);
bOk &= ORLACO_bWriteU24(psBuffer, 0x445566);
bOk &= ORLACO_bWriteU32(psBuffer, 0x778899aa);
if(!bOk){
ORLACO_vBufferDestroy(psBuffer);
return bOk;
}
printf("Buffer contains %d bytes after writing:", psBuffer->u32Offset);
for(int n = 0; n < psBuffer->u32Offset; n++)
{
printf(" %02x", psBuffer->pu8Data[n]);
}
printf("\n");
psBuffer->u32Offset = 0;
bOk &= ORLACO_bReadU8(psBuffer, &u8);
bOk &= ORLACO_bReadU16(psBuffer, &u16);
bOk &= ORLACO_bReadU24(psBuffer, &u24);
bOk &= ORLACO_bReadU32(psBuffer, &u32);
printf("u8=%02x u16=%04x u24=%06x, u32=%08x\n", u8, u16, u24, u32);
// Free the buffer
ORLACO_vBufferDestroy(psBuffer);
return bOk;
}
/****************************************************************************
*
* NAME: ORLACO_bDiscover
*
* DESCRIPTION:
* Sends a broadcast discovery message to identify cameras
*
* RETURNS:
* bool_t TRUE if successful, FALSE otherwise
*
****************************************************************************/
bool_t ORLACO_bDiscover(ORLACO_tsInstance *psInstance)
{
bool_t bOk = TRUE;
ORLACO_tsMsg sMsg;
if(psInstance->eVerbosity >= E_ORLACO_VERBOSITY_DEBUG) printf("%s()\n", __FUNCTION__);
// Allocate a buffer
ORLACO_tsBuffer *psBuffer = ORLACO_psBufferCreate(ORLACO_BUFFER_LENGTH);
if(psBuffer == NULL)
{
printf("Error: Buffer allocation failed in %s\n", __FUNCTION__);
return FALSE;
}
// Clear any previous discovery results
psInstance->u16NumCameras = 0;
if(psInstance->psCameras != NULL)
{
free(psInstance->psCameras);
psInstance->psCameras = NULL;
}
psInstance->u16ServiceID = 0xffff;
// Construct the message header
sMsg.u16ServiceID = psInstance->u16ServiceID;
sMsg.u16MethodID = E_ORLACO_METHOD_ID_SERVICE_DISCOVERY;
sMsg.u32Length = 8;
sMsg.u16ClientID = psInstance->u16ClientID;
sMsg.u16SessionID = ORLACO_u16GetSessionID(psInstance);
sMsg.u8SomeIPVersion = 1;
sMsg.u8InterfaceVersion = 1;
sMsg.u8MessageType = E_ORLACO_MESSAGE_TYPE_NOTIFICATION;
sMsg.u8ReturnCode = E_ORLACO_RETURN_CODE_OK;
sMsg.uPayload.sServiceDiscoveryPayload.u8Flags = 0;
sMsg.uPayload.sServiceDiscoveryPayload.u24Reserved = 0;
sMsg.uPayload.sServiceDiscoveryPayload.u32LengthOfEntriesArrayInBytes = ORLACO_SD_OPTION_LENGTH * 1;
sMsg.uPayload.sServiceDiscoveryPayload.u32LengthOfOptionsArrayInBytes = 0;
// Service entry 0
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[0].u8Type = 0; // Find
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[0].u8Index1stOptions = 0;
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[0].u8Index2ndOptions = 0;
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[0].u8NumberOfOptions = 0;
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[0].u16ServiceID = psInstance->u16ServiceID;
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[0].u16InstanceID = 0xffff;
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[0].u8MajorVersion = 0xff;
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[0].u24TTL = 3600; // 1 hour
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[0].u32MinorVersion = 0xffffffff; // Any
sMsg.u32Length += 12 + sMsg.uPayload.sServiceDiscoveryPayload.u32LengthOfEntriesArrayInBytes + sMsg.uPayload.sServiceDiscoveryPayload.u32LengthOfOptionsArrayInBytes;
// Write the message header into the byte buffer
bOk &= ORLACO_bWriteMessageHeaderIntoBuffer(psBuffer, &sMsg);
bOk &= ORLACO_bWriteU8(psBuffer, sMsg.uPayload.sServiceDiscoveryPayload.u8Flags);
bOk &= ORLACO_bWriteU24(psBuffer, sMsg.uPayload.sServiceDiscoveryPayload.u24Reserved);
bOk &= ORLACO_bWriteU32(psBuffer, sMsg.uPayload.sServiceDiscoveryPayload.u32LengthOfEntriesArrayInBytes);
bOk &= ORLACO_bWriteServiceDiscoveryServiceEntryIntoBuffer(psBuffer, &sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[0]);
bOk &= ORLACO_bWriteU32(psBuffer, sMsg.uPayload.sServiceDiscoveryPayload.u32LengthOfOptionsArrayInBytes);
// If we couldn't write the message to the buffer for some reason, free the buffer and then exit
if(!bOk)
{
ORLACO_vBufferDestroy(psBuffer);
return FALSE;
}
// Send the message
if(!ORLACO_bSendDatagram(psInstance->Socket, &psInstance->fdBroadcast, psBuffer))
{
return FALSE;
}
while(ORLACO_bReceiveDatagram(psInstance, &sMsg, E_ORLACO_MESSAGE_TYPE_NOTIFICATION))
{
// If we got some options but the service id is 0xffff, probably our own broadcast so drop it
if((sMsg.uPayload.sServiceDiscoveryPayload.u32LengthOfEntriesArrayInBytes >= ORLACO_SD_OPTION_LENGTH) && (sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[0].u16ServiceID == 0xffff))
{
if(psInstance->eVerbosity >= E_ORLACO_VERBOSITY_DEBUG) printf("Skipping message since its probably our own broadcast in %s\n", __FUNCTION__);
continue;
}
// If we've already seen a message from this camera, skip it
if(ORLACO_bIPAlreadyInArray(psInstance, sMsg.uSrcAddr))
{
if(psInstance->eVerbosity >= E_ORLACO_VERBOSITY_DEBUG) printf("Skipping message since we've already seen this camera before in %s\n", __FUNCTION__);
continue;
}
psInstance->u16NumCameras++;
psInstance->psCameras = realloc(psInstance->psCameras, sizeof(ORLACO_tsCamera) * psInstance->u16NumCameras);
psInstance->psCameras[psInstance->u16NumCameras-1].uIP.u32IP = sMsg.uSrcAddr.u32IP;
if(sMsg.uPayload.sServiceDiscoveryPayload.u32LengthOfEntriesArrayInBytes >= ORLACO_SD_OPTION_LENGTH)
{
memcpy(&psInstance->psCameras[psInstance->u16NumCameras-1].sDiscoveryServiceEntry, &sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[0], sizeof(ORLACO_tsServiceDiscoveryServiceEntry));
}
else
{
memset(&psInstance->psCameras[psInstance->u16NumCameras-1].sDiscoveryServiceEntry, 0, sizeof(ORLACO_tsServiceDiscoveryServiceEntry));
}
if(psInstance->eVerbosity >= E_ORLACO_VERBOSITY_INFO) printf("Got response from IP %d.%d.%d.%d Len=%d\n", sMsg.uSrcAddr.au8IP[3], sMsg.uSrcAddr.au8IP[2], sMsg.uSrcAddr.au8IP[1], sMsg.uSrcAddr.au8IP[0], sMsg.uPayload.sServiceDiscoveryPayload.u32LengthOfEntriesArrayInBytes);
for(int n = 0; n < sMsg.uPayload.sServiceDiscoveryPayload.u32LengthOfEntriesArrayInBytes; n += ORLACO_SD_OPTION_LENGTH)
{
if(psInstance->eVerbosity >= E_ORLACO_VERBOSITY_INFO) printf("Option %d Type=%02x ServiceID=%04x InstanceID=%04x V=%d.%d 1stOptionsIdx=%d 2ndOptionsIdx=%d OptionsNum=%02x\n\n",
n,
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[n].u8Type,
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[n].u16ServiceID,
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[n].u16InstanceID,
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[n].u8MajorVersion,
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[n].u32MinorVersion,
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[n].u8Index1stOptions,
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[n].u8Index2ndOptions,
sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[n].u8NumberOfOptions
);
psInstance->u16ServiceID = sMsg.uPayload.sServiceDiscoveryPayload.asServiceEntry[n].u16ServiceID;
}
}
return TRUE;
}
/****************************************************************************
*
* NAME: ORLACO_bSetCamExclusive
*
* DESCRIPTION:
* Sends a "Set Camera Exclusive" message containing the specified exclusive time
*
* RETURNS:
* bool_t TRUE if successful, FALSE otherwise
*
****************************************************************************/
bool_t ORLACO_bSetCamExclusive(ORLACO_tsInstance *psInstance, uint32_t u32ExclusiveTime)
{
bool_t bOk = TRUE;
ORLACO_tsMsg sMsg;
if(psInstance->eVerbosity >= E_ORLACO_VERBOSITY_DEBUG) printf("%s()\n", __FUNCTION__);
// Allocate a buffer
ORLACO_tsBuffer *psBuffer = ORLACO_psBufferCreate(ORLACO_BUFFER_LENGTH);
if(psBuffer == NULL)
{
printf("Error: Buffer allocation failed in %s\n", __FUNCTION__);
return FALSE;
}
// Construct the message header
sMsg.u16ServiceID = psInstance->u16ServiceID;
sMsg.u16MethodID = E_ORLACO_METHOD_ID_SET_CAM_EXCLUSIVE;
sMsg.u32Length = 8;
sMsg.u16ClientID = psInstance->u16ClientID;
sMsg.u16SessionID = ORLACO_u16GetSessionID(psInstance);
sMsg.u8SomeIPVersion = 1;
sMsg.u8InterfaceVersion = 1;
sMsg.u8MessageType = E_ORLACO_MESSAGE_TYPE_REQUEST;
sMsg.u8ReturnCode = E_ORLACO_RETURN_CODE_OK;
// Add the message payload and adjust the length field to include it
sMsg.u32Length += sizeof(sMsg.uPayload.sSetCamExclusivePayload);
sMsg.uPayload.sSetCamExclusivePayload.u32ExclusiveTime = u32ExclusiveTime;
// Write the message header into the byte array buffer
bOk &= ORLACO_bWriteMessageHeaderIntoBuffer(psBuffer, &sMsg);
// Write the payload into the buffer
bOk &= ORLACO_bWriteU32(psBuffer, sMsg.uPayload.sSetCamExclusivePayload.u32ExclusiveTime);
// If we couldn't write the message to the buffer for some reason, free the buffer and then exit
if(!bOk)
{
ORLACO_vBufferDestroy(psBuffer);
return FALSE;
}
// Send the message
if(!ORLACO_bSendDatagram(psInstance->Socket, &psInstance->fdUnicast, psBuffer))
{
return FALSE;
}
// See if we get a response
bOk &= ORLACO_bReceiveDatagram(psInstance, &sMsg, E_ORLACO_METHOD_ID_SET_CAM_EXCLUSIVE);
return bOk;
}
/****************************************************************************
*
* NAME: ORLACO_bEraseCamExclusive
*
* DESCRIPTION:
* Sends a "Erase Camera Exclusive" message
*
* RETURNS:
* bool_t TRUE if successful, FALSE otherwise
*
****************************************************************************/
bool_t ORLACO_bEraseCamExclusive(ORLACO_tsInstance *psInstance)
{
bool_t bOk = TRUE;
ORLACO_tsMsg sMsg;
if(psInstance->eVerbosity >= E_ORLACO_VERBOSITY_DEBUG) printf("%s()\n", __FUNCTION__);
// Allocate a buffer
ORLACO_tsBuffer *psBuffer = ORLACO_psBufferCreate(ORLACO_BUFFER_LENGTH);
if(psBuffer == NULL)
{
printf("Error: Buffer allocation failed in %s\n", __FUNCTION__);
return FALSE;
}
// Construct the message header
sMsg.u16ServiceID = psInstance->u16ServiceID;
sMsg.u16MethodID = E_ORLACO_METHOD_ID_ERASE_CAM_EXCLUSIVE;
sMsg.u32Length = 8;
sMsg.u16ClientID = psInstance->u16ClientID;
sMsg.u16SessionID = ORLACO_u16GetSessionID(psInstance);
sMsg.u8SomeIPVersion = 1;
sMsg.u8InterfaceVersion = 1;
sMsg.u8MessageType = E_ORLACO_MESSAGE_TYPE_REQUEST;
sMsg.u8ReturnCode = E_ORLACO_RETURN_CODE_OK;
// Write the message header into the byte array buffer
bOk &= ORLACO_bWriteMessageHeaderIntoBuffer(psBuffer, &sMsg);
// If we couldn't write the message to the buffer for some reason, free the buffer and then exit
if(!bOk)
{
ORLACO_vBufferDestroy(psBuffer);