123 lines
5.2 KiB
C#
123 lines
5.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Thermo.Active.Model.DTOModels.AlarmModels;
|
|
using YamlDotNet.Core.Tokens;
|
|
|
|
namespace Thermo.Active.CmsConnectGateway
|
|
{
|
|
public static class CMSConnectConstants
|
|
{
|
|
public const string IP_ADDR_LABEL = "IP_ADDRESS=";
|
|
public const string GATEWAY_LABEL = "DEFAULT_GATEWAY=";
|
|
public const string DNSIP_LABEL = "DNS_IP=";
|
|
public const string DNSPREFIX_LABEL = "DNS_SUFFIX=";
|
|
public const string PROXY_ADDR_LABEL = "PROXY=";
|
|
public const string NO_PROXY_LABEL = "NO_PROXY=";
|
|
public const string UNDEF_VALUE = "none";
|
|
public const string CONNECTION_OK_VALUE = "OK";
|
|
public const string CONNECTION_NOWEB_VALUE = "NO_WEB";
|
|
public const string CONNECTION_NOPORT_VALUE = "NO_PORTS";
|
|
|
|
public const int REBOOT_MINUTES_MAX = 2;
|
|
public const int REBOOT_MSWAIT_BETWEEN_OP = 500;
|
|
|
|
public const string ADMIN_COMMAND = "sudo ";
|
|
public const string SSH_SET_PROXY_COMMAND = ADMIN_COMMAND + "./setProxy.sh ";
|
|
public const string SSH_SET_DNSIP_COMMAND = ADMIN_COMMAND + "./setDnsIp.sh ";
|
|
public const string SSH_SET_DNSSUFFIX_COMMAND = ADMIN_COMMAND + "./setDnsSuffix.sh ";
|
|
public const string SSH_SET_NETWORK_COMMAND = ADMIN_COMMAND + "./setNetwork.sh ";
|
|
public const string SSH_GET_NETWORK_COMMAND = ADMIN_COMMAND + "./getNetworkConfiguration.sh ";
|
|
public const string SSH_GET_PROXY_COMMAND = ADMIN_COMMAND + "./getProxyConfiguration.sh ";
|
|
public const string SSH_TEST_CONNECTION_COMMAND = ADMIN_COMMAND + "./testConnection.sh ";
|
|
public const string SSH_GW_REBOOT_COMMAND = ADMIN_COMMAND + "./gatewayReboot.sh ";
|
|
|
|
public const string YAML_CONFIG_FILE = "./example-mconnect.conf.yaml";
|
|
|
|
|
|
public const string CONNECT_UNDEFINED = "UNDEFINED";
|
|
public const string CONNECT_MACHINE_STAUTS_EXE = "EXE";
|
|
public const string CONNECT_MACHINE_STAUTS_READY = "READY";
|
|
public const string CONNECT_MACHINE_STAUTS_SETUP = "SETUP";
|
|
public const string CONNECT_MACHINE_STAUTS_FAIL = "FAIL";
|
|
public const string CONNECT_MACHINE_STAUTS_POWEROFF = "POWER_OFF";
|
|
|
|
public const string CONNECT_PROC_STAUTS_EXE = "EXE";
|
|
public const string CONNECT_PROC_STAUTS_READY = "READY";
|
|
public const string CONNECT_PROC_STAUTS_HOLD = "HOLD";
|
|
public const string CONNECT_PROC_STAUTS_FHOLD = "FEED_HOLD";
|
|
public const string CONNECT_PROC_STAUTS_OSTOP = "OPTIONAL_STOP";
|
|
public const string CONNECT_PROC_STAUTS_PSTOPPED = "PROGRAM_STOPPED";
|
|
|
|
public const string CONNECT_PROC_MODE_AUTO = "AUTOMATIC";
|
|
public const string CONNECT_PROC_MODE_EDIT = "EDIT";
|
|
public const string CONNECT_PROC_MODE_JOG = "MANUAL_JOG";
|
|
|
|
public static string ConvertThermoToConnectStatus(int status)
|
|
{
|
|
switch (status)
|
|
{
|
|
case 0: return CONNECT_MACHINE_STAUTS_POWEROFF;
|
|
case 1: return CONNECT_MACHINE_STAUTS_READY;
|
|
case 2: return CONNECT_MACHINE_STAUTS_EXE;
|
|
case 4: return CONNECT_MACHINE_STAUTS_SETUP;
|
|
case 8: return CONNECT_MACHINE_STAUTS_FAIL;
|
|
case 16: return CONNECT_MACHINE_STAUTS_READY;
|
|
case 128: return CONNECT_MACHINE_STAUTS_FAIL;
|
|
default: return CONNECT_UNDEFINED;
|
|
}
|
|
}
|
|
|
|
public static string ConvertThermoToConnectProcessStatus(int status)
|
|
{
|
|
switch (status)
|
|
{
|
|
case 0: return CONNECT_PROC_STAUTS_READY;
|
|
case 1: return CONNECT_PROC_STAUTS_READY;
|
|
case 2: return CONNECT_PROC_STAUTS_EXE;
|
|
case 4: return CONNECT_PROC_STAUTS_FHOLD;
|
|
case 8: return CONNECT_PROC_STAUTS_OSTOP;
|
|
case 16: return CONNECT_PROC_STAUTS_HOLD;
|
|
case 128: return CONNECT_PROC_STAUTS_HOLD;
|
|
default: return CONNECT_UNDEFINED;
|
|
}
|
|
}
|
|
public static string ConvertThermoToConnectProcessMode(int status)
|
|
{
|
|
switch (status)
|
|
{
|
|
case 1: return CONNECT_PROC_MODE_EDIT;
|
|
case 2: return CONNECT_PROC_MODE_AUTO;
|
|
case 4: return CONNECT_PROC_MODE_JOG;
|
|
default: return CONNECT_UNDEFINED;
|
|
}
|
|
}
|
|
|
|
public static bool ConvertThermoToConnectPower(int status)
|
|
{
|
|
switch (status)
|
|
{
|
|
case 0: return false;
|
|
default: return true;
|
|
}
|
|
}
|
|
public static bool ConvertThermoToConnectMachineAlarm(DTOAlarmsModel alarms)
|
|
{
|
|
return alarms.PlcAlarms.Count > 0;
|
|
}
|
|
|
|
public static string ConvertThermoToConnectAlarms(DTOAlarmsModel alarms)
|
|
{
|
|
List<string> alms = new List<string>();
|
|
foreach (DTOPlcAlarmModel alarm in alarms.PlcAlarms) {
|
|
int severity = alarm.IsWarning ? 500 : 900;
|
|
alms.Add(alarm.Id.ToString("D6") + "|" + severity);
|
|
}
|
|
return string.Join(",", alms);
|
|
}
|
|
|
|
}
|
|
}
|