Skip to content

Commit

Permalink
New Remote Protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
“寧々” committed May 10, 2022
1 parent fafa0b3 commit 0e9445d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 16 deletions.
4 changes: 3 additions & 1 deletion ReservoirServer/Enterty/AMQDataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ enum AMQDataType
C0202_InfoResponse,
C0203_ChartResponse,
C0301_AlertData,
C0302_WeatherData
C0302_WeatherData,
C0401_PreReleaseData,
}

static class AMQDataTypeString
Expand All @@ -29,6 +30,7 @@ static class AMQDataTypeString
{"0203", AMQDataType.C0203_ChartResponse},
{"0301", AMQDataType.C0301_AlertData},
{"0302", AMQDataType.C0302_WeatherData},
{"0401", AMQDataType.C0401_PreReleaseData},
};

public static AMQDataType String2Type(string s)
Expand Down
17 changes: 16 additions & 1 deletion ReservoirServer/Enterty/SimpleBoxData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,22 @@ class SimpleBoxData : IBoxData

class BoxDataWithDate : SimpleBoxData
{
public DateTime @DateTime;
public DateTime @DateTime { get; set; }
}

class BoxAlertData : BoxDataWithDate
{
public DateTime DateEnd { get; set; }
public BoxAlertData() { }
public BoxAlertData(BoxDataWithDate data)
{
this.PlatformN = data.PlatformN;
this.DeviceN = data.DeviceN;
this.Type = data.Type;
this.Message = data.Message;
this.DateTime = data.DateTime;

}
}

class BoxDataHeartBeat : IBoxData
Expand Down
5 changes: 5 additions & 0 deletions ReservoirServer/Enterty/SimpleSubscribeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class SimpleSubscribeData : ISubscribeData
public object Message { get; set; }
}

class SubscribDataAlertData : SimpleSubscribeData
{
public DateTime DateEnd { get; set; }
}

public interface ISubscribeData {
//public string Type { get; set; }
}
Expand Down
2 changes: 1 addition & 1 deletion ReservoirServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace ReservoirServer
class Program
{
//TODO: Log file, Safety(Encryption), JSON error catch, system service
public static readonly string version = "1.08";
public static readonly string version = "1.09";

#if DEBUG
public static string VERSION => version + "a";
Expand Down
49 changes: 36 additions & 13 deletions ReservoirServer/SimpleBoxAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,9 @@ public void SimpleBoxDataReportHandler(string data)
_remote.SendQueue(json);
}

public void SimpleBoxDataSubscribeHandler(string json)
protected void SendDataToMultiBox(SimpleBoxData boxdata, string[] boxes)
{
SimpleSubscribeData subdata = JsonConvert.DeserializeObject<SimpleSubscribeData>(json);
SimpleBoxData boxdata = new BoxDataWithDate()
{
Type = subdata.Type,
Message = subdata.Message,
PlatformN = subdata.PlatformN,
DateTime = subdata.DateTime,
};

foreach (string bid in subdata.DeviceN)
foreach (string bid in boxes)
{
Box box = _list[bid];
if (box != null)
Expand All @@ -112,12 +103,41 @@ public void SimpleBoxDataSubscribeHandler(string json)
var client = box.ComClient;
online = (box.State == BoxState.Online);
box.locker.ExitReadLock();
if(online)
if (online)
_server.SendPack(client, senddata);
}
}
}

public void SimpleBoxDataSubscribeHandler(string json)
{
SimpleSubscribeData subdata = JsonConvert.DeserializeObject<SimpleSubscribeData>(json);
SimpleBoxData boxdata = new BoxDataWithDate()
{
Type = subdata.Type,
Message = subdata.Message,
PlatformN = subdata.PlatformN,
DateTime = subdata.DateTime,
};

SendDataToMultiBox(boxdata, subdata.DeviceN);
}

public void AlertBoxDataSubscribeHandler(string json)
{
SubscribDataAlertData subdata = JsonConvert.DeserializeObject<SubscribDataAlertData>(json);
SimpleBoxData boxdata = new BoxAlertData()
{
Type = subdata.Type,
Message = subdata.Message,
PlatformN = subdata.PlatformN,
DateTime = subdata.DateTime,
DateEnd = subdata.DateEnd
};

SendDataToMultiBox(boxdata, subdata.DeviceN);
}

public void StartJob()
{
_server.Start();
Expand Down Expand Up @@ -146,10 +166,13 @@ private void _remote_OnSubscribeReceived(string message)
case AMQDataType.C0201_RTData:
case AMQDataType.C0202_InfoResponse:
case AMQDataType.C0203_ChartResponse:
case AMQDataType.C0301_AlertData:
case AMQDataType.C0302_WeatherData:
case AMQDataType.C0401_PreReleaseData:
SimpleBoxDataSubscribeHandler(message);
break;
case AMQDataType.C0301_AlertData:
AlertBoxDataSubscribeHandler(message);
break;
}
}
catch (System.Exception ex)
Expand Down

0 comments on commit 0e9445d

Please sign in to comment.