Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/1547487222_tangerineautomationsystem.json
T

1 line
38 KiB
JSON
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"repo": "1547487222/tangerineautomationsystem", "files": {"ConsoleApp2/Program.cs": {"25cff9b296b6ba6d0e8ea1d17a79c4c9b9b36f71": {"t": 1785746200.812373, "n": 35892, "h": "cebe671740f59a67", "c": "using System.Diagnostics.CodeAnalysis;\nusing System.Management;\nusing System.Net.NetworkInformation;\nusing System.Reflection;\nusing System.Runtime.CompilerServices;\nusing System.Runtime.Loader;\nusing System.Text;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing Microsoft.Extensions.DependencyInjection;\nusing Newtonsoft.Json;\nusing Newtonsoft.Json.Linq;\nusing QStandaedPlatform.Engine.Common.Common;\nusing QStandaedPlatform.Engine.Common.Common.ModuleEntitys;\nusing QStandaedPlatform.Engine.Components.Modbus;\nusing QStandaedPlatform.Engine.Laboratory;\nnamespace ConsoleApp2\n{\n\n public class Data\n {\n public string Name { get; set; }\n\n public string Age { get; set; }\n \n public string Score { get; set; }\n\n\n\n }\n\n\n\n internal class Program\n {\n #region\n public class Message\n {\n public string role { get; set; }\n\n public string content { get; set; }\n }\n public class Data\n {\n public string model { get; set; }\n\n public List<Message> messages { get; set; }\n\n public bool stream { get; set; }\n }\n\n\n public class AlarmInfo\n {\n public AlarmInfo()\n {\n AlarmItems = new List<AlarmItem>();\n }\n public List<AlarmItem> AlarmItems { get; set; }\n }\n\n public class AlarmItem\n {\n /// <summary>\n /// 报警编号\n /// </summary>\n public int AlarmCode { get; set; }\n /// <summary>\n /// 报警描述\n /// </summary>\n public string Description { get; set; }\n /// <summary>\n /// 报警地址\n /// </summary>\n public string Address { get; set; }\n }\n\n #endregion\n \n [Flags]\n public enum AlarmStatus : ushort\n {\n None = 0, // 无报警\n WrongPassword = 1 << 0, // D190.1 输入密码错误\n DoorNotClosed = 1 << 1, // D190.2 设备门没有关\n YAxisError = 1 << 2, // D190.3 Y轴电机报警\n InitTimeout = 1 << 3, // D190.4 初始化超时\n ZAxisTimeout = 1 << 4, // D190.5 Z轴电机超时报警\n XAxisTimeout = 1 << 5, // D190.6 X轴电机超时报警\n WaitFlowTimeout = 1 << 6, // D190.7 等待流量超时报警\n //托盘监测报警\n TrayMonitor = 1 << 7, // D190.8 托盘监测报警\n }\n [Flags]\n public enum GasSamplingState : ushort\n {\n None = 0, // 无状态\n WakeUpPower = 1 << 0, // D140.0 唤醒伺服电源\n WakeUpSuccess = 1 << 1, // D140.1 唤醒伺服电源成功\n LoopWaiting = 1 << 2, // D140.2 循环(时间)小时等待中\n WaitForCooling = 1 << 3, // D140.3 等待风冷结束\n ZAxisOrigin = 1 << 4, // D140.4 Z轴回原点\n YAxisOrigin = 1 << 5, // D140.5 Y轴回原点\n YAxisToTubeBottom = 1 << 6, // D140.6 Y轴移动到铜管下压位\n ZAxisToGasPosition = 1 << 7, // D140.7 Z轴下压到通气位置\n WaitForFlow = 1 << 8, // D140.8 等待流量到达\n TorqueModePress = 1 << 9, // D140.9 扭矩模式下压\n ZAxisPressReset = 1 << 10, // D140.10 Z轴下压完成回零点\n ServoSleep = 1 << 11, // D140.11 伺服进入休眠\n AllCopperDone = 1 << 12, // D140.12 9个铜管全部做完等待取料\n\n // D140.13, D140.14, D140.15 预留\n }\n static ushort GetAlarmStatus()\n {\n return (ushort)(AlarmStatus.DoorNotClosed | AlarmStatus.WrongPassword);\n }\n static async Task Main(string[] args)\n {\n #region\n AlarmInfo alarmInfo = new AlarmInfo();\n alarmInfo.AlarmItems.Add(new AlarmItem \n {\n Address=\"M108\", AlarmCode=1, Description= \"整机有报警\"\n });\n alarmInfo.AlarmItems.Add(new AlarmItem\n {\n Address = \"M401\",\n AlarmCode = 2,\n Description = \"初始化失败\"\n });\n alarmInfo.AlarmItems.Add(new AlarmItem\n {\n Address = \"M430\",\n AlarmCode = 3,\n Description = \"x步进电机报警\"\n });\n alarmInfo.AlarmItems.Add(new AlarmItem\n {\n Address = \"M431\",\n AlarmCode = 4,\n Description = \"Y步进电机报警\"\n });\n alarmInfo.AlarmItems.Add(new AlarmItem\n {\n Address = \"M432\",\n AlarmCode = 5,\n Description = \"Z步进电机报警\"\n });\n alarmInfo.AlarmItems.Add(new AlarmItem\n {\n Address = \"M450\",\n AlarmCode = 6,\n Description = \"拍照失败\"\n });\n alarmInfo.AlarmItems.Add(new AlarmItem\n {\n Address = \"B415\",\n AlarmCode = 7,\n Description = \"管路中检测不到酸液\"\n });\n alarmInfo.AlarmItems.Add(new AlarmItem\n {\n Address = \"B416\",\n AlarmCode = 8,\n Description = \"管路中检测不到温泉液体\"\n });\n alarmInfo.AlarmItems.Add(new AlarmItem\n {\n Address = \"B420\",\n AlarmCode = 9,\n Description = \"温泉加液中 检测不到液体\"\n });\n alarmInfo.AlarmItems.Add(new AlarmItem\n {\n Address = \"B422\",\n AlarmCode = 10,\n Description = \"托盘1未就绪\"\n });\n alarmInfo.AlarmItems.Add(new AlarmItem\n {\n Address = \"B423\",\n AlarmCode = 11,\n Description = \"托盘2未就绪\"\n\n });\n alarmInfo.AlarmItems.Add(new AlarmItem\n {\n Address = \"B424\",\n AlarmCode = 12,\n Description = \"托盘3未就绪\"\n });\n\n\n\n\n\n\n\n\n\n\n\n //var josn = JsonConvert.SerializeObject(alarmInfo);\n //File.WriteAllText(\"AlarmInfo.json\",josn);\n //var apiKey = \"sk-4cf4682e5bf545b7ab3e1fea8149a6f9\"; // 替换为你的 API Key\n //var url = \"https://api.deepseek.com/chat/completions\";\n\n //using (var client = new HttpClient())\n //{\n // client.DefaultRequestHeaders.Add(\"Authorization\", $\"Bearer {apiKey}\");\n\n // var jsonData = JsonConvert.SerializeObject(new Data() \n // {\n // model= \"deepseek-chat\",\n // messages = new List<Message>() \n // {\n // new Message{ content=\"You are a helpful assistant.\", role=\"system\" },\n // }\n // });\n\n //var content = new StringContent(jsonData, Encoding.UTF8, \"application/json\");\n\n // try\n // {\n // var response = await client.PostAsync(url, content);\n // response.EnsureSuccessStatusCode();\n\n // var responseBody = await response.Content.ReadAsStringAsync();\n // Console.WriteLine(responseBody);\n // }\n // catch (HttpRequestException e)\n // {\n // Console.WriteLine($\"Request error: {e.Message}\");\n // }\n // }\n //Console.ReadLine();\n //var settings = new JsonSerializerSettings\n //{\n // PreserveReferencesHandling = PreserveReferencesHandling.Objects,\n // ReferenceLoopHandling = ReferenceLoopHandling.Serialize\n //};\n //var json= File.ReadAllText(\"flow.json\");\n //var flowInfoOptions = JsonConvert.DeserializeObject<FlowInfoOptions>(json, settings);\n\n\n //IServiceCollection descriptors = new ServiceCollection();\n //descriptors.AddTransient<SaltTool>();\n //descriptors.AddTransient<VibrateTool>();\n ////Container.ConfigProvider(descriptors);\n //ToolDescriptions.InitToolRunTimeDesc();\n //Flow flow = new();\n //if (flowInfoOptions != null)\n //flow.Deserialize(flowInfoOptions);\n //var guid1 = Guid.NewGuid();\n //var guid2 = Guid.NewGuid();\n //flow.CreateNewTool(\"加盐模块\", guid1);\n //flow.CreateNewTool(\"振荡模块\", guid2);\n //var tool1 = flow.GetTool(guid1);\n //var tool2 = flow.GetTool(guid2);\n //flow.Connect(tool2.InputPins[0].Id, tool1.OutputPins[1].Id);\n //flow.Connect(tool1.InputPins[0].Id, tool2.OutputPins[0].Id);\n\n //var flowInfoOptions = flow.Serialize();\n\n\n //var json = JsonConvert.SerializeObject(flowInfoOptions, settings);\n //var streamWriter= File.CreateText(\"flow.json\");\n //streamWriter.AutoFlush = true;\n //streamWriter.Write(json);\n #endregion\n\n // var status = GetAlarmStatus();\n\n // // var json = \"[{\\\"Index\\\":1,\\\"ParamName\\\":\\\"scanQrCode\\\",\\\"Comment\\\":\\\"扫码\\\",\\\"Value\\\":0,\\\"Flag\\\":0,\\\"Unit\\\":\\\"\\\",\\\"Element\\\":\\\"[{\\\\\\\"type\\\\\\\":\\\\\\\"InputNumber\\\\\\\",\\\\\\\"precision\\\\\\\":0,\\\\\\\"max\\\\\\\":0,\\\\\\\"min\\\\\\\":0,\\\\\\\"disabled\\\\\\\":true,\\\\\\\"show\\\\\\\":true}]\\\"},{\\\"Index\\\":2,\\\"ParamName\\\":\\\"samplingVolume\\\",\\\"Comment\\\":\\\"血样取样量\\\",\\\"Value\\\":250,\\\"Flag\\\":1,\\\"Unit\\\":\\\"ul\\\",\\\"Element\\\":\\\"[{\\\\\\\"type\\\\\\\":\\\\\\\"InputNumber\\\\\\\",\\\\\\\"precision\\\\\\\":0,\\\\\\\"max\\\\\\\":1500,\\\\\\\"min\\\\\\\":0,\\\\\\\"disabled\\\\\\\":false}]\\\"},{\\\"Index\\\":3,\\\"ParamName\\\":\\\"addAcidAndACN\\\",\\\"Comment\\\":\\\"加酸乙腈加入量\\\",\\\"Value\\\":1000,\\\"Flag\\\":1,\\\"Unit\\\":\\\"ul\\\",\\\"Element\\\":\\\"[{\\\\\\\"type\\\\\\\":\\\\\\\"InputNumber\\\\\\\",\\\\\\\"precision\\\\\\\":0,\\\\\\\"max\\\\\\\":1500,\\\\\\\"min\\\\\\\":0,\\\\\\\"disabled\\\\\\\":false}]\\\"},{\\\"Index\\\":4,\\\"ParamName\\\":\\\"vortexTime1\\\",\\\"Comment\\\":\\\"涡旋时间\\\",\\\"Value\\\":120,\\\"Flag\\\":1,\\\"Unit\\\":\\\"s\\\",\\\"Element\\\":\\\"[{\\\\\\\"type\\\\\\\":\\\\\\\"InputNumber\\\\\\\",\\\\\\\"precision\\\\\\\":0,\\\\\\\"max\\\\\\\":1500,\\\\\\\"min\\\\\\\":0,\\\\\\\"disabled\\\\\\\":false}]\\\"},{\\\"Index\\\":4,\\\"ParamName\\\":\\\"vortexVelocity1\\\",\\\"Comment\\\":\\\"涡旋速度\\\",\\\"Value\\\":1500,\\\"Flag\\\":1,\\\"Unit\\\":\\\"rpm\\\",\\\"Element\\\":\\\"[{\\\\\\\"type\\\\\\\":\\\\\\\"InputNumber\\\\\\\",\\\\\\\"precision\\\\\\\":0,\\\\\\\"max\\\\\\\":1500,\\\\\\\"min\\\\\\\":0,\\\\\\\"disabled\\\\\\\":false}]\\\"},{\\\"Index\\\":5,\\\"ParamName\\\":\\\"addSalt\\\",\\\"Comment\\\":\\\"加盐量\\\",\\\"Value\\\":500,\\\"Flag\\\":1,\\\"Unit\\\":\\\"mg\\\",\\\"Element\\\":\\\"[{\\\\\\\"type\\\\\\\":\\\\\\\"InputNumber\\\\\\\",\\\\\\\"precision\\\\\\\":0,\\\\\\\"max\\\\\\\":1500,\\\\\\\"min\\\\\\\":0,\\\\\\\"disabled\\\\\\\":false}]\\\"},{\\\"Index\\\":6,\\\"ParamName\\\":\\\"vortexTime2\\\",\\\"Comment\\\":\\\"加盐后涡旋时间\\\",\\\"Value\\\":120,\\\"Flag\\\":1,\\\"Unit\\\":\\\"s\\\",\\\"Element\\\":\\\"[{\\\\\\\"type\\\\\\\":\\\\\\\"InputNumber\\\\\\\",\\\\\\\"precision\\\\\\\":0,\\\\\\\"max\\\\\\\":1500,\\\\\\\"min\\\\\\\":0,\\\\\\\"disabled\\\\\\\":false}]\\\"},{\\\"Index\\\":6,\\\"ParamName\\\":\\\"vortexVelocity2\\\",\\\"Comment\\\":\\\"加盐后涡旋速度\\\",\\\"Value\\\":1500,\\\"Flag\\\":1,\\\"Unit\\\":\\\"rpm\\\",\\\"Element\\\":\\\"[{\\\\\\\"type\\\\\\\":\\\\\\\"InputNumber\\\\\\\",\\\\\\\"precision\\\\\\\":0,\\\\\\\"max\\\\\\\":1500,\\\\\\\"min\\\\\\\":0,\\\\\\\"disabled\\\\\\\":false}]\\\"}]\";\n // // var aaa = (JArray.FromObject(JsonConvert.DeserializeObject(json)));\n // // var data=new List<int>(){1,2,3,4,5};\n // //var sss= JsonConvert.SerializeObject(data);\n // // JArray a = (JArray)JsonConvert.DeserializeObject(sss);\n\n // // 输入字符串\n // string input = \"406 \";\n\n //var cdabBytes= ConvertToCDABString(input).Replace(\" \", \"\").Trim(new char[] {'\\0' });\n // Console.WriteLine(\"转换字符:\"+ cdabBytes);\n\n\n // 模板代码\n\n //BqjxModuleClassDef bqjxModuleClassDef = new()\n //{\n // ModuleClassName = \"TotalLiquidTransferModule\",\n // ModuleClassDescription = \"全液量转移模块\",\n // ModuleBaseClassName = \"ModuleBase\"\n //};\n //bqjxModuleClassDef.BqjxModuleMethodDefs.Add(new BqjxModuleMethodDef\n //{\n // ModuleMethodName = \"TotalLiquidTransfer\",\n // BqjxModuleMethodParamDefs = new List<BqjxModuleMethodParamDef> \n // {\n // new BqjxModuleMethodParamDef{ ModuleMethodParamName=\"liquids\", ModuleMethodParamType=\"float\" }\n // }\n //});\n //var code= ModuleCodeGenerator.GenerateModuleCode(bqjxModuleClassDef);\n\n //var path= Path.Combine(AppDomain.CurrentDomain.BaseDirectory,\"Codes\", bqjxModuleClassDef.ModuleClassName+\".cs\");\n\n //if (!Directory.Exists(Path.GetDirectoryName(path)))\n //{\n // Directory.CreateDirectory(Path.GetDirectoryName(path));\n //}\n //File.WriteAllText(path, code);\n //var saltTubeRackName = \"加盐试管架\";\n //var vortexTubeRackName = \"涡旋工位\";\n //ExecutionContext executionContext = new() { TaskInfo = \"\" };\n\n //LinkNode linkNode = new();\n //linkNode.Action = new StartAction(context => \n //{\n // Console.WriteLine(\"开始\");\n // //写入\n // context.Datas[saltTubeRackName] = \"A1\";\n // context.Datas[vortexTubeRackName] = \"A2\";\n //});\n //linkNode.Action = new TubeRack() { TubeRackName = \"加盐\" };\n //BqjxModuleDef bqjxModuleDef = new();\n //bqjxModuleDef.BqjxModuleClassDef.ModuleClassName = \"ConcentrationModuleBase\";\n //bqjxModuleDef.BqjxModuleClassDef.ModuleBaseClassName = \"ModuleBase\";\n //bqjxModuleDef.BqjxModuleClassDef.ModuleClassDescription=\"浓缩模块基类\";\n //bqjxModuleDef.BqjxModuleClassDef.BqjxModuleMethodDefs.Add(new BqjxModuleMethodDef\n //{\n // FuncCodeName = \"Concentration\",\n // ModuleMethodName = \"Concentration\",\n // BqjxModuleMethodParamDefs = \n // {\n // new (){ ModuleMethodParamName=\"decisionTime\", ModuleMethodParamType=\"float\" },\n // new (){ ModuleMethodParamName=\"transitionTime\", ModuleMethodParamType=\"float\" },\n // new (){ ModuleMethodParamName=\"channel1Vel\", ModuleMethodParamType=\"float\" },\n // new (){ ModuleMethodParamName=\"channel2Vel\", ModuleMethodParamType=\"float\" },\n // new (){ ModuleMethodParamName=\"channel1Terminalflow\", ModuleMethodParamType=\"float\" },\n // new (){ ModuleMethodParamName=\"channel2Terminalflow\", ModuleMethodParamType=\"float\" },\n // new (){ ModuleMethodParamName=\"channel1StartingTemperature\", ModuleMethodParamType=\"float\" },\n // new (){ ModuleMethodParamName=\"channel1TransitionTemperature\", ModuleMethodParamType=\"float\" },\n // new (){ ModuleMethodParamName=\"channel2StartingTemperature\", ModuleMethodParamType=\"float\" },\n // new (){ ModuleMethodParamName=\"channel2TransitionTemperature\", ModuleMethodParamType=\"float\" },\n // }\n //});\n //var code = ModuleCodeGenerator.GenerateModuleBaseCode(bqjxModuleDef);\n //Console.WriteLine(code);\n\n // 获取所有网络接口\n //NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();\n\n //foreach (NetworkInterface network in networkInterfaces)\n //{\n // // 忽略回环接口、未启用的接口以及非以太网和无线网卡的接口\n // if (network.OperationalStatus == OperationalStatus.Up &&\n // network.NetworkInterfaceType != NetworkInterfaceType.Loopback &&\n // (network.NetworkInterfaceType == NetworkInterfaceType.Ethernet ||\n // network.NetworkInterfaceType == NetworkInterfaceType.Wireless80211))\n // {\n // Console.WriteLine(\"网络接口名称: \" + network.Name);\n // Console.WriteLine(\"描述: \" + network.Description);\n // Console.WriteLine(\"MAC 地址: \" + network.GetPhysicalAddress().ToString());\n // Console.WriteLine();\n // }\n\n\n //}\n\n //using (var searcher = new ManagementObjectSearcher(\"SELECT SerialNumber FROM Win32_BaseBoard\"))\n //{\n // foreach (var item in searcher.Get())\n // {\n // var ss= item[\"SerialNumber\"]?.ToString().Trim();\n // }\n //}\n //var str = new string[] {\"A01\",\"B02\",\"A02\",\"A04\",\"B06\",\"C01\",\"D01\",\"C06\",\"D02\" };\n ////排序\n //var result = str.OrderBy(x => x).ToArray();\n //Console.WriteLine(string.Join(\",\", result));\n //DefaultLoggerProviderAware _loggerProviderAware = new();\n //_loggerProviderAware.Configure();\n //LoggerProviderManager.RegisterLoggerProviderAware(_loggerProviderAware);\n //ModularDev modularDev = new(new H5uModbusTcpMock(\"\", 502));\n //await modularDev.HomeAsync();\n //await modularDev.CheckModuleHomeDoneAsync();\n //await modularDev.WriteParameterAsync([]);\n //await modularDev.ModuleExecuteAsync();\n //await modularDev.CheckModuleDoneAsync();\n\n //for (int a = 0; a < 288; a++)\n //{\n // ModuleReportRunDataEntity moduleReportRunDataEntity = new();\n // moduleReportRunDataEntity.ModuleName = \"加液模块\";\n // moduleReportRunDataEntity.ModuleActionDescription = \"\";\n // moduleReportRunDataEntity.Alarms =\n //[\n // new ModuleReportAlarmEntity\n // {\n // AlarmCode=\"ALM_01\",\n // }\n //];\n // moduleReportRunDataEntity.ModuleParameter = \"\";\n // moduleReportRunDataEntity.PlatFormName = \"加液平台\";\n // moduleReportRunDataEntity.StartDay = new DateOnly(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);\n // moduleReportRunDataEntity.StartTime = DateTime.Now;\n // moduleReportRunDataEntity.TaskDatas = [];\n // for (int i = 0; i < 300; i++)\n // {\n // var taskData = new ModuleReportMonitorTaskDataOnceEntity();\n // for (int j = 0; j < 5; j++)\n // {\n // taskData.ModuleReportCollectTaskDataItemEntities.Add(new ModuleReportMonitorTaskDataItemEntity\n // {\n // MonitorName = $\"采集项{j}\",\n // MonitorTime = DateTime.Now,\n // MonitorValue = i.ToString()\n // });\n // }\n // moduleReportRunDataEntity.TaskDatas.Add(taskData);\n // }\n\n // var json = JsonConvert.SerializeObject(moduleReportRunDataEntity);\n //}\n ReentrantLockService<Data> lockService = new ReentrantLockService<Data>();\n\n Data data = new Data() { model=\"你好\" };\n //Task.Run(() => \n //{\n // using (var lockVc = lockService.Acquire(data, \"key1\"))\n // {\n // Thread.Sleep(3000);\n // Console.WriteLine($\"key1:{data.model}\");\n // }\n //});\n //Task.Run(() =>\n //{\n // using (var lockVc = lockService.Acquire(data, \"key2\"))\n // {\n // Thread.Sleep(2000);\n // Console.WriteLine($\"key2:{data.model}\");\n // }\n //});\n // 按顺序发起 Parallel.For 的锁请求\n //var tasks = new List<Task>();\n //for (int i = 0; i < 10; i++)\n //{\n // int index = i; // 捕获循环变量\n // tasks.Add(Task.Run(() =>\n // {\n // using var lockVc = lockService.Acquire(data, $\"key{index}\");\n // Thread.Sleep(1000);\n // Console.WriteLine($\"{index}:{data.model}\");\n // var lockse= lockService.Acquire(data, $\"key{index}\");\n // Thread.Sleep(1000);\n // Console.WriteLine($\"二次锁{index}:{data.model}\");\n // lockse.Dispose();\n // }));\n //}\n\n //// 等待所有任务完成\n //await Task.WhenAll(tasks);\n TemporaryTimingWheel timingWheel = new TemporaryTimingWheel();\n timingWheel.RegisterNotify(\"1\", (task) => \n {\n Console.WriteLine($\"执行任务1,{task.Id}{task.RemainingRounds}\");\n });\n timingWheel.RegisterNotify(\"2\", (task) => \n {\n Console.WriteLine($\"执行任务2,{task.Id},{DateTime.Now},{task.RemainingRounds}\");\n });\n timingWheel.AddTask(\"1\",new TemporaryTask \n {\n Id=1, RemainingRounds=5\n });\n Thread.Sleep(5000);\n for (int i = 0; i < 10000000; i++)\n {\n timingWheel.AddTask(\"2\", new TemporaryTask { Id = i, RemainingRounds = 5+i/100 });\n }\n Console.ReadLine();\n }\n static string ConvertToCDABString(string input)\n {\n byte[] bytes = ASCIIEncoding.ASCII.GetBytes(input);\n int paddingLength = 2 - (bytes.Length % 2);\n if (paddingLength == 2) paddingLength = 0;\n byte[] paddedBytes = new byte[bytes.Length + paddingLength];\n Array.Copy(bytes, paddedBytes, bytes.Length);\n byte[] cdabBytes = new byte[paddedBytes.Length];\n for (int i = 0; i < paddedBytes.Length; i += 2)\n {\n if (i + 2 <= paddedBytes.Length)\n {\n cdabBytes[i] = paddedBytes[i + 1];\n cdabBytes[i + 1] = paddedBytes[i];\n }\n else\n {\n cdabBytes[i] = paddedBytes[i];\n }\n }\n return ASCIIEncoding.ASCII.GetString(cdabBytes).Replace(\" \", \"\").Trim(new char[] { '\\0' });\n }\n }\n /// <summary>\n /// 模块定义\n /// </summary>\n public class BqjxModuleDef\n {\n /// <summary>\n /// 命名空间名称\n /// </summary>\n public string NamespaceName { get; set; }\n\n /// <summary>\n /// 模块类定义\n /// </summary>\n public BqjxModuleClassDef BqjxModuleClassDef { get; set; } = new BqjxModuleClassDef();\n }\n public class BqjxModuleClassDef\n {\n /// <summary>\n /// 模块名称\n /// </summary>\n public string ModuleClassName { get; set; }\n\n public string ModuleClassDescription { get; set; }\n /// <summary>\n /// 模块基类名称\n /// </summary>\n public string ModuleBaseClassName { get; set; }\n\n\n public List<BqjxModulePropertyDef> BqjxModulePropertyDefs { get; set; } = [];\n public List<BqjxModuleMethodDef> BqjxModuleMethodDefs { get; set; } = [];\n }\n\n public class BqjxModulePropertyDef\n {\n public string ModulePropertyName { get; set; }\n\n public string ModulePropertyType { get; set; }\n }\n\n public class BqjxModuleMethodDef\n {\n public string ModuleMethodName { get; set; }\n\n public string FuncCodeName { get; set; }\n public List<BqjxModuleMethodParamDef> BqjxModuleMethodParamDefs { get; set; } = [];\n }\n\n public class BqjxModuleMethodParamDef\n {\n public string ModuleMethodParamName { get; set; }\n\n public string ModuleMethodParamType { get; set; }\n }\n\n public static class ModuleCodeGenerator\n {\n /// <summary>\n /// 生成模块基类代码\n /// </summary>\n /// <param name=\"bqjxModuleClassDef\"></param>\n /// <returns></returns>\n public static string GenerateModuleBaseCode(BqjxModuleDef bqjxModuleDef)\n {\n StringBuilder sb = new ();\n\n //命名空间\n sb.AppendLine(\"using BQJX.Core.Common.Common.JsonAccess;\");\n sb.AppendLine(\"using BQJX.Core.Common.Interface;\");\n sb.AppendLine(\"using BQJX.Modules.Common;\");\n sb.AppendLine(\"using System;\");\n sb.AppendLine(\"using System.Collections.Generic;\");\n sb.AppendLine(\"using System.Linq;\");\n sb.AppendLine(\"using System.Text;\");\n sb.AppendLine(\"using System.Threading.Tasks;\");\n sb.AppendLine();\n sb.AppendLine(\"namespace \"+ bqjxModuleDef.NamespaceName);\n\n // 类头部注释\n sb.AppendLine(\"/// <summary>\");\n sb.AppendLine(\"/// \" + bqjxModuleDef.BqjxModuleClassDef.ModuleClassDescription);\n sb.AppendLine(\"/// </summary>\");\n // 类声明\n sb.AppendLine($\"public abstract class {bqjxModuleDef.BqjxModuleClassDef.ModuleClassName} : {bqjxModuleDef.BqjxModuleClassDef.ModuleBaseClassName}\");\n sb.AppendLine(\"{\");\n\n // 构造函数\n //sb.AppendLine($\" public {bqjxModuleClassDef.ModuleClassName}(IModuleEntity moduleEntity) : base()\");\n //sb.AppendLine(\" {\");\n //sb.AppendLine(\" this.ModuleName = moduleEntity.ModuleName;\");\n //sb.AppendLine(\" this.PlatFormName = moduleEntity.PlatFormName;\");\n //sb.AppendLine(\" _plc = moduleEntity.PLC;\");\n //sb.AppendLine(\" _autoCtlInfo = new AutoControlInfo();\");\n //sb.AppendLine($\" _logger = MyLoggerFactory.GetLogger(typeof({bqjxModuleClassDef.ModuleClassName}));\");\n //sb.AppendLine(\" }\");\n sb.AppendLine();\n\n // Execute 方法\n sb.AppendLine(\" public override object Execute(Dictionary<string, object> parameters, string methodName, IGlobalStatus gs)\");\n sb.AppendLine(\" {\");\n sb.AppendLine(\" switch (methodName)\");\n sb.AppendLine(\" {\");\n foreach (var item in bqjxModuleDef.BqjxModuleClassDef.BqjxModuleMethodDefs)\n {\n sb.AppendLine($\" case nameof({item.ModuleMethodName}):\");\n if (item.BqjxModuleMethodParamDefs.Count > 0)\n {\n foreach (var paramDef in item.BqjxModuleMethodParamDefs)\n {\n sb.AppendLine($\" var {paramDef.ModuleMethodParamName.ToLower()} =({paramDef.ModuleMethodParamType})parameters[{paramDef.ModuleMethodParamName}] \");\n }\n }\n if (item.BqjxModuleMethodParamDefs.Count > 0)\n {\n sb.AppendLine($\" return {item.ModuleMethodName}({string.Join(\",\", item.BqjxModuleMethodParamDefs.Select(p => p.ModuleMethodParamName.ToLower()))},gs);\");\n }\n else\n {\n sb.AppendLine($\" return {item.ModuleMethodName}(gs);\");\n }\n }\n sb.AppendLine(\" default:\");\n sb.AppendLine(\" _logger?.Error($\\\"method is not exist name :{methodName}\\\");\");\n sb.AppendLine(\" return 0;\");\n sb.AppendLine(\" }\");\n sb.AppendLine(\" }\");\n sb.AppendLine();\n\n // 方法\n foreach (var item in bqjxModuleDef.BqjxModuleClassDef.BqjxModuleMethodDefs)\n {\n if (item.BqjxModuleMethodParamDefs.Count > 0)\n {\n sb.AppendLine($\" public int {item.ModuleMethodName}({string.Join(\",\", item.BqjxModuleMethodParamDefs.Select(p =>$\"{p.ModuleMethodParamType} {p.ModuleMethodParamName.ToLower()}\"))},IGlobalStatus gs)\");\n }\n else\n sb.AppendLine($\" public int {item.ModuleMethodName}(IGlobalStatus gs)\");\n sb.AppendLine(\" {\");\n sb.AppendLine(\"#if VIRTUAL\");\n sb.AppendLine($\" _logger?.Info($\\\"{item.ModuleMethodName} \\\");\");\n sb.AppendLine(\" Thread.Sleep(5000);\");\n sb.AppendLine(\" return Task.FromResult(true);\");\n sb.AppendLine(\"#endif\");\n sb.AppendLine(\" try\");\n sb.AppendLine(\" {\");\n if (item.BqjxModuleMethodParamDefs.Count > 0)\n {\n sb.AppendLine($\" var result = ExecuteCommand<float>(new float[]{string.Join(\",\", item.BqjxModuleMethodParamDefs.Select(p => p.ModuleMethodParamName.ToLower()))}, FuncCodeEnum.{item.FuncCodeName}, gs);\");\n }\n else\n {\n sb.AppendLine($\" var result = ExecuteCommand<float>(null, FuncCodeEnum.{item.FuncCodeName}, gs);\");\n }\n sb.AppendLine(\" if (result != 99999)\");\n sb.AppendLine(\" {\");\n sb.AppendLine($\" _logger?.Warn($\\\"unable to {item.ModuleMethodName} code:{{result}}\\\");\");\n sb.AppendLine(\" }\");\n sb.AppendLine(\" return result;\");\n sb.AppendLine(\" }\");\n sb.AppendLine(\" catch (Exception ex)\");\n sb.AppendLine(\" {\");\n sb.AppendLine(\" _logger?.Error(ex.ToString());\");\n sb.AppendLine(\" return (int)CommandExecuteErrCode.InnerErr;\");\n sb.AppendLine(\" }\");\n sb.AppendLine(\" }\");\n }\n sb.AppendLine();\n\n // GetEnvironmentData 方法\n sb.AppendLine(\" public override Task<Dictionary<string, float>> GetEnvironmentData()\");\n sb.AppendLine(\" {\");\n sb.AppendLine(\" return Task.FromResult(new Dictionary<string, float>());\");\n sb.AppendLine(\" }\");\n sb.AppendLine();\n\n // GetMonitorData 方法\n sb.AppendLine(\" public override Task<Dictionary<string, float>> GetMonitorData()\");\n sb.AppendLine(\" {\");\n sb.AppendLine(\" return Task.FromResult(new Dictionary<string, float>());\");\n sb.AppendLine(\" }\");\n sb.AppendLine();\n\n // SetEnvironmentData 方法\n sb.AppendLine(\" public override Task<bool> SetEnvironmentData(Dictionary<string, float> floatDatas)\");\n sb.AppendLine(\" {\");\n sb.AppendLine(\" return Task.FromResult(false);\");\n sb.AppendLine(\" }\");\n sb.AppendLine();\n\n // GetErrorInfoEntities 方法\n sb.AppendLine(\" protected override List<ErrInfoEntity>? GetErrorInfoEntities()\");\n sb.AppendLine(\" {\");\n sb.AppendLine(\" try\");\n sb.AppendLine(\" {\");\n sb.AppendLine($\" var stringInfo = File.ReadAllText($\\\"./{{nameof({bqjxModuleDef.BqjxModuleClassDef.ModuleClassName})}}AlarmInfo.json\\\");\");\n sb.AppendLine(\" return JsonHelper.ConvertToObject<List<ErrInfoEntity>>(stringInfo);\");\n sb.AppendLine(\" }\");\n sb.AppendLine(\" catch (Exception ex)\");\n sb.AppendLine(\" {\");\n sb.AppendLine(\" _logger?.Error(ex.ToString());\");\n sb.AppendLine(\" return null;\");\n sb.AppendLine(\" }\");\n sb.AppendLine(\" }\");\n\n sb.AppendLine(\"}\");\n\n return sb.ToString();\n }\n }\n\n\n public class ActionResult\n {\n //是否成功\n public bool IsSuccess { get; set; }\n\n\n public object ReturnValue { get; set; }\n\n public static ActionResult Success(object returnValue)\n {\n return new ActionResult { IsSuccess = true, ReturnValue = returnValue };\n }\n\n public static ActionResult Fail()\n {\n return new ActionResult { IsSuccess = false };\n }\n }\n\n public class ExecutionContext\n {\n public string TaskInfo { get; set; }\n public Dictionary<string,object> Datas { get; set; } = new Dictionary<string, object>();\n }\n\n public interface IAction\n {\n Task Execute(ExecutionContext executionContext);\n }\n\n /// <summary>\n /// 条件节点\n /// </summary>\n public class Condition : IAction\n {\n public IAction TrueAction { get; set; }\n\n public IAction FalseAction { get; set; }\n\n public Func<ExecutionContext, bool> ConditionFunc { get; set; }\n public async Task Execute(ExecutionContext executionContext)\n {\n if (ConditionFunc(executionContext))\n {\n await TrueAction.Execute(executionContext);\n }\n else\n {\n await FalseAction.Execute(executionContext);\n }\n }\n }\n\n public class LinkNode : IAction\n {\n public IAction Action { get; set; }\n\n public LinkNode Next { get; set; }\n\n public async Task Execute(ExecutionContext executionContext)\n {\n await Action.Execute(executionContext);\n var root = Next;\n if (root != null)\n {\n while (root != null)\n {\n await Next.Execute(executionContext);\n root = Next.Next;\n }\n }\n }\n }\n\n public class TreeNode : IAction\n {\n public IAction Action { get; set; }\n\n public List<TreeNode> Children { get; set; } = [];\n\n public async Task Execute(ExecutionContext executionContext)\n {\n await Traverse(this,executionContext);\n }\n internal static async Task Traverse(TreeNode treeNode, ExecutionContext executionContext)\n {\n await treeNode.Execute(executionContext);\n foreach (var item in treeNode.Children)\n {\n await Traverse(item, executionContext);\n }\n }\n }\n\n public class ForEach : IAction\n {\n public List<IAction> Actions { get; set; } = [];\n\n public bool IsParallel { get; set; }\n\n public async Task Execute(ExecutionContext executionContext)\n {\n if (IsParallel)\n {\n foreach (var item in Actions.AsParallel())\n {\n await item.Execute(executionContext);\n }\n }\n else\n foreach (var item in Actions)\n {\n await item.Execute(executionContext);\n }\n }\n }\n\n public class StartAction : IAction\n {\n private readonly Action<ExecutionContext> _startAction;\n public StartAction(Action<ExecutionContext> action)\n {\n _startAction = action;\n }\n public Task Execute(ExecutionContext executionContext)\n {\n _startAction(executionContext);\n return Task.CompletedTask;\n }\n }\n\n public class FlowChart\n {\n private readonly List<IAction> nodes = [];\n public void AddRootNode(IAction node)\n {\n nodes.Add(node);\n }\n public void Execute(ExecutionContext executionContext)\n {\n nodes.AsParallel().ForAll(async node =>\n {\n await node.Execute(executionContext);\n });\n }\n }\n\n\n\n //public class Node\n //{\n // public string Name { get; set; }\n\n // public List<Pin> InputPins { get; set; } = [];\n\n // public List<Pin> OutputPins { get; set; } = [];\n //}\n\n //public class Pin\n //{\n // public List<Node> Connections { get; set; } = [];\n //}\n\n\n public class Sample\n {\n public Sample(string name)\n {\n SampleName = name;\n }\n public string SampleName { get; set; }\n }\n\n public interface IBlackboard\n {\n \n }\n\n public interface IBlock\n {\n bool Execute(IBlackboard blackboard);\n }\n\n public class Module : IBlock\n {\n\n public bool Execute(IBlackboard blackboard)\n {\n return true;\n }\n }\n\n public class Platform : IBlock\n {\n public bool Execute(IBlackboard blackboard)\n {\n return true;\n }\n }\n\n}\n"}}}}