///--------------------------------------------------------------------------
/// 文 件 名:HardwareManageARS.cs
/// 功能描述:硬件管理模块
/// 硬件信息的读取及更改
/// 创建标识:赵丽 2011-10-30
/// 修改标识:赵丽 2011-11-25
///--------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
//using RealVote;
using GeneralLib;
namespace SunVoteARSPPT
{
#region 委托
///
/// 读写基站表决特性委托
///
///
public delegate void BasicFeatureEvent(int BaseID);
///
/// 基站配置委托
///
public delegate void BaseConfigEvent(int BaseID);//基站配置信息委托
///
/// 基站硬件信息
///
public delegate void BaseModelInfoEvent(int BaseID); //基站硬件信息委托
///
/// 基站IP地址
///
///
public delegate void BaseIPAddressEvent(int BaseID);// 基站IP地址委托
///
/// 键盘更换委托
///
/// 原始键盘
/// 新键盘
public delegate void KeyChangeEvent(string originalKey, string newKey);
///
/// 硬件监控委托
///
/// 基站ID号
/// 键盘ID号
/// 在线键盘数量
public delegate void HardwareMonitorEvent(int BaseID, string KeyID, int OnLineKeyNum);
///
/// 自动表决测试委托
///
/// 基站ID号
/// 键盘ID号
/// 在线键盘数量
public delegate void HardwareTestEvent(int BaseID, string KeyID, int OnLineKeyNum);
///
/// 读键盘硬件信息委托
///
/// 键盘信息类
public delegate void KeyModelInfoEvent(KeyModelInfoParam keyModelInfoObj);//键盘硬件信息
///
/// 键盘测试
///
///
///
public delegate void KeyTestStatusEvent(string BaseTag, string KeyID, string KeyValue);
///
/// 键盘状态
///
///
public delegate void KeyMonitorStatusEvent(int BaseID, string KeyID, double BatteryVoltage);
///
/// 设置表决特性事件
///
public delegate void ReadOnlyEvent(bool ReadOnly);
#endregion
#region 信息类
///
/// 键盘硬件信息
/// 说明:存储键盘硬件信息参数
///
public class KeyModelInfoParam
{
///
/// 键盘ID
///
public int KeyID { get; set; }
///
/// 键盘型号
///
public int HModel { get; set; }
///
/// 键盘硬件版本
///
public int HVer { get; set; }
///
/// 键盘软件型号
///
public int SVer { get; set; }
///
/// 键盘序列号
///
public string HSerial { get; set; }
}
///
/// 硬件监控键盘返回状态
/// 说明:返回硬件监控时键盘参数
///
public class KeyResponsStatus
{
///
/// 基站标签
///
public string BaseTag { get; set; }
///
/// 键盘编号
///
public string KeyID { get; set; }
///
/// 输入状态
///
public int InputStatus { get; set; }
///
/// 充电状态
///
public int ChargeStatus { get; set; }
///
/// 电池电压
///
public double BatteryVoltage { get; set; }
///
/// 射频接受信号强度
///
public int RfIntensity { get; set; }
public KeyResponsStatus()
{
BaseTag = "1";
KeyID = "1";
InputStatus = -1;
ChargeStatus = 0;
BatteryVoltage = 0;
RfIntensity = 0;
}
}
#endregion
///
/// HardwareManageARS
/// 硬件管理类(ARS系列)
/// 功能说明:读取基站信息、更改基站的各项参数信息
///
public class HardwareManageARS
{
///
/// 操作类型
///
private enum OperationType
{
otRead = 1,
otWrite = 2
}
///
/// 键盘管理类
///
private SunVote.KeypadManage keypadManage = null;
///
/// 基站管理类
///
public SunVote.BaseManage baseManage = null;
///
/// 硬件监控类
///
private SunVote.HardwareMonitor hardwareMonitor = null;
///
/// 硬件测试类
///
private SunVote.HardwareTest hardwareTest = null;
///
/// 键盘硬件信息
///
private KeyModelInfoParam keyModelInfoParam = null;
///
/// SDK操作类型(otRead读,otWrite 写)
///
private OperationType operationType = OperationType.otRead;
///
/// 记录键盘的状态
///
public OrderedDictionary KeyStatus = new OrderedDictionary();
#region 枚举
///
/// 键盘关机模式
///
public enum EKeyPowerOffModel
{
///
/// 禁止关机
///
kmForbid = 1,
///
/// 允许关机
///
kmAllow = 2
}
///
/// 蜂鸣模式
///
public enum EBuzzerModel
{
///
/// 禁止蜂鸣
///
bmForbid = 1,
///
/// 允许蜂鸣
///
bmAllow = 2
}
public enum EComitMode
{
///
/// 按OK键提交
///
cmForbid = 0,
///
/// 延时自动提交
///
cmAllow = 1
}
#endregion
#region 属性
///
/// 可用键盘数量
///
private int avilableKeyNum = 0;
///
/// 记录反馈的键盘数量
///
public int KeyNum = 0;
///
/// 记录检测的基站
///
public string CheckBase = "0";
///
/// 参与者人数
///
private int personNum;
///
/// 参与者人数
///
public int PersonNum
{
get
{ //2013-2-28 赵丽 获取人员个数为-1报错(权限设置问题,未启用名单设置了权限)
return personNum > 0 ? personNum : 0;
}
set
{
if (personNum != value)
{
personNum = value;
//写配置文件
//SysConfigEvent("Device", "PersonNum", value);
}
}
}
///
/// 键盘范围
///
private string rangeOfKey;
///
/// 键盘范围
///
public string RangeOfKey
{
get { return rangeOfKey; }
set
{
if (rangeOfKey != value)
{
rangeOfKey = value;
//更新可用键盘数量
avilableKeyNum = GetKeyNum(value);
InitKeypadRangeSet(rangeOfKey);//杨斌 2016-05-19
//重新初始存储键盘信息的数组
iniKeyStatus();
}
}
}
///
/// 是否开启硬件监控
///
private bool hardwareMonitorEnable = false;
public bool HardwareMonitorEnable
{
get
{
return hardwareMonitorEnable;
}
set
{
if (hardwareMonitorEnable != value)
{
hardwareMonitorEnable = value;
hardwareMonitor.Enabled = value;
}
}
}
///
/// 是否开启硬件测试
///
private bool hardwareTestEnable = false;
public bool HardwareTestEnable
{
get { return hardwareTestEnable; }
set
{
if (hardwareTestEnable != value)
{
hardwareTestEnable = value;
//杨斌 2015-03-13
if (GlobalInfo.GetSdkType() == 0)
{
if (hardwareTestEnable) { hardwareTest.Start(); } else { hardwareTest.Stop(); }
}
else if (GlobalInfo.GetSdkType() == 1)
{
PVSServer.MyPVS pvs = FrmPvsServer.GetMyPvs();
if (pvs != null)
{
if (hardwareTestEnable)
{
FrmPvsServer.GetFrmPvs().VoteStart(15, "0");
}
else
{
FrmPvsServer.GetFrmPvs().VoteStop();
}
}
}
}
}
}
///
/// 硬件测试启动模式
/// 0:继续
/// 1:清空重新开始
/// 2:重新提交并重新开始
///
private int hardwareTestStarMode = 0;
public int HardwareTestStarMode
{
get { return hardwareTestStarMode; }
set
{
hardwareTestStarMode = value;
hardwareTest.StartMode = value;
}
}
///
/// 读硬件信息是否完成,未完成不能做其他操作
///
private bool readBaseInfo = true;
public bool ReadBaseInfo
{
get { return readBaseInfo; }
set
{
if (readBaseInfo != value)
{
readBaseInfo = value;
if (ReadOnlyEvent != null)
ReadOnlyEvent(value);
}
}
}
///
/// 写基站列表表决特性
///
private bool WriteBaseList = false;
///
/// 记录当前更改基站的位置
///
private int BasePos = 0;
///
/// 记录读基站信息的次数
///
private int ReadInfoNum = 0;
///
/// 键盘关机模式
///
private EKeyPowerOffModel keyPowerOffModel = 0;
///
/// 键盘关机模式
///
public EKeyPowerOffModel KeyPowerOffModel
{
get { return keyPowerOffModel; }
set
{
if (readBaseInfo) { return; }
if (keyPowerOffModel != value)
{
int PowerOffModel = 0;
BasePos = 0;
WriteBaseList = false;
keyPowerOffModel = value;
//设置键盘关机模式
if (keyPowerOffModel == EKeyPowerOffModel.kmForbid) { PowerOffModel = 255; } else { PowerOffModel = 0; }
for (int i = 0; i < BaseConnect.BaseList.Count; i++)
{
//更新基站的键盘关机模式
if (BaseConnect[i].BaseConnectStatus == BasePara.ConnectStatus.csSuccess)
{
ReadBaseInfo = true;
BasePos = i + 1;
operationType = OperationType.otWrite;
baseManage.SetBasicFeature(BaseConnect[i].BaseID, 0,
PowerOffModel, BaseConnect.BackLightMode,
BaseConnect.BuzzerMode, 1);
BaseConnect.KeyOffTime = PowerOffModel;
//不能连续发命令,只能在事件中设置下一个基站
if (BaseConnect.MultiBase == 1)
WriteBaseList = true;
break;
}
}
}
}
}
///
/// 蜂鸣模式
///
private EBuzzerModel buzzerModel = 0;
///
/// 蜂鸣模式
/// 杨斌 2015-03-16
///
public EBuzzerModel BuzzerModel
{
get { return buzzerModel; }
set
{
if (readBaseInfo) { return; }
if (buzzerModel != value)
{
//更新键盘的蜂鸣模式
int buzzer = 0;
BasePos = 0;
WriteBaseList = false;
buzzerModel = value;
if (buzzerModel == EBuzzerModel.bmAllow) { buzzer = 1; } else { buzzer = 0; }
for (int i = 0; i < BaseConnect.BaseList.Count; i++)
{
if (BaseConnect[i].BaseConnectStatus == BasePara.ConnectStatus.csSuccess)
{
ReadBaseInfo = true;
BasePos = i + 1;
operationType = OperationType.otWrite;
//杨斌 2015-03-16
if (GlobalInfo.GetSdkType() == 0)
{
baseManage.SetBasicFeature(BaseConnect[i].BaseID, 0,
BaseConnect.KeyOffTime, BaseConnect.BackLightMode,
buzzer, 1);
}
if (GlobalInfo.GetSdkType() == 1)
{
int beep = (buzzer == 0 ? 1 : 0);
PVSServer.MyPVS pvs = FrmPvsServer.GetMyPvs();
if (pvs != null)
{
pvs.BaseCmd(0, 1, "2," + BaseConnect[i].BaseID + "," + BaseConnect[i].BaseChannel + "," + beep);
}
}
BaseConnect.BuzzerMode = buzzer;
if (BaseConnect.MultiBase == 1)
WriteBaseList = true;
break;
}
}//设置蜂鸣模式
}
}
}
/*杨斌 2017-04-19
///
/// 提交模式
///
private EComitMode comitMode = 0;
public EComitMode ComitMode
{
get { return comitMode; }
set
{
if (readBaseInfo) { return; }
if (comitMode != value)
{
int comitValue = 0;
BasePos = 0;
WriteBaseList = false;
comitMode = value;
if (comitMode == EComitMode.cmAllow) { comitValue = 1; } else { comitValue = 0; }
for (int i = 0; i < BaseConnect.BaseList.Count; i++)
{
if (BaseConnect[i].BaseConnectStatus == BasePara.ConnectStatus.csSuccess)
{
ReadBaseInfo = true;
BasePos = i + 1;
operationType = OperationType.otWrite;
baseManage.SetBasicFeature(BaseConnect[i].BaseID, 0,
BaseConnect.KeyOffTime, BaseConnect.BackLightMode,
BaseConnect.BuzzerMode, 1);
BaseConnect.CommitMode = 1;
if (BaseConnect.MultiBase == 1)
WriteBaseList = true;
break;
}
}
}
}
}
*/
///
/// 新键盘编号
///
private string newKeyID;
///
/// 新键盘编号
///
public string NewKeyID
{
get { return newKeyID; }
set
{
newKeyID = value;
//如果原编号与新编号不相同,触发事件,通知更改数据库信息
if (newKeyID != originalKeyID)
{
if (KeyChangeEvent != null)
KeyChangeEvent(originalKeyID, newKeyID);
}
}
}
///
/// 原键盘编号(便于事件操作)
///
private string originalKeyID;
///
/// 原键盘编号
///
public string OriginalKeyID
{
get { return originalKeyID; }
set { originalKeyID = value; }
}
private string keyModel = "M52";
///
/// 键盘型号
///
public string KeyModel
{
get { return keyModel; }
set
{
if (keyModel != value)
{
keyModel = value;
//SysConfigEvent("Device", "KeypadType", value);
}
}
}
///
/// 键盘监控模式
///
private int hardwareTestMode = 0;
public int HardwareTestMode
{
get { return hardwareTestMode; }
set
{
hardwareTest.Stop();
hardwareTestMode = value;
hardwareTest.Mode = value;
}
}
///
/// 基站连接类
///
public BaseConnect BaseConnect { get; set; }
///
/// 工作电压
///
public double Voltage { get; set; }
///
/// 最大的键盘编号
///
public static int maxKeyID = 9999;
///
/// 是否重连基站
///
private bool reConnect = false;
///
/// 读键盘信息的标志位
///
public bool ReadKeyModelInfoFlag = false;
#endregion
#region 构造函数
///
/// 构造函数
///
public HardwareManageARS(BaseConnect baseConnect)
{
return;//屏蔽。杨斌 2017-04-19
BaseConnect = baseConnect;
//定义键盘型号信息,作为事件 传出参数
keyModelInfoParam = new KeyModelInfoParam();
//基站管理类
baseManage = new SunVote.BaseManage();
baseManage.BaseConnection = BaseConnect.baseConnection;
//读基站配置文件绑定事件
baseManage.BaseConfig += new SunVote.IBaseManageEvents_BaseConfigEventHandler(baseManage_baseConfig);
//读基站表决特性绑定事件
baseManage.BasicFeature += new SunVote.IBaseManageEvents_BasicFeatureEventHandler(baseManage_basicFeature);
//读基站硬件信息绑定事件
baseManage.BaseModelInfo += new SunVote.IBaseManageEvents_BaseModelInfoEventHandler(baseManage_baseModelInfo);
baseManage.BaseModelInfoEx += baseManage_BaseModelInfoEx;
baseManage.BaseIPAddress += new SunVote.IBaseManageEvents_BaseIPAddressEventHandler(baseManage_BaseIPAddress);
//基站配对模式 杨斌 2013-05-08
baseManage.BaseAddConfig += new SunVote.IBaseManageEvents_BaseAddConfigEventHandler(baseManage_BaseAddConfig);
//基站软件狗 杨斌 2015-01-22
baseManage.BaseSoftDog += new SunVote.IBaseManageEvents_BaseSoftDogEventHandler(baseManage_BaseSoftDog);
//基站频点冲突。杨斌 2016-04-19
//baseManage.ChannelInterference += baseManage_ChannelInterference;//屏蔽。杨斌 2016-10-26。
//自动更换频点事件。杨斌 2016-04-20
//baseManage.ChannelAutoChange += baseManage_ChannelAutoChange;//屏蔽。杨斌 2016-10-26。
//键盘管理类
keypadManage = new SunVote.KeypadManage();
keypadManage.BaseConnection = BaseConnect.baseConnection;
//读键盘硬件信息绑定事件
keypadManage.KeyModelInfo += new SunVote.IKeypadManageEvents_KeyModelInfoEventHandler(keypadManage_KeyModelInfo);
keypadManage.KeyModelInfoEx += keypadManage_KeyModelInfoEx;//杨斌 2016-02-22
//基站连接成功后返回事件
BaseConnect.ReadBaseInfoEvent += new ReadBaseInfoEvent(baseConnect_readBaseInfoEvent);
//硬件监控
hardwareMonitor = new SunVote.HardwareMonitor();
hardwareMonitor.BaseConnection = BaseConnect.baseConnection;
hardwareMonitor.KeyStatus += new SunVote.IHardwareMonitorEvents_KeyStatusEventHandler(hardwareMonitor_keyStatus);
hardwareMonitor.Enabled = false;
//硬件测试类
hardwareTest = new SunVote.HardwareTest();
hardwareTest.BaseConnection = BaseConnect.baseConnection;
//键盘测试绑定事件
hardwareTest.KeyMonitorStatus += new SunVote.IHardwareTestEvents_KeyMonitorStatusEventHandler(hardwareTest_KeyMonitorStatus);
//键盘测试绑定事件
hardwareTest.KeyTestStatus += new SunVote.IHardwareTestEvents_KeyTestStatusEventHandler(hardwareTest_KeyTestStatus);
hardwareTest.StartMode = 1;
//基站连接产生事件
if (baseConnect != null)//杨斌 2016-12-13
baseConnect.ConnectEvent += new ConnectEvent(baseConnect_ConnectEvent);
//杨斌 2015-01-09
hardwareMonitor.KeyStatusSN += new SunVote.IHardwareMonitorEvents_KeyStatusSNEventHandler(hardwareMonitor_KeyStatusSN);
hardwareTest.KeyMonitorStatusSN += new SunVote.IHardwareTestEvents_KeyMonitorStatusSNEventHandler(hardwareTest_KeyMonitorStatusSN);
hardwareTest.KeyTestStatusSN += new SunVote.IHardwareTestEvents_KeyTestStatusSNEventHandler(hardwareTest_KeyTestStatusSN);
//PVS事件。杨斌 2015-03-17
FrmPvsServer.GetFrmPvs().OnBaseEvent += myPVS_BaseEvent;//基站配置等
FrmPvsServer.GetFrmPvs().OnKeyEvent += myPVS_KeyEvent;//键盘事件
FrmPvsServer.GetFrmPvs().OnKeyVote += myPVS_KeyVote;//电量测试
}
int ChannelAutoChange = -1;
///
/// 基站自动更换频点事件。杨斌 2016-04-20
///
void baseManage_ChannelAutoChange(int BaseID, int ChannelNo)
{
if (ChannelAutoChange != ChannelNo)
{
DicChannelSame.Clear();
ChannelAutoChange = ChannelNo;
MessageBox.Show("频点" + ChannelNo + "连接成功");
}
}
System.Windows.Forms.Timer TmrChannelSame = null;
Dictionary DicChannelSame = new Dictionary();
///
/// 频点冲突,自动换频点。
/// 杨斌 2016-04-19
///
///
///
void baseManage_ChannelInterference(int BaseID, int ChannelNo)
{
if (TmrChannelSame == null)
{
TmrChannelSame = new System.Windows.Forms.Timer();
TmrChannelSame.Tick += TmrChannelSame_Tick;
}
if (!DicChannelSame.ContainsKey(ChannelNo))
{
DicChannelSame.Add(ChannelNo, 0);
if (!TmrChannelSame.Enabled)
{
TmrChannelSame.Tag = BaseID;
TmrChannelSame.Interval = 2000;
TmrChannelSame.Enabled = true;
}
}
}
void TmrChannelSame_Tick(object sender, EventArgs e)
{
TmrChannelSame.Enabled = false;
string msg = GlobalInfo.SysLanguage.LPT.ReadString("Other", "ChannelInterference", "同频点冲突,是否自动换频?选“是”更换频点,点“否”不再提示。");
string title = GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "prompt", "提示");
if (MessageBox.Show(msg, title, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
ChannelAutoChange = -1;
baseManage.AutoChangeChannel((int)TmrChannelSame.Tag);
}
}
void myPVS_BaseEvent(int ID, int iMode, string sInfo)
{
switch (operationType)
{
case OperationType.otRead:
if (iMode == 3)
{
string[] ary = sInfo.Split(new char[] { ',' });
int BaseChannel = 0;
int.TryParse(ary[0], out BaseChannel);
ReadBaseInfo = false;
ReadInfoNum = 0;
//杨斌 2015-03-17
if (!BaseConnect.BaseList.Contains(ID.ToString()))
{
BaseConnect.BaseList.Add(ID.ToString(), new BasePara());
}
BaseConnect[ID.ToString()].BaseChannel = BaseChannel;
//将获得的键盘ID写到配置文件中
if (BaseConfigEvent != null)
BaseConfigEvent(ID);
}
break;
case OperationType.otWrite:
//更改基站编号重连基站
if (reConnect)
{
reConnect = false;
BaseConnect.ReConnect = true;
}
BaseConnect.Connect();//杨斌 2015-03-18
break;
}
}
void myPVS_KeyEvent(int ID, int iMode, string sInfo)
{
if (!ReadKeyModelInfoFlag) { return; }
keyModelInfoParam.KeyID = ID;
//keyModelInfoParam.HModel = HModel;
//keyModelInfoParam.HSerial = HSerial;
//keyModelInfoParam.HVer = HVer;
//keyModelInfoParam.SVer = SVer;
if (KeyModelInfoEvent != null)
KeyModelInfoEvent(keyModelInfoParam);
}
void myPVS_KeyVote(int ID, int iMode, string sInfo)
{
if (iMode != 15)
return;
double BatteryVoltage = 0;
double.TryParse(sInfo, out BatteryVoltage);
BatteryVoltage = BatteryVoltage * 0.02;
if (KeyMonitorStatusEvent != null)
KeyMonitorStatusEvent(0, ID.ToString(), BatteryVoltage);
}
void keypadManage_KeyModelInfoEx(int KeyID, int HModel, string HVer, string SVer, string HSerial)
{
if (GlobalInfo.GetSdkType() == 1)
return;
if (!ReadKeyModelInfoFlag) { return; }
keyModelInfoParam.KeyID = KeyID;
keyModelInfoParam.HModel = HModel;
keyModelInfoParam.HSerial = HSerial;
keyModelInfoParam.HVer = ConvertOper.Convert(HVer).ToInt;
keyModelInfoParam.SVer = ConvertOper.Convert(SVer).ToInt;
if (KeyModelInfoEvent != null)
KeyModelInfoEvent(keyModelInfoParam);
}
///
/// 读键盘信息
///
///
///
///
///
///
void keypadManage_KeyModelInfo(int KeyID, int HModel, int HVer, int SVer, string HSerial)
{
if (GlobalInfo.GetSdkType() == 1)
return;
if (!ReadKeyModelInfoFlag) { return; }
keyModelInfoParam.KeyID = KeyID;
keyModelInfoParam.HModel = HModel;
keyModelInfoParam.HSerial = HSerial;
keyModelInfoParam.HVer = HVer;
keyModelInfoParam.SVer = SVer;
if (KeyModelInfoEvent != null)
KeyModelInfoEvent(keyModelInfoParam);
}
///
/// 基站连接事件
///
///
void baseConnect_ConnectEvent(string statusStr)
{
///有基站连接,且处于幻灯片放映状态,不需要读基站信息
if ((GetConnectBaseNum() > 0) && (GlobalInfo.baseConnect.IsResponse))
{
ReadBaseInfo = false;
BaseConnect.NeedReadBaseInfo = false;
}
else
{
if (GlobalInfo.GetSdkType() == 1)
{
ReadBaseInfo = false;
BaseConnect.NeedReadBaseInfo = false;
}
else
{
ReadBaseInfo = true;
BaseConnect.NeedReadBaseInfo = true;
}
}
//不处于幻灯片放映状态
//if ((statusStr != "") && (!GlobalInfo.baseConnect.IsResponse))
// ReadBaseInfo = true;
}
#endregion
#region SDK事件方法
void baseConnect_readBaseInfoEvent(int BaseID)
{
operationType = OperationType.otRead;//读信息
//杨斌 2015-03-16
if (GlobalInfo.GetSdkType() == 0)
{
baseManage.GetConfig(BaseID);
baseManage.GetAddConfig(BaseID);//杨斌 2013-05-08
}
if (GlobalInfo.GetSdkType() == 1)
{
PVSServer.MyPVS pvs = FrmPvsServer.GetMyPvs();
if (pvs != null)
{
pvs.BaseCmd(0, 1, "1");
}
}
}
void hardwareTest_KeyTestStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
{
if (KeyTestStatusEvent != null)
KeyTestStatusEvent(BaseTag, KeySN, KeyValue);
}
void hardwareTest_KeyMonitorStatusSN(string BaseTag, string KeySN, int InputStatus, int ChargeStatus, double BatteryVoltage, int RfIntensity, double KeyTime)
{
if (KeyMonitorStatusEvent != null)
KeyMonitorStatusEvent(Convert.ToInt32(BaseTag), KeySN, BatteryVoltage);
}
void hardwareMonitor_KeyStatusSN(string BaseTag, string KeySN, int InputStatus, int ChargeStatus, double BatteryVoltage, int RfIntensity, double KeyTime)
{
if (GlobalInfo.GetSdkType() == 1)
return;
//KeyShutDownEvent(KeyID);
string newKey = KeySN;
//键值为基站号+键盘号
if (!KeyStatus.Contains(newKey))
{
//不在键盘可用范围内的不考虑
KeyStatus.Add(newKey, new KeyResponsStatus());
this[newKey].BaseTag = BaseTag;
if (InputStatus != -1)
{
BaseConnect[BaseTag].OnLineKeyNum += 1;
if (HardwareMonitorEvent != null)
HardwareMonitorEvent(Convert.ToInt32(this[newKey].BaseTag), KeySN, BaseConnect[this[newKey].BaseTag].OnLineKeyNum);
}
}//不存在该键值
else
{
if (InputStatus != this[newKey].InputStatus)
{
if (BaseTag != "0") { this[newKey].BaseTag = BaseTag; }
if (InputStatus != 0)
{
BaseConnect[this[newKey].BaseTag].OnLineKeyNum -= 1;
BaseConnect[this[newKey].BaseTag].ELVKeyNum -= 1;
}//不在线
else
{
//读的电压值小于键盘配置文件电压
if (BatteryVoltage < Voltage)
{
BaseConnect[this[newKey].BaseTag].ELVKeyNum += 1;
}//测试电压<工作电压
BaseConnect[this[newKey].BaseTag].OnLineKeyNum += 1;
}
if (HardwareMonitorEvent != null)
HardwareMonitorEvent(Convert.ToInt32(this[newKey].BaseTag), KeySN, BaseConnect[this[newKey].BaseTag].OnLineKeyNum);
}//状态改变,更新在线键盘个数
}//存在该键值
this[newKey].InputStatus = InputStatus;
this[newKey].KeyID = KeySN;
this[newKey].ChargeStatus = ChargeStatus;
this[newKey].BatteryVoltage = BatteryVoltage;
this[newKey].RfIntensity = RfIntensity;
}
///
/// 硬件监控
///
/// 基站标签
/// 键盘编号
/// 输入状态
/// 充电状态
/// 电池电量
/// 射频接收信号强度
void hardwareMonitor_keyStatus(string BaseTag, int KeyID, int InputStatus, int ChargeStatus, double BatteryVoltage, int RfIntensity)
{
hardwareMonitor_KeyStatusSN(BaseTag, KeyID.ToString(), InputStatus, ChargeStatus, BatteryVoltage, RfIntensity, 0);
}
///
/// 测试按键
///
/// 基站标签
/// 键盘编号
/// 提交值
void hardwareTest_KeyTestStatus(string BaseTag, int KeyID, string KeyValue)
{
hardwareTest_KeyTestStatusSN(BaseTag, KeyID.ToString(), KeyValue, 0);
}
///
/// 测试键盘状态
///
/// 基站标签
/// 键盘ID
/// 在线状态
/// 充电状态
/// 电池电压
/// 射频接受信号强度
void hardwareTest_KeyMonitorStatus(string BaseTag, int KeyID, int InputStatus, int ChargeStatus, double BatteryVoltage, int RfIntensity)
{
hardwareTest_KeyMonitorStatusSN(BaseTag, KeyID.ToString(), InputStatus, ChargeStatus, BatteryVoltage, RfIntensity, 0);
}
///
/// 硬件配置
///
/// 基站ID
/// 基站频点
/// 最小键盘ID
/// 最大键盘ID
/// 射频功率等级
void baseManage_baseConfig(int BaseID, int BaseChannel, int KeyIDMin, int KeyIDMax, int RFPower)
{
if (GlobalInfo.GetSdkType() == 1)
return;
switch (operationType)
{
case OperationType.otRead:
ReadBaseInfo = false;
ReadInfoNum = 0;
BaseConnect[BaseID.ToString()].BaseChannel = BaseChannel;
BaseConnect.KeyIDMin = KeyIDMin;
BaseConnect.KeyIDMax = KeyIDMax;
BaseConnect.KeyIDMin = KeyIDMin;
BaseConnect.RFPower = RFPower;
baseManage.GetBasicFeature(BaseID);
//将获得的键盘ID写到配置文件中
if (BaseConfigEvent != null)
BaseConfigEvent(BaseID);
break;
case OperationType.otWrite:
//更改基站编号重连基站
if (reConnect)
{
reConnect = false;
BaseConnect.ReConnect = true;
}
break;
}
}
///
///基站表决特性
///
/// 基站ID
/// 报告模式
/// 键盘关机时间
/// 背光模式
/// 蜂鸣模式
/// 提交模式
void baseManage_basicFeature(int BaseID, int KeyReportMode, int KeyOffTime, int BackLightMode, int BuzzerMode, int CommitMode)
{
if (GlobalInfo.GetSdkType() == 1)
return;
switch (operationType)
{
case OperationType.otRead:
BaseConnect.KeyReportMode = KeyReportMode;
//BaseConnect.KeyOffTime = KeyOffTime;
BaseConnect.BackLightMode = BackLightMode;
//BaseConnect.BuzzerMode = BuzzerMode;
//BaseConnect.CommitMode = CommitMode;
baseManage.GetModelInfo(BaseID);
if (BasicFeatureEvent != null)
BasicFeatureEvent(BaseID);
break;
case OperationType.otWrite:
//写关机模式和蜂鸣模式
//if (WriteBaseList)
if (BaseConnect.MultiBase == 1)
{
for (int i = BasePos; i < BaseConnect.BaseList.Count; i++)
{
BasePos = i + 1;
if (BaseConnect[i].BaseConnectStatus == BasePara.ConnectStatus.csSuccess)
{
baseManage.SetBasicFeature(BaseConnect[i].BaseID, 0,
KeyOffTime, BaseConnect.BackLightMode, BuzzerMode, 1);
break;
}
}
if (BasePos >= 8) { ReadBaseInfo = false; }
}
else
ReadBaseInfo = false;
break;
}
}
///
/// 读基站配对模式
/// 杨斌 2013-05-08
///
///
///
///
void baseManage_BaseAddConfig(int BaseID, int MatchMode, string BaseName)
{
if (GlobalInfo.GetSdkType() == 1)
return;
string sID = BaseID.ToString();
BaseConnect[sID].BaseMatchMode = MatchMode;
BaseConnect[sID].BaseName = BaseName;
if (BaseModelInfoEvent != null)
BaseModelInfoEvent(BaseID);
}
void baseManage_BaseModelInfoEx(int BaseID, int HModel, string HVer, string SVer, string HSerial)
{
if (GlobalInfo.GetSdkType() == 1)
return;
switch (operationType)
{
case OperationType.otRead:
ReadInfoNum += 1;
BaseConnect[BaseID.ToString()].BaseModel = HModel;
BaseConnect[BaseID.ToString()].BaseSerialNumber = HSerial;
if (BaseModelInfoEvent != null)
BaseModelInfoEvent(BaseID);
//连接类型为TCP/IP,读IP地址
if (BaseConnect.ConnectType == 2)
{
baseManage.GetIPAddress(BaseID);
}
else
{
//基站信息读取完毕
//if (ReadInfoNum == BaseConnect.BaseNum)
if (ReadInfoNum == GetConnectBaseNum())
{
operationType = OperationType.otWrite;
BasePos = 0;
WriteBaseList = true;
if (!readBaseInfo)
baseManage.SetBasicFeature(BaseID, 0, BaseConnect.KeyOffTime,
BaseConnect.BackLightMode, BaseConnect.BuzzerMode, 1);
InitSoftDog();//软件狗。杨斌 2015-01-22
}
}
break;
case OperationType.otWrite:
break;
}
}
///
/// 硬件信息
///
/// 基站编号
/// 硬件型号
/// 硬件版本
/// 软件版本
/// 序列号
void baseManage_baseModelInfo(int BaseID, int HModel, int HVer, int SVer, string HSerial)
{
baseManage_BaseModelInfoEx(BaseID, HModel, HVer.ToString(), SVer.ToString(), HSerial);
}
///
/// 判断软件狗
/// 杨斌 2015-01-22n
///
void InitSoftDog()
{
if (GlobalInfo.OEMLogo != OEMLogos.oemRealVote)
{
GlobalInfo.SoftDogOK = true;
return;
}
try
{
if (GlobalInfo.RealVoteSoftDog == null)
{
//GlobalInfo.RealVoteSoftDog = new SoftDog();
}
GlobalInfo.SoftDogOK = false;
baseManage.GetSoftDog(BaseConnect[0].BaseID, @"@SUNVOTE");
FrmDebugMsg.ShowMsg("InitSoftDog Called");
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
void baseManage_BaseSoftDog(int BaseID, string UserPart1, string UserPart2)
{
if (GlobalInfo.OEMLogo == OEMLogos.oemRealVote)
{
try
{
FrmDebugMsg.ShowMsg("baseManage_BaseSoftDog BaseID=" + BaseID
+ " UserPart1=" + UserPart1 + " UserPart2=" + UserPart2);
if (BaseID > 0)
{
FrmDebugMsg.ShowMsg("Call RealVoteSoftDog.LogOn ...");
//GlobalInfo.SoftDogOK = (GlobalInfo.RealVoteSoftDog.LogOn(UserPart1, UserPart2));
FrmDebugMsg.ShowMsg("SoftDogOK=" + GlobalInfo.SoftDogOK.ToString());
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
}
///
/// 获得连接基站的个数
///
///
public int GetConnectBaseNum()
{
int iNum = 0;
for (int i = 0; i < BaseConnect.BaseList.Count; i++)
{
if (BaseConnect[i].BaseConnectStatus == BasePara.ConnectStatus.csSuccess)
iNum++;
}
return iNum;
}
///
/// 读基站IP
///
/// 基站ID
/// IP地址
void baseManage_BaseIPAddress(int BaseID, string Address)
{
if (GlobalInfo.GetSdkType() == 1)
return;
switch (operationType)
{
case OperationType.otRead:
BaseConnect[BaseID.ToString()].BaseIPAddress = Address;
if (BaseIPAddressEvent != null)
BaseIPAddressEvent(BaseID);
//基站信息读取完毕
//if (ReadInfoNum == BaseConnect.BaseNum)
if (ReadInfoNum == GetConnectBaseNum())
{
operationType = OperationType.otWrite;
BasePos = 0;
WriteBaseList = true;
if (!readBaseInfo)
baseManage.SetBasicFeature(BaseID, 0, BaseConnect.KeyOffTime,
BaseConnect.BackLightMode, BaseConnect.BuzzerMode,
1);
}
break;
case OperationType.otWrite:
BaseConnect.ReConnect = true;
break;
}
}
#endregion
#region 方法
///
/// 初始化键盘状态
///
public void iniKeyStatus()
{
KeyStatus.Clear();
//清空各基站的在线、弱电基站数量
if (BaseConnect != null)//杨斌 2016-12-13
{
for (int i = 0; i < BaseConnect.BaseList.Count; i++)
{
BaseConnect[i].OnLineKeyNum = 0;
BaseConnect[i].ELVKeyNum = 0;
}
}
//未设有效键盘范围
if (rangeOfKey == "") { return; }
//if (!PersonNumEqualKeyNum()) { return; }
string[] aryAvilableKey = rangeOfKey.Split(',');
for (int i = 0; i < aryAvilableKey.Length; i++)
{
if (aryAvilableKey[i].IndexOf('-') != -1)
{
int pos = aryAvilableKey[i].LastIndexOf('-') + 1;
int minKey = Convert.ToInt32(aryAvilableKey[i].Substring(0, pos - 1));
int maxKey = Convert.ToInt32(aryAvilableKey[i].Substring(pos, aryAvilableKey[i].Length - pos));
if (minKey > maxKey)
{
int keyID = minKey;
minKey = maxKey;
maxKey = keyID;
}
for (int j = minKey; j <= maxKey; j++)
{
if (!KeyStatus.Contains(j.ToString()))
{
KeyStatus.Add(j.ToString(), new KeyResponsStatus());
//默认值不在线
this[j.ToString()].InputStatus = -1;
this[j.ToString()].KeyID = j.ToString();
}
}
}
else
{
if (!KeyStatus.Contains(aryAvilableKey[i]))
{
KeyStatus.Add(aryAvilableKey[i], new KeyResponsStatus());
//默认值不在线
this[aryAvilableKey[i]].InputStatus = -1;
this[aryAvilableKey[i]].KeyID = aryAvilableKey[i];
}
}
}
}
///
/// 读键盘硬件信息
///
public void ReadKeyModelInfo()
{
if (!ReadKeyModelInfoFlag) { return; }
if (GlobalInfo.GetSdkType() == 0)
{
keypadManage.GetModelInfo();
}
else if (GlobalInfo.GetSdkType() == 1)
{
PVSServer.MyPVS pvs = FrmPvsServer.GetMyPvs();
if (pvs != null)
{
pvs.KeyCmd(0, 1, "1");
}
}
}
///
/// 遥控关机
/// 杨斌 2015-03-16
///
public void RemoteOff()
{
if (GlobalInfo.GetSdkType() == 0)
{
keypadManage.RemoteOff(0);
}
if (GlobalInfo.GetSdkType() == 1)
{
PVSServer.MyPVS pvs = FrmPvsServer.GetMyPvs();
if (pvs != null)
{
for (int i = 1; i <= 20; i++)
{
pvs.KeyCmd(0, 2, "1,1");
for (int n = 1; n <= 1000; n++)
Application.DoEvents();
}
}
}
}
///
/// 更改基站频点
/// 杨斌 2015-03-16
///
/// 基站ID
/// 新频点号
public void ChangeBaseChannel(int iBaseID, int newChannel)
{
if (!BaseConnect.BaseList.Contains(iBaseID.ToString())) { return; }
operationType = OperationType.otWrite;
if (GlobalInfo.GetSdkType() == 0)
{
baseManage.SetConfig(iBaseID, iBaseID, newChannel,
BaseConnect.KeyIDMin, BaseConnect.KeyIDMax,
BaseConnect.RFPower);
}
if (GlobalInfo.GetSdkType() == 1)
{
int beep = (BaseConnect.BuzzerMode == 0 ? 1 : 0);
PVSServer.MyPVS pvs = FrmPvsServer.GetMyPvs();
if (pvs != null)
{
pvs.BaseCmd(0, 1, "2," + iBaseID + "," + newChannel + "," + beep);
}
}
BaseConnect[iBaseID.ToString()].BaseChannel = newChannel;
//写配置文件
//SysConfigBaseListEvent(iBaseID, "Channel", newChannel);
}
///
/// 更改IP地址
///
/// 基站编号
/// IP地址
public void ChangeBaseIPAddress(int iBaseID, string IPAddress)
{
if (!BaseConnect.BaseList.Contains(iBaseID.ToString())) { return; }
operationType = OperationType.otWrite;
//只能改配置文件,不能改基站信息
//baseManage.SetIPAddress(iBaseID, IPAddress);
BaseConnect[iBaseID.ToString()].BaseConnectStatus = BasePara.ConnectStatus.csDisconnect;
BaseConnect[iBaseID.ToString()].BaseIPAddress = IPAddress;
BaseConnect.SingleBaseIP = IPAddress;
////写配置文件
//SysConfigBaseListEvent(iBaseID, "IP", IPAddress);
}
///
/// 更改基站启用状态
///
/// 基站ID
/// 启用状态
public void ChangeEnableStatus(int iBaseID, bool Status)
{
if (iBaseID != 0)
{
if (!BaseConnect.BaseList.Contains(iBaseID.ToString())) { return; }
BaseConnect[iBaseID.ToString()].BaseID = iBaseID;
BaseConnect[iBaseID.ToString()].EnableStatus = Status;
////写配置文件事件
//SysConfigBaseListEvent(iBaseID, "Enabled", Status);
}
}
///
/// 有效键盘范围设置。杨斌 2016-05-19
///
public List KeypadRangeSet = new List();
///
/// 判断是否在有效键盘范围内。若无设置范围,则返回true
/// 杨斌 2016-05-19
///
///
///
public bool JudgeKeypadRangeSet(string KeyID)
{
bool res = false;
if (KeypadRangeSet.Count > 0)
res = KeypadRangeSet.Contains(KeyID);
else
res = true;
return res;
}
///
/// 初始化有效键盘范围设置。杨斌 2016-05-19
///
///
public void InitKeypadRangeSet(string range)
{
KeypadRangeSet.Clear();
List ls = FrmImportSlideSelect.GetNumRange(range);
foreach (var v in ls)
{
string key = v.ToString();
if (!KeypadRangeSet.Contains(key))
KeypadRangeSet.Add(key);
}
}
///
/// 判断键盘是否可用
///
/// 键盘ID
/// true:合法键盘,false:不合法键盘
public bool JudgeKeyStatus(string KeyID)
{
bool bValue = false;
//没有设置有效键盘范围,默认都有效
if (rangeOfKey == "") { return true; }
string[] aryAvilableKey = rangeOfKey.Split(',');
for (int i = 0; i < aryAvilableKey.Length; i++)
{
if (aryAvilableKey[i].IndexOf('-') != -1)
{
int pos = aryAvilableKey[i].LastIndexOf('-') + 1;
int minKey = Convert.ToInt32(aryAvilableKey[i].Substring(0, pos - 1));
int maxKey = Convert.ToInt32(aryAvilableKey[i].Substring(pos, aryAvilableKey[i].Length - pos));
for (int j = minKey; j <= maxKey; j++)
{
if (KeyID == j.ToString())
{
bValue = true;
break;
}//判断为有效键盘
}
}
else
{
if (KeyID.ToString() == aryAvilableKey[i])
{
bValue = true;
break;
}
}
}
return bValue;
}
///
/// 判断键盘数量和参与人数是否相等
///
/// true:参与人数与键盘数量一致,false:参与人数与键盘数量不一致
public bool PersonNumEqualKeyNum()
{
return (avilableKeyNum == personNum) ? true : false;
}
///
/// 获得有效键盘个数,判断键盘范围的有效性
/// 根据输入的键盘范围获得有效键盘数量及判断输入的键盘范围是否合法
///
/// -1:格式不正确
/// -2:设置键盘数量超过可设置的范围(1-400)
///
///
public int GetKeyNum(string KeyZoon)
{
int KeyNum = 0;
List keylist = new List();
string[] aryAvilableKey = KeyZoon.Split(',');
for (int i = 0; i < aryAvilableKey.Length; i++)
{
int pos = aryAvilableKey[i].IndexOf('-');
if (pos != -1)
{
if (pos == (aryAvilableKey[i].LastIndexOf('-')))
{
if (pos == 0) { KeyNum = -1; break; }
if ((aryAvilableKey[i].Length - (pos + 1)) == 0) { KeyNum = -1; break; }
pos += 1;
int minKey = Convert.ToInt32(aryAvilableKey[i].Substring(0, pos - 1));
int maxKey = Convert.ToInt32(aryAvilableKey[i].Substring(pos, aryAvilableKey[i].Length - pos));
if (minKey > maxKey)
{
int keyID = minKey;
minKey = maxKey;
maxKey = keyID;
}
if ((maxKey > maxKeyID) || (minKey == 0))
{
KeyNum = -2;
break;
}//超过范围
for (int j = minKey; j <= maxKey; j++)
{
if (!keylist.Contains(j.ToString()))
{
keylist.Add(j.ToString());
KeyNum += 1;
}
}
}
else
{
KeyNum = -1;
break;
}
}
else
{
if (!keylist.Contains(aryAvilableKey[i]))
{
//为空继续下一个
if (aryAvilableKey[i] == "") { KeyNum = -1; break; }
if ((Convert.ToInt32(aryAvilableKey[i]) > maxKeyID) || (aryAvilableKey[i] == "0"))
{
KeyNum = -2;
break;
}
keylist.Add(aryAvilableKey[i]);
KeyNum += 1;
}
}
}
return KeyNum;
}
#endregion
#region 事件
///
/// 基站配置文件事件
///
public event BaseConfigEvent BaseConfigEvent;
///
/// 基站表决特性事件
///
public event BasicFeatureEvent BasicFeatureEvent;
///
/// 基站硬件型号事件
///
public event BaseModelInfoEvent BaseModelInfoEvent;
///
/// 基站IP地址事件
///
public event BaseIPAddressEvent BaseIPAddressEvent;
///
/// 键盘编号改变
///
public event KeyChangeEvent KeyChangeEvent;
///
/// 读键盘硬件信息事件
///
public event KeyModelInfoEvent KeyModelInfoEvent;
///
/// 硬件监控,在线键盘更新改变
///
public event HardwareMonitorEvent HardwareMonitorEvent;
///
/// 键盘测试
///
public event KeyTestStatusEvent KeyTestStatusEvent;
///
/// 键盘监控
///
public event KeyMonitorStatusEvent KeyMonitorStatusEvent;
///
/// 是否可设置表决特性
///
public event ReadOnlyEvent ReadOnlyEvent;
#endregion
# region 索引
///
/// 从键获取键盘状态信息
///
/// 键值
///
public KeyResponsStatus this[string key]
{
get
{
return ((KeyResponsStatus)(KeyStatus[key]));
}
set
{
KeyStatus[key] = (KeyResponsStatus)value;
}
}
///
/// 从值获取键盘状态信息
///
/// 索引值
///
public KeyResponsStatus this[int index]
{
get
{
return ((KeyResponsStatus)(KeyStatus[index]));
}
set
{
KeyStatus[index] = (KeyResponsStatus)value;
}
}
#endregion
}
}