Commit 29995785 authored by 潘栩锋's avatar 潘栩锋 :bicyclist:

Merge remote-tracking branch 'remotes/origin/dev8.0-hongrui' into dev8.0-filmCasting

......@@ -454,22 +454,28 @@ namespace FlyADBase
{
if (!IsConnected)
{
//没有连接,复位计数
position_no_changed_cnt = 0;
return;
}
if (DriveStatus != DRIVE_MAN_STATUS.RUNNING)
{
//当前状态不是在运行中,复位计数
position_no_changed_cnt = 0;
return;
}
if (Position != last_position)
{
//当前位置 与 之前不一样, 位置发生了变化, 正常。
last_position = Position;
//复位计数
position_no_changed_cnt = 0;
Is10sNoMove = false;
return;
}
position_no_changed_cnt++;
if (position_no_changed_cnt >= 10)
{
......@@ -477,10 +483,13 @@ namespace FlyADBase
//异常
DriveStatus = DRIVE_MAN_STATUS.STOP_MANUAL;
position_no_changed_cnt = 0;
Is10sNoMove = true;
logger.Error($"当前状态=RUNNING, 但连续10秒,脉冲一样({Position}p)");
return;
}
if (driveman_wait.CheckMark(TimeSpan.FromSeconds(2)))//每2秒检查一次
if (driveman_wait.CheckMark(TimeSpan.FromSeconds(2)))
{
//每2秒检查一次
driveman_wait.Mark();
CurrObjSys.GetValueEx(
conn,
......
......@@ -52,6 +52,11 @@ namespace FlyADBase
/// </summary>
public bool IsFinish { get; set; }
/// <summary>
/// 运行状态,10秒也没有动
/// </summary>
public bool Is10sNoMove { get; set; }
/// <summary>
/// 机架修正
/// </summary>
......
......@@ -94,6 +94,10 @@ namespace FlyADBase
/// </summary>
bool IsFinish { get; }
/// <summary>
/// 运行状态,10秒也没有动
/// </summary>
bool Is10sNoMove { get; }
/// <summary>
/// ad滞后修正 单位ms
......
......@@ -12,9 +12,9 @@ namespace Misc
{
public event PropertyChangedEventHandler PropertyChanged;
public string Language { get; set; } = "zh";
public string filePath = "culture.json";
string dirPath;
protected string dirPath;
public List<string> langs { get; } = new List<string>();
static Dictionary<string, string> langInfos;
......
using FLY.Thick.RemoteHistory;
using FObjBase;
using SQLite;
using SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FLY.OBJComponents.Common
{
public class FlyData_WarningHistory : IFlyData,IDbBase
/// <summary>
/// 数据库的 ERROR
/// </summary>
public class FlyData_WarningHistory : IDbBase
{
/// <summary>
/// ID
/// </summary>
public Int64 ID { get; set; }
/// <summary>
/// 时间
......@@ -48,41 +47,12 @@ namespace FLY.OBJComponents.Common
Time = Time,
ErrCode = ErrCode,
State = State,
Description = Description
Description = Description,
Accessory = Accessory,
ID = ID,
CanReset = CanReset
};
}
public string GetHeader()
{
return "时间,出错码,状态,描述";
}
public bool TryParse(string header, string str)
{
string[] items = str.Split(new char[] { ',' });
if (items.Length < 4)
return false;
DateTime dt;
if (DateTime.TryParse(items[0], out dt))
Time = dt;
else
return false;
int b;
if (int.TryParse(items[1], out b))
ErrCode = b;
else
return false;
ERR_STATE state;
if (Enum.TryParse<ERR_STATE>(items[2], out state))
State = state;
else
return false;
Description = items[3];
return true;
}
public override string ToString()
{
......@@ -91,6 +61,8 @@ namespace FLY.OBJComponents.Common
str += "," + ErrCode.ToString();
str += "," + State.ToString();
str += "," + Description;
if (!string.IsNullOrEmpty(Accessory))
str += "," + Accessory;
return str;
}
}
......
......@@ -79,14 +79,11 @@
<Compile Include="Server.OBJProxy\PLCProxySystem_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\RemoteHistory_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\SyncProp_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\WarningSystem_OBJProxy.cs" />
<Compile Include="Server\Buffer.cs" />
<Compile Include="Server\BufferSQLite.cs" />
<Compile Include="Server\BufferStorage.cs" />
<Compile Include="Server\BufferError.cs" />
<Compile Include="Server\BulkDbSQLite.cs" />
<Compile Include="Server\ErrorConf.cs" />
<Compile Include="Server\History.cs" />
<Compile Include="Server\JsonDist.cs" />
<Compile Include="Server\Model\DB_Error.cs" />
<Compile Include="Server\Model\IErrorDBModel.cs" />
......@@ -94,7 +91,6 @@
<Compile Include="Server\PeriodicallySaveData.cs" />
<Compile Include="Server\PLCProxySystem.cs" />
<Compile Include="Server\WarningSystem2.cs" />
<Compile Include="Server\WarningSystem.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="FodyWeavers.xml">
......
using FLY.OBJComponents.Common;
using FLY.OBJComponents.OBJ_INTERFACE;
using FObjBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FLY.OBJComponents.Server.OBJProxy
{
public class WarningSystem_OBJProxy : FObj
{
#region 延时推送 MARKNO
const int MARKNO_PUSH_PARAMS = 1;
const int MARKNO_PUSH_REASONLIST = 2;
const int MARKNO_PUSH_NEWESTLIST = 3;
#endregion
WarningSystem mWarningSystem;
Buffer_OBJProxy<FlyData_WarningHistory> mReasonListOBJProxy;
Buffer_OBJProxy<FlyData_WarningHistory> mNewestListOBJProxy;
/// <summary>
/// 使用id,id+1,id+2
/// </summary>
/// <param name="objsys_idx"></param>
/// <param name="id"></param>
/// <param name="warningSystem"></param>
public WarningSystem_OBJProxy(int objsys_idx, uint id, WarningSystem warningSystem)
: base(objsys_idx)
{
ID = id;
mWarningSystem = warningSystem;
mWarningSystem.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mWarningSystem_PropertyChanged);
mReasonListOBJProxy = new Buffer_OBJProxy<FlyData_WarningHistory>(objsys_idx, id+1, mWarningSystem.ReasonList);
mNewestListOBJProxy = new Buffer_OBJProxy<FlyData_WarningHistory>(objsys_idx, id+2, mWarningSystem.NewestList);
}
void mWarningSystem_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
Dictionary<string, object> p = new Dictionary<string, object>();
p.Add(e.PropertyName, Misc.PropertiesManager.GetValue(mWarningSystem, e.PropertyName));
string json = JsonConvert.SerializeObject(p);
CurrObjSys.PushObjInfoEx(
this, WARNING_OBJ_INTERFACE.PUSH_PARAMS,
Misc.Converter.StringToBytes(json)
);
}
public override void GetValue(IFConn from, uint srcid, ushort memid, out byte[] infodata)
{
switch (memid)
{
case WARNING_OBJ_INTERFACE.GET_PARAMS:
{
Dictionary<string, object> p = new Dictionary<string, object>();
//IEnumerable<string> propertynames = Misc.PropertiesManager.GetAllPropertyNames(mWarningSystem);
string[] propertynames = mWarningSystem.GetPropertys();
foreach (string pn in propertynames)
{
p.Add(pn, Misc.PropertiesManager.GetValue(mWarningSystem, pn));
}
string json = JsonConvert.SerializeObject(p);
infodata = Misc.Converter.StringToBytes(json);
}
break;
default:
infodata = null;
break;
}
}
public override void SetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
{
switch (memid)
{
case WARNING_OBJ_INTERFACE.SET_PARAMS:
{
string json = Misc.Converter.BytesToString(infodata);
Dictionary<string, object> datas = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
foreach (KeyValuePair<string, object> kv in datas)
{
PropertiesManager_JSON.SetValue(this, kv.Key, kv.Value);
}
return;
}
break;
}
}
public override void CallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] infodata)
{
switch (funcid)
{
case WARNING_OBJ_INTERFACE.CALL_RESET:
mWarningSystem.Reset();
break;
case WARNING_OBJ_INTERFACE.CALL_SILENCE:
mWarningSystem.Silence();
break;
}
}
}
}
......@@ -26,7 +26,8 @@ namespace FLY.OBJComponents.Server
Time = lc.Time,
ErrCode = lc.ErrCode,
Descrption = lc.Description,
IsOn = lc.State == ERR_STATE.ON
IsOn = lc.State == ERR_STATE.ON,
Accessory = lc.Accessory
};
}
static FlyData_WarningHistory mapDb2Lc(Db_Error db)
......@@ -37,7 +38,8 @@ namespace FLY.OBJComponents.Server
Time = db.Time,
ErrCode = db.ErrCode,
Description = db.Descrption,
State = db.IsOn? ERR_STATE.ON: ERR_STATE.OFF
State = db.IsOn? ERR_STATE.ON: ERR_STATE.OFF,
Accessory = db.Accessory
};
}
}
......
using FLY.OBJComponents.Common;
using FLY.Thick.RemoteHistory;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Threading;
namespace FLY.OBJComponents.Server
{
/// <summary>
/// 使用csv文件保存数据的buffer, T必须是 IFlyData
/// </summary>
/// <typeparam name="T"></typeparam>
public class BufferStorage<T> : Buffer<T>
where T : IFlyData, new()
{
/// <summary>
/// 多少分钟保存一次数据
/// </summary>
TimeSpan SaveInterval = TimeSpan.FromMinutes(5);
/// <summary>
/// 5分钟时间不动作保存数据
/// </summary>
DispatcherTimer timer;
/// <summary>
/// 数据改变
/// </summary>
bool hasChanged = false;
/// <summary>
/// 保存的数据路径
/// </summary>
string FilePath;
/// <summary>
///
/// </summary>
/// <param name="filepath">数据存储路径</param>
/// <param name="saveInterval">数据保存周期时间 单位:分钟</param>
/// <param name="capacity">数据总容量</param>
public BufferStorage(string filepath, int saveInterval = 5, int capacity = 1000) : base(capacity)
{
FilePath = filepath;
SaveInterval = TimeSpan.FromMinutes(saveInterval);
Load();
if (saveInterval > 0)
{
timer = new DispatcherTimer();
timer.Interval = SaveInterval;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
this.BufferChanged += BufferStorage_BufferChanged;
}
private void BufferStorage_BufferChanged(object sender, NotifyBufferChangedEventArgs<T> e)
{
hasChanged = true;
}
/// <summary>
/// N分钟执行一次
/// </summary>
void timer_Tick(object sender, EventArgs e)
{
if (hasChanged)
{
Save();
}
}
void Load()
{
if (string.IsNullOrEmpty(FilePath))
return;
Reset();
hasChanged = false;
try
{
using (StreamReader sr = new StreamReader(FilePath, Encoding.GetEncoding("GB2312")))
{
string header = sr.ReadLine();
if (string.IsNullOrEmpty(header))
return;
while (!sr.EndOfStream)
{
T t = new T();
if (t.TryParse(header, sr.ReadLine()))
{
Add(t);
}
}
}
}
catch (Exception e)
{
}
}
void Save()
{
if (string.IsNullOrEmpty(FilePath))
return;
if (!hasChanged)
return;
hasChanged = false;
if (list.Count == 0)
{
//删除掉文件
File.Delete(FilePath);
return;
}
//以附加的方式打开只写文件。
//若文件不存在,则会建立该文件,
//如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。
using (StreamWriter sw = new StreamWriter(FilePath, false, Encoding.GetEncoding("GB2312")))
{
sw.WriteLine(list[0].GetHeader());
for (int i = 0; i < list.Count; i++)
sw.WriteLine(list[i].ToString());
sw.Flush();
sw.Close();
}
}
}
}
......@@ -15,6 +15,9 @@ namespace FLY.OBJComponents.Server.Model
[Table("Error")]
public class Db_Error:IDbBase
{
/// <summary>
///
/// </summary>
[Key]
[Index]
[PropertyIndex(0)]
......
......@@ -7,9 +7,18 @@ using System.Threading.Tasks;
namespace FLY.OBJComponents.Server.Model
{
/// <summary>
/// 有 ERROR表的数据库
/// </summary>
public interface IErrorDBModel
{
/// <summary>
///
/// </summary>
SQLiteHelper sqliteHelper { get; }
/// <summary>
///
/// </summary>
DBTable<Db_Error> TbError { get; }
}
}
using FLY.OBJComponents.Common;
using FLY.OBJComponents.IService;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FLY.OBJComponents.Server
{
/// <summary>
/// 报警管理系统
/// </summary>
[Obsolete("已经作废,应该使用WarningSystem2")]
public class WarningSystem : INotifyPropertyChanged, IWarningService
{
#region IWarningService
/// <summary>
/// 使能
/// </summary>
public bool Enable { get; set; }
/// <summary>
/// 正在响铃
/// </summary>
public bool IsRinging { get; private set; }
/// <summary>
/// 当前正在报警的!!!!!!
/// </summary>
public IBuffer<FlyData_WarningHistory> ReasonList { get; private set; }
/// <summary>
/// 最近报警列表
/// </summary>
public IBuffer<FlyData_WarningHistory> NewestList { get; private set; }
#endregion
public WarningSystem()
{
Enable = true;
ReasonList = new Buffer<FlyData_WarningHistory>();
}
public void Init()
{
NewestList = new BufferStorage<FlyData_WarningHistory>("warning_newest.csv");
}
public void Init(IBufferAdd<FlyData_WarningHistory> newestList)
{
NewestList = newestList;
}
public void Reset()
{
ReasonList.Reset();
IsRinging = false;
}
public void Silence()
{
IsRinging = false;
}
#region IWarningServiceSimple
public void Add(int errcode, string description)
{
Add(errcode, description, ERR_STATE.ON, "");
}
public void Add(int errcode, string description, ERR_STATE state)
{
Add(errcode, description, state, "");
}
public void Add(int errcode, string description, ERR_STATE state, string accessory)
{
if (!Enable)
return;
FlyData_WarningHistory reason = new FlyData_WarningHistory();
reason.Time = DateTime.Now;
reason.ErrCode = errcode;
reason.Description = description;
reason.State = state;
reason.Accessory = accessory;
FlyData_WarningHistory error = null;
Buffer<FlyData_WarningHistory> reasonList = ReasonList as Buffer<FlyData_WarningHistory>;
int error_id = 0;
if (reasonList.Count > 0)
{
int idx = reasonList.list.FindIndex(e => e.ErrCode == errcode);
if (idx >= 0)
{
error_id = reasonList.GetID(idx);
error = reasonList.list[idx];
}
}
switch (state)
{
case ERR_STATE.ON:
if (error == null)
{
reasonList.Add(reason.Clone());
}
else
{
//已经有了,再发生,不管它。
return;
}
break;
case ERR_STATE.OFF:
if (error == null)
{
//没有在报警,不管它。
return;
}
else
{
error.State = state;
reasonList.Remove(error_id);
}
break;
}
var newestList = NewestList as IBufferAdd<FlyData_WarningHistory>;
newestList.Add(reason);
if (reasonList.Count > 0)
{
IsRinging = true;
}
else
{
Reset();
}
}
public void Remove(int errcode) {
FlyData_WarningHistory error = null;
Buffer<FlyData_WarningHistory> reasonList = ReasonList as Buffer<FlyData_WarningHistory>;
if (reasonList.Count == 0)
return;
int idx = reasonList.list.FindIndex(e => e.ErrCode == errcode);
if (idx < 0)
return;
int error_id = reasonList.GetID(idx);
error = reasonList.list[idx];
error.State = ERR_STATE.OFF;
reasonList.Remove(error_id);
var newestList = NewestList as IBufferAdd<FlyData_WarningHistory>;
newestList.Add(new FlyData_WarningHistory
{
Time = DateTime.Now,
ErrCode = errcode,
Description = error.Description,
State = ERR_STATE.OFF
});
if (reasonList.Count > 0)
{
IsRinging = true;
}
else
{
Reset();
}
}
#endregion
/// <summary>
/// 获取能被交易的属性
/// </summary>
/// <returns></returns>
public string[] GetPropertys()
{
return new string[] {
"Enable"
};
}
#region INotifyPropertyChanged 成员
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
}
......@@ -74,7 +74,13 @@ namespace FLY.OBJComponents.Server
#region IWarningServiceSimple
public void Update(ERRNO errno, string accessory = "", bool canReset = true)
{
Add(errno.Code, errno.Description,
accessory: accessory,
isUpdate: true,
canReset: canReset);
}
public void Update(int errcode, string description, string accessory="", bool canReset=true)
{
......
......@@ -11,20 +11,8 @@ using System.Diagnostics;
namespace FLY.Thick.Base.Server
{
public abstract class GM_Base : IGageMode, INotifyErrorArisen
public abstract class GM_Base : IGageMode
{
/// <summary>
/// 启动时出错,已经在运行了
/// </summary>
public const byte ERRNO_StartUp_IsRunning = 1;
/// <summary>
/// 启动时出错,AD卡连接断开
/// </summary>
public const byte ERRNO_StartUp_FlyADNoConnected = 2;
/// <summary>
/// 参数异常
/// </summary>
public const byte ERRNO_StartUp_Param = 3;
/// <summary>
/// 参数异常
/// </summary>
......@@ -40,11 +28,6 @@ namespace FLY.Thick.Base.Server
/// </summary>
public bool IsRunning { get; protected set; }
public event ErrorArisenEventHander ErrorArisenEvent;
protected void NotifyError(byte errno)
{
ErrorArisenEvent?.Invoke(this, new ErrorArisenEventArgs() { Errno = errno });
}
#endregion
protected IFlyADClientAdv mFlyAD;
......@@ -69,11 +52,11 @@ namespace FLY.Thick.Base.Server
{
if (IsRunning)
{
NotifyError(ERRNO_StartUp_IsRunning);
return;
}
if (!mFlyAD.IsConnected)
{
NotifyError(ERRNO_StartUp_FlyADNoConnected);
return;
}
IsRunning = true;
FObjBase.PollModule.Current.Poll_Config(onpoll_func);
......@@ -97,28 +80,7 @@ namespace FLY.Thick.Base.Server
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
#endregion
/// <summary>
/// 等待停止;
/// 正常停止返回true,没有停止及异常停止返回false
/// </summary>
/// <returns></returns>
protected bool WaitFinish()
{
switch (mFlyAD.DriveStatus)
{
case DRIVE_MAN_STATUS.STOP://完成任务
case DRIVE_MAN_STATUS.LIMIT:
{
return true;
}
case DRIVE_MAN_STATUS.STOP_MANUAL://异常
{
NotifyError(ERRNO_Running_Manual);
Stop(); return false;
}
}
return false;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment