예제 #1
0
 private void OnDtcDataRcv(SensorData sd)
 {
     switch (sd.Data[2])
     {
         case 60:
             {
                 //m_nsRobotControl.Write(ROBOT_GO_FORWARD, 0, ROBOT_GO_FORWARD.Length);
                 WriteLine("60");
             }break;
         case 61:
             {
                 //m_nsRobotControl.Write(ROBOT_STOP, 0, ROBOT_GO_FORWARD.Length);
                 WriteLine("61");
             }break;
         case 62:
             {
                 //m_nsRobotControl.Write(ROBOT_GO_BACKWARD, 0, ROBOT_GO_BACKWARD.Length);
                 WriteLine("62");
             }break;
         default:break;
     } // end of switch
 }
예제 #2
0
        private void OnSensorDataRcv(SensorData sd)
        {
            switch ((byte)sd.ClustID)
            {
                case (byte)ZIGBEE_CLUST_ID.LIGHT_ID:
                { // 光照强度传感器
                    m_nBrightnessLevel = (int)sd.Data[2];
                    lblAverageBrightness.Text =
                        strEnvironmentInfoCaption[2] +
                        strBrightness[m_nBrightnessLevel];
                }break;
                case (byte)ZIGBEE_CLUST_ID.TEMP_ID:
                { // 温度传感器
                    m_nTemperature = ((int)sd.Data[3] * 256 + sd.Data[2]) / 10;
                    lblAverageTemp.Text =
                        strEnvironmentInfoCaption[0] +
                        m_nTemperature.ToString() + strCelsius;
                }break;
                case (byte)ZIGBEE_CLUST_ID.TPHU_ID:
               		{ // 温湿度传感器
                    m_nHumidity = (int)sd.Data[2];
                    lblAverageHumidity.Text =
                        strEnvironmentInfoCaption[1] +
                        m_nHumidity.ToString() + strHumidity;
               		}break;
                case (byte)ZIGBEE_CLUST_ID.SMOKE_ID:
               		{ // 烟雾传感器

               		}break;
                case (byte)ZIGBEE_CLUST_ID.LOCATION_INFO:
                {
                    #region 定位信息
                    int x = sd.Data[2] + sd.Data[3] * 256;
                    int y = sd.Data[4] + sd.Data[5] * 256;

                    if (-1 == m_nRobotAddress && sd.CMD == (byte)ZigBeeCMD.CMD_ROBOT)
                    {
                        m_nRobotAddress = sd.Address;
                        MoveRobot(x, y);
                    }
                    else
                    {
                        if (sd.Address == m_nUserAddress)
                            MoveRobot(x, y);
                    }

                    if (-1 == m_nUserAddress && sd.CMD == (byte)ZigBeeCMD.CMD_USER)
                    {
                        m_nUserAddress = sd.Address;
                        MoveUser(x, y);
                    }
                    else
                    {
                        if (sd.Address == m_nRobotAddress)
                            MoveUser(x, y);
                    }
                    #endregion 定位信息
                } break;
                case (byte)ZIGBEE_CLUST_ID.SECURITY_ID:
               		{

               		}break;
                default: break;
            } // end of switch
        }
예제 #3
0
        /// <summary>
        /// 执行小偷驱逐动作~
        /// </summary>
        /// <param name="sd"></param>
        private void OnBreakInAlert(SensorData sd)
        {
            System.Diagnostics.Debug.WriteLine(
                string.Format(
                    "data[2] = {0}, data[3] = {1}",
                    sd.Data[2].ToString(),
                    sd.Data[3].ToString()
                ));
            if (sd.Data[2] == (byte)0)
            {
                m_bDoorIsOpen = false;
                lastData = 0;

                BreakInHappened = false;
                ((Control)this).Invoke(CloseAlertForm);
            }
            else
            {
                m_bDoorIsOpen = true;

                if (AlertJudge(sd.Data[3]))
                { // 当前状态为 入侵报警
                    if (!BreakInHappened)
                    { // 上一状态为 安全
                        if (null == m_frmBreak)
                        { // 实际执行的状态为 安全
                            StartTimer();
                        } // end of if
                        else
                        { // 实际执行的状态为 报警
                            StopTimer();
                        }
                        // 更新上一状态
                        BreakInHappened = true;
                    } // end of if
                    else
                    { // 若上一状态为报警,则什么也不做
                    } // end of else
                } // end of if
                else
                { // 当前状态为 安全
                    if (BreakInHappened)
                    { // 上一状态为 报警
                        if (null != m_frmBreak)
                        { // 实际执行的状态为 报警
                            StartTimer();
                        } // end of if
                        else
                        { // 实际执行的状态为 安全
                            StopTimer();
                        }
                        BreakInHappened = false;
                    } // end of if
                    else
                    { // 若上一状态为安全,则什么也不做
                    } // end of else
                } // end of else
            } // end of else
        }