Skip to content

Commit

Permalink
2022.03.06 修复Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
“寧々” committed Mar 6, 2022
1 parent 0f91f45 commit 5919a75
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
8 changes: 7 additions & 1 deletion ReservoirServer/BoxStateReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ private void Timer_Elapsed(object sender, ElapsedEventArgs e)

private void Report(KeyValuePair<string, Box> val)
{
Box box = val.Value;
try
{
Box box = val.Value;

DateTime now = DateTime.Now;

box.locker.EnterWriteLock();
Expand Down Expand Up @@ -99,6 +100,11 @@ private void Report(KeyValuePair<string, Box> val)
{
Console.Error.WriteLine(ex.ToString());
}
finally
{
box.locker.ExitWriteLock();
box.locker.ExitReadLock();
}

}

Expand Down
6 changes: 6 additions & 0 deletions ReservoirServer/Enterty/SimpleBoxData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ class SimpleBoxData : IBoxData
public string PlatformN { get; set; }
public string DeviceN { get; set; }
public string Type { get; set; }


public object Message { get; set; }

}

class BoxDataWithDate : SimpleBoxData
{
public DateTime @DateTime;
}

class BoxDataHeartBeat : IBoxData
{
public string PlatformN { get; set; }
Expand Down
1 change: 1 addition & 0 deletions ReservoirServer/GlobalConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static class GlobalConfig
public static string TopicName => ini.GetValue("activemq", "topicname");
public static byte ReporterMaxCoreUsage => (byte)ini.GetInteger("reporter", "maxcoreusage");
public static int ReportInterval => ini.GetInteger("reporter", "reportinterval");
public static string BoxServerCharset=> ini.GetValue("boxserver", "charset");

public static void ParseConfigFile(string fname)
{
Expand Down
4 changes: 3 additions & 1 deletion ReservoirServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
Expand All @@ -15,7 +16,7 @@ namespace ReservoirServer
class Program
{
//TODO: Log file, Safety(Encryption), JSON error catch, system service
public static readonly string version = "1.05";
public static readonly string version = "1.06";

#if DEBUG
public static string VERSION => version + "a";
Expand All @@ -32,6 +33,7 @@ class Program
static void Main(string[] args)
{
CommandParser cmd = new CommandParser(args);
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
string inipath = null;
bool ver = false;
cmd.Parse(out inipath, out logpath, out ver);
Expand Down
5 changes: 3 additions & 2 deletions ReservoirServer/SimpleBoxAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ public void SimpleBoxDataReportHandler(string data)
public void SimpleBoxDataSubscribeHandler(string json)
{
SimpleSubscribeData subdata = JsonConvert.DeserializeObject<SimpleSubscribeData>(json);
SimpleBoxData boxdata = new SimpleBoxData()
SimpleBoxData boxdata = new BoxDataWithDate()
{
Type = subdata.Type,
Message = subdata.Message,
PlatformN = subdata.PlatformN,
DateTime = subdata.DateTime,
};

foreach (string bid in subdata.DeviceN)
Expand All @@ -105,7 +106,7 @@ public void SimpleBoxDataSubscribeHandler(string json)
if (box != null)
{
boxdata.DeviceN = bid;
string senddata = JsonConvert.SerializeObject(boxdata);
string senddata = JsonConvert.SerializeObject(boxdata, jsonSettings);
box.locker.EnterReadLock();
var client = box.ComClient;
box.locker.ExitReadLock();
Expand Down
7 changes: 5 additions & 2 deletions ReservoirServer/SimpleBoxServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace ReservoirServer
public delegate void OnBoxDisconnectedDlg(IComClient client);
public delegate void OnBoxDataRecDlg(IComClient client, string data);


class SimpleBoxServer
{
BoxTCPDriver tcpserver = new BoxTCPDriver();
Expand All @@ -23,6 +24,8 @@ class SimpleBoxServer
public virtual event OnBoxDisconnectedDlg OnBoxDisconnected;
public virtual event OnBoxDataRecDlg OnBoxDataRec;

private string _charset = GlobalConfig.BoxServerCharset;

public SimpleBoxServer(string serverID, IPAddress ip, ushort port)
{
this.PlatformID = serverID;
Expand All @@ -37,7 +40,7 @@ public SimpleBoxServer(string serverID, IPAddress ip, ushort port)
public virtual void SendPack(IComClient client,string data)
{

tcpserver.SendDataAsync(client, Encoding.UTF8.GetBytes(data));
tcpserver.SendDataAsync(client, Encoding.GetEncoding(_charset).GetBytes(data));
}

protected virtual void Tcpserver_OnTransmitError(IComClient client, Exception ex)
Expand All @@ -47,7 +50,7 @@ protected virtual void Tcpserver_OnTransmitError(IComClient client, Exception ex

protected virtual void Tcpserver_OnComDataReceived(IComClient client, byte[] data)
{
string s = Encoding.UTF8.GetString(data);
string s = Encoding.GetEncoding(_charset).GetString(data);
OnBoxDataRec?.Invoke(client, s);
}

Expand Down

0 comments on commit 5919a75

Please sign in to comment.