コード例 #1
0
ファイル: MainForm.cs プロジェクト: jay-JYPark/DMB-System
        void forSpSoc_RecvNetSessionClient(object sender, DmbNetSessionRecvEventArgs e)
        {
            try
            {
                List <DmbProtocolBase> lstDmbProtoBase = new List <DmbProtocolBase>();
                DmbNetDataReceiver.ParseDmbPacket(e.Buff, e.Len, (this.forSpSoc.GetDmbNetSessionContext(e.DmbProfile.IpAddr, e.DmbProfile.Port)).TcpClient, out lstDmbProtoBase);

                foreach (DmbProtocolBase protoBase in lstDmbProtoBase)
                {
                    if (protoBase.Cmd != DmbDefineCmd.CmdP)
                    {
                    }

                    switch (protoBase.Cmd)
                    {
                    case DmbDefineCmd.CmdA:     //발령
                        DmbProtocolCmdA protoA = protoBase as DmbProtocolCmdA;
                        WMessage        wMsg   = new WMessage();
                        wMsg.AbortStatus        = 0;
                        wMsg.BoolControl        = false;
                        wMsg.BoolProcessing     = true;
                        wMsg.CommitPart         = WMessage.E_sendPart.All;
                        wMsg.DDateTime          = protoA.OrderTime;
                        wMsg.EndpointPart       = WMessage.E_sendPart.None;
                        wMsg.ID                 = uint.Parse(protoA.MsgId);
                        wMsg.IntControl         = 0;
                        wMsg.IntProcessing      = 1;
                        wMsg.Message            = protoA.Message;
                        wMsg.ProtoA             = protoA;
                        wMsg.RCount             = (uint)protoA.RgnCount;
                        wMsg.Repeats            = 1;
                        wMsg.Interval           = 0;
                        wMsg.SDevice_ALL        = false;
                        wMsg.SDevice_마을앰프       = true;
                        wMsg.SDevice_모니터링       = true;
                        wMsg.SDevice_상황실        = true;
                        wMsg.SDevice_유관기관       = true;
                        wMsg.SendID             = 0;
                        wMsg.SendMode           = (protoA.Mode == DmbDefineOrderMode.Real) ? (byte)3 : (byte)0;
                        wMsg.SMSMsg             = protoA.CbsMsg;
                        wMsg.SOPT_CONTROL       = false;
                        wMsg.SOPT_DMB           = (protoA.MsgType == DmbDefineMsgType.Navi) ? true : false;
                        wMsg.SOPT_ETC           = false;
                        wMsg.SOPT_LIVE          = false;
                        wMsg.SOPT_SMS           = (protoA.CbsMsg == string.Empty) ? false : true;
                        wMsg.SOPT_STOREDMESSAGE = (protoA.MsgType == DmbDefineMsgType.Sto) ? true : false;
                        wMsg.SOPT_TTS           = (protoA.MsgType == DmbDefineMsgType.Tts) ? true : false;
                        wMsg.SOPT_WARNING       = false;
                        wMsg.StoMsg             = protoA.Message;
                        wMsg.TkPriority         = 2;
                        wMsg.TkRegion           = (protoA.SectionCode == DmbDefineSectionCode.National) ? (uint)1 :
                                                  (protoA.SectionCode == DmbDefineSectionCode.Administrative) ? (uint)3 :
                                                  (protoA.SectionCode == DmbDefineSectionCode.Terminal) ? (uint)4 : (uint)2;
                        wMsg.TTSMsg = protoA.Message;

                        //AL1 = 공습
                        //AL2 = 경계
                        //AL3 = 재난위험
                        //ACL = 해제
                        if (protoA.DisasterCode == "AL1" || protoA.DisasterCode == "AL2" || protoA.DisasterCode == "AL3" || protoA.DisasterCode == "ACL")
                        {
                            wMsg.SOPT_DMB           = false;
                            wMsg.SOPT_SMS           = false;
                            wMsg.SOPT_STOREDMESSAGE = false;
                            wMsg.SOPT_TTS           = false;
                            wMsg.SOPT_WARNING       = true;
                        }

                        broadcast broad = null;

                        for (int i = 0; i < protoA.LstStage.Count; i++)
                        {
                            broad             = new broadcast();
                            broad.BoolAborted = false;
                            broad.BoolProcess = true;
                            broad.WMessageID  = uint.Parse(protoA.MsgId);
                            broad.StageID     = (uint)protoA.LstStage[i] + 2;
                            wMsg.BCenterList.Add(broad);
                        }

                        mapMessageRegion mmr = null;

                        for (int i = 0; i < protoA.LstFullCode.Count; i++)
                        {
                            mmr          = new mapMessageRegion();
                            mmr.DestFlag = (protoA.SectionCode == DmbDefineSectionCode.Terminal) ? (uint)1 : 0;
                            //mmr.ParentID = protoA.LstFullCode[i];
                            mmr.ParentName = protoA.LstFullCode[i];
                            mmr.WMessageID = uint.Parse(protoA.MsgId);
                            wMsg.MapTarget.Add(mmr);
                        }

                        this.mainviewform.datamanager_onWMessageUpdate(wMsg);
                        break;

                    case DmbDefineCmd.CmdF:     //제어
                        DmbProtocolCmdF protoF      = protoBase as DmbProtocolCmdF;
                        DmbProtocolCmdA subProtoA   = DmbProtocolFactory.CreateDmbProtocol(DmbDefineCmd.CmdA) as DmbProtocolCmdA;
                        string          ctrlMessage = string.Empty;

                        if (protoF.CtrlCode == DmbDefineControlCode.Reset)
                        {
                            P03 p = PMng.GetPObject("31", "1") as P03;
                            ctrlMessage = PMng.MakeFrame(p);
                        }
                        else if (protoF.CtrlCode == DmbDefineControlCode.AmpOutput)
                        {
                            //(0 : 0.1%, 1 : 25%, 2 : 50%, 3 : 75%, 4 : 90%, 5 : 100%)
                            if (protoF.LstCtrlData[0] == "1")
                            {
                                P03 p = PMng.GetPObject("38", "0") as P03;
                                ctrlMessage = PMng.MakeFrame(p);
                            }
                            else if (protoF.LstCtrlData[0] == "2")
                            {
                                P03 p = PMng.GetPObject("38", "2") as P03;
                                ctrlMessage = PMng.MakeFrame(p);
                            }
                            else if (protoF.LstCtrlData[0] == "3")
                            {
                                P03 p = PMng.GetPObject("38", "3") as P03;
                                ctrlMessage = PMng.MakeFrame(p);
                            }
                            else if (protoF.LstCtrlData[0] == "4")
                            {
                                P03 p = PMng.GetPObject("38", "5") as P03;
                                ctrlMessage = PMng.MakeFrame(p);
                            }
                        }
                        else if (protoF.CtrlCode == DmbDefineControlCode.Ars)
                        {
                            //프로토콜 없음
                        }
                        else if (protoF.CtrlCode == DmbDefineControlCode.SignBoard)
                        {
                        }

                        WMessage wMsgCtrl = new WMessage();
                        wMsgCtrl.AbortStatus        = 0;
                        wMsgCtrl.BoolControl        = true;
                        wMsgCtrl.BoolProcessing     = true;
                        wMsgCtrl.CommitPart         = WMessage.E_sendPart.All;
                        wMsgCtrl.DDateTime          = protoF.CtrlTime;
                        wMsgCtrl.EndpointPart       = WMessage.E_sendPart.None;
                        wMsgCtrl.ID                 = uint.Parse(protoF.MsgId);
                        wMsgCtrl.IntControl         = 1;
                        wMsgCtrl.IntProcessing      = 1;
                        wMsgCtrl.Message            = ctrlMessage;
                        wMsgCtrl.ProtoF             = protoF;
                        wMsgCtrl.RCount             = (uint)protoF.RgnCount;
                        wMsgCtrl.Repeats            = 1;
                        wMsgCtrl.Interval           = 5;
                        wMsgCtrl.SDevice_ALL        = true;
                        wMsgCtrl.SDevice_마을앰프       = true;
                        wMsgCtrl.SDevice_모니터링       = true;
                        wMsgCtrl.SDevice_상황실        = true;
                        wMsgCtrl.SDevice_유관기관       = true;
                        wMsgCtrl.SendDevice         = WMessage.E_DeviceType.All;
                        wMsgCtrl.SendID             = 0;
                        wMsgCtrl.SendMode           = (byte)0;
                        wMsgCtrl.SMSMsg             = string.Empty;
                        wMsgCtrl.SOPT_CONTROL       = true;
                        wMsgCtrl.SOPT_DMB           = false;
                        wMsgCtrl.SOPT_ETC           = false;
                        wMsgCtrl.SOPT_LIVE          = false;
                        wMsgCtrl.SOPT_SMS           = false;
                        wMsgCtrl.SOPT_STOREDMESSAGE = false;
                        wMsgCtrl.SOPT_TTS           = false;
                        wMsgCtrl.SOPT_WARNING       = false;
                        wMsgCtrl.StoMsg             = "특수수신기 제어";
                        wMsgCtrl.TkPriority         = 2;
                        wMsgCtrl.TkRegion           = (protoF.SectionCode == DmbDefineSectionCode.National) ? (uint)1 :
                                                      (protoF.SectionCode == DmbDefineSectionCode.Administrative) ? (uint)3 :
                                                      (protoF.SectionCode == DmbDefineSectionCode.Terminal) ? (uint)4 : (uint)2;
                        wMsgCtrl.TTSMsg = ctrlMessage;

                        broadcast broadCtrl = null;

                        for (int i = 0; i < this.datamanager.BroadList.Count; i++)
                        {
                            broadCtrl             = new broadcast();
                            broadCtrl.BoolAborted = false;
                            broadCtrl.BoolProcess = true;
                            broadCtrl.WMessageID  = uint.Parse(protoF.MsgId);
                            broadCtrl.StageID     = (uint)this.datamanager.BroadList[i].ID;
                            wMsgCtrl.BCenterList.Add(broadCtrl);
                        }

                        mapMessageRegion mmrCtrl = null;

                        for (int i = 0; i < protoF.LstFullCode.Count; i++)
                        {
                            mmrCtrl            = new mapMessageRegion();
                            mmrCtrl.DestFlag   = (protoF.SectionCode == DmbDefineSectionCode.Terminal) ? (uint)1 : 0;
                            mmrCtrl.ParentName = protoF.LstFullCode[i];
                            mmrCtrl.WMessageID = uint.Parse(protoF.MsgId);
                            wMsgCtrl.MapTarget.Add(mmrCtrl);
                        }

                        subProtoA.DisasterCode = "STT";
                        subProtoA.SectionCode  = protoF.SectionCode;
                        subProtoA.LstStage.Add(DmbDefineStage.Kbs);
                        subProtoA.LstStage.Add(DmbDefineStage.Mbc);
                        subProtoA.LstStage.Add(DmbDefineStage.Sbs);
                        subProtoA.LstStage.Add(DmbDefineStage.Ytn);
                        wMsgCtrl.ProtoA = subProtoA;

                        this.mainviewform.datamanager_onWMessageUpdate(wMsgCtrl);
                        break;

                    case DmbDefineCmd.CmdG:     //상태요청
                        P01             p01            = new P01();
                        string          allRequestData = this.AllDeviceStatusRequest(p01);
                        DmbProtocolCmdG protoG         = protoBase as DmbProtocolCmdG;
                        DmbProtocolCmdA subProtoA1     = DmbProtocolFactory.CreateDmbProtocol(DmbDefineCmd.CmdA) as DmbProtocolCmdA;
                        WMessage        wMsgCtrl1      = new WMessage();
                        wMsgCtrl1.AbortStatus        = 0;
                        wMsgCtrl1.BoolControl        = true;
                        wMsgCtrl1.BoolProcessing     = true;
                        wMsgCtrl1.CommitPart         = WMessage.E_sendPart.All;
                        wMsgCtrl1.DDateTime          = DateTime.Now;
                        wMsgCtrl1.EndpointPart       = WMessage.E_sendPart.None;
                        wMsgCtrl1.ID                 = 1;
                        wMsgCtrl1.IntControl         = 1;
                        wMsgCtrl1.IntProcessing      = 1;
                        wMsgCtrl1.Message            = allRequestData;
                        wMsgCtrl1.RCount             = 1;
                        wMsgCtrl1.Repeats            = 1;
                        wMsgCtrl1.Interval           = 5;
                        wMsgCtrl1.SDevice_ALL        = true;
                        wMsgCtrl1.SDevice_마을앰프       = true;
                        wMsgCtrl1.SDevice_모니터링       = true;
                        wMsgCtrl1.SDevice_상황실        = true;
                        wMsgCtrl1.SDevice_유관기관       = true;
                        wMsgCtrl1.SendDevice         = WMessage.E_DeviceType.All;
                        wMsgCtrl1.SendID             = 0;
                        wMsgCtrl1.SendMode           = (byte)0;
                        wMsgCtrl1.SMSMsg             = string.Empty;
                        wMsgCtrl1.SOPT_CONTROL       = true;
                        wMsgCtrl1.SOPT_DMB           = false;
                        wMsgCtrl1.SOPT_ETC           = false;
                        wMsgCtrl1.SOPT_LIVE          = false;
                        wMsgCtrl1.SOPT_SMS           = false;
                        wMsgCtrl1.SOPT_STOREDMESSAGE = false;
                        wMsgCtrl1.SOPT_TTS           = false;
                        wMsgCtrl1.SOPT_WARNING       = false;
                        wMsgCtrl1.StoMsg             = "특수수신기 상태요청";
                        wMsgCtrl1.TkPriority         = 2;
                        wMsgCtrl1.TkRegion           = 4;
                        wMsgCtrl1.TTSMsg             = allRequestData;

                        broadcast broadCtrl1 = null;

                        for (int i = 0; i < this.datamanager.BroadList.Count; i++)
                        {
                            broadCtrl1             = new broadcast();
                            broadCtrl1.BoolAborted = false;
                            broadCtrl1.BoolProcess = true;
                            broadCtrl1.WMessageID  = 1;
                            broadCtrl1.StageID     = (uint)this.datamanager.BroadList[i].ID;
                            wMsgCtrl1.BCenterList.Add(broadCtrl1);
                        }

                        mapMessageRegion mmrCtrl1 = null;
                        mmrCtrl1            = new mapMessageRegion();
                        mmrCtrl1.DestFlag   = 1;
                        mmrCtrl1.ParentName = protoG.CdmaNumber;
                        mmrCtrl1.WMessageID = 1;
                        wMsgCtrl1.MapTarget.Add(mmrCtrl1);

                        subProtoA1.DisasterCode = "STT";
                        subProtoA1.SectionCode  = DmbDefineSectionCode.Terminal;
                        subProtoA1.LstStage.Add(DmbDefineStage.Kbs);
                        subProtoA1.LstStage.Add(DmbDefineStage.Mbc);
                        subProtoA1.LstStage.Add(DmbDefineStage.Sbs);
                        subProtoA1.LstStage.Add(DmbDefineStage.Ytn);
                        wMsgCtrl1.ProtoA = subProtoA1;

                        this.mainviewform.datamanager_onWMessageUpdate(wMsgCtrl1);
                        break;
                    }
                }

                this.logMng.File_Mng(string.Format("시도(특수수신기) 서비스 => 데이터 수신시각 : {0}\n데이터 : {1}",
                                                   DateTime.Now.ToString(), DMBBIZ.DmbUtility.DmbUtilityMng.IDmbEtcUtility.Bytes2HexString(e.Buff)));
            }
            catch (Exception ex)
            {
                DmbLoggingMng.ILoggingException.WriteException("MainForm", "forSpSoc_RecvNetSessionClient - ", ex);
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: jay-JYPark/DMB-System
        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                // 재실행 방지 코드
                bool  executeProc;
                Mutex mutex = new Mutex(true, Application.ProductName, out executeProc);

                if (!executeProc)
                {
                    //MessageBox.Show("방송 DMB송출 시스템이 이미 실행중입니다.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //this.Dispose();
                    //Application.Exit();
                    //return;
                }

                DmbBizActivator.Active(DmbDefineActivatorCode.ForProv);
                TcpProfileMng.LoadNavProfileConfig();
                TcpProfileMng.LoadSpProfileConfig();
                this.SetServerState(); //서버상태 부분

                this.logMng = new LogManager();
                this.logMng.Dir_Mng();

                DmbProtocolCmdP protoP = DmbProtocolFactory.CreateDmbProtocol(DmbDefineCmd.CmdP) as DmbProtocolCmdP;
                protoP.IP       = DMBBIZ.DmbUtility.DmbUtilityMng.IDmbEtcUtility.GetIPv4();
                this.forNaviSoc = new DmbNetSessionClientMng();
                this.forNaviSoc.PollingDatas = DmbProtocolFactory.MakeFrame(protoP);

                foreach (TcpProfileData eachTcpProfileData in TcpProfileMng.LstNavTcpProfileData)
                {
                    DmbProfile profileForDmb = new DmbProfile();
                    profileForDmb.IpAddr = eachTcpProfileData.IpAddr;
                    profileForDmb.Port   = eachTcpProfileData.Port;
                    profileForDmb.Name   = "ForNav";

                    this.forNaviSoc.AddProfile(profileForDmb);
                }

                this.forNaviSoc.ConnectNetSessionClient += new DmbNetSessionConnectEventHandler(forNaviSoc_ConnectNetSessionClient);
                this.forNaviSoc.RecvNetSessionClient    += new DmbNetSessionRecvEventHandler(forNaviSoc_RecvNetSessionClient);
                this.forNaviSoc.CloseNetSessionClient   += new DmbNetSessionCloseEventHandler(forNaviSoc_CloseNetSessionClient);

                this.forSpSoc = new DmbNetSessionClientMng();
                this.forSpSoc.PollingDatas = DmbProtocolFactory.MakeFrame(protoP);

                foreach (TcpProfileData eachTcpProfileData in TcpProfileMng.LstSpTcpProfileData)
                {
                    DmbProfile profileForWeb = new DmbProfile();
                    profileForWeb.IpAddr = eachTcpProfileData.IpAddr;
                    profileForWeb.Port   = eachTcpProfileData.Port;
                    profileForWeb.Name   = "ForSp";

                    this.forSpSoc.AddProfile(profileForWeb);
                }

                this.forSpSoc.ConnectNetSessionClient += new DmbNetSessionConnectEventHandler(forSpSoc_ConnectNetSessionClient);
                this.forSpSoc.RecvNetSessionClient    += new DmbNetSessionRecvEventHandler(forSpSoc_RecvNetSessionClient);
                this.forSpSoc.CloseNetSessionClient   += new DmbNetSessionCloseEventHandler(forSpSoc_CloseNetSessionClient);

                this.forNaviSoc.StartSessionClientMng();
                this.forSpSoc.StartSessionClientMng();

                this.datamanager = DataManager.getInstance();
                this.Text       += " " + DMBBIZ.DmbUtility.DmbUtilityMng.IDmbEtcUtility.GetVersionInfo();
                //this.Text += this.mainVersionStr;
                mainviewform = new MainViewForm();
                secession    = new Secession();
                recvmng      = RecvMng.getInstance();
                serialMng    = SerialMng.getInstance();
                tcpcheck     = new TcpCheck();

                mainviewform.MdiParent      = this;
                mainviewform.Dock           = DockStyle.Fill;
                MainToolStripButton.Checked = true;
                mainviewform.Show();

                this.tcpcheck.ConnectionCheckEvt += new TcpCheck.ConnectionCheckHandle(tcpcheck_ConnectionCheckEvt);
                this.tcpconnect(); //tcp통신연결 부분
            }
            catch (Exception ex)
            {
                Console.WriteLine("MainForm_Load - " + ex.Message);
            }
        }