FuJuntang
2022-07-06 e795b6226a92961ae10d5ef497d2f78fe88fb918
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
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
 
#include "PTZBinding.nsmap"
#include "capabilities/capa.h"
#include "ptz/ptz.h"
#include "probe/probe.h"
#include "proto_comm.h"
#include "proto_dbg.h"
 
int main(int argc, char **argv)
{
    int ret;
    PosCur pos_get;
    int preset0, preset1, preset2;
    float pval, tval, zval;
    float speed_p, speed_t, speed_z;
    PtzDevs *handle = NULL;
 
    ret = proto_PTZInit();
    if (ret < 0) {
      printf("PTZ initialization failure!\n");
 
      return 0;
    }
 
    handle = proto_PTZGethandle();
 
    /*test case 1: Get the current position*/
    proto_PTZ_GetStatus(handle, &pos_get, USERNAME, PASSWORD); 
    printf("current pos: p %3.2f, t %3.2f, z %3.2f\n", pos_get.p, pos_get.t, pos_get.z);
    /*test case 1 end*/
 
    /*test case 2: run toward different directions with different speed, e.g. left\right\left-down\right-up and etc.*/
    speed_p = MIN_SPEED;
    speed_t = MIN_SPEED;
    /*run toward left direction with the lowest speed*/
    proto_PTZControl(handle, PTZ_CMD_LEFT, speed_p, speed_t, 0, USERNAME, PASSWORD);
    
    sleep(25);
    
    /*stop run*/
    proto_PTZStop(handle, USERNAME, PASSWORD);
 
    speed_p = MAX_SPEED; 
    speed_t = MAX_SPEED;
    /*run toward left-down direction with the highest speed*/
    proto_PTZControl(handle, PTZ_CMD_LEFTDOWN, speed_p, speed_t, 0, USERNAME, PASSWORD);
    
    sleep(25);
    
    /*stop run*/
    proto_PTZStop(handle, USERNAME, PASSWORD);
 
    speed_p = (MIN_SPEED + MAX_SPEED) / 2; 
    speed_t = MAX_SPEED;
    /*run toward right-down with the mid speed*/
    proto_PTZControl(handle, PTZ_CMD_RIGHTDOWN, speed_p, speed_t, 0, USERNAME, PASSWORD);
    
    sleep(25);
 
    /*stop run*/
    proto_PTZStop(handle, USERNAME, PASSWORD);
 
    speed_p = (MIN_SPEED + MAX_SPEED) / 2; 
    speed_t = (MIN_SPEED + MAX_SPEED) / 2;
    /*run toward right direction with mid speed*/
    proto_PTZControl(handle, PTZ_CMD_RIGHT, speed_p, speed_t, 0, USERNAME, PASSWORD);
    
    sleep(25);
 
    /*stop run*/
    proto_PTZStop(handle, USERNAME, PASSWORD);
 
    /*Get the current position*/
    proto_PTZ_GetStatus(handle, &pos_get, USERNAME, PASSWORD);
    printf("current pos: p %3.2f, t %3.2f, z %3.2f\n", pos_get.p, pos_get.t, pos_get.z);
    /*test case 2 end*/
 
    /*test case 3: Preset set - set the tradditional preset pos like hikon*/
    proto_PTZPreset(handle, "index_0", PRESET_SET, &preset0, USERNAME, PASSWORD);
 
    proto_PTZPreset(handle, "index_1", PRESET_SET, &preset1, USERNAME, PASSWORD);
 
    proto_PTZPreset(handle, "index_2", PRESET_SET, &preset2, USERNAME, PASSWORD);
    /*test case 3 end*/
 
    /*test case 4: Preset goto - go to the preset pos*/
    proto_PTZPreset(handle, NULL, PRESET_GOTO, &preset0, USERNAME, PASSWORD);
 
    proto_PTZPreset(handle, NULL, PRESET_GOTO, &preset1, USERNAME, PASSWORD);
 
    proto_PTZPreset(handle, NULL, PRESET_GOTO, &preset2, USERNAME, PASSWORD);
    /*test case 4 end*/
 
    /*test case 5: Preset remove - delete the preset pos*/
    proto_PTZPreset(handle, NULL, PRESET_REMOVE, &preset0, USERNAME, PASSWORD);
 
    proto_PTZPreset(handle, NULL, PRESET_REMOVE, &preset1, USERNAME, PASSWORD);
 
    proto_PTZPreset(handle, NULL, PRESET_REMOVE, &preset2, USERNAME, PASSWORD);
    /*test case 5 end*/
 
    /*test case 6: zoom-in*/
    zval = MAX_ZOOM;
    proto_PTZSet(handle, 0, 0, zval, USERNAME, PASSWORD);
    proto_PTZWaitStopped(handle, USERNAME, PASSWORD);
    /*test case 6 end*/
 
    /*test case 7: zoom out*/
    zval = MAX_ZOOM / 2;
    proto_PTZSet(handle, 0, 0, zval, USERNAME, PASSWORD);
    proto_PTZWaitStopped(handle, USERNAME, PASSWORD);
 
    zval = MIN_ZOOM;
    proto_PTZSet(handle, 0, 0, zval, USERNAME, PASSWORD);
    proto_PTZWaitStopped(handle, USERNAME, PASSWORD);
    /*test case 7 end*/
 
    /*test case 8: put the pixel (x, y) at the center of the image*/
    proto_PTZ_GetStatus(handle, &pos_get, USERNAME, PASSWORD);
    proto_PTZGetPT(handle, 0, 0, &pval, &tval, USERNAME, PASSWORD);
    proto_PTZSet(handle, pval, tval, pos_get.z, USERNAME, PASSWORD);
    sleep(20);
    /*test case 8 end*/
 
    /*test case 9:
    * firstly, put the object enter point at the image center;
    * secondly, zoom in the object that is describled with left-up and right-down pixel;
    * finally, restore the image as original size;
    */
    float data;
    proto_PTZ_GetStatus(handle, &pos_get, USERNAME, PASSWORD);
    proto_PTZGetPT(handle, 0, 0, &pval, &tval, USERNAME, PASSWORD);
    proto_PTZSet(handle, pval, tval, pos_get.z, USERNAME, PASSWORD);
    proto_PTZWaitStopped(handle, USERNAME, PASSWORD);
    data = proto_PTZZoom_get(handle, 1280 / 2 - 1280 / 4, 960 / 4, 1280 * 3 / 4, 960 * 3 / 4);
    proto_PTZSet(handle, 0, 0, data, USERNAME, PASSWORD);
    proto_PTZWaitStopped(handle, USERNAME, PASSWORD); 
 
    proto_PTZSet(handle, 0, 0, 1, USERNAME, PASSWORD);
    proto_PTZWaitStopped(handle, USERNAME, PASSWORD);
    /*test case 9 end*/
 
    /*test case 10: Preset touring*/
    /*test case 10-1: 
     *set the preset tour whose type is the tradditional one like hikon mode*/
    /*Set the preset pos table*/
    PresetToure_tradnode posTradnode[] = {
                      {2, MIN_TOUR_TIME}, 
                      {3, MIN_TOUR_TIME + 20}, 
                      {4, MIN_TOUR_TIME}
    };
 
    proto_PTZPreset_tradtour_set(handle, posTradnode, sizeof(posTradnode) / sizeof(posTradnode[0]));
   
    /*Start the tradditional tour*/
    ret = proto_PTZPreset_tour_start(handle, TOUR_COMM);
    if (ret) {
      printf("start the tour failed!\n");
 
      goto EXIT;
    }
 
    sleep(6000);
 
    /*Stop the preset tour*/
    proto_PTZPreset_tour_stop(handle);  
  
    /*test case 10-2: 
     *set the self-defined preset tour by ourselves*/    
    /*Set the preset pos table*/
    PresetToure_node posNode[] = {
                                    {0, 0, 1280 / 2 - 50, 960 / 2 - 50, 1280 /2 + 50, 960 / 2 + 50, MIN_TOUR_TIME}, 
                                    {1280, 960, 1280 / 2 - 500, 980 / 2 - 400, 1280 / 2 + 500, 980 / 2 + 400, 20}, 
                                    {600, 300, 1280 / 2 - 200, 980 / 2 - 200, 1280 / 2 + 200, 980 /2 + 200, MIN_TOUR_TIME}
                                };
    proto_PTZPreset_tour_set(handle, posNode, sizeof(posNode) / sizeof(posNode[0]));
    ret = proto_PTZPreset_tour_start(handle, TOUR_PRIV);
    if (ret) {
      printf("start the tour failed!\n");
 
      goto EXIT;
    }
  
    printf("in starting re-set test to press key:\n");
    getchar();
    proto_PTZPreset_tour_set(handle, posNode, sizeof(posNode) / sizeof(posNode[0]));
 
    printf("stop the tour to press the key:\n");
    getchar();
    proto_PTZPreset_tour_stop(handle);
    /*test case 10 end*/
 
EXIT:
 
    /*finally, remember release the resources when exitting!!!*/
    printf("now release the handle:\n");
    proto_PTZClose();
 
    return 0;
}