Skip to content

Commit

Permalink
Add dynamic range for ptz
Browse files Browse the repository at this point in the history
  • Loading branch information
roleoroleo committed Jul 19, 2024
1 parent d72d5c9 commit 7cb7db0
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 42 deletions.
32 changes: 32 additions & 0 deletions conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ int process_conf_file(char *file)
service_ctx.events_enable = EVENTS_NONE;
service_ctx.events_num = 0;

service_ctx.ptz_node.max_step_x = 360.0;
service_ctx.ptz_node.max_step_y = 180.0;
service_ctx.ptz_node.get_position = NULL;
service_ctx.ptz_node.is_moving = NULL;
service_ctx.ptz_node.move_left = NULL;
Expand Down Expand Up @@ -230,6 +232,8 @@ int process_conf_file(char *file)
//PTZ Profile for ONVIF PTZ Service
} else if ((strcasecmp(param, "ptz") == 0) && (strcasecmp(value, "1") == 0)) {
service_ctx.ptz_node.enable = 1;
service_ctx.ptz_node.max_step_x = 360.0;
service_ctx.ptz_node.max_step_y = 180.0;
service_ctx.ptz_node.get_position = NULL;
service_ctx.ptz_node.is_moving = NULL;
service_ctx.ptz_node.move_left = NULL;
Expand All @@ -244,6 +248,32 @@ int process_conf_file(char *file)
service_ctx.ptz_node.remove_preset = NULL;
service_ctx.ptz_node.jump_to_abs = NULL;
service_ctx.ptz_node.jump_to_rel = NULL;
} else if (strcasecmp(param, "max_step_x") == 0) {
errno = 0;
service_ctx.ptz_node.max_step_x = strtod(value, &endptr);

/* Check for various possible errors */
if (errno == ERANGE || (errno != 0 && service_ctx.ptz_node.max_step_x == 0.0)) {
log_error("Wrong option: %s", line);
return -1;
}
if (endptr == value) {
log_error("Wrong option: %s", line);
return -1;
}
} else if (strcasecmp(param, "max_step_y") == 0) {
errno = 0;
service_ctx.ptz_node.max_step_y = strtod(value, &endptr);

/* Check for various possible errors */
if (errno == ERANGE || (errno != 0 && service_ctx.ptz_node.max_step_y == 0.0)) {
log_error("Wrong option: %s", line);
return -1;
}
if (endptr == value) {
log_error("Wrong option: %s", line);
return -1;
}
} else if ((strcasecmp(param, "get_position") == 0) && (service_ctx.ptz_node.enable == 1)) {
service_ctx.ptz_node.get_position = (char *) malloc(strlen(value) + 1);
strcpy(service_ctx.ptz_node.get_position, value);
Expand Down Expand Up @@ -445,6 +475,8 @@ void print_conf_help()
fprintf(stderr, "\n");
fprintf(stderr, "\t#PTZ\n");
fprintf(stderr, "\tptz=1\n");
fprintf(stderr, "\tmax_step_x=360\n");
fprintf(stderr, "\tmax_step_y=180\n");
fprintf(stderr, "\tget_position=/tmp/sd/yi-hack/bin/ipc_cmd -g\n");
fprintf(stderr, "\tis_moving=/tmp/sd/yi-hack/bin/ipc_cmd -u\n");
fprintf(stderr, "\tmove_left=/tmp/sd/yi-hack/bin/ipc_cmd -m left\n");
Expand Down
2 changes: 2 additions & 0 deletions onvif_simple_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ typedef struct {

typedef struct {
int enable;
double max_step_x;
double max_step_y;
char *get_position;
char *is_moving;
char *move_left;
Expand Down
Binary file added onvif_simple_server.o
Binary file not shown.
90 changes: 80 additions & 10 deletions ptz_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,58 +128,128 @@ int ptz_get_service_capabilities()

int ptz_get_configurations()
{
long size = cat(NULL, "ptz_service_files/GetConfigurations.xml", 0);
char max_x[256];
char max_y[256];

sprintf(max_x, "%.1f", service_ctx.ptz_node.max_step_x);
sprintf(max_y, "%.1f", service_ctx.ptz_node.max_step_y);

long size = cat(NULL, "ptz_service_files/GetConfigurations.xml", 8,
"%MIN_X%", "0.0",
"%MAX_X%", max_x,
"%MIN_Y%", "0.0",
"%MAX_Y%", max_y);

fprintf(stdout, "Content-type: application/soap+xml\r\n");
fprintf(stdout, "Content-Length: %ld\r\n\r\n", size);

return cat("stdout", "ptz_service_files/GetConfigurations.xml", 0);
return cat("stdout", "ptz_service_files/GetConfigurations.xml", 8,
"%MIN_X%", "0.0",
"%MAX_X%", max_x,
"%MIN_Y%", "0.0",
"%MAX_Y%", max_y);
}

int ptz_get_configuration()
{
long size = cat(NULL, "ptz_service_files/GetConfiguration.xml", 0);
char max_x[256];
char max_y[256];

sprintf(max_x, "%.1f", service_ctx.ptz_node.max_step_x);
sprintf(max_y, "%.1f", service_ctx.ptz_node.max_step_y);

long size = cat(NULL, "ptz_service_files/GetConfiguration.xml", 8,
"%MIN_X%", "0.0",
"%MAX_X%", max_x,
"%MIN_Y%", "0.0",
"%MAX_Y%", max_y);

fprintf(stdout, "Content-type: application/soap+xml\r\n");
fprintf(stdout, "Content-Length: %ld\r\n\r\n", size);

return cat("stdout", "ptz_service_files/GetConfiguration.xml", 0);
return cat("stdout", "ptz_service_files/GetConfiguration.xml", 8,
"%MIN_X%", "0.0",
"%MAX_X%", max_x,
"%MIN_Y%", "0.0",
"%MAX_Y%", max_y);
}

int ptz_get_configuration_options()
{
long size = cat(NULL, "ptz_service_files/GetConfigurationOptions.xml", 0);
char max_x[256];
char max_y[256];

sprintf(max_x, "%.1f", service_ctx.ptz_node.max_step_x);
sprintf(max_y, "%.1f", service_ctx.ptz_node.max_step_y);

long size = cat(NULL, "ptz_service_files/GetConfigurationOptions.xml", 8,
"%MIN_X%", "0.0",
"%MAX_X%", max_x,
"%MIN_Y%", "0.0",
"%MAX_Y%", max_y);

fprintf(stdout, "Content-type: application/soap+xml\r\n");
fprintf(stdout, "Content-Length: %ld\r\n\r\n", size);

return cat("stdout", "ptz_service_files/GetConfigurationOptions.xml", 0);
return cat("stdout", "ptz_service_files/GetConfigurationOptions.xml", 8,
"%MIN_X%", "0.0",
"%MAX_X%", max_x,
"%MIN_Y%", "0.0",
"%MAX_Y%", max_y);
}

int ptz_get_nodes()
{
long size = cat(NULL, "ptz_service_files/GetNodes.xml", 0);
char max_x[256];
char max_y[256];

sprintf(max_x, "%.1f", service_ctx.ptz_node.max_step_x);
sprintf(max_y, "%.1f", service_ctx.ptz_node.max_step_y);

long size = cat(NULL, "ptz_service_files/GetNodes.xml", 8,
"%MIN_X%", "0.0",
"%MAX_X%", max_x,
"%MIN_Y%", "0.0",
"%MAX_Y%", max_y);

fprintf(stdout, "Content-type: application/soap+xml\r\n");
fprintf(stdout, "Content-Length: %ld\r\n\r\n", size);

return cat("stdout", "ptz_service_files/GetNodes.xml", 0);
return cat("stdout", "ptz_service_files/GetNodes.xml", 8,
"%MIN_X%", "0.0",
"%MAX_X%", max_x,
"%MIN_Y%", "0.0",
"%MAX_Y%", max_y);
}

int ptz_get_node()
{
char max_x[256];
char max_y[256];

sprintf(max_x, "%.1f", service_ctx.ptz_node.max_step_x);
sprintf(max_y, "%.1f", service_ctx.ptz_node.max_step_y);

const char *node_token = get_element("NodeToken", "Body");
if (strcmp("PTZNodeToken", node_token) != 0) {
send_fault("ptz_service", "Sender", "ter:InvalidArgVal", "ter:NoEntity", "No entity", "No such node on the device");
return -1;
}

long size = cat(NULL, "ptz_service_files/GetNode.xml", 0);
long size = cat(NULL, "ptz_service_files/GetNode.xml", 8,
"%MIN_X%", "0.0",
"%MAX_X%", max_x,
"%MIN_Y%", "0.0",
"%MAX_Y%", max_y);

fprintf(stdout, "Content-type: application/soap+xml\r\n");
fprintf(stdout, "Content-Length: %ld\r\n\r\n", size);

return cat("stdout", "ptz_service_files/GetNode.xml", 0);
return cat("stdout", "ptz_service_files/GetNode.xml", 8,
"%MIN_X%", "0.0",
"%MAX_X%", max_x,
"%MIN_Y%", "0.0",
"%MAX_Y%", max_y);
}

int ptz_get_presets()
Expand Down
8 changes: 4 additions & 4 deletions ptz_service_files/GetConfiguration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
<tt:Range>
<tt:URI>http://www.onvif.org/ver10/tptz/PanTiltSpaces/PositionGenericSpace</tt:URI>
<tt:XRange>
<tt:Min>0</tt:Min>
<tt:Max>360</tt:Max>
<tt:Min>%MIN_X%</tt:Min>
<tt:Max>%MAX_X%</tt:Max>
</tt:XRange>
<tt:YRange>
<tt:Min>0</tt:Min>
<tt:Max>180</tt:Max>
<tt:Min>%MIN_Y%</tt:Min>
<tt:Max>%MAX_Y%</tt:Max>
</tt:YRange>
</tt:Range>
</tt:PanTiltLimits>
Expand Down
16 changes: 8 additions & 8 deletions ptz_service_files/GetConfigurationOptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
<tt:AbsolutePanTiltPositionSpace>
<tt:URI>http://www.onvif.org/ver10/tptz/PanTiltSpaces/PositionGenericSpace</tt:URI>
<tt:XRange>
<tt:Min>0</tt:Min>
<tt:Max>360</tt:Max>
<tt:Min>%MIN_X%</tt:Min>
<tt:Max>%MAX_X%</tt:Max>
</tt:XRange>
<tt:YRange>
<tt:Min>0</tt:Min>
<tt:Max>180</tt:Max>
<tt:Min>%MIN_Y%</tt:Min>
<tt:Max>%MAX_Y%</tt:Max>
</tt:YRange>
</tt:AbsolutePanTiltPositionSpace>
<tt:AbsoluteZoomPositionSpace>
Expand All @@ -44,12 +44,12 @@
<tt:RelativePanTiltTranslationSpace>
<tt:URI>http://www.onvif.org/ver10/tptz/PanTiltSpaces/TranslationGenericSpace</tt:URI>
<tt:XRange>
<tt:Min>-360</tt:Min>
<tt:Max>360</tt:Max>
<tt:Min>-%MAX_X%</tt:Min>
<tt:Max>%MAX_X%</tt:Max>
</tt:XRange>
<tt:YRange>
<tt:Min>-180</tt:Min>
<tt:Max>180</tt:Max>
<tt:Min>-%MAX_Y%</tt:Min>
<tt:Max>%MAX_Y%</tt:Max>
</tt:YRange>
</tt:RelativePanTiltTranslationSpace>
<tt:RelativePanTiltTranslationSpace>
Expand Down
8 changes: 4 additions & 4 deletions ptz_service_files/GetConfigurations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
<tt:Range>
<tt:URI>http://www.onvif.org/ver10/tptz/PanTiltSpaces/PositionGenericSpace</tt:URI>
<tt:XRange>
<tt:Min>0</tt:Min>
<tt:Max>360</tt:Max>
<tt:Min>%MIN_X%</tt:Min>
<tt:Max>%MAX_X%</tt:Max>
</tt:XRange>
<tt:YRange>
<tt:Min>0</tt:Min>
<tt:Max>180</tt:Max>
<tt:Min>%MIN_Y%</tt:Min>
<tt:Max>%MAX_Y%</tt:Max>
</tt:YRange>
</tt:Range>
</tt:PanTiltLimits>
Expand Down
16 changes: 8 additions & 8 deletions ptz_service_files/GetNode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
<tt:AbsolutePanTiltPositionSpace>
<tt:URI>http://www.onvif.org/ver10/tptz/PanTiltSpaces/PositionGenericSpace</tt:URI>
<tt:XRange>
<tt:Min>0</tt:Min>
<tt:Max>360</tt:Max>
<tt:Min>%MIN_X%</tt:Min>
<tt:Max>%MAX_X%</tt:Max>
</tt:XRange>
<tt:YRange>
<tt:Min>0</tt:Min>
<tt:Max>180</tt:Max>
<tt:Min>%MIN_Y%</tt:Min>
<tt:Max>%MAX_Y%</tt:Max>
</tt:YRange>
</tt:AbsolutePanTiltPositionSpace>
<tt:AbsoluteZoomPositionSpace>
Expand All @@ -46,12 +46,12 @@
<tt:RelativePanTiltTranslationSpace>
<tt:URI>http://www.onvif.org/ver10/tptz/PanTiltSpaces/TranslationGenericSpace</tt:URI>
<tt:XRange>
<tt:Min>-360</tt:Min>
<tt:Max>360</tt:Max>
<tt:Min>-%MAX_X%</tt:Min>
<tt:Max>%MAX_X%</tt:Max>
</tt:XRange>
<tt:YRange>
<tt:Min>-180</tt:Min>
<tt:Max>180</tt:Max>
<tt:Min>-%MAX_Y%</tt:Min>
<tt:Max>%MAX_Y%</tt:Max>
</tt:YRange>
</tt:RelativePanTiltTranslationSpace>
<tt:RelativePanTiltTranslationSpace>
Expand Down
16 changes: 8 additions & 8 deletions ptz_service_files/GetNodes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
<tt:AbsolutePanTiltPositionSpace>
<tt:URI>http://www.onvif.org/ver10/tptz/PanTiltSpaces/PositionGenericSpace</tt:URI>
<tt:XRange>
<tt:Min>0</tt:Min>
<tt:Max>360</tt:Max>
<tt:Min>%MIN_X%</tt:Min>
<tt:Max>%MAX_X%</tt:Max>
</tt:XRange>
<tt:YRange>
<tt:Min>0</tt:Min>
<tt:Max>180</tt:Max>
<tt:Min>%MIN_Y%</tt:Min>
<tt:Max>%MAX_Y%</tt:Max>
</tt:YRange>
</tt:AbsolutePanTiltPositionSpace>
<tt:AbsoluteZoomPositionSpace>
Expand All @@ -46,12 +46,12 @@
<tt:RelativePanTiltTranslationSpace>
<tt:URI>http://www.onvif.org/ver10/tptz/PanTiltSpaces/TranslationGenericSpace</tt:URI>
<tt:XRange>
<tt:Min>-360</tt:Min>
<tt:Max>360</tt:Max>
<tt:Min>-%MAX_X%</tt:Min>
<tt:Max>%MAX_X%</tt:Max>
</tt:XRange>
<tt:YRange>
<tt:Min>-180</tt:Min>
<tt:Max>180</tt:Max>
<tt:Min>-%MAX_Y%</tt:Min>
<tt:Max>%MAX_Y%</tt:Max>
</tt:YRange>
</tt:RelativePanTiltTranslationSpace>
<tt:RelativePanTiltTranslationSpace>
Expand Down

0 comments on commit 7cb7db0

Please sign in to comment.