void sUser_Closed(SendReceive SendRecv) { sUser.Stop(); flagConnection = false; this.socket_Closed(MyID); }
public clsCCETestPanel(string tmpCCEIP, int tmpCCEPort) { cceIP = tmpCCEIP; netPort = tmpCCEPort; sSocket = new ServerSocket(); sSocket.Accepted += new AcceptedEvent(sSocket_Accepted); sUser = new SendReceive(); sUser.Received += new ReceivedEvent(sUser_Received); sUser.Closed += new CloseEvent(sUser_Closed); //Server 구현( Accept 대기 ) localEndPoint = new IPEndPoint(IPAddress.Any, netPort); sSocket.Start(localEndPoint); int i = 0; for (i = 0; i < 9; i++) { tmpCcpSt[i] = new CcpSt(); tmpConsoleSt[i] = new ConsoleSt(); } for (i = 0; i < 32; i++) { tmpBaseSt[i] = new BaseSt(); } }
void sUser_Received(SendReceive SendRecv, byte[] buffer, int lng) { #region 수신된 Data 기본처리 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' int i = 0, j = 0; int chkSum = 0, iLow, iHigh; byte bL = 0x00, bH = 0x00; if (clsCommon.flagDebug[MyID]) { string tmpStrData = null; if (clsCommon.flagDataViewTypeASCII) { tmpStrData = Encoding.Default.GetString(buffer, 0, lng); } else { for (i = 0; i < lng; i++) { tmpStrData += string.Format(" {0:X2}", buffer[i]); } } this.sendReceiveDataView(MyID, false, tmpStrData); } //CheckSum 검사 for (i = 0; i < lng - 2; i++) { chkSum = chkSum ^ buffer[i]; } iLow = chkSum & 0x0F; iHigh = chkSum >> 4; bH = clsCommon.HexaConvert(iHigh); bL = clsCommon.HexaConvert(iLow); if ((bH != buffer[lng - 2]) || (bL != buffer[lng - 1])) { //AddStatus("CheckSum 오류!!"); return; } this.dataSendReceive(MyID, false); //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #endregion j = 2; byte tmpSuID = buffer[j++]; //수신 ID byte tmpSongID = buffer[j++]; //송신 ID byte tmpCMD = buffer[j++]; //CMD byte tmpLng = buffer[j++]; //Data 길이 if (tmpSuID != clsCommon.ID_PC) { return; //수신 ID가 PC가 아니면 처리하지 않는다. } byte[] tmpByte = new byte[8]; switch (tmpCMD) { case CMD_Polling: break; case CMD_MPU_ST: //M : MPU 자체의 동작 상태와 전원부 상태 보고 CpuSt tmpCpuSt = new CpuSt(); //Main/Stby 동작 상태 tmpCpuSt.mainStby = buffer[j++]; //main cpu fault, stby cpu fault, main power fault, stby power fault tmpCpuSt.cpuSt = BitInfoToByte(buffer[j++]); this.mpu_CpuSt(MyID, tmpCpuSt); break; case CMD_CIF_ST: //C : Conlol I/F와 Broad I/F의 동작 상태 보고 #region Conlol I/F와 Broad I/F의 동작 상태 처리 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' //CCP의 Communication Fault 상태 tmpByte = BitInfoToByte(buffer[j++]); //CCP9~16 Communication Fault if (tmpByte[0] == 0) { tmpCcpSt[8].flagCommunicationFault = true; } else { tmpCcpSt[8].flagCommunicationFault = false; } tmpByte = BitInfoToByte(buffer[j++]); //CCP1~8 Communication Fault for (i = 0; i < 8; i++) { if (tmpByte[i] == 0) { tmpCcpSt[i].flagCommunicationFault = true; } else { tmpCcpSt[i].flagCommunicationFault = false; } } //Console I/F의 Communication Fault 상태 tmpByte = BitInfoToByte(buffer[j++]); //Console I/F 9 Communication Fault, Broad I/F Communication Fault tmpConsoleSt[8].otherSt[0] = tmpByte[0]; tmpByte = BitInfoToByte(buffer[j++]); //Console I/F 1~8 Communication Fault for (i = 0; i < 8; i++) { tmpConsoleSt[i].otherSt[0] = tmpByte[i]; } tmpBroadSt.otherSt[0] = tmpByte[1]; //Console I/F 1~9의 상태 for (i = 0; i < 9; i++) { //ch, ptt, broad tmpByte = BitInfoToByte(buffer[j++]); //CH byte tmpCh = 0; if (tmpByte[0] == 1) { tmpCh = 1; } if (tmpByte[1] == 1) { tmpCh += 2; } tmpConsoleSt[i].ch = (byte)(tmpCh + 1); tmpConsoleSt[i].otherSt[1] = tmpByte[2]; //ptt tmpConsoleSt[i].otherSt[2] = tmpByte[5]; //broad } //Broad I/F의 상태 tmpBroadSt.otherSt = BitInfoToByte(buffer[j++]); //CCP의 PC 연결 상태 tmpByte = BitInfoToByte(buffer[j++]); //CCP9~16 PC Communication Fault if (tmpByte[0] == 0) { tmpCcpSt[8].flagPCCommFault = true; } else { tmpCcpSt[8].flagPCCommFault = false; } tmpByte = BitInfoToByte(buffer[j++]); //CCP1~8 PC Communication Fault for (i = 0; i < 8; i++) { if (tmpByte[i] == 0) { tmpCcpSt[i].flagPCCommFault = true; } else { tmpCcpSt[i].flagPCCommFault = false; } } this.mpu_CcpConsoleBroadSt(MyID, tmpCcpSt, tmpConsoleSt, tmpBroadSt); //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #endregion break; case CMD_BIF_ST: //B : Base I/F의 동작 상태 보고 #region Base I/F의 동작 상태 처리 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' //Base I/F의 Communication Fault 상태 for (i = 3; i >= 0; i--) { tmpByte = BitInfoToByte(buffer[j++]); for (int k = 0; k < 8; k++) { tmpBaseSt[i * 8 + k].otherSt[0] = tmpByte[k]; } } //Base I/F 1~30의 상태 for (i = 0; i < 30; i++) { //ch, ptt, busy, ebysy, broad, fault tone 1, fault tone 2 tmpByte = BitInfoToByte(buffer[j++]); //CH byte tmpCh = 0; if (tmpByte[0] == 1) { tmpCh = 1; } if (tmpByte[1] == 1) { tmpCh += 2; } tmpBaseSt[i].ch = (byte)(tmpCh + 1); tmpBaseSt[i].otherSt[1] = tmpByte[2]; //ptt tmpBaseSt[i].otherSt[2] = tmpByte[3]; //busy tmpBaseSt[i].otherSt[3] = tmpByte[4]; //ebusy tmpBaseSt[i].otherSt[4] = tmpByte[5]; //broad tmpBaseSt[i].otherSt[5] = tmpByte[6]; //fault tone 1 tmpBaseSt[i].otherSt[6] = tmpByte[7]; //fault tone 2 } this.mpu_BaseSt(MyID, tmpBaseSt); //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #endregion break; case CMD_GAIN_ST: //G : Gain값 상태 보고 #region Gain값 상태 처리 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' byte[] tmpGainValue = new byte[8]; byte tmpID = buffer[j++]; //Gain값 if (tmpID == clsCommon.ID_Broad) { //Broad I/F의 Gain값은 4Byte for (i = 0; i < 4; i++) { tmpGainValue[i] = buffer[j++]; } } else { //Console I/F와 Base I/F8의 Gain값은 Byte for (i = 0; i < 8; i++) { tmpGainValue[i] = buffer[j++]; } } this.mpu_GainValue(MyID, tmpID, tmpGainValue); //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #endregion break; case CMD_BIF_GRP_ST: //R : Broad I/F의 선택 기지국 상태 보고 #region Broad I/F의 선택 기지국 상태 처리 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' byte[,] tmpUnitSelectedSt = new byte[3, 32]; //Broad I/F의 Broad 1,2,3 각각의 선택 기지국 상태 for (i = 0; i < 3; i++) { for (int k = 0; k < 4; k++) { tmpByte = BitInfoToByte(buffer[j++]); //Base I/F 1~8 Communication Fault for (int l = 0; l < 8; l++) { tmpUnitSelectedSt[i, k * 8 + l] = tmpByte[l]; } } } this.mpu_BroadUnitSelectedSt(MyID, tmpUnitSelectedSt); //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #endregion break; case clsNMSMainMachine.CMD_LineTest: byte tmpLevelValue = buffer[j++]; mpu_LineTestValue(MyID, tmpLevelValue); break; case CMD_Other: byte SubCMD = buffer[j++]; //Sub CMD switch (SubCMD) { case CMD_IF_UseSt: //U : 각 I/F의 사용 유무 보고 #region 각 I/F의 사용 유무 처리 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' UseSt tmpUseSt = new UseSt(); //CCP 사용유무 tmpByte = BitInfoToByte(buffer[j++]); for (i = 0; i < 8; i++) { if (tmpByte[i] == 1) { tmpUseSt.flagCCP[i] = true; } else { tmpUseSt.flagCCP[i] = false; } } //Console I/F 사용유무 tmpByte = BitInfoToByte(buffer[j++]); for (i = 0; i < 8; i++) { if (tmpByte[i] == 1) { tmpUseSt.flagConsole[i] = true; } else { tmpUseSt.flagConsole[i] = false; } } //기타 사용유무(CCP9, Console9, Broad) tmpByte = BitInfoToByte(buffer[j++]); if (tmpByte[0] == 1) { tmpUseSt.flagCCP[8] = true; } else { tmpUseSt.flagCCP[8] = false; } if (tmpByte[1] == 1) { tmpUseSt.flagConsole[8] = true; } else { tmpUseSt.flagConsole[8] = false; } if (tmpByte[2] == 1) { tmpUseSt.flagBroad = true; } else { tmpUseSt.flagBroad = false; } //Base I/F 사용유무 for (i = 0; i < 4; i++) { tmpByte = BitInfoToByte(buffer[j++]); for (int k = 0; k < 8; k++) { if (tmpByte[k] == 1) { tmpUseSt.flagBase[i * 8 + k] = true; } else { tmpUseSt.flagBase[i * 8 + k] = false; } } } this.mpu_IfUseSt(MyID, tmpUseSt); //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #endregion break; } break; } }