|
|
@@ -3,6 +3,7 @@ using System.Threading;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Media;
|
|
|
using GSG.NET.Logging;
|
|
|
+using GSG.NET.Quartz;
|
|
|
using OHVConnector;
|
|
|
|
|
|
namespace OHVProtocolServer
|
|
|
@@ -22,6 +23,8 @@ namespace OHVProtocolServer
|
|
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
+ QuartzUtils.Init( 10 );
|
|
|
+
|
|
|
double b = 1;
|
|
|
var s = b.ToString("00.00").Replace(".", "");
|
|
|
|
|
|
@@ -58,8 +61,146 @@ namespace OHVProtocolServer
|
|
|
private void Manager_OnRecd(OCSMessage msg)
|
|
|
{
|
|
|
logger.I(msg.LogFormat());
|
|
|
+
|
|
|
+ switch ( msg.Kind )
|
|
|
+ {
|
|
|
+ case OHVConnector.eKind.Unknown:
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.E://Error 보고 요청.
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.S://마지막으로 읽은 TagNo
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.B://battery Report
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.T://위치 응답
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.C://제어 요청
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.P://수동명령보고
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.I:
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.O:
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.A://Alive
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.L:
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.U:
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.F:
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.M:
|
|
|
+ ReceiveMCommand( msg );
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.R:
|
|
|
+ ReceiveRCommand( msg );
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.H:
|
|
|
+ break;
|
|
|
+ case OHVConnector.eKind.Z:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ void Reply( OCSMessage recieve )
|
|
|
+ {
|
|
|
+ var reply = new OCSMessage();
|
|
|
+ reply.Kind = recieve.Kind;
|
|
|
+ reply.Tag = recieve.Tag;
|
|
|
+ reply.SubCode = recieve.SubCode;
|
|
|
+ this.manager.Reply( reply );
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private void ReceiveRCommand( OCSMessage msg )
|
|
|
+ {
|
|
|
+ this.Reply( msg );
|
|
|
+
|
|
|
+ if ( msg.SubCode.Equals( "100" ) )
|
|
|
+ {
|
|
|
+ int tag = Convert.ToInt32( this.txtTag.Text );
|
|
|
+ Send_Scmd( tag );
|
|
|
+ }
|
|
|
+ if ( msg.SubCode.Equals( "010" ) )
|
|
|
+ {
|
|
|
+ Send_Bcmd( 12.34 );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Send_Scmd( int point )
|
|
|
+ {
|
|
|
+ var msg = new OCSMessage();
|
|
|
+ msg.Kind = eKind.S;
|
|
|
+ msg.Tag = point.ToString( "0000" );
|
|
|
+ msg.SubCode = this.txtSubCode.Text;
|
|
|
+
|
|
|
+ this.manager.Send( msg );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void ReceiveMCommand( OCSMessage msg )
|
|
|
+ {
|
|
|
+ this.Reply( msg );
|
|
|
+
|
|
|
+ //var info = sql.VehicleInfoDAL.GetInfo();
|
|
|
+ //if ( info.MachineMode == eMachineMode.LocalMode )
|
|
|
+ //{
|
|
|
+ // logger.E( $"[OCS] Cmd - Current Mode Local Mode " );
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
+
|
|
|
+ //var hasCommand = this.sql.CommandDAL.GetCmd();
|
|
|
+ //if ( hasCommand != null )
|
|
|
+ //{
|
|
|
+ // //Todo: 충전 중에는 어떻게 하지???
|
|
|
+ // if ( !hasCommand.IsSecondCommanded )
|
|
|
+ // sql.CommandDAL.Delete( hasCommand );
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // logger.E( $"[OCS] Cmd - {msg.Kind} Message Tag [{msg.Tag}] - Already Load/Unload " );
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+
|
|
|
+ //}
|
|
|
+
|
|
|
+ //var cmd = new Command();
|
|
|
+
|
|
|
+ //switch ( msg.SubCode )
|
|
|
+ //{
|
|
|
+ // case "000": //Move
|
|
|
+ // cmd.Type = eCommandType.Move;
|
|
|
+ // break;
|
|
|
+ // case "001": //Move and Load
|
|
|
+ // cmd.Type = eCommandType.MoveNLoad;
|
|
|
+ // break;
|
|
|
+ // case "002": //Move and Unload
|
|
|
+ // cmd.Type = eCommandType.MoveNUnload;
|
|
|
+ // break;
|
|
|
+ // case "003": //Move and Charge
|
|
|
+ // cmd.Type = eCommandType.Charging;
|
|
|
+ // break;
|
|
|
+ // default:
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
+
|
|
|
+ ////Todo: 등록 되어 있는 경로 가 있는 지 확인 필요.
|
|
|
+ //var route = this.sql.RouteDal.GetRouteFromOCSMatchID( msg.Tag );
|
|
|
+ //if ( route == null )
|
|
|
+ //{
|
|
|
+ // logger.E( $"[OCS] Message Tag [{msg.Tag}] - not found route" );
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
+
|
|
|
+ //cmd.TargetID = route.Name;
|
|
|
+
|
|
|
+ //this.sql.CommandDAL.Add( cmd );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void Manager_OnLog(string id, string log)
|
|
|
{
|
|
|
logger.I(log);
|
|
|
@@ -73,11 +214,31 @@ namespace OHVProtocolServer
|
|
|
private void Con_OnHsmsDiscontd(string id, Exception e)
|
|
|
{
|
|
|
this.btnConnect.Background = Brushes.Gray;
|
|
|
+
|
|
|
+ QuartzUtils.StopSchedule( "BatteryReport" );
|
|
|
}
|
|
|
|
|
|
private void Con_OnHsmsContd(string id)
|
|
|
{
|
|
|
this.btnConnect.Background = Brushes.Green;
|
|
|
+
|
|
|
+ QuartzUtils.Invoke( "BatteryReport", QuartzUtils.GetExpnMinute( 1 ), BatteryState_Report );
|
|
|
+ }
|
|
|
+
|
|
|
+ void BatteryState_Report()
|
|
|
+ {
|
|
|
+ Send_Bcmd( 55.12 );
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Send_Bcmd( double volt )
|
|
|
+ {
|
|
|
+ var msg = new OCSMessage();
|
|
|
+ msg.Kind = eKind.B;
|
|
|
+ var bData = volt;
|
|
|
+ msg.Tag = bData.ToString( "00.00" ).Replace( ".", "" );
|
|
|
+ msg.SubCode = this.txtSubCode.Text;
|
|
|
+
|
|
|
+ this.manager.Send( msg );
|
|
|
}
|
|
|
|
|
|
private void btnConnect_Click(object sender, RoutedEventArgs e)
|