コード例 #1
0
ファイル: MainForm.cs プロジェクト: othane/kowhai
 private void LoadTree(KowhaiTree tree)
 {
     OpenFileDialog d = new OpenFileDialog();
     d.Filter = "Kowhai Files | *.kowhai";
     d.DefaultExt = "kowhai";
     if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         string text = System.IO.File.ReadAllText(d.FileName);
         Kowhai.kowhai_node_t[] descriptor;
         byte[] data;
         if (KowhaiSerialize.Deserialize(text, out descriptor, out data) == Kowhai.STATUS_OK)
         {
             tree.UpdateDescriptor(descriptor, SymbolStrings, null);
             tree.UpdateData(data, 0);
         }
     }
 }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: othane/kowhai
        void kowhaiTree_DataChange(object sender, KowhaiTree.DataChangeEventArgs e)
        {
            Application.DoEvents();
            System.Threading.Thread.Sleep(250);

            byte[] buffer = new byte[PACKET_SIZE];
            Kowhai.kowhai_symbol_t[] symbols = KowhaiTree.KowhaiNodeInfo.CreateNodeInfoSymbolList(e.Info).ToArray();
            KowhaiProtocol.kowhai_protocol_t prot = new KowhaiProtocol.kowhai_protocol_t();
            prot.header.command = KowhaiProtocol.CMD_WRITE_DATA;
            prot.header.id = GetTreeId();
            int bytesRequired;
            KowhaiProtocol.CreateReadDataPacket(buffer, PACKET_SIZE, ref prot, symbols, out bytesRequired);
            int overhead;
            KowhaiProtocol.kowhai_protocol_get_overhead(ref prot, out overhead);
            int offset = 0;
            int maxPayloadSize = PACKET_SIZE - overhead;
            while (e.Buffer.Length - offset > maxPayloadSize)
            {
                KowhaiProtocol.CreateWriteDataPacket(buffer, PACKET_SIZE, ref prot, symbols, CopyArray(e.Buffer, offset, maxPayloadSize), (ushort)offset, out bytesRequired);
                comms.Send(buffer, bytesRequired);
                offset += maxPayloadSize;
            }
            prot.header.command = KowhaiProtocol.CMD_WRITE_DATA_END;
            KowhaiProtocol.CreateWriteDataPacket(buffer, PACKET_SIZE, ref prot, symbols, CopyArray(e.Buffer, offset, e.Buffer.Length - offset), (ushort)offset, out bytesRequired);
            comms.Send(buffer, bytesRequired);
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: othane/kowhai
        void kowhaiTree_NodeRead(object sender, KowhaiTree.NodeReadEventArgs e)
        {
            Application.DoEvents();
            System.Threading.Thread.Sleep(250);

            byte[] buffer = new byte[PACKET_SIZE];
            Kowhai.kowhai_symbol_t[] symbols = KowhaiTree.KowhaiNodeInfo.CreateNodeInfoSymbolList(e.Info).ToArray();
            KowhaiProtocol.kowhai_protocol_t prot = new KowhaiProtocol.kowhai_protocol_t();
            prot.header.command = KowhaiProtocol.CMD_READ_DATA;
            prot.header.id = GetTreeId();
            int bytesRequired;
            KowhaiProtocol.CreateReadDataPacket(buffer, PACKET_SIZE, ref prot, symbols, out bytesRequired);
            comms.Send(buffer, bytesRequired);
        }
コード例 #4
0
ファイル: NodeEditForm.cs プロジェクト: Ehsan70/beaverbot
 void kowhaiTree1_DataChange(object sender, KowhaiTree.DataChangeEventArgs e)
 {
     kowhaiTree1.UpdateData(e.Buffer, e.Info.Offset);
     tbHex.Text = BytesToHexString(kowhaiTree1.GetData());
 }
コード例 #5
0
ファイル: NodeEditForm.cs プロジェクト: Ehsan70/beaverbot
 void kowhaiTree1_NodeRead(object sender, KowhaiTree.NodeReadEventArgs e)
 {
 }
コード例 #6
0
ファイル: NodeEditForm.cs プロジェクト: Ehsan70/beaverbot
 public void UpdateTree(Kowhai.kowhai_node_t[] descriptor, string[] symbols, byte[] data, KowhaiTree.KowhaiNodeInfo info)
 {
     kowhaiTree1.UpdateDescriptor(descriptor, symbols, info);
     kowhaiTree1.UpdateData(data, 0);
     tbHex.Text = BytesToHexString(data);
 }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: Ehsan70/beaverbot
        void kowhaiTree_NodeRead(object sender, KowhaiTree.NodeReadEventArgs e)
        {
            Application.DoEvents();
            System.Threading.Thread.Sleep(250);

            byte[] buffer = new byte[PACKET_SIZE];
            List<ushort> arrayIndexes = CreateNodeInfoArrayIndexList(e.Info);
            Kowhai.kowhai_symbol_t[] symbols = Kowhai.GetSymbolPath(GetDescriptor(sender), e.Info.KowhaiNode, e.Info.NodeIndex, arrayIndexes.ToArray());
            KowhaiProtocol.kowhai_protocol_t prot = new KowhaiProtocol.kowhai_protocol_t();
            prot.header.tree_id = GetTreeId(sender);
            prot.header.command = KowhaiProtocol.CMD_READ_DATA;
            int bytesRequired;
            KowhaiProtocol.Create(buffer, PACKET_SIZE, ref prot, symbols, out bytesRequired);
            //sock.Send(buffer, bytesRequired);
            SendData(buffer, bytesRequired);
        }
コード例 #8
0
ファイル: MainForm.cs プロジェクト: Ehsan70/beaverbot
        void kowhaiTree_DataChange(object sender, KowhaiTree.DataChangeEventArgs e)
        {
            Application.DoEvents();
            System.Threading.Thread.Sleep(250);

            byte[] buffer = new byte[PACKET_SIZE];
            List<ushort> arrayIndexes = CreateNodeInfoArrayIndexList(e.Info);
            Kowhai.kowhai_symbol_t[] symbols = Kowhai.GetSymbolPath(GetDescriptor(sender), e.Info.KowhaiNode, e.Info.NodeIndex, arrayIndexes.ToArray());
            KowhaiProtocol.kowhai_protocol_t prot = new KowhaiProtocol.kowhai_protocol_t();
            prot.header.tree_id = GetTreeId(sender);
            prot.header.command = KowhaiProtocol.CMD_WRITE_DATA;
            int bytesRequired;
            KowhaiProtocol.Create(buffer, PACKET_SIZE, ref prot, symbols, out bytesRequired);
            int overhead;
            KowhaiProtocol.kowhai_protocol_get_overhead(ref prot, out overhead);
            int offset = 0;
            int maxPayloadSize = PACKET_SIZE - overhead;
            while (e.Buffer.Length - offset > maxPayloadSize)
            {
                KowhaiProtocol.Create(buffer, PACKET_SIZE, ref prot, symbols, CopyArray(e.Buffer, offset, maxPayloadSize), (ushort)offset, out bytesRequired);
                //sock.Send(buffer, bytesRequired);
                SendData(buffer, bytesRequired);
                offset += maxPayloadSize;
            }
            KowhaiProtocol.Create(buffer, PACKET_SIZE, ref prot, symbols, CopyArray(e.Buffer, offset, e.Buffer.Length - offset), (ushort)offset, out bytesRequired);
            //sock.Send(buffer, bytesRequired);
            SendData(buffer, bytesRequired);
        }
コード例 #9
0
ファイル: MainForm.cs プロジェクト: Ehsan70/beaverbot
 private List<ushort> CreateNodeInfoArrayIndexList(KowhaiTree.KowhaiNodeInfo info)
 {
     List<ushort> arrayIndexes = new List<ushort>();
     while (info != null)
     {
         arrayIndexes.Add(info.ArrayIndex);
         info = info.Parent;
     }
     arrayIndexes.Reverse();
     return arrayIndexes;
 }
コード例 #10
0
ファイル: KowhaiTree.cs プロジェクト: othane/kowhai
 public static List<Kowhai.kowhai_symbol_t> CreateNodeInfoSymbolList(KowhaiTree.KowhaiNodeInfo info)
 {
     List<Kowhai.kowhai_symbol_t> syms = new List<Kowhai.kowhai_symbol_t>();
     while (info != null)
     {
         syms.Add(new Kowhai.kowhai_symbol_t(info.KowhaiNode.symbol, info.ArrayIndex));
         info = info.Parent;
     }
     syms.Reverse();
     return syms;
 }