using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BatCharging.Model;
using BatCharging.Service;
using Monitor.LogService;
using Newtonsoft.Json;
namespace Monitor.ChargeTest
{
public partial class FrmChargeResult : Form
{
#region 处理结果消息委托
//ListBox文本框类型委托
private delegate void SetListBoxCallBack(string str);
private SetListBoxCallBack MsgConnectLogCallBack; //服务端或客户端连接状态信息委托
//RichTextBox文本框类型委托
private delegate void SetRTxtCallBack(string str);
private SetRTxtCallBack RTxtSendFramesInfoCallBack; //客户端发送数据帧委托
private SetRTxtCallBack RTxtRecvFramesInfoCallBack; //客户端接收数据帧委托
#endregion 处理结果消息委托
public FrmChargeResult()
{
InitializeComponent();
MsgConnectLogCallBack = new SetListBoxCallBack(PrintConnectLogMsg);
RTxtSendFramesInfoCallBack = new SetRTxtCallBack(PrintSendFramesInfo);
RTxtRecvFramesInfoCallBack = new SetRTxtCallBack(PrintRecvFramesInfo);
}
///
/// 窗体加载事件
///
///
///
private void FrmRwTcpCanResult_Load(object sender, EventArgs e)
{
}
///
/// 字节数组转16进制字符串:空格分隔
///
///
///
public string BytesToHexStr(byte[] byteDatas)
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < byteDatas.Length; i++)
{
builder.Append(string.Format("{0:X2} ", byteDatas[i]));
}
return builder.ToString().Trim();
}
#region 委托事件方法
///
/// 连接状态日志
///
///
private void PrintConnectLogMsg(string message)
{
if (lstBoxConnect.Items.Count <= 12)
{
lstBoxConnect.Items.Add(message);
lstBoxConnect.SelectedIndex = lstBoxConnect.Items.Count - 1;
lstBoxConnect.ClearSelected();
}
else
{
lstBoxConnect.Items.Clear();
lstBoxConnect.Items.Add(message);
lstBoxConnect.SelectedIndex = lstBoxConnect.Items.Count - 1;
lstBoxConnect.ClearSelected();
}
}
///
/// 显示发送的数据帧信息
///
/// 发送的数据帧信息
private void PrintSendFramesInfo(string msg)
{
if (lstSendFrameInfo.Items.Count <= 12)
{
lstSendFrameInfo.Items.Add(msg);
lstSendFrameInfo.SelectedIndex = lstSendFrameInfo.Items.Count - 1;
lstSendFrameInfo.ClearSelected();
}
else
{
lstSendFrameInfo.Items.Clear();
lstSendFrameInfo.Items.Add(msg);
lstSendFrameInfo.SelectedIndex = lstSendFrameInfo.Items.Count - 1;
lstSendFrameInfo.ClearSelected();
}
}
///
/// 显示接收到的数据帧信息
///
/// 接收到的数据帧信息
private void PrintRecvFramesInfo(string msg)
{
if (lstRecvFrameInfo.Items.Count <= 12)
{
lstRecvFrameInfo.Items.Add(msg);
lstRecvFrameInfo.SelectedIndex = lstRecvFrameInfo.Items.Count - 1;
lstSendFrameInfo.ClearSelected();
}
else
{
lstRecvFrameInfo.Items.Clear();
lstRecvFrameInfo.Items.Add(msg);
lstRecvFrameInfo.SelectedIndex = lstRecvFrameInfo.Items.Count - 1;
lstRecvFrameInfo.ClearSelected();
}
}
#endregion 委托事件方法
///
/// 设置textbox文本
///
///
///
private static void SetTextBoxSafe(TextBox tb, string text)
{
if (tb.InvokeRequired)
tb.Invoke(new Action(() => tb.Text = text));
else
tb.Text = text;
}
///
/// 客户端关闭
///
///
///
private void BtnNetClose_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.ChargerDisConnect();
}
///
/// 充电机网络连接
///
///
///
private void BtnChrg01Connect_Click(object sender, EventArgs e)
{
string strIp = txtChargeIp.Text.Trim();
int iPort = Convert.ToInt32(txtChargePort.Text.Trim());
int destaddr = Convert.ToInt32(txtDestAddr.Text.Trim());
CmnChargerParam._CHR00TCPCLIENT.ConnectedStatusChanged += ChargerMgrTool_ConnectedStatusChanged;
CmnChargerParam._CHR00TCPCLIENT.ChargerConnect(strIp, iPort, destaddr);
CmnChargerParam._CHR00TCPCLIENT.DataSended += ChargerMgrTool_DataSended;
CmnChargerParam._CHR00TCPCLIENT.DataReceived += ChargerMgrTool_DataReceived;
}
///
/// 充电机断开连接
///
///
///
private void BtnCloseConnect_Click(object sender, EventArgs e)
{
if (CmnChargerParam._CHR00TCPCLIENT != null)
{
if (CmnChargerParam._CHR00TCPCLIENT.F_NetConnected)
{
CmnChargerParam._CHR00TCPCLIENT.ChargerDisConnect();
}
}
}
///
/// 数据接收解析
///
///
///
private void ChargerMgrTool_DataReceived(object sender, DataRecvedEventArgs e)
{
string result = "";
byte[] data = e.Data;
if (data != null)
{
result += "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "]" + "RECV HEX:";
result += BytesToHexStr(data);
lstRecvFrameInfo.Invoke(RTxtRecvFramesInfoCallBack, result);
}
}
///
/// 数据发送
///
///
///
private void ChargerMgrTool_DataSended(object sender, DataSendedEventArgs e)
{
string result = "";
byte[] data = e.Data;
if (data != null)
{
result += "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "]" + "SEND HEX:";
result += BytesToHexStr(data);
lstSendFrameInfo.Invoke(RTxtSendFramesInfoCallBack, result);
}
}
///
/// 连接状态改变
///
///
///
private void ChargerMgrTool_ConnectedStatusChanged(object sender, LogEventArgs e)
{
lstBoxConnect.Invoke(MsgConnectLogCallBack, e.IsContent);
}
private void FrmChargeResult_Load(object sender, EventArgs e)
{
}
///
/// 获取充电机尖峰平谷对象值
///
///
private SharpPeakTimeRangeIde GetSharpPeakTimeRange()
{
SharpPeakTimeRangeIde timeRng = new SharpPeakTimeRangeIde();
timeRng.RecordType = 47;
timeRng.NumTimePeriods = 24;
timeRng.StartTimePeriod1 = "00:00";
timeRng.TimePeriodPeakIden1 = 4;
timeRng.StartTimePeriod2 = "08:00";
timeRng.TimePeriodPeakIden2 = 3;
timeRng.StartTimePeriod3 = "15:00";
timeRng.TimePeriodPeakIden3 = 2;
timeRng.StartTimePeriod4 = "19:00";
timeRng.TimePeriodPeakIden4 = 1;
timeRng.StartTimePeriod5 = "22:00";
timeRng.TimePeriodPeakIden5 = 2;
timeRng.StartTimePeriod6 = "23:00";
timeRng.TimePeriodPeakIden6 = 3;
timeRng.StartTimePeriod7 = "00:00";
timeRng.TimePeriodPeakIden7 = 4;
timeRng.StartTimePeriod8 = "00:00";
timeRng.TimePeriodPeakIden8 = 3;
timeRng.StartTimePeriod9 = "00:00";
timeRng.TimePeriodPeakIden9 = 2;
timeRng.StartTimePeriod10 = "00:00";
timeRng.TimePeriodPeakIden10 = 1;
timeRng.StartTimePeriod11 = "00:00";
timeRng.TimePeriodPeakIden11 = 2;
timeRng.StartTimePeriod12 = "00:00";
timeRng.TimePeriodPeakIden12 = 3;
timeRng.StartTimePeriod13 = "00:00";
timeRng.TimePeriodPeakIden13 = 4;
timeRng.StartTimePeriod14 = "00:00";
timeRng.TimePeriodPeakIden14 = 3;
timeRng.StartTimePeriod15 = "00:00";
timeRng.TimePeriodPeakIden15 = 2;
timeRng.StartTimePeriod16 = "00:00";
timeRng.TimePeriodPeakIden16 = 1;
timeRng.StartTimePeriod17 = "00:00";
timeRng.TimePeriodPeakIden17 = 2;
timeRng.StartTimePeriod18 = "00:00";
timeRng.TimePeriodPeakIden18 = 3;
timeRng.StartTimePeriod19 = "00:00";
timeRng.TimePeriodPeakIden19 = 4;
timeRng.StartTimePeriod20 = "00:00";
timeRng.TimePeriodPeakIden20 = 3;
timeRng.StartTimePeriod21 = "00:00";
timeRng.TimePeriodPeakIden21 = 2;
timeRng.StartTimePeriod22 = "00:00";
timeRng.TimePeriodPeakIden22 = 1;
timeRng.StartTimePeriod23 = "00:00";
timeRng.TimePeriodPeakIden23 = 2;
timeRng.StartTimePeriod24 = "00:00";
timeRng.TimePeriodPeakIden24 = 3;
return timeRng;
}
///
/// 设置充电机尖峰平谷
///
///
///
private void BtnChrg01SharpPeak_Click(object sender, EventArgs e)
{
SharpPeakTimeRangeIde timeRng = GetSharpPeakTimeRange();
CmnChargerParam._CHR00TCPCLIENT.SendPeakTimePeriod(timeRng);
}
///
/// 开启充电
///
///
///
private void BtnChrg01Start_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendRemoteStartCharing(100, 1, 3600, 0);
}
///
/// 充电机停止充电
///
///
///
private void BtnChrg01Stop_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.F_StopReason = 0;
CmnChargerParam._CHR00TCPCLIENT.F_IsCanSendStopCmd = true;
CmnChargerParam._CHR00TCPCLIENT.SendRemoteStopCmdThread();
}
///
/// 充电机鉴权
///
///
///
private void BtnChrg01SignIn_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendCharingSignIn();
}
///
/// 监控平台应答充电启动完成帧
///
///
///
private void button1_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendStartChargingFinishedRes(0, 0);
}
///
/// 监控平台应答充电停止完成帧
///
///
///
private void button2_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendStopChargingFinishedRes(0);
}
///
/// 监控平台应答充电设备登录签到报文
///
///
///
private void button3_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendCharingLoginRes();
}
///
/// 发送功率调节指令
///
///
///
private void button6_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendPowerRegulate(30);
}
///
/// 下发辅源控制指令
///
///
///
private void button7_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendAuxiliaryPowerControl(0);
}
///
/// 下发掉线停止充电
///
///
///
private void button8_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendDisconnectStopCharge(1, 0);
}
///
/// 下发站外允许充电SOC
///
///
///
private void button9_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendOutsideAllowChargeSOC(1);
}
///
/// 监控平台下发版本号查询
///
///
///
private void button5_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendVersionNumber();
}
///
/// 主动上送充电记录响应
///
///
///
private void button10_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendRecordChargResp(0, 0);
}
///
/// 监控平台心跳应答
///
///
///
private void button11_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendCharingHeartRes();
}
///
/// 站控查询监控网关尖峰平谷设置
///
///
///
private void button13_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendQueryPeakTime(0);
}
///
/// 站控响应充放电机上报模块状态
///
///
///
private void button4_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendUpModelStationResp(0);
}
#region 协议格式
///
/// (CMD=1)后台服务器下发充电桩整形工作参数
///
///
///
private void button14_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send1();
}
///
/// (CMD=3)后台服务器下发充电桩字符型参数
///
///
///
private void button15_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send3();
}
///
/// (CMD=5)后台服务器下发充电桩控制命令
///
///
///
private void button16_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send5();
}
///
/// (CMD=7)后台服务器下发充电桩开启充电控制命令
///
///
///
private void button17_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send7();
}
///
/// (CMD=9)后台服务器应答桩上传命令请求(预留)
///
///
///
private void button18_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send9();
}
#endregion
#region 充电桩主动上传数据
///
/// (CMD=101)服务器应答心跳包信息
///
///
///
private void button20_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send101();
}
///
///
///
///
///
private void button21_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send103();
}
///
///
///
///
///
private void button19_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send105();
}
///
///
///
///
///
private void button22_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.Send107();
}
///
///
///
///
///
private void button23_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.Send109();
}
///
///
///
///
///
private void button24_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send111();
}
///
///
///
///
///
private void button26_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send113();
}
#endregion
#region 充电信息数据
private void button27_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send201();
}
private void button12_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send203();
}
private void button28_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send205();
}
private void button29_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send207();
}
private void button30_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send209();
}
#endregion
#region 直流充电桩 BMS 信息数据(预留)
#endregion
#region 历史记录
#endregion
#region 升级命令
#endregion
#region 与计费策略相关的指令
#endregion
#region 白名单报文
#endregion
#region FTP 远程升级和 FTP 方式日志上传
#endregion
#region 协议方式日志上传
#endregion
}
}