123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- using Edge.Core.Parser.BinaryParser.Attributes;
- using Edge.Core.Parser.BinaryParser;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Edge.Core.Parser.BinaryParser.MessageEntity;
- using static VeederRoot_ATG_Console.MessageEntity.MessageBase;
- namespace VeederRoot_ATG_Console.MessageEntity
- {
- public static class FunctionCodeWrapper
- {
- private static List<Tuple<string, FuncCode, MessageFormat>> map
- = new List<Tuple<string, FuncCode, MessageFormat>>()
- {
- new Tuple<string, FuncCode, MessageFormat>("i201",
- FuncCode.QueryInTankInventoryReport, MessageFormat.Computer ),
- new Tuple<string, FuncCode, MessageFormat>("I201",
- FuncCode.QueryInTankInventoryReport, MessageFormat.Display),
- new Tuple<string, FuncCode, MessageFormat>("i501",
- FuncCode.QueryTimeOfDay, MessageFormat.Computer),
- new Tuple<string, FuncCode, MessageFormat>("I501",
- FuncCode.QueryTimeOfDay, MessageFormat.Display),
- new Tuple<string, FuncCode, MessageFormat>("s501",
- FuncCode.SetTimeOfDay, MessageFormat.Computer),
- new Tuple<string, FuncCode, MessageFormat>("S501",
- FuncCode.SetTimeOfDay, MessageFormat.Display),
- new Tuple<string, FuncCode, MessageFormat>("i205",
- FuncCode.QueryInTankStatusReport, MessageFormat.Computer),
- new Tuple<string, FuncCode, MessageFormat>("I205",
- FuncCode.QueryInTankStatusReport, MessageFormat.Display),
- new Tuple<string, FuncCode, MessageFormat>("i20C",
- FuncCode.QueryInTankMostRecentDeliveryReport, MessageFormat.Computer),
- new Tuple<string, FuncCode, MessageFormat>("I20C",
- FuncCode.QueryInTankMostRecentDeliveryReport, MessageFormat.Display),
- new Tuple<string, FuncCode, MessageFormat>("i505",
- FuncCode.QuerySystemTypeAndLanguageFlags, MessageFormat.Computer),
- new Tuple<string, FuncCode, MessageFormat>("I505",
- FuncCode.QuerySystemTypeAndLanguageFlags, MessageFormat.Display),
- new Tuple<string, FuncCode, MessageFormat>("i517",
- FuncCode.QuerySystemTypeAndLanguageFlags_Extended, MessageFormat.Computer),
- new Tuple<string, FuncCode, MessageFormat>("I517",
- FuncCode.QuerySystemTypeAndLanguageFlags_Extended, MessageFormat.Display),
- new Tuple<string, FuncCode, MessageFormat>("s505",
- FuncCode.SetSystemTypeAndLanguageFlags, MessageFormat.Computer),
- new Tuple<string, FuncCode, MessageFormat>("S505",
- FuncCode.SetSystemTypeAndLanguageFlags, MessageFormat.Display),
- new Tuple<string, FuncCode, MessageFormat>("i602",
- FuncCode.QueryTankProductLabel, MessageFormat.Computer),
- new Tuple<string, FuncCode, MessageFormat>("I602",
- FuncCode.QueryTankProductLabel, MessageFormat.Display),
- new Tuple<string, FuncCode, MessageFormat>("s602",
- FuncCode.SetTankProductLabel, MessageFormat.Computer),
- new Tuple<string, FuncCode, MessageFormat>("S602",
- FuncCode.SetTankProductLabel, MessageFormat.Display),
- new Tuple<string, FuncCode, MessageFormat>("i607",
- FuncCode.QueryTankDiameter, MessageFormat.Computer),
- new Tuple<string, FuncCode, MessageFormat>("I607",
- FuncCode.QueryTankDiameter, MessageFormat.Display),
- new Tuple<string, FuncCode, MessageFormat>("s607",
- FuncCode.SetTankDiameter, MessageFormat.Computer),
- new Tuple<string, FuncCode, MessageFormat>("S607",
- FuncCode.SetTankDiameter, MessageFormat.Display),
- new Tuple<string, FuncCode, MessageFormat>("i101",
- FuncCode.QuerySystemStatusReport, MessageFormat.Computer),
- new Tuple<string, FuncCode, MessageFormat>("I101",
- FuncCode.QuerySystemStatusReport, MessageFormat.Display),
- new Tuple<string, FuncCode, MessageFormat>("iA01",
- FuncCode.QueryInTankDiagnosticReport, MessageFormat.Computer),
- new Tuple<string, FuncCode, MessageFormat>("IA01",
- FuncCode.QueryInTankDiagnosticReport, MessageFormat.Display)
- };
-
-
-
-
-
- public static Tuple<MessageFormat, FuncCode> FromRawCode(string rawCode)
- {
- return map.Where(c => rawCode.StartsWith(c.Item1))
- .Select(s => new Tuple<MessageFormat, FuncCode>(s.Item3, s.Item2)).FirstOrDefault();
- }
-
-
-
-
-
-
- public static string ToRawCode(MessageFormat messageFormat, FuncCode functionCode)
- {
- return map.Where(c => c.Item2 == functionCode && c.Item3 == messageFormat)
- .Select(s => s.Item1).FirstOrDefault();
- }
- }
- public abstract class MessageBase : MessageBaseGeneric
- {
- public enum MessageFormat
- {
-
-
-
-
-
-
-
- Computer,
-
-
-
-
-
-
-
- Display,
- }
- public enum FuncCode
- {
-
-
-
- QuerySystemTypeAndLanguageFlags,
-
-
-
- QuerySystemTypeAndLanguageFlags_Extended,
-
-
-
- SetSystemTypeAndLanguageFlags,
-
-
-
- QueryInTankInventoryReport,
-
-
-
- QueryTimeOfDay,
-
-
-
- SetTimeOfDay,
-
-
-
- QueryInTankStatusReport,
-
-
-
- QueryInTankMostRecentDeliveryReport,
-
-
-
- QueryTankProductLabel,
-
-
-
- SetTankProductLabel,
-
-
-
- QueryTankDiameter,
-
-
-
- SetTankDiameter,
-
-
-
- QuerySystemStatusReport,
-
-
-
-
- QueryInTankDiagnosticReport,
- Undefined,
- }
- [Format(1, EncodingType.BIN, -9999)]
- public byte SOH { get; set; } = 0x01;
-
-
-
-
- [Format(6, EncodingType.ASCII, -9000)]
- public string FunctionCodeRaw { get; set; }
-
-
-
-
- public Tuple<MessageFormat, FuncCode, string> FunctionCode
- {
- get
- {
- var c = FunctionCodeWrapper.FromRawCode(this.FunctionCodeRaw);
- return new Tuple<MessageFormat,
- FuncCode,
- string>(
- c.Item1,
- c.Item2,
- this.FunctionCodeRaw.Substring(4, 2));
- }
- set
- {
- var raw = FunctionCodeWrapper.ToRawCode(value.Item1, value.Item2);
- if (string.IsNullOrEmpty(raw))
- throw new ArgumentException("Can't find raw function code for: " + value.Item1 + " - " + value.Item2);
- if (!string.IsNullOrEmpty(value.Item3))
- raw += value.Item3.PadLeft(2, '0');
- else
- raw = raw.PadRight(6, '0');
- if (raw.Length != 6) throw new ArgumentException("Function code must have length 6, but now is " + raw.Length);
- this.FunctionCodeRaw = raw;
- }
- }
- }
- }
|