fujuntang
2022-04-28 51ccd8155f029d66366d0df8e2baf886ffd50000
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
#ifndef __SRV_PTZ_H__
#define __SRV_PTZ_H__
 
#ifdef __cplusplus
extern "C" {
#endif
 
#include <semaphore.h>
#include <pthread.h>
 
#include "capabilities/capa.h"
 
#define USERNAME        "On_admin"                                                
#define PASSWORD        "a12345678"
 
#define HK_IDS_2DE      1
 
#if defined(HK_IDS_2DE)
 
#define COEF_H_A      180
#define COEF_H_B      180
 
#define COEF_V_A      -52.5
#define COEF_V_B      37.5
 
#define COEF_Z_A      31
#define COEF_Z_B      1
 
#define MAX_FOVH      60.2
#define MIN_FOVH      2.3
 
#define MAX_FOVV      39.0
#define MIN_FOVV      2.1
#endif 
 
#define MAX_VAL       360
 
#define MAX_ZOOM      COEF_Z_A
#define MIN_ZOOM      0
 
#define MAX_SPEED     MAX_ZOOM
#define MIN_SPEED     MIN_ZOOM
 
#define MIN_TOUR_TIME   15
#define MIN_TOUR_POS    2
 
#define WT_TIME         5
#define STOP_WT_TIME    3
 
#define MAX_IMG_SCALE   0.5
 
#define PI              3.14159
#define  RAD2ANG(x)     (180 / PI * x)
#define ANG2RAD(x)      (PI / 180 * x)
 
#define COEF_FH_A       1.626
#define COEF_FH_B       0.634
#define COEF_FH_C       0.177
 
#define COEF_FV_A       0.953
#define COEF_FV_B       0.598
#define COEF_FV_C       0.166
 
#define ENABLE          0
#define DISABLE         1
 
/*PTZ working stat*/
enum PTZStat {
  RUNNING,
  IDLE,
  UNKNOWN,
};
 
/*the current PTZ positions*/
typedef struct _PosCur
{
  float p;
  float t;
  float z;
 
  enum PTZStat stat;
 
} PosCur;
 
/*the PTZ control command*/
enum PTZCMD
{
  PTZ_CMD_LEFT,
  PTZ_CMD_RIGHT,
  PTZ_CMD_UP,
  PTZ_CMD_DOWN,
  PTZ_CMD_LEFTUP,
  PTZ_CMD_LEFTDOWN,
  PTZ_CMD_RIGHTUP,
  PTZ_CMD_RIGHTDOWN,
  PTZ_CMD_ZOOM_IN,
  PTZ_CMD_ZOOM_OUT,
};
 
/*the tradditional preset control command*/
enum PreSetCMD
{
  PRESET_SET,
  PRESET_GOTO,
  PRESET_GET,
  PRESET_REMOVE,
};
 
/*the supported two types of tours*/
enum tourType {
  
  TOUR_PRIV, //our self-defined tour type  
 
  TOUR_COMM, //for the traditional tour type such as Hikon
};
 
/*Set the preset pos table:
 * Note (pos0_x, pos0_y) and (pos1_x, pos1_y) must be aligned with the image center pixle (x, y)
*/
typedef struct _PresetToure_node {
 
  int x; /*the pixel pos (x, y)*/
  int y;
 
  int pos0_x; /*the left-up pixel*/
  int pos0_y;
 
  int pos1_x; /*the right-down pixel*/
  int pos1_y; 
 
  int time_sec; /*the tour time*/
} PresetToure_node;
 
/*Set the preset pos table*/
typedef struct _PresetToure_tradnode {
  int posToken; /*the preset token*/
  
  int time_sec; /*the tour time*/
}PresetToure_tradnode;
 
/*the operational handle*/
typedef struct _PtzDevs {
 
  struct tagCapabilities capa;
 
  struct tagProfile *profilesToken;
 
  PresetToure_node *posNode;
  int posNode_count;
 
  PresetToure_tradnode *postradNode;
  int postradNode_count;
 
  timer_t timer_id;
 
  sem_t sem_tour;
 
  pthread_mutex_t node_mutex;
 
  pthread_cond_t cond;
 
  /*the device work stat*/
  char dev_stat;
 
  char wt_stat;
 
  /*the touring process work stat*/
  char proc_stat;
 
  enum tourType tour_type;
 
} PtzDevs;
 
int proto_PTZInit(void);
void proto_PTZClose(void);
PtzDevs *proto_PTZGethandle(void);
int proto_PTZControl(PtzDevs *DevData, enum PTZCMD cmd, float speed_p, float speed_t, \
                       float speed_z, const char *username, const char *passwd);
int proto_PTZStop(PtzDevs *DevData, const char *username, const char *passwd);
int proto_PTZSetStep(PtzDevs *DevData, enum PTZCMD cmd, float pos_p, float pos_t, float pos_z, \
                        const char *username, const char *passwd);
int proto_PTZ_GetStatus(PtzDevs *DevData, PosCur *pos_get, const char *username, const char *passwd);
int proto_PTZSet(PtzDevs *DevData, float pos_p, float pos_t, float pos_z, const char *username, const char *passwd);
int proto_PTZGetPT(PtzDevs *DevData, int x, int y, float *p, float *t, const char *username, const char *passwd);
 
static float ptz_fovv_get(float pos);
static float ptz_fovh_get(float pos);
 
static float pos_calc_p(float pos);
static float pos_calc_t(float pos);
static float pos_calc_z(float pos);
 
static float pos_res_p(float pos);
static float pos_res_t(float pos);
static float pos_res_z(float pos);
 
static int img_w_get(PtzDevs *DevData);
static int img_h_get(PtzDevs *DevData);
 
int proto_PTZPreset(PtzDevs *DevData, const char *posName, enum PreSetCMD cmd, \
                      int *posToken, const char *username, const char *passwd);
int proto_PTZ_ImagingSet(PtzDevs *DevData, float speed, const char *username, const char *passwd);
 
static void *task_preset_touring(void *arg);
float proto_PTZZoom_get(PtzDevs *DevData, int x0, int y0, int x1, int y1); 
int proto_PTZPreset_tradtour_set(PtzDevs *DevData, PresetToure_tradnode *PosArr, int n);
int proto_PTZPreset_tour_set(PtzDevs *DevData, PresetToure_node *PosArr, int n);
int proto_PTZPreset_tour_start(PtzDevs *DevData, enum tourType type);
void proto_PTZWaitStopped(PtzDevs *DevData, const char *username, const char *passwd);
void proto_PTZPreset_tour_stop(PtzDevs *DevData);
 
static void timer_handler(union sigval para);
static int timer_init(timer_t *timer_index);
static int timer_start(timer_t timer_index, int sec);
static int timer_stop(timer_t timer_index);
static int timer_destroy(timer_t timer_index);
 
#ifdef __cplusplus
}
#endif
 
#endif