Note PTZ Controller Decode Part 4

準備寫一個PTZ Controller test program Using .Net & C#,不過又是沒搞過的新東西。
概念是須要產生測試封包送到解碼板上去看動作對不對。
也順便在寫測試程式時,可以比較了解 packet 的組成,之後寫Decode 比較快
 
這是一個非常基本的框,也許須要數次重整
做的好的話是用一個 Properties File or registry or Directory(spec. directory and include files) 去讓程式動態從DLL Create/Reuse(採用 Factory Pattern)

    class PelcoD : Packet
    {
        const byte STX = 0xFF;
        const int posAddress = 1;

        public byte[] GenerationPacket(Command cmd)
        {
            byte[] result = new byte[] { STX, 0x00, 0x00, 0x00, 0x00, 0x00 };

            result[posAddress] = cmd.Address;
            // Todo: implement to here
            switch (cmd.OP)
            {
                case Command.CommandSet.UP: // Tile Up
                    break;
                case Command.CommandSet.DOWN: // Tile Down
                    break;
                case Command.CommandSet.LEFT: // Pan Left
                    break;
                case Command.CommandSet.RIGHT: // Pan Right
                    break;
                case Command.CommandSet.IN: // Zoom In
                    break;
                case Command.CommandSet.OUT: // Zoom Out
                    break;
                case Command.CommandSet.NEAR:   // Focus near
                    break;
                case Command.CommandSet.FAR:    // Focus far
                    break;
            }
            return result;
        }
    }

    class PelcoP : Packet
    {
        const byte STX = 0xA0;
        const byte ETX = 0xAF;
        const int posAddress = 1;

        public byte[] GenerationPacket(Command cmd)
        {
            byte[] result = new byte[] { STX, 0x00, 0x00, 0x00, 0x00, 0x00, ETX, 0x00 };
            
            result[posAddress] = cmd.Address;

            // Todo: implement to here
            switch (cmd.OP)
            {
                case Command.CommandSet.UP: // Tile Up
                    break;
                case Command.CommandSet.DOWN: // Tile Down
                    break;
                case Command.CommandSet.LEFT: // Pan Left
                    break;
                case Command.CommandSet.RIGHT: // Pan Right
                    break;
                case Command.CommandSet.IN: // Zoom In
                    break;
                case Command.CommandSet.OUT: // Zoom Out
                    break;
                case Command.CommandSet.NEAR:   // Focus near
                    break;
                case Command.CommandSet.FAR:    // Focus far
                    break;
            }
            
            return result;

        }
    }

    class KID312 : Packet
    {
        public byte[] GenerationPacket(Command cmd)
        {
            // Todo: implement to here
            switch (cmd.OP)
            {
                case Command.CommandSet.UP: // Tile Up
                    break;
                case Command.CommandSet.DOWN: // Tile Down
                    break;
                case Command.CommandSet.LEFT: // Pan Left
                    break;
                case Command.CommandSet.RIGHT: // Pan Right
                    break;
                case Command.CommandSet.IN: // Zoom In
                    break;
                case Command.CommandSet.OUT: // Zoom Out
                    break;
                case Command.CommandSet.NEAR:   // Focus near
                    break;
                case Command.CommandSet.FAR:    // Focus far
                    break;
            }
            byte[] result = new byte[] { 0x32, 0x04, 0x95 };
            return result;
        }
    }

    class YANN : Packet
    {
        public byte[] GenerationPacket(Command cmd)
        {
            byte[] result = new byte[] { 0x32, 0x04, 0x95 };
            // Todo: implement to here
            switch (cmd.OP)
            {
                case Command.CommandSet.UP: // Tile Up
                    break;
                case Command.CommandSet.DOWN: // Tile Down
                    break;
                case Command.CommandSet.LEFT: // Pan Left
                    break;
                case Command.CommandSet.RIGHT: // Pan Right
                    break;
                case Command.CommandSet.IN: // Zoom In
                    break;
                case Command.CommandSet.OUT: // Zoom Out
                    break;
                case Command.CommandSet.NEAR:   // Focus near
                    break;
                case Command.CommandSet.FAR:    // Focus far
                    break;
            }

            return result;
        }
    }

畫面完成 , Pan/Tile 用 CheckBox 可以不用一直用點


發現一個不錯的 Serial Debug Tools 要是有空也許自己來寫一個, below picture from : http://www.windmill.co.uk/serial.html


有提供一個 Free Limiter Version, 網站上還帶有不錯的Pelco-D/P 教學 http://www.232analyzer.com/RS232_Examples/CCTV/Pelco_D_Pelco_P_Examples_Tutorial.HTM
廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s

%d 位部落客按了讚: