Added PTZ support

This commit is contained in:
wagner.oliveira 2022-12-16 19:24:05 -05:00
parent ae7b43d1be
commit a78a6f084c
5 changed files with 161 additions and 0 deletions

View File

@ -108,6 +108,19 @@ http://user:password@ip:8080/cgi-bin/telneton.cgi
http://user:password@ip:8080/cgi-bin/telneton.cgi
```
#### PTZ Notes (rotatable camera)
For the rotatable camera I made a basic PTZ control page you can access under:
```
http://user:password@ip:8080/ptz.html
```
You can send direct commands from other applications to control the motors with this URL:
```
http://user:password@ip:8080/cgi-bin/motor.cgi?dir=X&dist=N
```
The `dir` parameter defines direction of the motion and should be either `up`, `down`, `left` or `right`
The `dist` parameter defines how much to move, should be a value between 1 and probably 50 (I recommend 10).
I put together rather quickly and did not do a lot of testing so try it out and feel free to review the source (motor.c)
#### Final note
If you'd like more details about the whole process or have any issues, open an issue in github and we can discuss it further!

26
mmc/cgi-bin/motor.cgi Normal file
View File

@ -0,0 +1,26 @@
#!/bin/sh
echo -e "Content-type: text/plain\r"
echo -e "\r"
echo ${REQUEST_URI}
TMP=${REQUEST_URI#*dist=};
DIST=${TMP%&*}
TMP=${REQUEST_URI#*dir=};
DIR=${TMP%&*}
PID=$(pgrep anyka_ipc)
echo DIST=$DIST DIR=$DIR PID=$PID
if [ "$DIR" == "up" ] || [ "$DIR" == "down" ]; then
ADDR=431684
else
ADDR=431614
fi
if [ "$DIR" == "down" ] || [ "$DIR" == "left" ]; then
VAL=ffa60000
else
VAL=5b0000
fi
if [ "$PID" != "" ] && [ "$DIR" != "" ]; then
/tmp/sd/motor $PID $ADDR 40046d40 $VAL $DIST 2>/dev/null
fi

BIN
mmc/motor Normal file

Binary file not shown.

59
mmc/ptz.html Normal file
View File

@ -0,0 +1,59 @@
<html>
<body>
<style>
.hide { position:absolute; top:-1px; left:-1px; width:1px; height:1px; }
</style>
<iframe name="hiddenFrame" class="hide"></iframe>
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{border-color:black;border-style:solid;border-width:0px;font-family:Arial, sans-serif;font-size:14px;
overflow:hidden;padding:10px 5px;word-break:normal;}
.tg th{border-color:black;border-style:solid;border-width:0px;font-family:Arial, sans-serif;font-size:14px;
font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg .tg-0lax{text-align:left;vertical-align:top}
</style>
<table class="tg">
<thead>
<tr>
<th class="tg-0lax"></th>
<th class="tg-0lax"><center>
<form action="/cgi-bin/motor.cgi" method="get" target="hiddenFrame">
<input type="hidden" name="dist" value="10">
<button type="submit" value="up" name="dir">Up</button>
</form>
</center></th>
<th class="tg-0lax"></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tg-0lax">
<form action="/cgi-bin/motor.cgi" method="get" target="hiddenFrame">
<input type="hidden" name="dist" value="10">
<button type="submit" value="left" name="dir">Left</button>
</form>
</td>
<td class="tg-0lax"></td>
<td class="tg-0lax">
<form action="/cgi-bin/motor.cgi" method="get" target="hiddenFrame">
<input type="hidden" name="dist" value="10">
<button type="submit" value="right" name="dir">Right</button>
</form>
</td>
</tr>
<tr>
<td class="tg-0lax"></td>
<td class="tg-0lax">
<form action="/cgi-bin/motor.cgi" method="get" target="hiddenFrame">
<input type="hidden" name="dist" value="10">
<button type="submit" value="down" name="dir">Down</button>
</form>
</td>
<td class="tg-0lax"></td>
</tr>
</tbody>
</table>
</body>
</html>

63
motor.c Normal file
View File

@ -0,0 +1,63 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
int fd;
int main(int ac, char *av[])
{
// Show usage
if(ac < 5) {
fprintf(stderr, "usage: %s PID motoraddress iocmd value [count]\n", av[0]);
exit(1);
}
// Set memory path
char mem_path[64];
snprintf(mem_path, sizeof(mem_path), "/proc/%s/mem", av[1]);
// Open memory of process
if((fd = open(mem_path, O_RDONLY)) < 0) {
fprintf(stderr, "Can't access %s\n", av[1]);
perror(":");
exit(1);
}
// Get params
ulong mtrfdaddr = strtoul(av[2], 0, 16);
ulong iocmd = strtoul(av[3], 0, 16);
ulong value = strtoul(av[4], 0, 16);
ulong count = 1;
if(ac >= 6)
count = strtoul(av[5], 0, 10);
// Read motor file descriptor value
lseek(fd, mtrfdaddr, SEEK_SET);
ulong mtrfd = 0;
read(fd, &mtrfd, 4);
// Feedback
fprintf(stderr, "mtrfdaddr=%x mtrfd=%x val=%x\n", mtrfdaddr, mtrfd, value);
// Send command if we have a valid descriptor
if(mtrfd!=0) {
char fd_path[64];
snprintf(fd_path, sizeof(fd_path), "/proc/%s/fd/%d", av[1], mtrfd);
int new_fd = open(fd_path, O_RDWR);
fprintf(stderr, "fd_path=%s new_fd=%d\n", fd_path, new_fd);
int ret = 0;
while(count-- > 0) {
ret = ioctl(new_fd, iocmd, (int32_t*) &value);
usleep(10000);
fprintf(stderr, "count=%d\n", count);
}
fprintf(stderr, "ret=%x\n", ret);
close(new_fd);
}
exit(0);
}