#include <fcntl.h>
#include <stdio.h>

extern void exit(int);

void PTZzoom(int zoom)  // from 0(wide) -- 1023(tele)
{
  unsigned char cmd[]={0x88,0x01,0x04,0x47,0,0,0,0,0xFF};
  int fd,i;
  
  if ((fd=open("/dev/ttyS0", O_RDWR))<0) {
    perror("open() serial:");
    exit(1); }

  cmd[4]=(zoom & 0xf000)>>12;
  cmd[5]=(zoom & 0x0f00)>>8;
  cmd[6]=(zoom & 0x00f0)>>4;
  cmd[7]=(zoom & 0x000f);

  fprintf(stderr,"PTZ camera cmd:");
  for (i=0;i<sizeof(cmd);i++)
    fprintf(stderr,"0x%02X ",cmd[i]);
  fprintf(stderr,"\n");
  if (write(fd,cmd,sizeof(cmd))<0){
    perror("write() serial:");
    exit(1); }
    
  if (close(fd)<0) {
    perror("close() serial:");
    exit(1); }
}

