| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- using GSG.NET.Concurrent;
- using GSG.NET.Logging;
- using NetMQ.Sockets;
- using NetMQ;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using NetMQ.Monitoring;
- namespace OHVDriveLogger
- {
- public class ZmqManager
- {
- Logger logger = Logger.GetLogger();
- SubscriberSocket sub = null;
- NetMQPoller poller = null;
- private bool isReqConnected;
- public bool IsReqConnected
- {
- get { return isReqConnected; }
- set { isReqConnected = value; }
- }
- private bool isDriveMoving = false;
- public bool IsDriveMoving
- {
- get { return isDriveMoving; }
- set { isDriveMoving = value; }
- }
- private double frontLoadFacter;
- public double FrontLoadFacter
- {
- get { return frontLoadFacter * 0.1; }
- set { frontLoadFacter = value; }
- }
- private double rearLoadFacter;
- public double RearLoadFacter
- {
- get { return rearLoadFacter * 0.1; }
- set { rearLoadFacter = value; }
- }
- private double frontRPM;
- public double FrontRPM
- {
- get { return Math.Truncate( frontRPM * 10 )/10; }
- set { frontRPM = value; }
- }
- private double rearRPM;
- public double RearRPM
- {
- get { return Math.Truncate( rearRPM * 10 ) / 10; }
- set { rearRPM = value; }
- }
- private double batteryCurrent;
- public double BatteryCurrent
- {
- get { return batteryCurrent; }
- set { batteryCurrent = value; }
- }
- private int currentPoint;
- public int CurrentPoint
- {
- get { return currentPoint; }
- set { currentPoint = value; }
- }
- private string currentRailForm;
- public string CurrentRailForm
- {
- get { return currentRailForm; }
- set { currentRailForm = value; }
- }
- private string currentMCR = "0";
- public string CurrentMCR
- {
- get { return currentMCR; }
- set { currentMCR = value; }
- }
- private string isContain;
- public string IsContain
- {
- get { return isContain; }
- set { isContain = value; }
- }
- private string batteryVoltage;
- public string BatteryVoltage
- {
- get { return batteryVoltage; }
- set { batteryVoltage = value; }
- }
- private string batterySOC;
- public string BatterySOC
- {
- get { return batterySOC; }
- set { batterySOC = value; }
- }
- public ZmqManager()
- {
- NetMQ.NetMQConfig.Cleanup();
- }
- public void Init()
- {
- sub = new SubscriberSocket();
- sub.Connect( "tcp://127.0.0.1:5565" );
- sub.Connect( "tcp://127.0.0.1:5570" );
- sub.Subscribe( "" ); //All
- sub.ReceiveReady += Sub_ReceiveReady;
- this.poller = new NetMQPoller { this.sub };
- this.poller.RunAsync();
- }
- public void Dispose()
- {
- this.poller.Stop();
- this.poller.Dispose();
- this.sub.Dispose();
- }
- private void Sub_ReceiveReady( object sender, NetMQ.NetMQSocketEventArgs e )
- {
- var ret = e.Socket.ReceiveMultipartStrings();
- //logger.I( ret );
- try
- {
- var v = ret[1].Split( '/' );
- switch ( ret[0] )
- {
- case "7028":
- this.FrontRPM = Convert.ToDouble( v[0] );
- this.RearRPM = Convert.ToDouble( v[1] );
- break;
- case "7030":
- this.FrontLoadFacter = Convert.ToDouble( v[0] );
- this.RearLoadFacter = Convert.ToDouble( v[1] );
- break;
- case "7121":
- this.CurrentMCR = v[0];
- break;
- case "Contain":
- this.IsContain = v[0];
- break;
- case "BatteryCurrent":
- this.BatteryCurrent = Convert.ToDouble( v[0] );
- break;
- case "BatteryVoltage":
- this.BatteryVoltage = v[0];
- break;
- case "BatterySOC":
- this.BatterySOC = v[0];
- break;
- case "DriveStart":
- if ( v[0].Equals( "True" ) )
- this.IsDriveMoving = true;
- else
- this.IsDriveMoving = false;
- break;
- case "CurrentPoint":
- CurrentPoint = Convert.ToInt32( v[0] );
- break;
- case "CurrentRailFrom":
- CurrentRailForm = v[0];
- break;
- default:
- break;
- }
- }
- catch ( Exception excpetion )
- {
- logger.E( excpetion );
- }
- }
- }
- }
|