Exemplo n.º 1
0
 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);
         }
     }
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 void kowhaiTree1_DataChange(object sender, KowhaiTree.DataChangeEventArgs e)
 {
     kowhaiTree1.UpdateData(e.Buffer, e.Info.Offset);
     tbHex.Text = BytesToHexString(kowhaiTree1.GetData());
 }
Exemplo n.º 5
0
 void kowhaiTree1_NodeRead(object sender, KowhaiTree.NodeReadEventArgs e)
 {
 }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
 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;
 }
Exemplo n.º 10
0
 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;
 }