Mostly EOL and LUT Management
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
using System;
|
||||
using Logic.ProductionToProductMapper.Cordonel;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Logic.ProductionToProductMapper.Cordonel;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile;
|
||||
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
|
||||
using Xylem.Common.Utils.ProcessExec.EventArguments;
|
||||
|
||||
using Xylem.Common.Logic.ProductionOrderCore.File;
|
||||
using Xylem.Common.Logic.SoftwareAccessHelper;
|
||||
using Xylem.Common.Utils.Crc16Ccitt;
|
||||
|
||||
namespace Xylem.Common.Ui.GenesisToolBox
|
||||
{
|
||||
@@ -20,12 +22,6 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
public partial class FrmLutManagement : Form
|
||||
{
|
||||
#region Variables
|
||||
private readonly MeterBatch _meterBatch = new MeterBatch();
|
||||
private GenesisMeter _currentGenesis;
|
||||
private const String StrConnecting = "Connecting to PCB";
|
||||
private const String StrNotConnected = "NOT CONNECTED";
|
||||
private const String StrPartPcbConnected = "PCB ID: ";
|
||||
private const String StrOverallProcess = "Overall Process";
|
||||
|
||||
private MeterLutUpdate _meterLutUpdate;
|
||||
|
||||
@@ -43,6 +39,35 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
private const String StrLutFileInvalid = "LUT FILE INVALID";
|
||||
private const String StrLutFileValid = "LUT file loaded";
|
||||
|
||||
private const String StrLutFileId = "GEN_LUT\0";
|
||||
private const Int32 IndexLutFileId = 0;
|
||||
private const Int32 LengthLutFileId = 8;
|
||||
|
||||
// data length, calculated from version field to the end of the data section
|
||||
private const Int32 IndexDataLength = 8;
|
||||
private const Int32 LengthDataLength = 4;
|
||||
|
||||
// CCITT-CRC-16 , calculated from version field to the end of the data section
|
||||
private const Int32 IndexCrc = 12;
|
||||
private const Int32 LengthCrc = 2;
|
||||
|
||||
// version
|
||||
private const Int32 IndexVersion = 14;
|
||||
private const Int32 LengthVersion = 2;
|
||||
|
||||
// meter size as enumeration
|
||||
private const Int32 IndexMeterSize = 16;
|
||||
|
||||
// header size of file
|
||||
private const Int32 LutFileHeaderLength = LengthLutFileId + LengthDataLength + LengthCrc + LengthVersion;
|
||||
|
||||
// data size of file
|
||||
private const Int32 LutFileDataLength = 730;
|
||||
|
||||
// LUT file entire file size
|
||||
private const Int32 SizeLutFile = LutFileHeaderLength + LutFileDataLength;
|
||||
|
||||
|
||||
// external update remarks form
|
||||
private readonly FrmHistory _frmHistory = new FrmHistory();
|
||||
|
||||
@@ -65,37 +90,163 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
public FrmLutManagement()
|
||||
{
|
||||
InitializeComponent();
|
||||
//
|
||||
// cordonelMetrologyLutBindingSource
|
||||
//
|
||||
this.cordonelMetrologyLutBindingSource.DataSource = typeof(CordonelMetrologyLut);
|
||||
|
||||
var cultureInfo = new CultureInfo("en-GB");
|
||||
Thread.CurrentThread.CurrentUICulture = cultureInfo;
|
||||
Thread.CurrentThread.CurrentCulture = cultureInfo;
|
||||
_version = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
}
|
||||
private void btnOpenLutFile_Click(object sender, EventArgs e)
|
||||
|
||||
string _StrLutRegion;
|
||||
string _StrLutVersion;
|
||||
MeterSize _MeterSize;
|
||||
UInt16 _FileCrc;
|
||||
UInt16 _Version;
|
||||
UInt32 _DataLength;
|
||||
string lutFilePathName;
|
||||
string lutFileName;
|
||||
private void btnOpenLutFile_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dlgOpenLuFile.ShowDialog() != DialogResult.OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var ErrorMessage = "";
|
||||
lutFilePathName = dlgOpenLuFile.FileName;
|
||||
|
||||
|
||||
lutFileName = Path.GetFileNameWithoutExtension(lutFilePathName);
|
||||
var BinData = new List<Byte>(File.ReadAllBytes(lutFilePathName));
|
||||
// check if LUT file contains data
|
||||
if (BinData == null)
|
||||
{
|
||||
ErrorMessage = "File size mismatch!";
|
||||
}
|
||||
btnStore.Enabled = false;
|
||||
var IsValid = false;
|
||||
|
||||
var IndexLutFileId = 0;
|
||||
var LengthLutFileId = 8;
|
||||
var IndexDataLength = 8;
|
||||
var LengthDataLength = 4;
|
||||
// extract the identifier and check, if this is a LUT file
|
||||
var StrLutFileId = Encoding.UTF8.GetString(BinData.ToArray(), IndexLutFileId, IndexDataLength);
|
||||
_StrLutRegion = lutFileName.Split('_')[3];
|
||||
_StrLutVersion = lutFileName.Split('_')[2];
|
||||
_MeterSize = (MeterSize)BinData[IndexMeterSize];
|
||||
_FileCrc = (UInt16)(BinData[IndexCrc] + (BinData[IndexCrc + 1] << 8));
|
||||
_Version = (UInt16)(BinData[IndexVersion] + (BinData[IndexVersion + 1] << 8));
|
||||
_DataLength = (UInt32)(BinData[IndexDataLength]
|
||||
+ (BinData[IndexDataLength + 1] << 8)
|
||||
+ (BinData[IndexDataLength + 2] << 16)
|
||||
+ (BinData[IndexDataLength + 3] << 24));
|
||||
// calculate CRC and compare this with the file CRC
|
||||
var entireFile = new List<Byte>();
|
||||
entireFile.AddRange(BinData);
|
||||
var payload = new List<Byte>();
|
||||
payload.AddRange(entireFile.GetRange(IndexVersion, LutFileDataLength + LengthVersion));
|
||||
var calculatedCrc = Crc16Ccitt.CalculateMsb1021(payload.ToArray());
|
||||
if (calculatedCrc != _FileCrc)
|
||||
{
|
||||
ErrorMessage = "CRC mismatch!";
|
||||
|
||||
}
|
||||
|
||||
var CalculatedCrc = calculatedCrc;
|
||||
IsValid = true;
|
||||
|
||||
btnStore.Enabled = IsValid;
|
||||
tbxLutFilePathName.Text = lutFilePathName;
|
||||
tbxMeterLutCrc.Text = _FileCrc.ToString("X4");
|
||||
tbxMeterMeterSize.Text = _MeterSize.ToString();
|
||||
tbxRegionRadio.Text = _StrLutRegion;
|
||||
tbxVersion.Text = _StrLutVersion;
|
||||
tbxDataLengt.Text = _DataLength.ToString();
|
||||
//lutFilePathName.
|
||||
////mettbl_202203101419_v0.04_EMEA_DN50_v1.00_0xC50F
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Clear data table and set genesis to not connected
|
||||
/// </summary>
|
||||
private void Init()
|
||||
{
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void label6_Click(object sender, EventArgs e)
|
||||
{
|
||||
private void label6_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
||||
|
||||
var FileList = new Dictionary<String, String>();
|
||||
|
||||
|
||||
|
||||
var fileConfig = new FileInfo(tbxLutFilePathName.Text);
|
||||
FileList = new Dictionary<String, String>();
|
||||
FileList.Add(fileConfig.Name, fileConfig.FullName);
|
||||
|
||||
|
||||
|
||||
StringBuilder sbUrl = new StringBuilder();
|
||||
// sbUrl.Append("http://10.49.40.25/MeterProcessState/api/FileUpToDate/PostLutFile");
|
||||
sbUrl.Append("http://localhost:56011//api/FileUpToDate/PostLutFile");
|
||||
//
|
||||
|
||||
|
||||
sbUrl.Append($"?DataLength={_DataLength}");
|
||||
sbUrl.Append($"&version={_Version}");
|
||||
sbUrl.Append($"&crc={_FileCrc}");
|
||||
sbUrl.Append($"&Metersize={_MeterSize.GetHashCode()}");
|
||||
sbUrl.Append($"&Region={_StrLutRegion}");
|
||||
|
||||
|
||||
|
||||
|
||||
var result = LocalWebRequest.PostBinaryFileRequestAsync(sbUrl.ToString(), lutFileName, File.ReadAllBytes(lutFilePathName), 2800);
|
||||
|
||||
}
|
||||
|
||||
private void label4_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void btnLoad_Click(object sender, EventArgs e)
|
||||
{
|
||||
StringBuilder sbUrl = new StringBuilder();
|
||||
// sbUrl.Append("http://10.49.40.25/MeterProcessState/api/FileUpToDate/GetLutFiles");
|
||||
sbUrl.Append("http://localhost:56011/api/FileUpToDate/GetLutFiles");
|
||||
//sbUrl.Append($"?DataLength={_DataLength}");
|
||||
//sbUrl.Append($"&version={_Version}");
|
||||
//sbUrl.Append($"&crc={_FileCrc}");
|
||||
//sbUrl.Append($"&Metersize={_MeterSize.GetHashCode()}");
|
||||
//sbUrl.Append($"&Region={_StrLutRegion}");
|
||||
|
||||
var ret = LocalWebRequest.GetRequest(sbUrl.ToString());
|
||||
|
||||
|
||||
|
||||
var a = JsonConvert.DeserializeObject<List<CordonelMetrologyLut>>(ret);
|
||||
dgvLuts.DataSource = a;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user