Exemplo n.º 1
0
        //write to register with absolute address, for bootloader use
        public void writebyte_abs_reg(byte[] regaddr, byte[] value)
        {
            FrameBuffer ofrm = new FrameBuffer();

            ofrm.cmd  = (byte)'W';
            ofrm.addr = this.node_id;
            byte[] regbuffer = new byte[16];
            byte[] valbuffer = new byte[16];
            byte[] outbuffer = new byte[32];
            int    outptr    = 0;

            for (int i = 0; i < regaddr.GetLength(0); i++)
            {
                regbuffer[outptr] = regaddr[i];
                valbuffer[outptr] = (byte)value[i];
                outptr++;
            }
            ofrm.generate_write_frame(outbuffer, regbuffer, valbuffer, 0, (byte)(outptr));
            port.AddVCommand(outbuffer);
        }
Exemplo n.º 2
0
        //write to group address
        public void writebyte_group_reg(byte group_addr, string[] regaddr, byte[] value)
        {
            FrameBuffer ofrm = new FrameBuffer();

            ofrm.cmd  = (byte)'W';
            ofrm.addr = group_addr;
            byte[] regbuffer = new byte[16];
            byte[] valbuffer = new byte[16];
            byte[] outbuffer = new byte[32];
            int    outptr    = 0;

            for (int i = 0; i < regaddr.GetLength(0); i++)
            {
                regbuffer[outptr] = reg_type_tbl[regaddr[i]].pos;
                valbuffer[outptr] = (byte)value[i];
                outptr++;
            }
            ofrm.generate_write_frame(outbuffer, regbuffer, valbuffer, 0, (byte)(outptr));
            port.AddVCommand(outbuffer);
        }
Exemplo n.º 3
0
        private void write_vregs(string[] names, UInt32[] values)
        {
            if (NodeAgent.IsDebug)
            {
                for (int i = 0; i < names.Length; i++)
                {
                    if (curr_conf.ContainsKey(names[i]))
                    {
                        curr_conf[names[i]] = values[i];
                    }
                }
                return;
            }

            FrameBuffer ofrm = new FrameBuffer();

            ofrm.cmd = (byte)'W';
            if (!curr_conf["addr"].HasValue)
            {
                throw new Exception("Invalid node address");
            }
            ofrm.addr = (byte)curr_conf["addr"].Value;
            byte[] regbuffer = new byte[16];
            byte[] valbuffer = new byte[16];
            byte[] outbuffer = new byte[32];
            int    outptr    = 0;

            for (int i = 0; i < names.GetLength(0); i++)
            {
                if (reg_type_tbl[names[i]].size == 8)
                {
                    regbuffer[outptr] = reg_type_tbl[names[i]].pos;
                    valbuffer[outptr] = (byte)values[i];
                    outptr++;
                }
                if (reg_type_tbl[names[i]].size == 16)
                {
                    valbuffer[outptr]     = (byte)(values[i] % 256);
                    valbuffer[outptr + 1] = (byte)(values[i] / 256);
                    regbuffer[outptr]     = reg_type_tbl[names[i]].pos;
                    regbuffer[outptr + 1] = (byte)(regbuffer[outptr] + 1);
                    outptr = outptr + 2;
                }
                if (reg_type_tbl[names[i]].size == 32)
                {
                    valbuffer[outptr + 0] = (byte)(values[i] % 256);
                    values[i]             = (UInt32)(values[i] / 256);
                    valbuffer[outptr + 1] = (byte)(values[i] % 256);
                    values[i]             = (UInt32)(values[i] / 256);
                    valbuffer[outptr + 2] = (byte)(values[i] % 256);
                    values[i]             = (UInt32)(values[i] / 256);
                    valbuffer[outptr + 3] = (byte)(values[i] % 256);
                    regbuffer[outptr]     = reg_type_tbl[names[i]].pos;
                    regbuffer[outptr + 1] = (byte)(regbuffer[outptr] + 1);
                    regbuffer[outptr + 2] = (byte)(regbuffer[outptr] + 2);
                    regbuffer[outptr + 3] = (byte)(regbuffer[outptr] + 3);

                    outptr = outptr + 4;
                }
            }
            ofrm.generate_write_frame(outbuffer, regbuffer, valbuffer, 0, (byte)(outptr));
            port.AddVCommand(outbuffer);
        }
Exemplo n.º 4
0
        private void write_vregs(string[] names, UInt32[] values)
        {
            if (NodeAgent.IsDebug)
            {
                for (int i = 0;i< names.Length;i++)
                {
                    if(curr_conf.ContainsKey(names[i]))
                        curr_conf[names[i]] = values[i];
                }
                return;
            }

            FrameBuffer ofrm = new FrameBuffer();
            ofrm.cmd = (byte)'W';
            if (!curr_conf["addr"].HasValue)
            {
                throw new Exception("Invalid node address");
            }
            ofrm.addr = (byte)curr_conf["addr"].Value;
            byte[] regbuffer = new byte[16];
            byte[] valbuffer = new byte[16];
            byte[] outbuffer = new byte[32];
            int outptr = 0;
            for (int i = 0; i < names.GetLength(0); i++)
            {
                if (reg_type_tbl[names[i]].size == 8)
                {
                    regbuffer[outptr] = reg_type_tbl[names[i]].pos;
                    valbuffer[outptr] = (byte)values[i];
                    outptr++;
                }
                if (reg_type_tbl[names[i]].size == 16)
                {
                    valbuffer[outptr ] = (byte)(values[i] % 256);
                    valbuffer[outptr + 1] = (byte)(values[i] / 256);
                    regbuffer[outptr] = reg_type_tbl[names[i]].pos;
                    regbuffer[outptr + 1] = (byte)(regbuffer[outptr] + 1);
                    outptr = outptr + 2;
                }
                if (reg_type_tbl[names[i]].size == 32)
                {
                    valbuffer[outptr + 0] = (byte)(values[i] % 256);
                    values[i] = (UInt32)(values[i] / 256);
                    valbuffer[outptr + 1] = (byte)(values[i] % 256);
                    values[i] = (UInt32)(values[i] / 256);
                    valbuffer[outptr + 2] = (byte)(values[i] % 256);
                    values[i] = (UInt32)(values[i] / 256);
                    valbuffer[outptr + 3] = (byte)(values[i] % 256);
                    regbuffer[outptr] = reg_type_tbl[names[i]].pos;
                    regbuffer[outptr + 1] = (byte)(regbuffer[outptr] + 1);
                    regbuffer[outptr + 2] = (byte)(regbuffer[outptr] + 2);
                    regbuffer[outptr + 3] = (byte)(regbuffer[outptr] + 3);

                    outptr = outptr + 4;
                }
            }
            ofrm.generate_write_frame(outbuffer, regbuffer, valbuffer, 0, (byte)(outptr));
            port.AddVCommand(outbuffer);
        }
Exemplo n.º 5
0
 //write to register with absolute address, for bootloader use
 public void writebyte_abs_reg(byte[] regaddr, byte[] value)
 {
     FrameBuffer ofrm = new FrameBuffer();
     ofrm.cmd = (byte)'W';
     ofrm.addr = this.node_id;
     byte[] regbuffer = new byte[16];
     byte[] valbuffer = new byte[16];
     byte[] outbuffer = new byte[32];
     int outptr = 0;
     for (int i = 0; i < regaddr.GetLength(0); i++)
     {
          regbuffer[outptr] = regaddr[i];
          valbuffer[outptr] = (byte)value[i];
          outptr++;
     }
     ofrm.generate_write_frame(outbuffer, regbuffer, valbuffer, 0, (byte)(outptr));
     port.AddVCommand(outbuffer);
 }
Exemplo n.º 6
0
 //write to group address
 public void writebyte_group_reg(byte group_addr, string[] regaddr, byte[] value)
 {
     FrameBuffer ofrm = new FrameBuffer();
     ofrm.cmd = (byte)'W';
     ofrm.addr = group_addr;
     byte[] regbuffer = new byte[16];
     byte[] valbuffer = new byte[16];
     byte[] outbuffer = new byte[32];
     int outptr = 0;
     for (int i = 0; i < regaddr.GetLength(0); i++)
     {
         regbuffer[outptr] = reg_type_tbl[regaddr[i]].pos;
         valbuffer[outptr] = (byte)value[i];
         outptr++;
     }
     ofrm.generate_write_frame(outbuffer, regbuffer, valbuffer, 0, (byte)(outptr));
     port.AddVCommand(outbuffer);
 }