Big changes

This commit is contained in:
Duc
2025-03-13 12:04:22 -07:00
parent c689fcb7f9
commit ffa9905494
748 changed files with 199255 additions and 3743 deletions

View File

@@ -0,0 +1,53 @@
// **********************************************************************************************************
// ChamberException.cs
// 1/8/2024
// NGI - Next Generation Interceptor
//
// Contract No. HQ0856-21-C-0003/1022000209
//
// THIS DOCUMENT DOES NOT CONTAIN TECHNOLOGY OR TECHNICAL DATA CONTROLLED UNDER EITHER THE U.S.
// INTERNATIONAL TRAFFIC IN ARMS REGULATIONS OR THE U.S. EXPORT ADMINISTRATION REGULATIONS.
//
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION PROPRIETARY TO RAYTHEON
// COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT.
// DISCLOSURE TO UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO RAYTHEON
// COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS CONTENTS SHALL BE FURNISHED OR DISCLOSED
// TO OR COPIED OR USED BY PERSONS OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF
// RAYTHEON COMPANY.
//
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
//
// DESTRUCTION NOTICE: FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN DOD 5220.22-M,
// NATIONAL INDUSTRIAL SECURITY PROGRAM OPERATING MANUAL, FEBRUARY 2006,
// INCORPORATING CHANGE 1, MARCH 28, 2013, CHAPTER 5, SECTION 7, OR DODM 5200.01-VOLUME 3,
// DOD INFORMATION SECURITY PROGRAM: PROTECTION OF CLASSIFIED INFORMATION, ENCLOSURE 3,
// SECTION 17. FOR CONTROLLED UNCLASSIFIED INFORMATION FOLLOW THE PROCEDURES IN DODM 5200.01-VOLUME 4,
// INFORMATION SECURITY PROGRAM: CONTROLLED UNCLASSIFIED INFORMATION.
//
// CONTROLLED BY: MISSILE DEFENSE AGENCY
// CONTROLLED BY: GROUND-BASED MIDCOURSE DEFENSE PROGRAM OFFICE
// CUI CATEGORY: CTI
// DISTRIBUTION/DISSEMINATION CONTROL: F
// POC: Alex Kravchenko (1118268)
// **********************************************************************************************************
using System;
namespace Raytheon.Instruments.Lib
{
public class ChamberException : Exception
{
public ChamberException()
{
}
public ChamberException(string message)
: base(message)
{
}
public ChamberException(string message, Exception inner)
: base(message, inner)
{
}
}
}

View File

@@ -0,0 +1,101 @@
// **********************************************************************************************************
// Constants.cs
// 6/8/2023
// NGI - Next Generation Interceptor
//
// Contract No. HQ0856-21-C-0003/1022000209
//
// THIS DOCUMENT DOES NOT CONTAIN TECHNOLOGY OR TECHNICAL DATA CONTROLLED UNDER EITHER THE U.S.
// INTERNATIONAL TRAFFIC IN ARMS REGULATIONS OR THE U.S. EXPORT ADMINISTRATION REGULATIONS.
//
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION PROPRIETARY TO RAYTHEON
// COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT.
// DISCLOSURE TO UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO RAYTHEON
// COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS CONTENTS SHALL BE FURNISHED OR DISCLOSED
// TO OR COPIED OR USED BY PERSONS OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF
// RAYTHEON COMPANY.
//
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
//
// DESTRUCTION NOTICE: FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN DOD 5220.22-M,
// NATIONAL INDUSTRIAL SECURITY PROGRAM OPERATING MANUAL, FEBRUARY 2006,
// INCORPORATING CHANGE 1, MARCH 28, 2013, CHAPTER 5, SECTION 7, OR DODM 5200.01-VOLUME 3,
// DOD INFORMATION SECURITY PROGRAM: PROTECTION OF CLASSIFIED INFORMATION, ENCLOSURE 3,
// SECTION 17. FOR CONTROLLED UNCLASSIFIED INFORMATION FOLLOW THE PROCEDURES IN DODM 5200.01-VOLUME 4,
// INFORMATION SECURITY PROGRAM: CONTROLLED UNCLASSIFIED INFORMATION.
//
// CONTROLLED BY: MISSILE DEFENSE AGENCY
// CONTROLLED BY: GROUND-BASED MIDCOURSE DEFENSE PROGRAM OFFICE
// CUI CATEGORY: CTI
// DISTRIBUTION/DISSEMINATION CONTROL: F
// POC: Alex Kravchenko (1118268)
// **********************************************************************************************************
namespace Raytheon.Instruments.Lib
{
public static class Constants
{
// LSPS (ATK) Constants
public const int LSPS_AUTOFILL_STATE_OFF = 0;
public const int LSPS_AUTOFILL_STATE_COOLING = 1;
public const int LSPS_AUTOFILL_STATE_WARMING = 2;
public const int LSPS_BB_CSTATE_LN2_COOLING = 0;
public const int LSPS_BB_CSTATE_CONTROLLING = 1;
public const int LSPS_BB_CSTATE_NOT_CONTROLLING = 2;
public const int LSPS_CHOPPER_STATE_OFF = 10;
public const int LSPS_CHOPPER_STATE_ON = 11;
public const int LSPS_CHOPPER_STATE_MOVING = 12;
public const int LSPS_CHOPPER_STATE_STOP_OPEN = 13;
public const int LSPS_CHOPPER_STATE_STOP_CLOSED = 14;
public const int LSPS_CHOPPER_STATE_FIND_ERROR = 15;
public const int LSPS_CHOPPER_STATE_MOVE_ERROR = 16;
public const int LSPS_CHOPPER_STATE_CHANGE_DIR = 17;
public const int LSPS_CHOPPER_STATE_CHANGE_SPEED = 18;
public const int LSPS_CHOPPER_STATE_LOOKING_FOR_STOP_OPEN = 19;
public const int LSPS_CHOPPER_STATE_LOOKING_FOR_STOP_CLOSED = 20;
public const int LSPS_GALIL_WSTATUS_NEEDS_HOME = 0;
public const int LSPS_GALIL_WSTATUS_HOMING = 1;
public const int LSPS_GALIL_WSTATUS_MOVING = 2;
public const int LSPS_GALIL_WSTATUS_HOME_SWITCH_ERR = 3;
public const int LSPS_GALIL_WSTATUS_POS_SWITCH_ERR = 4;
public const int LSPS_GALIL_WSTATUS_FIND_POS_ERR = 5;
public const int LSPS_GALIL_WSTATUS_FIND_HOME_ERR = 6;
public const int LSPS_GALIL_WSTATUS_IN_POSITION = 7;
public const int LSPS_GALIL_WSTATUS_TIMEOUT = 8;
public const int LSPS_GALIL_SM_STATUS_LIMIT_SWITCH_ERR = -3;
public const int LSPS_GALIL_SM_STATUS_NEEDS_HOME = -2;
public const int LSPS_GALIL_SM_STATUS_MOVING = -1;
public const int LSPS_GALIL_SM_STATUS_IN_POSITION = 0;
public const int LSPS_GALIL_SM_STATUS_VELOCITY = 1;
public const int LSPS_GALIL_SM_CSTATUS_BEGINNING_OF_ROUTINE = -1;
public const int LSPS_GALIL_SM_CSTATUS_COMPLETED_ROUTINE = 1;
public const int LSPS_GALIL_SM_PSTATUS_PROFILE_ITT_ERR = -1;
public const int LSPS_GALIL_SM_PSTATUS_NO_PROFILE_LOADED = 0;
public const int LSPS_GALIL_SM_PSTATUS_LOADING_PROFILE = 1;
public const int LSPS_GALIL_SM_PSTATUS_FINISHED_LOADING_PROFILE = 2;
public const int LSPS_GALIL_SM_PSTATUS_MOVING_TO_START = 3;
public const int LSPS_GALIL_SM_PSTATUS_FINISHED_MOVING_TO_START = 4;
public const int LSPS_GALIL_SM_PSTATUS_RUNNING_PROFILE = 5;
public const int LSPS_NEEDS_HOME = 0;
public const int LSPS_TW_POS_HOME = 1;
public const int LSPS_TW_STATUS_HOMING = 1;
public const int LSPS_TW_STATUS_MOVING = 2;
public const int LSPS_TW_STATUS_HOME_SWITCH_ERR = 3;
public const int LSPS_TW_STATUS_POS_SWITCH_ERR = 4;
public const int LSPS_TW_STATUS_FIND_POS_ERR = 5;
public const int LSPS_TW_STATUS_FIND_HOME_ERR = 6;
public const int LSPS_TW_STATUS_IN_POSITION = 7;
public const int LSPS_FW_POS_MOVING = -1;
public const int LSPS_FW_POS_NEEDS_HOME = -2;
public const int LSPS_FW_POS_LIMIT_SW_ERR = -3;
public const int LSPS_FW_POS_HOME = 1;
public const int LSPS_FW_STATUS_HOMING = 1;
public const int LSPS_FW_STATUS_MOVING = 2;
public const int LSPS_FW_STATUS_HOME_SW_ERR = 3;
public const int LSPS_FW_STATUS_POS_SW_ERR = 4;
public const int LSPS_FW_STATUS_FIND_POS_ERR = 5;
public const int LSPS_FW_STATUS_FIND_HOME_ERR = 6;
public const int LSPS_FW_STATUS_IN_POSITION = 7;
public const int LSPS_FW_STATUS_TIMEOUT = 8;
}
}

View File

@@ -0,0 +1,273 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Raytheon.Instruments.LSPS
{
/// <summary>
/// Class for TCP client communication
/// </summary>
internal class TcpClientSock
{
private Socket sock_;
private string remoteAddress_;
private int remotePort_;
IPEndPoint remoteEP_;
IPAddress ipAddress_ = null;
private static object _syncObj = new object();
/// <summary>
/// Constructor
/// </summary>
/// <param name="remoteAddress"></param>
/// <param name="remotePort"></param>
public TcpClientSock(string remoteAddress, int remotePort)
{
remoteAddress_ = remoteAddress;
remotePort_ = remotePort;
// if remoteAddress is a hostname
if (!IPAddress.TryParse(remoteAddress_, out ipAddress_))
{
string preferredSubnet = "";
IPHostEntry host = Dns.GetHostEntry(remoteAddress_);
foreach (IPAddress ip in host.AddressList)
{
AddressFamily af = ip.AddressFamily;
if (af == AddressFamily.InterNetwork)
{
if (preferredSubnet != String.Empty)
{
if (Regex.IsMatch(ip.ToString(), preferredSubnet, RegexOptions.IgnoreCase))
ipAddress_ = ip;
}
else
ipAddress_ = ip;
if (ipAddress_ != null)
break;
}
}
}
if (ipAddress_ != null)
{
remoteEP_ = new IPEndPoint(ipAddress_, remotePort_);
}
else
throw new Exception("Unable to connect to " + remoteAddress_);
sock_ = new Socket(ipAddress_.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
}
/// <summary>
/// Connect to remote host
/// </summary>
/// <returns></returns>
public void Connect()
{
lock (_syncObj)
{
try
{
if (!sock_.Connected && IsRemoteHostAlive())
sock_.Connect(remoteEP_);
}
catch (ObjectDisposedException)
{
sock_ = new Socket(ipAddress_.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
if (IsRemoteHostAlive())
sock_.Connect(remoteEP_);
}
catch (Exception) { throw; }
}
}
/// <summary>
/// Disconnect from remote host
/// </summary>
/// <returns></returns>
public void Disconnect()
{
lock (_syncObj)
{
if (sock_.Connected)
{
sock_.Shutdown(SocketShutdown.Both);
sock_.Disconnect(true);
sock_.Close();
}
}
}
/// <summary>
/// Ping if remote host is alive
/// </summary>
/// <returns>true/false</returns>
bool IsRemoteHostAlive()
{
bool isRemoteHostAlive = true;
//Do a ping test to see if the server is reachable
try
{
Ping pingTest = new Ping();
PingReply reply = pingTest.Send(ipAddress_);
if (reply.Status != IPStatus.Success)
isRemoteHostAlive = false;
}
catch (PingException)
{
isRemoteHostAlive = false;
}
//See if the tcp state is ok
if (sock_.Poll(5000, SelectMode.SelectRead) && (sock_.Available == 0))
{
isRemoteHostAlive = false;
}
return isRemoteHostAlive;
}
/// <summary>
/// Send Command and Get Response
/// </summary>
/// <param name="command"></param>
/// <param name="responseTimeOutMs"></param>
/// <param name="responseBufSize"></param>
/// <returns>response in ASCII format</returns>
public string SendCommandAndGetResponse(string command, int responseTimeOutMs = 5000, int responseBufSize = 1024)
{
byte[] bytes = new byte[responseBufSize];
sock_.ReceiveTimeout = responseTimeOutMs;
int bytesRec = 0;
byte[] msg = Encoding.ASCII.GetBytes(command);
lock (_syncObj)
{
sock_.Send(msg);
try
{
bytesRec = sock_.Receive(bytes);
}
catch (SocketException ex)
{
throw new Exception("SocketException Error Code: " + ex.ErrorCode + $" ({((SocketError)ex.ErrorCode).ToString()})");
}
}
return Encoding.ASCII.GetString(bytes, 0, bytesRec);
}
/// <summary>
/// Read data from the device.
/// </summary>
/// <param name="dataBuf"></param>
/// <param name="responseTimeOutMs"></param>
/// <returns>The number of bytes read</returns>
public int Read(ref byte[] dataBuf, int responseTimeOutMs = 5000)
{
int bytesRec = 0;
sock_.ReceiveTimeout = responseTimeOutMs;
lock (_syncObj)
{
try
{
bytesRec = sock_.Receive(dataBuf);
}
catch (SocketException)
{
bytesRec = 0;
}
}
return bytesRec;
}
/// <summary>
/// Write data to device.
/// </summary>
/// <param name="dataBuf"></param>
/// <returns>The number of bytes written</returns>
public int Write(byte[] dataBuf)
{
int bytesWritten = 0;
lock (_syncObj)
{
try
{
bytesWritten = sock_.Send(dataBuf);
}
catch (SocketException)
{
bytesWritten = 0;
}
}
return bytesWritten;
}
/// <summary>
/// Write data to device.
/// </summary>
/// <param name="data"></param>
/// <returns>The number of bytes written</returns>
public int Write(string data)
{
int bytesWritten = 0;
byte[] msg = Encoding.ASCII.GetBytes(data);
lock (_syncObj)
{
try
{
bytesWritten = sock_.Send(msg);
}
catch (SocketException)
{
bytesWritten = 0;
}
}
return bytesWritten;
}
/// <summary>
/// Clear Hardware Receiver Buffer of residual data
/// </summary>
/// <returns>none</returns>
public void ClearReceiveBuffer()
{
byte[] bytes = new byte[1024];
sock_.ReceiveTimeout = 100;
int bytesRec = 0;
lock (_syncObj)
{
do
{
try
{
bytesRec = sock_.Receive(bytes);
}
catch (SocketException)
{
bytesRec = 0;
}
} while (bytesRec > 0);
}
}
}
}