Exemple #1
0
        public void ReceiveAction(DataPackage pkgData)
        {
            //收到 文件读写请求 的应答【采集器→主机】
            Struct_FileHead fileHead = new Struct_FileHead();
            Struct_Clock clock = new Struct_Clock();

            byte[] dataBuffer = pkgData.PureData;
            using (MemoryStream ms = new MemoryStream(dataBuffer))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    fileHead.Buffer = br.ReadBytes(4);      //要读取文件的参数
                    curDataLen = br.ReadInt32();            //文件长度。为 0 表示文件不存在,后续的内容均应为 0。

                    clock.Buffer = br.ReadBytes(7);         //文件起始时间
                    byte duration = br.ReadByte();          //文件持续时间长度,秒为单位。对于图片,此值为 0
                    br.ReadInt32();                         //保留字节

                    macState = 1;
                }
            }

            if (curDataLen > 0)
            {
                //读取文件数据, 发送读取数据的命令

                //创建数据存储文件
                curFileName = string.Format("File_{0}.dat", DateTime.Now.ToString("yyyyMMddHHmmss"));
                curStream = new FileStream(curFileName, FileMode.Create, FileAccess.Write);
                curBinaryWriter = new BinaryWriter(curStream);

                SendDataRead(curRecNo, 0);
            }
        }
        public void Set(bool isQuery, short stateInterval, byte thuEnable, byte tempInterval, byte humiInterval, byte GPIOEnable)
        {
            //查询/设置上报参数【主机→采集器】
            DataPackage pkgData = new DataPackage();
            pkgData.CtrlHead.CMD_ID = HCCommand.REPORTED_PARAMETER;
            pkgData.CtrlHead.CE_ID = ceInfo.CE_ID;
            pkgData.CtrlHead.FLAG = (byte)(isQuery ? 0 : 1);
            byte[] buffer = new byte[12];

            int n = 0;
            buffer[n++] = (byte)(stateInterval & 0xFF);
            buffer[n++] = (byte)(stateInterval >> 8);
            buffer[n++] = thuEnable;
            buffer[n++] = tempInterval;
            buffer[n++] = humiInterval;
            buffer[n++] = GPIOEnable;

            pkgData.PureData = buffer;

            pkgData.Pack();
            SendData(pkgData);

            //字段名                类型     字节数              描述
            //State_Interval        整形    2                   设备状态上报间隔,单位:秒 设置为 0 时不上报,默认为 0
            //Thu_Enable            整形    1                   温湿度变化上报是否开启, 1:开启 0:关闭, 默认开启
            //Temp_Interval         整形    1                   温度变化值,单位:1 度, 默认值:1
            //Humi_Interval         整形    1                   湿度变化值,单位:1%, 默认值:1
            //GPIO_Enable           整形    1                   开关量输入变化上报是否开启, 1:开启 0:关闭,默认开启
            //WorkSt
            //Reserved              整形    6                   保留
        }
        public void Receive(DataPackage pkgData)
        {
            //收到系统信息【采集器→主机】

            DeviceStatusItem deviceStatus = new DeviceStatusItem();

            byte[] dataBuffer = pkgData.PureData;

            using (MemoryStream ms = new MemoryStream(dataBuffer))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    deviceStatus.Time.Buffer = br.ReadBytes(7);
                    deviceStatus.TH.Buffer = br.ReadBytes(4);
                    deviceStatus.Status_D0 = br.ReadByte();
                    deviceStatus.Status_D1 = br.ReadByte();
                    deviceStatus.Status_D2 = br.ReadByte();
                    deviceStatus.Status_D3 = br.ReadByte();
                    deviceStatus.Status_D4 = br.ReadByte();

                }
            }

            if (OnDataChanged != null)
            {
                DataHandlerEventArgs eventArgs = new DataHandlerEventArgs();
                eventArgs.CMD_ID = pkgData.CtrlHead.CMD_ID;
                eventArgs.Value = deviceStatus;
                OnDataChanged(this, eventArgs);
            }
        }
        public void Receive(DataPackage pkgData)
        {
            //收到版本信息【采集器→主机】

            VersionItem verItem = new VersionItem();

            byte[] dataBuffer = pkgData.PureData;
            using (MemoryStream ms = new MemoryStream(dataBuffer))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    byte[] readBytes = br.ReadBytes(64);
                    verItem.SN = Encoding.Default.GetString(readBytes).Trim(new char[]{'\0'});     //序列号

                    readBytes = br.ReadBytes(32);
                    verItem.Ver = Encoding.Default.GetString(readBytes).Trim(new char[] { '\0' });    //firmware 版本

                }
            }

            if (OnDataChanged != null)
            {
                DataHandlerEventArgs eventArgs = new DataHandlerEventArgs();
                eventArgs.CMD_ID = pkgData.CtrlHead.CMD_ID;
                eventArgs.Value = verItem;
                OnDataChanged(this, eventArgs);
            }
        }
        public void Receive(DataPackage pkgData)
        {
            //收到上报参数
            ReportedParameterItem reportParameterItem = new ReportedParameterItem();

            byte[] dataBuffer = pkgData.PureData;

            using (MemoryStream ms = new MemoryStream(dataBuffer))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    reportParameterItem.StateInterval = br.ReadInt16();
                    reportParameterItem.ThuEnable = br.ReadByte();
                    reportParameterItem.TempInterval = br.ReadByte();
                    reportParameterItem.HumiInterval = br.ReadByte();
                    reportParameterItem.GPIOEnable = br.ReadByte();
                    //br.ReadBytes(6);
                }
            }

            if (OnDataChanged != null)
            {
                DataHandlerEventArgs eventArgs = new DataHandlerEventArgs();
                eventArgs.CMD_ID = pkgData.CtrlHead.CMD_ID;
                eventArgs.Value = reportParameterItem;
                OnDataChanged(this, eventArgs);
            }
        }
Exemple #6
0
 //public virtual void AttachSocketSendHandler(DataPackageHandler value)
 //{
 //    OnSocketSend = value;
 //}
 protected virtual void SendData(DataPackage pkgData)
 {
     if (OnSocketSend != null)
     {
         OnSocketSend(pkgData);
     }
 }
Exemple #7
0
        public void StartCapture()
        {
            //启动
            DataPackage pkgData = new DataPackage();
            pkgData.CtrlHead.CE_ID = 0;
            pkgData.CtrlHead.CMD_ID = HCCommand.IMAGE_START;

            Struct_Video videoData = new Struct_Video();

            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    bw.Write((byte)0);
                    bw.Write((byte)0);
                    bw.Write((byte)0);      //更新参数: 0-不更新,1-更新
                    bw.Write(videoData.Buffer);
                    bw.Write((byte)0);
                }

                pkgData.PureData = ms.ToArray();
            }

            pkgData.Pack();
            SendData(pkgData);
        }
Exemple #8
0
 public void Send(DataPackage pkgData)
 {
     //发送数据
     if (OnSocketSend != null)
     {
         OnSocketSend(pkgData);
     }
 }
Exemple #9
0
        public void DataReceive(DataPackage pkgData)
        {
            if (!dataHandlerDict.ContainsKey(runMode)) { return; }

            IDataHandler dataHandler = dataHandlerDict[runMode];

            dataHandler.DataReceive(pkgData);
        }
Exemple #10
0
        public override void DataReceive(DataPackage pkgData)
        {
            uint cmdID = pkgData.CtrlHead.CMD_ID;

            if (!dataHandlerDict.ContainsKey(cmdID)) { return; }

            dataHandlerDict[cmdID].DataReceive(pkgData);
        }
Exemple #11
0
 public void Receive(DataPackage pkgData)
 {
     //处理数据
     if (dictDataProcessProviders.ContainsKey(pkgData.CtrlHead.CMD_ID))
     {
         dictDataProcessProviders[pkgData.CtrlHead.CMD_ID].Process(pkgData);
     }
 }
Exemple #12
0
 protected override void ProcessDataPackage(DataPackage pkgData)
 {
     //处理收到的数据包
     if (OnDataReceive != null)
     {
         OnDataReceive(pkgData);
     }
 }
Exemple #13
0
 public void Send(DataPackage pkgData)
 {
     //将数据添加到发送队列
     lock (queueFrameSend)
     {
         queueFrameSend.Enqueue(pkgData);
         eventFrameSend.Set();   //设置信号,通知有数据进入队列
     }
 }
        public override void DataReceive(DataPackage pkgData)
        {
            uint cmdID = pkgData.CtrlHead.CMD_ID;

            if (cmdID == HCCommand.REPORTED_PARAMETER)
            {
                Receive(pkgData);
            }
        }
Exemple #15
0
        public override void DataReceive(DataPackage pkgData)
        {
            uint cmdID = pkgData.CtrlHead.CMD_ID;

            if (cmdID == HCCommand.CE_ID_SET)
            {
                Receive(pkgData);
            }
        }
Exemple #16
0
        public override void DataReceive(DataPackage pkgData)
        {
            uint cmdID = pkgData.CtrlHead.CMD_ID;

            if (cmdID == HCCommand.SYSTEM_INFO)
            {
                //启动
                Receive(pkgData);
            }
        }
        public override void DataReceive(DataPackage pkgData)
        {
            uint cmdID = pkgData.CtrlHead.CMD_ID;

            if (cmdID == HCCommand.QUERY_VERSION)
            {
                //启动
                Receive(pkgData);
            }
        }
Exemple #18
0
        //---------------------------------------------------------------------
        //查询系统信息
        public void Query()
        {
            //查询系统信息【主机→采集器】
            DataPackage pkgData = new DataPackage();
            pkgData.CtrlHead.CMD_ID = HCCommand.SYSTEM_INFO;
            pkgData.CtrlHead.CE_ID = ceInfo.CE_ID;
            pkgData.PureData = BitConverter.GetBytes((uint)0);

            pkgData.Pack();
            SendData(pkgData);
        }
        public override void DataReceive(DataPackage pkgData)
        {
            uint cmdID = pkgData.CtrlHead.CMD_ID;
            ceInfo.CE_ID = pkgData.CtrlHead.CE_ID;  //更新设备CE_ID

            if (cmdID == HCCommand.QUERY_DEVICE_STATUS)
            {
                //启动
                Receive(pkgData);
            }
        }
        //---------------------------------------------------------------------
        /// <summary>
        /// 恢复出厂设置
        /// </summary>
        public void Reset()
        {
            DataPackage pkgData = new DataPackage();
            pkgData.CtrlHead.CMD_ID = HCCommand.FACTORY_RESET;
            pkgData.CtrlHead.CE_ID = ceInfo.CE_ID;

            pkgData.PureData = buffer;

            pkgData.Pack();

            SendData(pkgData);
        }
Exemple #21
0
        void Test()
        {
            //Struct_Clock clock = new Struct_Clock();
            //clock.Year = 2014;
            //clock.Month = 9;
            //clock.Date = 24;
            //clock.Hour = 10;
            //clock.Minute = 30;
            //clock.Second = 05;
            //byte[] buffer = clock.Buffer;

            //byte[] tmpBuffer = new byte[buffer.Length];
            //Array.Copy(buffer, tmpBuffer, tmpBuffer.Length);
            //Struct_Clock c1 = new Struct_Clock();
            //c1.Buffer = tmpBuffer;

            //--------------------------------------------

            DataPackage pkgData = new DataPackage();
            pkgData.CtrlHead.CE_ID = 0;
            pkgData.CtrlHead.CMD_ID = HCCommand.IMAGE_START;

            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    Struct_TempHumi tempHumi = new Struct_TempHumi();
                    tempHumi.Humi_V = 1;
                    tempHumi.Temp_S = 2;
                    tempHumi.Temp_V = 3;
                    tempHumi.R = 4;

                    int imageLen = 1024;
                    byte status_ctl = 0x3B;
                    byte recNo = 0x01;
                    bw.Write(imageLen);
                    bw.Write(tempHumi.Buffer);
                    bw.Write(status_ctl);
                    bw.Write(recNo);
                    bw.Write((short)0);

                }
                pkgData.PureData = ms.ToArray();
            }

            pkgData.Pack();
            SendData(pkgData);

            //--------------------------------------------

            //StartCapture();
        }
Exemple #22
0
        public void Receive(DataPackage pkgData)
        {
            //收到系统信息【采集器→主机】
            SysInfoItem sysInfo = new SysInfoItem();

            byte[] dataBuffer = pkgData.PureData;
            using (MemoryStream ms = new MemoryStream(dataBuffer))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    byte[] readBytes = br.ReadBytes(32);
                    sysInfo.VenderCode = Encoding.Default.GetString(readBytes);     //厂商代码

                    readBytes = br.ReadBytes(32);
                    sysInfo.VenderName = Encoding.Default.GetString(readBytes);     //厂商名称

                    readBytes = br.ReadBytes(32);
                    sysInfo.ProductType = Encoding.Default.GetString(readBytes);    //产品型号

                    readBytes = br.ReadBytes(32);
                    sysInfo.HwVersion = Encoding.Default.GetString(readBytes);      //硬件版本

                    readBytes = br.ReadBytes(32);
                    sysInfo.LoaderVersion = Encoding.Default.GetString(readBytes);  //Loader 版本

                    readBytes = br.ReadBytes(32);
                    sysInfo.LoaderCompileTime = Encoding.Default.GetString(readBytes);  //Loader 编译时间

                    readBytes = br.ReadBytes(64);
                    sysInfo.ProductSN = Encoding.Default.GetString(readBytes);    //产品序列号

                    readBytes = br.ReadBytes(6);
                    sysInfo.MacAddr = Utils.ConvertTools.ToHexString(readBytes, "-");      //MAC 地址

                    short value = br.ReadInt16();
                    sysInfo.CPUTFrequency = string.Format("{0} MHz", value);      //CPU 主频 MHz

                    value = br.ReadInt16();
                    sysInfo.DDRFrequency = string.Format("{0} MHz", value);       //DDR 主频 MHz
                }
            }

            if (OnDataChanged != null)
            {
                DataHandlerEventArgs eventArgs = new DataHandlerEventArgs();
                eventArgs.CMD_ID = pkgData.CtrlHead.CMD_ID;
                eventArgs.Value = sysInfo;
                OnDataChanged(this, eventArgs);
            }
        }
        public void Query(byte value)
        {
            //查询设备状态【主机→采集器】
            //当设置标志位为 1 时,该字节用来设置定反位状态
            statusBuffer[0] = value;

            DataPackage pkgData = new DataPackage();
            pkgData.CtrlHead.CMD_ID = HCCommand.QUERY_DEVICE_STATUS;
            pkgData.CtrlHead.CE_ID = ceInfo.CE_ID;
            pkgData.PureData = statusBuffer;

            pkgData.Pack();
            SendData(pkgData);
        }
Exemple #24
0
        public void Receive(DataPackage pkgData)
        {
            //CE_ID=newID(当 newID=0 时,返回现有 ID),D_LEN=0【采集器→主机】

            ceInfo.CE_ID = pkgData.CtrlHead.CE_ID;  //更新当前CE_ID

            if (OnDataChanged != null)
            {
                DataHandlerEventArgs eventArgs = new DataHandlerEventArgs();
                eventArgs.CMD_ID = pkgData.CtrlHead.CMD_ID;
                eventArgs.Value = pkgData.CtrlHead.CE_ID;
                OnDataChanged(this, eventArgs);
            }
        }
Exemple #25
0
        public override void DataReceive(DataPackage pkgData)
        {
            uint cmdID = pkgData.CtrlHead.CMD_ID;

            if (cmdID == HCCommand.STREAM_SWITCH)
            {
                //收到实时码流打开或关闭的应答
                ReceiveStreamAction(pkgData);
            }
            else if (cmdID == HCCommand.DATA_READ)
            {
                //读取数据
                ReceiveDataRead(pkgData);
            }
        }
        //---------------------------------------------------------------------
        /// <summary>
        /// 查询版本号
        /// </summary>
        /// <param name="fwID">固件号,缺省为 0,表示查询主版本(文件系统)。否则按照下面,1- u-boot,2-内核,3-文件系统,4-日志版本,5-用户配置,6-出厂配置,7-升级区,8-系统区</param>
        /// <param name="board">0- 主板 1- 子功能板号</param>
        public void Query(byte fwID, byte board)
        {
            //查询版本号【主机→采集器】
            DataPackage pkgData = new DataPackage();
            pkgData.CtrlHead.CMD_ID = HCCommand.QUERY_VERSION;
            pkgData.CtrlHead.CE_ID = ceInfo.CE_ID;

            byte[] buffer = new byte[4];
            buffer[0] = fwID;
            buffer[1] = board;
            pkgData.PureData = buffer;

            pkgData.Pack();
            SendData(pkgData);
        }
Exemple #27
0
        //---------------------------------------------------------------------
        /// <summary>
        /// 设置CE_ID
        /// </summary>
        /// <param name="newID">newID(当 newID=0 时,返回现有 ID),D_LEN=0</param>
        public void Set(short newID)
        {
            //设置CE_ID,【主机→采集器】
            DataPackage pkgData = new DataPackage();
            pkgData.CtrlHead.CMD_ID = HCCommand.CE_ID_SET;
            pkgData.CtrlHead.CE_ID = (int)E_ADDR.Broadcast;

            byte[] buffer = new byte[6];

            buffer[0] = (byte)(newID & 0xFF);
            buffer[1] = (byte)(newID >> 8);

            pkgData.PureData = buffer;

            pkgData.Pack();
            SendData(pkgData);
        }
Exemple #28
0
        /// <summary>
        /// 关闭设备
        /// </summary>
        /// <param name="mode">模式:0-:power-off, 1-5:设置启动模式 1-5 reboot, 255-:取消关闭命令</param>
        /// <param name="code">代码:1-:用户主动执行, 2-:计划任务, 3-:模拟崩溃测试看门狗是否起效</param>
        /// <param name="delay">延时:0 为立即执行</param>
        public void Shutdown(byte mode, byte code, byte delay)
        {
            DataPackage pkgData = new DataPackage();
            pkgData.CtrlHead.CMD_ID = HCCommand.SHUTDOWN_DEVICE;
            pkgData.CtrlHead.CE_ID = ceInfo.CE_ID;

            byte[] buffer = new byte[4];

            buffer[0] = mode;
            buffer[1] = code;
            buffer[2] = delay;

            pkgData.PureData = buffer;

            pkgData.Pack();

            SendData(pkgData);
        }
Exemple #29
0
        public override void DataReceive(DataPackage pkgData)
        {
            uint cmdID = pkgData.CtrlHead.CMD_ID;

            if (cmdID == HCCommand.IMAGE_CAPTURE)
            {
                //启动
                ReceiveAction(pkgData);
            }
            else if (cmdID == HCCommand.DATA_READ)
            {
                //读取数据
                ReceiveDataRead(pkgData);
            }
            else if (cmdID == HCCommand.DATA_ACK)
            {
                //确认数据
                ReceiveDataACK(pkgData);
            }
        }
Exemple #30
0
        public override void DataReceive(DataPackage pkgData)
        {
            uint cmdID = pkgData.CtrlHead.CMD_ID;

            if (cmdID == HCCommand.FILE_RW_REQUEST)
            {
                //启动
                ReceiveAction(pkgData);
            }
            else if (cmdID == HCCommand.DATA_WRITE)
            {
                //写入数据
                ReceiveDataWrite(pkgData);
            }
            else if (cmdID == HCCommand.DATA_ACK)
            {
                //确认数据
                ReceiveDataACK(pkgData);
            }
        }