Initialization of 30 components changed, done in Initialize( ).

This commit is contained in:
Milan Hanajik
2021-04-03 00:54:27 +02:00
parent cb1a66381f
commit a58fe1f997
30 changed files with 347 additions and 445 deletions
+19 -34
View File
@@ -24,7 +24,6 @@ namespace TBF.Rig.Network.Comet.Ambient
readonly AmbientCfg myCfg;
readonly IPAddress ipAddress;
readonly int tcpPort;
TcpClient tcpClient;
NetworkStream networkStream;
@@ -39,9 +38,6 @@ namespace TBF.Rig.Network.Comet.Ambient
State state;
/// <summary>The state of the measurement</summary>
MsrmntState msrmntState;
///
/// Measured values when MsrmntState == MsrmntState.Valid
///
@@ -52,9 +48,8 @@ namespace TBF.Rig.Network.Comet.Ambient
/// <summary>Measurement time stamp when MsrmntState == MsrmntState.Valid</summary>
int msrmntTimeStamp;
public Ambient()
{
}
public Ambient() { }
/// <summary>
/// Ambient temperature / humidity / pressure meter 'Greco' connected via serial interface (RS232)
@@ -63,35 +58,28 @@ namespace TBF.Rig.Network.Comet.Ambient
: base(cfg)
{
myCfg = cfg as AmbientCfg;
if (myCfg == null) throw new ArgumentNullException("No configuration");
ipAddress = IPAddress.Parse(myCfg.IPAddress);
tcpPort = myCfg.TcpPort;
log.Warn(this.ToString());
}
public void Initialize()
public override void Initialize()
{
if (myCfg.DebugLevel == DebugMode.Simulate)
{
temperature = 20.0;
humidity = 40.0;
pressure = 1.0;
msrmntTimeStamp = StateMachine.Time;
msrmntState = MsrmntState.Valid;
log.FatalFormat("Ambient: temperature = {0:F1} C, humidity = {1:F1} %, pressure = {2:F0} mbar", temperature, humidity, 1000 * pressure);
return;
}
tcpClient = new TcpClient();
tcpClient.Connect(ipAddress, tcpPort);
networkStream = tcpClient.GetStream();
state = State.Idle;
msrmntState = MsrmntState.Busy;
log.FatalFormat("Initialization successful: {0}", this.ToString());
if (myCfg.DebugLevel == DebugMode.Simulate)
{
temperature = 20.0;
humidity = 40.0;
pressure = 1.0;
msrmntTimeStamp = StateMachine.Time;
log.FatalFormat("{0} - Device simulated", Name);
}
else
{
tcpClient = new TcpClient();
tcpClient.Connect(ipAddress, myCfg.TcpPort);
networkStream = tcpClient.GetStream();
state = State.Idle;
log.FatalFormat("{0} - Device successfully initialized", Name);
}
}
/// <summary>Run this device</summary>
@@ -123,7 +111,6 @@ namespace TBF.Rig.Network.Comet.Ambient
value = (int)bytes[9] * 256 + (int)bytes[10];
temperature = value / 10.0; /// Conversion to °C
msrmntTimeStamp = StateMachine.Time;
msrmntState = MsrmntState.Valid;
log.InfoFormat("Ambient temperature = {0:F1} C", temperature);
state = State.Idle;
break;
@@ -131,7 +118,6 @@ namespace TBF.Rig.Network.Comet.Ambient
value = (int)bytes[9] * 256 + (int)bytes[10];
humidity = value / 10.0; /// Conversion to R%
msrmntTimeStamp = StateMachine.Time;
msrmntState = MsrmntState.Valid;
log.InfoFormat("Ambient humidity = {0:F1} %", humidity);
state = State.Idle;
break;
@@ -139,7 +125,6 @@ namespace TBF.Rig.Network.Comet.Ambient
value = (int)bytes[9] * 256 + (int)bytes[10];
pressure = value / 10000.0; /// Conversion to bar
msrmntTimeStamp = StateMachine.Time;
msrmntState = MsrmntState.Valid;
log.InfoFormat("Ambient pressure = {0:F0} mbar", 1000 * pressure);
state = State.Idle;
break;