123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace AwInitilizer.Model
- {
- public enum ConnectorType
- {
- Unknown, None, CHadeMO, CCS1, CCS2, GBT, AC
- }
- public class SystemID
- {
- public ModelName ModelName { get; set; }
- public string SerialNumber { get; set; }
- public string sourceString { get; set; }
- public static bool TryParse(byte[] byteData, out SystemID connectInfo)
- {
- connectInfo = null;
- if (byteData == null || byteData.Length < 14)
- return false;
- string systemIDString = null;
- try
- {
- systemIDString = Encoding.ASCII.GetString(byteData);
- }
- catch
- {
- return false;
- }
- if (!string.IsNullOrEmpty(systemIDString))
- {
- return TryParse(systemIDString, out connectInfo);
- }
- return false;
- }
- public static bool TryParse(string byteString, out SystemID connectInfo)
- {
- connectInfo = null;
- SystemID tmp = new SystemID();
- tmp.sourceString = byteString;
- if (tmp.sourceString.Length < 14)
- return false;
- if (!ModelName.TryParse(tmp.sourceString.Substring(0, 14), out var model))
- return false;
- tmp.ModelName = model;
- tmp.SerialNumber = tmp.sourceString.Substring(14);
- connectInfo = tmp;
- return true;
- }
- public string ToWifiPwd()
- {
- return SerialNumber + ModelName.ToString();
- }
- public override string ToString()
- {
- return sourceString;
- }
- public override bool Equals(object obj)
- {
- return obj.ToString() == this.ToString();
- }
- public override int GetHashCode()
- {
- return this.ToString().GetHashCode();
- }
- public static bool operator ==(SystemID a, SystemID b)
- {
- string stra = null, strb = null;
- if (Object.Equals(a, null))
- stra = null;
- else
- stra = a.ToString();
- if (Object.Equals(b, null))
- strb = null;
- else
- strb = b.ToString();
- return string.Equals(a, b);
- }
- public static bool operator !=(SystemID a, SystemID b)
- {
- string stra = null, strb = null;
- if (Object.Equals(a, null))
- stra = null;
- else
- stra = a.ToString();
- if (Object.Equals(b, null))
- strb = null;
- else
- strb = b.ToString();
- return !string.Equals(a, b);
- }
- }
- public class ModelName
- {
- public enum EVSE_TYPE_CAT
- {
- Unknown,
- AC,
- DC,
- Hybrid
- }
- public enum EVSE_TYPE
- {
- Unknown,
- AC_Cordset,
- AC_Wallmount,
- AC_Pedestal,
- DC_Wallmount,
- DC_Standalong,
- DC_Movable,
- DC_Roadside,
- DC_Disppenser,
- DC_Outputpowercabinet
- }
- public enum EVSE_InputConfig
- {
- Y, D, L, S, W, T, E , N0, N1, N2, N3, N4, N5, N6, N7, N8, N9,
- }
- public enum EVSE_SafetyReg
- {
- Europoean,
- NorthAmerica,
- China,
- Taiwan,
- Japan,
- Singapor,
- Korea,
- UK,
- French,
- M,
- P,
- I,
- F,
- L
- }
- public enum EVSE_network
- {
- None,
- Ethernet,
- Ble,
- EthWiFi,
- Eth4G,
- EthBle,
- EthWiFi4G,
- }
- public EVSE_TYPE Type { get; private set; }
- public EVSE_InputConfig InputConfig { get; private set; }
- public EVSE_SafetyReg SafetyReg { get; private set; }
- public double RatedPower { get; private set; }
- public ConnectorType[] ConnectorTypes { get; private set; }
- public EVSE_network Network { get; private set; }
- public int Generation { get; private set; }
- public string CustomCode { get; private set; }
- public EVSE_TYPE_CAT Type_Cat { get => GetTypeCat(); }
- private string _modelNameString;
- public string modelNameString
- {
- get => _modelNameString;
- set
- {
- if (TryParse(value, out var result))
- {
- this.Type = result.Type;
- this.InputConfig = result.InputConfig;
- this.SafetyReg = result.SafetyReg;
- this.RatedPower = result.RatedPower;
- this.ConnectorTypes = result.ConnectorTypes;
- this.Network = result.Network;
- this.Generation = result.Generation;
- this.CustomCode = result.CustomCode;
- _modelNameString = value;
- }
- }
- }
- public static bool TryParse(byte[] modeNameByte, out ModelName modelName)
- {
- modelName = null;
- string modelNameString;
- try
- {
- modelNameString = Encoding.ASCII.GetString(modeNameByte);
- }
- catch
- {
- return false;
- }
- if (modelNameString.Length != 14 && modelNameString.Length != 12)
- return false;
- return TryParse(modelNameString, out modelName);
- }
- public static bool TryParse(string modeNameString, out ModelName modelName)
- {
- modelName = null;
- ModelName model = new ModelName();
- if (modeNameString == null || modeNameString.Length != 14)
- return false;
- bool isAc = modeNameString[0] == 'A';
- var typeString = modeNameString.Substring(0, 2);
- switch (typeString)
- {
- case "AC":
- model.Type = EVSE_TYPE.AC_Cordset;
- break;
- case "AW":
- model.Type = EVSE_TYPE.AC_Wallmount;
- break;
- case "AP":
- model.Type = EVSE_TYPE.AC_Pedestal;
- break;
- case "DW":
- model.Type = EVSE_TYPE.DC_Wallmount;
- break;
- case "DS":
- model.Type = EVSE_TYPE.DC_Standalong;
- break;
- case "DM":
- model.Type = EVSE_TYPE.DC_Movable;
- break;
- case "DR":
- model.Type = EVSE_TYPE.DC_Roadside;
- break;
- case "DD":
- model.Type = EVSE_TYPE.DC_Disppenser;
- break;
- case "DO":
- model.Type = EVSE_TYPE.DC_Outputpowercabinet;
- break;
- default:
- return false;
- }
- var inputConfigStr = modeNameString.Substring(2, 1);
- switch (inputConfigStr)
- {
- case "Y":
- model.InputConfig = EVSE_InputConfig.Y;
- break;
- case "D":
- model.InputConfig = EVSE_InputConfig.D;
- break;
- case "L":
- model.InputConfig = EVSE_InputConfig.L;
- break;
- case "S":
- model.InputConfig = EVSE_InputConfig.S;
- break;
- case "W":
- model.InputConfig = EVSE_InputConfig.W;
- break;
- case "T":
- model.InputConfig = EVSE_InputConfig.T;
- break;
- case "E":
- model.InputConfig = EVSE_InputConfig.E;
- break;
- case "0":
- model.InputConfig = EVSE_InputConfig.N0;
- break;
- case "1":
- model.InputConfig = EVSE_InputConfig.N1;
- break;
- case "2":
- model.InputConfig = EVSE_InputConfig.N2;
- break;
- case "3":
- model.InputConfig = EVSE_InputConfig.N3;
- break;
- case "4":
- model.InputConfig = EVSE_InputConfig.N4;
- break;
- case "5":
- model.InputConfig = EVSE_InputConfig.N5;
- break;
- case "6":
- model.InputConfig = EVSE_InputConfig.N6;
- break;
- case "7":
- model.InputConfig = EVSE_InputConfig.N7;
- break;
- case "8":
- model.InputConfig = EVSE_InputConfig.N8;
- break;
- case "9":
- model.InputConfig = EVSE_InputConfig.N9;
- break;
- default:
- return false;
- }
- var safeRegStr = modeNameString.Substring(3, 1);
- switch (safeRegStr)
- {
- case "E":
- model.SafetyReg = EVSE_SafetyReg.Europoean;
- break;
- case "U":
- model.SafetyReg = EVSE_SafetyReg.NorthAmerica;
- break;
- case "G":
- model.SafetyReg = EVSE_SafetyReg.China;
- break;
- case "C":
- model.SafetyReg = EVSE_SafetyReg.Taiwan;
- break;
- case "J":
- model.SafetyReg = EVSE_SafetyReg.Japan;
- break;
- case "T":
- model.SafetyReg = EVSE_SafetyReg.Singapor;
- break;
- case "K":
- model.SafetyReg = EVSE_SafetyReg.Korea;
- break;
- case "B":
- model.SafetyReg = EVSE_SafetyReg.UK;
- break;
- case "Z":
- model.SafetyReg = EVSE_SafetyReg.French;
- break;
- case "M":
- model.SafetyReg = EVSE_SafetyReg.M;
- break;
- case "P":
- model.SafetyReg = EVSE_SafetyReg.P;
- break;
- case "I":
- model.SafetyReg = EVSE_SafetyReg.I;
- break;
- case "F":
- model.SafetyReg = EVSE_SafetyReg.F;
- break;
- case "L":
- model.SafetyReg = EVSE_SafetyReg.L;
- break;
- default:
- return false;
- }
- var ratedPowerStr = modeNameString.Substring(4, 3);
- if (!int.TryParse(ratedPowerStr, out int ratedPowerNum) &&
- ratedPowerNum > 0)
- return false;
- double realnum = (double)ratedPowerNum / 10;
- var exp = ratedPowerNum % 10;
- model.RatedPower = (double)(realnum * (10 ^ exp));
- model.ConnectorTypes = new ConnectorType[3];
- var connectorListStr = modeNameString.Substring(7, 3);
- /*
- model.ConnectorTypes.Add(ConnectorType.CHadeMO);
- model.ConnectorTypes.Add(ConnectorType.CCS);
- model.ConnectorTypes.Add(ConnectorType.IEC);
- */
- for (int index = 0; index < 3; index++)
- {
- var connectorStr = connectorListStr.Substring(index, 1);
- switch (connectorStr)
- {
- case "0":
- //none connecter
- model.ConnectorTypes[index] = ConnectorType.None;
- break;
- case "1":
- case "2":
- case "3":
- case "4":
- case "5":
- case "6":
- model.ConnectorTypes[index] = ConnectorType.AC;
- break;
- case "J":
- model.ConnectorTypes[index] = ConnectorType.CHadeMO;
- break;
- case "U":
- case "V":
- model.ConnectorTypes[index] = ConnectorType.CCS1;
- break;
- case "E":
- case "F":
- model.ConnectorTypes[index] = ConnectorType.CCS2;
- break;
- case "G":
- model.ConnectorTypes[index] = ConnectorType.GBT;
- break;
- default:
- return false;
- }
- }
- var networkOpStr = modeNameString.Substring(10, 1);
- switch (networkOpStr)
- {
- case "0":
- model.Network = EVSE_network.None;
- break;
- case "E":
- model.Network = EVSE_network.Ethernet;
- break;
- case "B":
- model.Network = EVSE_network.Ble;
- break;
- case "W":
- model.Network = EVSE_network.EthWiFi;
- break;
- case "T":
- model.Network = EVSE_network.Eth4G;
- break;
- case "U":
- model.Network = EVSE_network.EthBle;
- break;
- case "D":
- case "A":
- model.Network = EVSE_network.EthWiFi4G;
- break;
- default:
- return false;
- }
- var genStr = modeNameString.Substring(11, 1);
- if (!int.TryParse(genStr, out var genInt))
- return false;
- model.Generation = genInt;
- model.CustomCode = modeNameString.Substring(12, 2);
- model._modelNameString = modeNameString;
- modelName = model;
- return true;
- }
- public ModelName() { }
- public override string ToString()
- {
- return modelNameString;
- }
- private EVSE_TYPE_CAT GetTypeCat()
- {
- string typeString = Type.ToString();
- if (typeString.Contains("AC"))
- return EVSE_TYPE_CAT.AC;
- else if (typeString.Contains("DC"))
- return EVSE_TYPE_CAT.DC;
- return EVSE_TYPE_CAT.Hybrid;
- }
- }
- }
|