#include "stdafx.h" #include "proc_cyber2.h" #include "util_hdlc.h" //#include "axis_base.h" #include #include #include #ifdef __TEST void WriteData(char* buf, int size) { // } #endif // ´Ü¼øÇÑ checksum(XOR) ÇÔ¼öÀÔ´Ï´Ù. -- cjy // ¹Ýȯ°ª : checksum value char check_sum(unsigned char* buf, int cnt) { // int i; unsigned char sum = 0; for(i = 0; i < cnt; ++i) { sum ^= buf[i]; } return sum; } // 2¹ÙÀÌÆ® ¼ýÀÚ¸¦ ÇÏÀ§, »óÀ§ ¹ÙÀÌÆ® ¼øÀ¸·Î Àß¶ó¼­ ³Ñ°ÜÁÝ´Ï´Ù. void split_value(int val, int* v1, int* v2) { *v1 = val & 0x00ff; // ÇÏÀ§ ¸ÕÀú~ *v2 = (val & 0xff00) >> 8; // »óÀ§ } /* Make_Protocol2³»ºÎ¿¡¼­ »ç¿ëµÇ´Â ÇÔ¼ö 1. cmd¹®ÀÚ¿­¿¡¼­ name°ªÀ» ã¾Æ¼­ name´ÙÀ½¿¡ ³ª¿À´Â µÎ°³ÀÇ ¼ýÀÚ¸¦ Á¤¼ö·Î º¯È¯ 2. º¯È¯µÈ Á¤¼ö¸¦ value_buf¿¡ Â÷·Ê´ë·Î ³Ö¾îÁÝ´Ï´Ù. */ void word_value_get(char* cmd, char* name, char* value_buf) { short value; // value int len; // name length char tmp[1024], num[3]; // Áغñ memset(tmp, 0x00, sizeof(tmp)); memset(num, 0x00, sizeof(tmp)); len = strlen(name); // convert //#ifdef __TEST sprintf(tmp, "%s", strstr(cmd, "pattern")); //#else // snprintf(tmp, sizeof(tmp)-1, "%s", strstr(cmd, "pattern")); //#endif num[0] = tmp[len]; num[1] = tmp[len+1]; num[2] = 0; // NULL value = (short)atoi(num); // get value_buf[0] = (char)(value & 0x00ff); // ÇÏÀ§ ¸ÕÀú~ value_buf[1] = (char)((value & 0xff00) >> 8); // »óÀ§ } int make_packet8(unsigned char* buf, int max_size, int camid, int cmd, int v1, int v2, int v3, int v4, int v5, int v6, int v7) { unsigned char protocol[30]; int hdlc_size; int size = 0; protocol[0] = (unsigned char)camid; // rx protocol[1] = 0x20; protocol[2] = 0x00; // tx -- ¾Æ¹«°Å³ª? protocol[3] = 0x10; size = 4; protocol[4] = (unsigned char)cmd; protocol[5] = (unsigned char)v1; protocol[6] = (unsigned char)v2; protocol[7] = (unsigned char)v3; protocol[8] = (unsigned char)v4; protocol[9] = (unsigned char)v5; protocol[10] = (unsigned char)v6; protocol[11] = (unsigned char)v7; size += 8; protocol[size] = check_sum(protocol, size); size++; hdlc_encode(protocol, size, buf, &hdlc_size); return hdlc_size; } int make_packet5(unsigned char* buf, int max_size, int camid, int cmd, int control, int v1, int v2, int v3) { unsigned char protocol[30]; int hdlc_size; int size = 0; protocol[0] = (unsigned char)camid; // rx protocol[1] = 0x20; protocol[2] = 0x00; // tx -- ¾Æ¹«°Å³ª? protocol[3] = 0x10; size = 4; protocol[4] = (unsigned char)cmd; protocol[5] = (unsigned char)control; // control protocol[6] = (unsigned char)v1; // pan speed(left, right) protocol[7] = (unsigned char)v2; // tilt speed(up,down) protocol[8] = (unsigned char)v3; // zoom speed size += 5; protocol[size] = check_sum(protocol, size); size++; hdlc_encode(protocol, size, buf, &hdlc_size); return hdlc_size; } int make_packet4(unsigned char* buf, int max_size, int camid, int cmd, int v1, int v2, int v3) { unsigned char protocol[30]; int hdlc_size; int size = 0; protocol[0] = (unsigned char)camid; // rx protocol[1] = 0x20; protocol[2] = 0x00; // tx -- ¾Æ¹«°Å³ª? protocol[3] = 0x10; size = 4; protocol[4] = (unsigned char)cmd; protocol[5] = (unsigned char)v1; // pan speed(left, right) protocol[6] = (unsigned char)v2; // tilt speed(up,down) protocol[7] = (unsigned char)v3; // zoom speed size += 4; protocol[size] = check_sum(protocol, size); size++; hdlc_encode(protocol, size, buf, &hdlc_size); return hdlc_size; } int make_packet3(unsigned char* buf, int max_size, int camid, int cmd, int v1, int v2) { unsigned char protocol[30]; int hdlc_size; int size = 0; protocol[0] = (unsigned char)camid; // rx protocol[1] = 0x20; protocol[2] = 0x00; // tx -- ¾Æ¹«°Å³ª? protocol[3] = 0x10; size = 4; protocol[4] = (unsigned char)cmd; protocol[5] = (unsigned char)v1; // control protocol[6] = (unsigned char)v2; // control size += 3; protocol[size] = check_sum(protocol, size); size++; hdlc_encode(protocol, size, buf, &hdlc_size); return hdlc_size; } int make_packet2(unsigned char* buf, int max_size, int camid, int cmd, int control) { unsigned char protocol[30]; int hdlc_size; int size = 0; protocol[0] = (unsigned char)camid; // rx protocol[1] = 0x20; protocol[2] = 0x00; // tx -- ¾Æ¹«°Å³ª? protocol[3] = 0x10; size = 4; protocol[4] = (unsigned char)cmd; protocol[5] = (unsigned char)control; // control size += 2; protocol[size] = check_sum(protocol, size); size++; hdlc_encode(protocol, size, buf, &hdlc_size); return hdlc_size; } int make_packet1(unsigned char* buf, int max_size, int camid, int cmd) { unsigned char protocol[30]; int hdlc_size; int size = 0; protocol[0] = (unsigned char)camid; // rx protocol[1] = 0x20; protocol[2] = 0x00; // tx -- ¾Æ¹«°Å³ª? protocol[3] = 0x10; size = 4; protocol[4] = (unsigned char)cmd; size += 1; protocol[size] = check_sum(protocol, size); size++; hdlc_encode(protocol, size, buf, &hdlc_size); return hdlc_size; } int c2_setspeed_pan(unsigned char* buf, int camid, int pans, int tilts, int zooms) { return make_packet4(buf, 1024, camid, 0x42, pans,tilts,zooms); } int c2_set_position(unsigned char* buf, int camid, int pan, int tilt, int ozoom, int dzoom) { int pan1, pan2; int tilt1, tilt2; int ozoom1, ozoom2; split_value(pan, &pan1, &pan2); split_value(tilt, &tilt1, &tilt2); split_value(ozoom, &ozoom1, &ozoom2); return make_packet8(buf, 1024, camid, 0x40, dzoom,pan1,pan2, tilt1, tilt2, ozoom1, ozoom2); } // pan, tilt¸¦ µÑ ´Ù 0À¸·Î ÁÖ¸é... STOP // panÀÌ 0x1 ~ 0x3f ¿À¸¥ÂÊ, -0x1 ~ -0x3f¸é ¿ÞÂÊ // tilt°¡ 0x1 ~ 0x3f¸é À§ÂÊ, -0x1 ~ -0x3f¸é ¾Æ·¡ÂÊ int c2_ptz(unsigned char* buf, int camid, int pan, int tilt, int bTurbo) { int control; int pan_sp; int tilt_sp; pan_sp = 0x3f; tilt_sp = 0x3f; // ??? pan_sp = abs(pan); tilt_sp = abs(tilt); // cmd(0x20), control, pan_sp, tilt_sp, zoom_sp // control ---- // right(0x2) // left(0x4) // up(0x8) // down(0x10) // tilt(0x20) // wide(0x40) control = 0; if(bTurbo == 1) control |= 1; // -100~100±îÁöÀÔ´Ï´Ù. :) 0Àº ½ºÅé if(pan == 0 && tilt == 0) { return make_packet5(buf, 1024, camid, 0x20, 0,0,0,0); } else { if(pan != 0 && tilt == 0) { // pan¸¸ ¿òÁ÷ÀÌ´Â °æ¿ì if(pan > 0) control |= 0x2; // right else control |= 0x4; // left return make_packet5(buf, 1024, camid, 0x20, control,pan_sp,0,0); } if(pan == 0 && tilt != 0) { // tilt¸¸ ¿òÁ÷ÀÌ´Â °æ¿ì if(tilt > 0) control |= 0x8; // up else control |= 0x10; // down return make_packet5(buf, 1024, camid, 0x20, control,0,tilt_sp,0); } if(pan != 0 && tilt != 0) { // pan°ú tilt °°ÀÌ ¿òÁ÷ÀÌ´Â °æ¿ì if(pan > 0) control |= 0x2; // right else control |= 0x4; // left if(tilt > 0) control |= 0x8; // up else control |= 0x10; // down return make_packet5(buf, 1024, camid, 0x20, control, pan_sp,tilt_sp,0); } } // return 0; } // zoom -- 0 À̸é stop // ¾ç¼ö¸é Zoom in // À½¼ö¸é Zoom out int c2_zoom(unsigned char* buf, int camid, int zoom) { int zoom_sp = 9; // ??? zoom_sp = abs(zoom); //int zoom_sp = speed_correction(zoom); if(zoom == 0) { // zoom stop return make_packet5(buf, 1024, camid, 0x20, 0x00, 0,0,0); } else if(zoom > 0) { // zoom in return make_packet5(buf, 1024, camid, 0x20, 0x40, 0,0,zoom_sp); } else { // zoom out return make_packet5(buf, 1024, camid, 0x20, 0x20, 0,0,zoom_sp); } } // ¾ç¼ö¸é near // À½¼ö¸é far int c2_focus(unsigned char* buf, int camid, int focus) { // int zoom_sp = speed_correction(zoom); if(focus == 0) { // focus stop -- return make_packet2(buf, 1024, camid, 0x21, 0); } else if(focus > 0) { // focus in(near) return make_packet2(buf, 1024, camid, 0x21, 1); } else { // focus out(far) return make_packet2(buf, 1024, camid, 0x21, 2); } } // iris open, closeó¸® ¼öÇà // iris°ª // 1 - iris open // -1 - iris close int c2_iris(unsigned char* buf, int camid, int iris) { if(iris == 0) { // iris stop -- ????? return make_packet2(buf, 1024, camid, 0x22, 0); } else if(iris > 0) { // iris in(iris open) return make_packet2(buf, 1024, camid, 0x22, 2); } else { // iris out(iris close) return make_packet2(buf, 1024, camid, 0x22, 1); } } int c2_setpreset(unsigned char* buf, int camid, int preset) { int v1, v2; split_value(preset, &v1, &v2); return make_packet3(buf, 1024, camid, 0x35, v1,v2); } int c2_gotopreset(unsigned char* buf, int camid, int preset) { int v1, v2; split_value(preset, &v1, &v2); return make_packet3(buf, 1024, camid, 0x31, v1,v2); } int c2_clearpreset(unsigned char* buf, int camid, int preset) { int v1, v2; split_value(preset, &v1, &v2); return make_packet3(buf, 1024, camid, 0x36, v1,v2); } int c2_presetmenu(unsigned char* buf, int camid) { return make_packet3(buf, 1024, camid, 0x31, 0,0); } int c2_tourmenu(unsigned char* buf, int camid) { return make_packet3(buf, 1024, camid, 0x32, 0,0); } int c2_patternmenu(unsigned char* buf, int camid) { return make_packet3(buf, 1024, camid, 0x34, 0,0); } int c2_scanmenu(unsigned char* buf, int camid) { return make_packet3(buf, 1024, camid, 0x33, 0,0); } int c2_menuon(unsigned char* buf, int camid) { return make_packet2(buf, 1024, camid, 0x10, 1); } int c2_menuoff(unsigned char* buf, int camid) { return make_packet2(buf, 1024, camid, 0x10, 2); } int c2_menutoggle(unsigned char* buf, int camid) { return make_packet2(buf, 1024, camid, 0x10, 0); } int c2_clear(unsigned char* buf, int camid) { return make_packet1(buf, 1024, camid, 0x11); } int c2_enter(unsigned char* buf, int camid) { return make_packet1(buf, 1024, camid, 0x12); } int c2_tour(unsigned char* buf, int camid, int num) { int v1, v2; split_value(num, &v1, &v2); return make_packet3(buf, 1024, camid, 0x32, v1, v2); } int c2_patternstart(unsigned char* buf, int camid, int num) { int v1, v2; split_value(num, &v1, &v2); return make_packet3(buf, 1024, camid, 0x37, v1, v2); } int c2_patternstop(unsigned char* buf, int camid) { return make_packet1(buf, 1024, camid, 0x38); } int c2_pattern(unsigned char* buf, int camid, int num) { int v1, v2; split_value(num, &v1, &v2); return make_packet3(buf, 1024, camid, 0x34, v1, v2); } int c2_scan(unsigned char* buf, int camid, int num) { int v1, v2; split_value(num, &v1, &v2); return make_packet3(buf, 1024, camid, 0x33, v1, v2); } int c2_home(unsigned char* buf, int camid) { return make_packet3(buf, 1024, camid, 0x30, 0x80,0x80); } /* #define CMD_HOME 0x30 rs = muti_cmd(CMD_HOME, ...); int muti_cmd(int cmd, unsigned char* buf, int camid, int num) { case(cmd) { case CMD_HOME : { rs = send_packet3(buf, 1024, camid, cmd, 0,0); break; } case CMD_HOME : { rs = send_packet3(buf, 1024, camid, cmd, 0,0); break; } } send_packet(pct); } */