Beispiel #1
0
        private void ProUpload(string msg, int addr)
        {
            int            num  = 0;
            YJ_LmstMsg_sum _sum = new YJ_LmstMsg_sum();

            if ((this.state_pl != 0) && (this.addr_pl == addr))
            {
                try
                {
                    _sum = (YJ_LmstMsg_sum)JsonConvert.DeserializeObject(msg, typeof(YJ_LmstMsg_sum));
                }
                catch
                {
                    YJ_Log.DEBUG("ProUpload recv error", 0);
                }
                if (string.Compare(_sum.c, "DataReq") == 0)
                {
                    YJ_Log.DEBUG(msg, 0);
                    if (this.ses_pl == _sum.n)
                    {
                        this.SendUploadData(addr, this.ses_pl, this.Buff_pl, this.DataLen_pl);
                    }
                    else if ((this.ses_pl + 1) == _sum.n)
                    {
                        try
                        {
                            num = this.reader_pl.Read(this.Buff_pl, 0, 0x80);
                        }
                        catch
                        {
                            YJ_Log.DEBUG("reader_pl recv error", 0);
                        }
                        if (num > 0)
                        {
                            this.DataLen_pl     = num;
                            this.ReadOffset_pl += num;
                            this.ses_pl++;
                            this.flags_pl++;
                            this.UploadFirmwareSchedule = (this.ReadOffset_pl * 100) / this.FileLen_pl;
                            this.SendUploadData(addr, this.ses_pl, this.Buff_pl, this.DataLen_pl);
                        }
                    }
                    else
                    {
                        YJ_Log.DEBUG("(ses_pl + 1) != m.n", 0);
                    }
                }
                else if (string.Compare(_sum.c, "UpdateFinish") == 0)
                {
                    this.file_pl.Close();
                    this.reader_pl.Close();
                    this.state_pl            = 0;
                    this.UploadFirmwareState = 1;
                    YJ_Log.DEBUG("UpdateFinish", 0);
                }
            }
        }
Beispiel #2
0
        private void UploadStateMachine()//上传状态机?
        {
            string     str;
            YJ_LmstMsg msg = new YJ_LmstMsg();

            switch (this.state_pl)
            {
            case 1:
                msg.c = "Reboot";
                str   = JsonConvert.SerializeObject(msg);
                this.AppLayerSend(this.addr_pl, str);
                this.TimeOut_pl.SetTime(500);
                this.state_pl            = 2;
                this.UploadFirmwareState = 0;
                break;

            case 2:
                if (this.TimeOut_pl.IsTimeOut())
                {
                    msg.c     = "UplaodFirmware";
                    msg.value = this.FileLen_pl;
                    str       = JsonConvert.SerializeObject(msg);
                    this.AppLayerSend(this.addr_pl, 6, str);
                    this.TimeOut_pl.SetTime(0xfa0);
                    this.state_pl = 3;
                }
                break;

            case 3:
                if (!this.TimeOut_pl.IsTimeOut())
                {
                    if (this.flags_pl > 0)
                    {
                        this.flags_pl = 0;
                        this.TimeOut_pl.SetTime(0xfa0);
                    }
                    break;
                }
                YJ_Log.DEBUG("Update fail!", 0);
                this.file_pl.Close();
                this.reader_pl.Close();
                this.UploadFirmwareState = -1;
                this.state_pl            = 0;
                break;
            }
        }
Beispiel #3
0
        private void StateMachineThrFunc()
        {
            int    num = 0;
            string str = "msg";

            byte[] buffer = new byte[this.Transport.MaxLtvPayload];
            int    addr   = 0;
            int    type   = 0;

            while (true)
            {
                Thread.Sleep(1);
                if (this.IsRebootAllNode)//函数RebootAllNode()的作用
                {
                    YJ_LmstMsg msg = new YJ_LmstMsg();
                    this.IsRebootAllNode = false;
                    msg.c = "Reboot";
                    string str2 = JsonConvert.SerializeObject(msg);
                    this.AppLayerSend(240, str2);
                    this.AppLayerSend(0x10, str2);
                    this.AppLayerSend(0x20, str2);
                    this.AppLayerSend(0x30, str2);
                }
                this.CheckeNodeTimeOut();  //检测超时?
                this.UploadStateMachine(); //上传状态机
                switch (num)
                {
                case 0:
                    if (this.Transport.IsConnection)
                    {
                        num = 1;
                        this.IsConnection = true;
                    }
                    break;

                case 1:
                    if (!this.Transport.IsConnection)
                    {
                        num = 0;
                        this.IsConnection = false;
                    }
                    else if (this.AppLayerRecv(ref addr, ref type, ref str, ref buffer) > 0)
                    {
                        if (type == 5)
                        {
                            YJ_Log.ERR(str, addr);
                        }
                        else if (type == 4)
                        {
                            YJ_Log.DEBUG(str, addr);
                        }
                        else if ((type == 7) || (type == 9))
                        {
                            this.ProUpload(str, addr);
                        }
                        else
                        {
                            this.ProNodeData(str, addr);
                            YJ_Log.DATA(str, addr);
                        }
                    }
                    break;
                }
            }
        }
Beispiel #4
0
        private void ProNodeData(string msg, int addr)
        {
            this.refreshNode(addr);
            int num = addr;

            if (num <= 0x20)
            {
                switch (num)
                {
                case 0x10:
                    try
                    {
                        this.ServoMotorNodeParam = (YJ_LmstMsg_sum)JsonConvert.DeserializeObject(msg, typeof(YJ_LmstMsg_sum));
                    }
                    catch
                    {
                        YJ_Log.DEBUG("ServoMotorNodeParam recv error", 0);
                    }
                    break;

                case 0x20:
                    try
                    {
                        this.SensorNodeParam = (YJ_LmstMsg_sum)JsonConvert.DeserializeObject(msg, typeof(YJ_LmstMsg_sum));
                    }
                    catch
                    {
                        YJ_Log.DEBUG("SensorNodeParam recv error", 0);
                    }
                    break;
                }
            }
            else
            {
                switch (num)
                {
                case 0x30:
                    try
                    {
                        this.DivingNodeParam = (YJ_LmstMsg_sum)JsonConvert.DeserializeObject(msg, typeof(YJ_LmstMsg_sum));
                    }
                    catch
                    {
                        YJ_Log.DEBUG("DivingNodeParam recv error", 0);
                    }
                    return;

                case 0xe0:
                    try
                    {
                        this.HeadNodeParam = (YJ_LmstMsg_sum)JsonConvert.DeserializeObject(msg, typeof(YJ_LmstMsg_sum));
                    }
                    catch
                    {
                        YJ_Log.DEBUG("HeadNodeParam recv error", 0);
                    }
                    return;
                }
                if (num == 240)
                {
                    try
                    {
                        this.TailNodeParam = (YJ_LmstMsg_sum)JsonConvert.DeserializeObject(msg, typeof(YJ_LmstMsg_sum));
                    }
                    catch
                    {
                        YJ_Log.DEBUG("TailNodeParam recv error", 0);
                    }
                }
            }
        }