|
@@ -1,606 +0,0 @@
|
|
|
-using AwInitilizer.Model;
|
|
|
-using Newtonsoft.Json;
|
|
|
-using System;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Linq;
|
|
|
-using System.Net.Http;
|
|
|
-using System.Text;
|
|
|
-using System.Text.RegularExpressions;
|
|
|
-using System.Threading.Tasks;
|
|
|
-using System.Windows;
|
|
|
-
|
|
|
-namespace AwInitilizer.Assist
|
|
|
-{
|
|
|
- public class EvApiResult<T>
|
|
|
- {
|
|
|
- public T Result { get; set; }
|
|
|
- public string Response { get; set; }
|
|
|
- }
|
|
|
-
|
|
|
- public class EvApiWifiResult
|
|
|
- {
|
|
|
- public int Rssi { get; set; }
|
|
|
- public int ErrorCode { get; set; }
|
|
|
- }
|
|
|
-
|
|
|
- public static class EvApi
|
|
|
- {
|
|
|
- internal static async Task<EvApiResult<bool>> ChekCsuBootCompelete()
|
|
|
- {
|
|
|
- var getResult = await EvHttpClient.GetQueryActionOpt2String();
|
|
|
- if (!getResult.IsSuccess ||
|
|
|
- string.IsNullOrEmpty(getResult.Msg))
|
|
|
- {
|
|
|
- return new EvApiResult<bool>() { Response = getResult.Msg, Result = false };
|
|
|
- }
|
|
|
-
|
|
|
- Regex rx = new Regex("(SystemStatus)\\\": ([0-9]*)");
|
|
|
- var matches = rx.Matches(getResult.Msg);
|
|
|
- if (matches.Count == 0)
|
|
|
- {
|
|
|
- return new EvApiResult<bool>()
|
|
|
- {
|
|
|
- Result = false,
|
|
|
- Response = getResult.Msg
|
|
|
- };
|
|
|
- }
|
|
|
- bool isAllPassed = true;
|
|
|
- for (int matchIndex = 0; matchIndex < matches.Count; matchIndex++)
|
|
|
- {
|
|
|
- var match = matches[matchIndex];
|
|
|
- if (match.Groups.Count != 3)
|
|
|
- {
|
|
|
- isAllPassed = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (match.Groups[2].Value != "1")
|
|
|
- {
|
|
|
- isAllPassed = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return new EvApiResult<bool>()
|
|
|
- {
|
|
|
- Result = isAllPassed,
|
|
|
- Response = getResult.Msg,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- internal static async Task<EvApiResult<bool>> CheckGetQueryAction()
|
|
|
- {
|
|
|
- var getResult = await EvHttpClient.GetQueryActionOpt2String();
|
|
|
- if (!getResult.IsSuccess ||
|
|
|
- string.IsNullOrEmpty(getResult.Msg))
|
|
|
- {
|
|
|
- return new EvApiResult<bool>() { Response = getResult.Msg, Result = false };
|
|
|
- }
|
|
|
-
|
|
|
- return new EvApiResult<bool>()
|
|
|
- {
|
|
|
- Result = !string.IsNullOrEmpty(getResult.Msg),
|
|
|
- Response = getResult.Msg
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- internal static async Task<EvApiResult<ButtonStatus>> GetButtonStatus()
|
|
|
- {
|
|
|
- var getResult = await EvHttpClient.GetButtonStatusString();
|
|
|
- var result = getResult.Msg;
|
|
|
-
|
|
|
- if (!getResult.IsSuccess)
|
|
|
- {
|
|
|
- return new EvApiResult<ButtonStatus>()
|
|
|
- {
|
|
|
- Result = null,
|
|
|
- Response = getResult.Msg
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- if (!result.Contains("Button1") ||
|
|
|
- !result.Contains("Button2"))
|
|
|
- {
|
|
|
- return new EvApiResult<ButtonStatus>()
|
|
|
- {
|
|
|
- Result = null,
|
|
|
- Response = result
|
|
|
- };
|
|
|
- }
|
|
|
- var values = JsonConvert.DeserializeObject<ButtonStatus>(result);
|
|
|
- return new EvApiResult<ButtonStatus>()
|
|
|
- {
|
|
|
- Result = values,
|
|
|
- Response = result,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- internal static async Task<EvApiResult<Dictionary<string, string>>> GetVersion()
|
|
|
- {
|
|
|
- var getResult = await EvHttpClient.GetQueryActionOpt1String();
|
|
|
- var toReturn = new Dictionary<string, string>();
|
|
|
-
|
|
|
- string result = getResult.Msg;
|
|
|
- if (!getResult.IsSuccess)
|
|
|
- {
|
|
|
- return new EvApiResult<Dictionary<string, string>>()
|
|
|
- {
|
|
|
- Result = null,
|
|
|
- Response = getResult.Msg,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- var values = JsonConvert.DeserializeObject<Dictionary<string, object>>(result);
|
|
|
-
|
|
|
- foreach (var pair in values)
|
|
|
- {
|
|
|
- if (pair.Value is string v)
|
|
|
- {
|
|
|
- toReturn.Add(pair.Key, v);
|
|
|
- }
|
|
|
- else if (pair.Value is Newtonsoft.Json.Linq.JArray a)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- var versionList = JsonConvert.DeserializeObject<List<string>>(a.ToString());
|
|
|
- for (int index = 0; index < versionList.Count; index++)
|
|
|
- {
|
|
|
- toReturn.Add(string.Format("{0}{1}", pair.Key, index), versionList[index]);
|
|
|
- }
|
|
|
- }
|
|
|
- catch
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return new EvApiResult<Dictionary<string, string>>()
|
|
|
- {
|
|
|
- Result = toReturn,
|
|
|
- Response = result
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- internal static async Task<EvApiResult<string>> GetTelcomModemImei()
|
|
|
- {
|
|
|
- var getResult = await EvHttpClient.GetQueryActionOpt3String();
|
|
|
- string result = getResult.Msg;
|
|
|
- if (!getResult.IsSuccess)
|
|
|
- {
|
|
|
- return new EvApiResult<string>()
|
|
|
- {
|
|
|
- Result = null,
|
|
|
- Response = getResult.Msg,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- Regex rx = new Regex("(TelcomModemImei)\\\": \"([0-9]*)\"");
|
|
|
- var matches = rx.Matches(result);
|
|
|
- string imeiString = string.Empty;
|
|
|
-
|
|
|
- if (matches.Count != 0)
|
|
|
- {
|
|
|
- var match = matches[0];
|
|
|
- if (match.Groups.Count != 3)
|
|
|
- {
|
|
|
- imeiString = string.Empty;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (match.Groups[2].Value is string imei)
|
|
|
- {
|
|
|
- imeiString = imei;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- imeiString = "";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- imeiString = "";
|
|
|
- }
|
|
|
-
|
|
|
- return new EvApiResult<string>()
|
|
|
- {
|
|
|
- Result = imeiString,
|
|
|
- Response = result
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- internal static async Task<EvApiResult<EvApiWifiResult>> GetWifiRssi()
|
|
|
- {
|
|
|
- var getResult = await EvHttpClient.GetQueryActionOpt3String();
|
|
|
- string result = getResult.Msg;
|
|
|
- if (!getResult.IsSuccess)
|
|
|
- {
|
|
|
- return new EvApiResult<EvApiWifiResult>()
|
|
|
- {
|
|
|
- Result = new EvApiWifiResult()
|
|
|
- {
|
|
|
- Rssi = 0,
|
|
|
- ErrorCode = 0
|
|
|
- },
|
|
|
- Response = getResult.Msg,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- Regex rx_mode = new Regex("(WifiMode)\\\": ([0-9]*)");
|
|
|
- var matches_mode = rx_mode.Matches(result);
|
|
|
- int rssi = 0;
|
|
|
- int errorCode = -1;
|
|
|
-
|
|
|
- if (matches_mode.Count != 0)
|
|
|
- {
|
|
|
- var match = matches_mode[0];
|
|
|
- if (match.Groups.Count != 3)
|
|
|
- {
|
|
|
- errorCode = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (int.TryParse(match.Groups[2].Value, out var wifiMode))
|
|
|
- {
|
|
|
- if (wifiMode != 1)
|
|
|
- {
|
|
|
- errorCode = 1;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- errorCode = 2;
|
|
|
- }
|
|
|
-
|
|
|
- if (errorCode != -1)
|
|
|
- {
|
|
|
- return new EvApiResult<EvApiWifiResult>()
|
|
|
- {
|
|
|
- Result = new EvApiWifiResult()
|
|
|
- {
|
|
|
- Rssi = rssi,
|
|
|
- ErrorCode = errorCode
|
|
|
- },
|
|
|
- Response = result
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- Regex rx = new Regex("(WifiRssi)\\\": (-?[0-9]*)");
|
|
|
- var matches = rx.Matches(result);
|
|
|
-
|
|
|
- if (matches.Count != 0)
|
|
|
- {
|
|
|
- var match = matches[0];
|
|
|
- if (match.Groups.Count != 3)
|
|
|
- {
|
|
|
- errorCode = 3;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (int.TryParse(match.Groups[2].Value, out var rssiSignal))
|
|
|
- {
|
|
|
- rssi = rssiSignal;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- errorCode = 4;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- errorCode = 5;
|
|
|
- }
|
|
|
-
|
|
|
- return new EvApiResult<EvApiWifiResult>()
|
|
|
- {
|
|
|
- Result = new EvApiWifiResult()
|
|
|
- {
|
|
|
- Rssi = rssi,
|
|
|
- ErrorCode = errorCode
|
|
|
- },
|
|
|
- Response = result
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- internal static async Task<EvApiResult<Dictionary<int, string>>> GetConnectorStatus()
|
|
|
- {
|
|
|
- var getResult = await EvHttpClient.GetQueryActionOpt2String();
|
|
|
- Dictionary<int, string> connectorStatusPair = new Dictionary<int, string>();
|
|
|
-
|
|
|
- string result = getResult.Msg;
|
|
|
- if (!getResult.IsSuccess)
|
|
|
- {
|
|
|
- return new EvApiResult<Dictionary<int, string>>()
|
|
|
- {
|
|
|
- Result = null,
|
|
|
- Response = getResult.Msg
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- Regex rx = new Regex("(SystemStatus)\\\": (\\d)");
|
|
|
- var matches = rx.Matches(result);
|
|
|
- for (int matchIndex = 0; matchIndex < matches.Count; matchIndex++)
|
|
|
- {
|
|
|
- var match = matches[matchIndex];
|
|
|
- if (match.Groups.Count != 3)
|
|
|
- {
|
|
|
- //LogWriter.Log($"Connector {matchIndex} status string mismatched");
|
|
|
- return new EvApiResult<Dictionary<int, string>>()
|
|
|
- {
|
|
|
- Result = null,
|
|
|
- Response = result
|
|
|
- };
|
|
|
- //InfoLog += $"Connector {matchIndex} status string mismatched\n";
|
|
|
- //Logger.Print($"Connector {matchIndex} status string mismatched", isError:true);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- connectorStatusPair.Add(matchIndex, match.Groups[2].Value);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return new EvApiResult<Dictionary<int, string>>()
|
|
|
- {
|
|
|
- Result = connectorStatusPair,
|
|
|
- Response = result,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- internal static async Task<EvApiResult<bool>> FactorySet()
|
|
|
- {
|
|
|
- var getResult = await EvHttpClient.GetFactorySetResultString();
|
|
|
- var result = getResult.Msg;
|
|
|
- if (!getResult.IsSuccess)
|
|
|
- {
|
|
|
- return new EvApiResult<bool>()
|
|
|
- {
|
|
|
- Result = false,
|
|
|
- Response = getResult.Msg
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- Regex rx = new Regex("(result)\":\"([a-zA-Z]*)\"");
|
|
|
- var matches = rx.Matches(result);
|
|
|
- if (matches.Count > 0 &&
|
|
|
- matches[0].Success &&
|
|
|
- matches[0].Groups.Count == 3 &&
|
|
|
- matches[0].Groups[2].Value.ToLower() == "success")
|
|
|
- {
|
|
|
- return new EvApiResult<bool>()
|
|
|
- {
|
|
|
- Result = true,
|
|
|
- Response = result
|
|
|
- };
|
|
|
- }
|
|
|
- return new EvApiResult<bool>()
|
|
|
- {
|
|
|
- Result = false,
|
|
|
- Response = result
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- internal static async Task<EvApiResult<bool>> SignalUpdateFirmware()
|
|
|
- {
|
|
|
- var result = await EvHttpClient.GetSignalUpdateFirmwareResultString();
|
|
|
- if (!result.IsSuccess)
|
|
|
- {
|
|
|
- return new EvApiResult<bool>()
|
|
|
- {
|
|
|
- Result = false,
|
|
|
- Response = result.Msg
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- return new EvApiResult<bool>()
|
|
|
- {
|
|
|
- Result = !string.IsNullOrEmpty(result.Msg),
|
|
|
- Response = result.Msg,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- internal static async Task<EvApiResult<bool>> SetAuthorisationMode(bool isAuthRequired)
|
|
|
- {
|
|
|
- var result = await EvHttpClient.SetSystemAction("AuthorisationMode", isAuthRequired ? "0" : "1");
|
|
|
- if (!result.IsSuccess)
|
|
|
- {
|
|
|
- return new EvApiResult<bool>()
|
|
|
- {
|
|
|
- Result = false,
|
|
|
- Response = result.Msg
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- return new EvApiResult<bool>()
|
|
|
- {
|
|
|
- Result = !string.IsNullOrEmpty(result.Msg),
|
|
|
- Response = result.Msg,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- internal static async Task<EvApiResult<string>> GetTelcomModemFwRev()
|
|
|
- {
|
|
|
- var key = "TelcomModemFwRev";
|
|
|
-
|
|
|
- var result = await GetVersion();
|
|
|
- if (result.Result is null)
|
|
|
- {
|
|
|
- return new EvApiResult<string> { Result = null, Response = result.Response };
|
|
|
- }
|
|
|
-
|
|
|
- var versionPairs = result.Result;
|
|
|
- if (versionPairs is null || !versionPairs.ContainsKey(key))
|
|
|
- {
|
|
|
- return new EvApiResult<string> { Result = string.Empty, Response = result.Response };
|
|
|
- }
|
|
|
-
|
|
|
- return new EvApiResult<string> { Result = versionPairs[key], Response = result.Response };
|
|
|
- }
|
|
|
-
|
|
|
- internal static async Task<EvApiResult<string>> GetTelcomSubModemFwRev()
|
|
|
- {
|
|
|
- var key = "TelcomSubModemFwRev";
|
|
|
-
|
|
|
- var result = await GetVersion();
|
|
|
- if (result.Result is null)
|
|
|
- {
|
|
|
- return new EvApiResult<string> { Result = null, Response = result.Response };
|
|
|
- }
|
|
|
-
|
|
|
- var versionPairs = result.Result;
|
|
|
- if (versionPairs is null || !versionPairs.ContainsKey(key))
|
|
|
- {
|
|
|
- return new EvApiResult<string> { Result = string.Empty, Response = result.Response };
|
|
|
- }
|
|
|
-
|
|
|
- return new EvApiResult<string> { Result = versionPairs[key], Response = result.Response };
|
|
|
- }
|
|
|
-
|
|
|
- internal static async Task<EvApiResult<SimStatusString>> GetTelcomSimStatus()
|
|
|
- {
|
|
|
- var result = await EvHttpClient.GetQueryActionOpt3String();
|
|
|
- if (!result.IsSuccess)
|
|
|
- {
|
|
|
- return new EvApiResult<SimStatusString>()
|
|
|
- {
|
|
|
- Result = null,
|
|
|
- Response = result.Msg
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- var simStatus = GetIntValue("TelcomSimStatus", result.Msg);
|
|
|
- var simIccid = GetStringValue("TelcomSimIccid", result.Msg);
|
|
|
- var simImsi = GetStringValue("TelcomSimImsi", result.Msg);
|
|
|
- return new EvApiResult<SimStatusString>()
|
|
|
- {
|
|
|
- Result = new SimStatusString() { IsInstalled = simStatus == 1, ICCID = simIccid, IMSI = simImsi },
|
|
|
- Response = result.Msg,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- internal static async Task<EvApiResult<SimStatusString>> GetTelcomSubSimStatus()
|
|
|
- {
|
|
|
- var result = await EvHttpClient.GetQueryActionOpt3String();
|
|
|
- if (!result.IsSuccess)
|
|
|
- {
|
|
|
- return new EvApiResult<SimStatusString>()
|
|
|
- {
|
|
|
- Result = null,
|
|
|
- Response = result.Msg
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- var simStatus = GetIntValue("TelcomSubSimStatus", result.Msg);
|
|
|
- var simIccid = GetStringValue("TelcomSubSimIccid", result.Msg);
|
|
|
- var simImsi = GetStringValue("TelcomSubSimImsi", result.Msg);
|
|
|
- return new EvApiResult<SimStatusString>()
|
|
|
- {
|
|
|
- Result = new SimStatusString() { IsInstalled = simStatus == 1, ICCID = simIccid, IMSI = simImsi },
|
|
|
- Response = result.Msg,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Not Tested
|
|
|
- /// </summary>
|
|
|
- /// <param name="fileName"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [Obsolete]
|
|
|
- internal static async Task<EvApiResult<bool>> Uploadfirmware(string fileName)
|
|
|
- {
|
|
|
- var result = await EvHttpClient.GetUploadfirmwareResultString(new List<string> { fileName });
|
|
|
- if (!result.IsSuccess)
|
|
|
- {
|
|
|
- return new EvApiResult<bool>()
|
|
|
- {
|
|
|
- Result = false,
|
|
|
- Response = result.Msg
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- return new EvApiResult<bool>()
|
|
|
- {
|
|
|
- Result = !string.IsNullOrEmpty(result.Msg),
|
|
|
- Response = result.Msg,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Not tested
|
|
|
- /// </summary>
|
|
|
- /// <param name="fileNames"></param>
|
|
|
- /// <returns></returns>
|
|
|
- internal static async Task<EvApiResult<bool>> Uploadfirmware(List<string> fileNames)
|
|
|
- {
|
|
|
- var result = await EvHttpClient.GetUploadfirmwareResultString(fileNames);
|
|
|
- if (!result.IsSuccess)
|
|
|
- {
|
|
|
- return new EvApiResult<bool>()
|
|
|
- {
|
|
|
- Result = false,
|
|
|
- Response = result.Msg
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- return new EvApiResult<bool>()
|
|
|
- {
|
|
|
- Result = !string.IsNullOrEmpty(result.Msg),
|
|
|
- Response = result.Msg,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- private static int? GetIntValue(string key, string source)
|
|
|
- {
|
|
|
- Regex rx = new Regex($"({key})\\\": ([0-9]*)");
|
|
|
- var matches = rx.Matches(source);
|
|
|
-
|
|
|
- if (matches.Count != 0)
|
|
|
- {
|
|
|
- var match = matches[0];
|
|
|
- if (match.Groups.Count != 3)
|
|
|
- {
|
|
|
- return null;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (int.TryParse(match.Groups[2].Value, out var val))
|
|
|
- {
|
|
|
- return val;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private static string GetStringValue(string key, string source)
|
|
|
- {
|
|
|
- Regex rx = new Regex($"({key})\\\": \"([a-zA-Z0-9]*)\"");
|
|
|
- var matches = rx.Matches(source);
|
|
|
-
|
|
|
- if (matches.Count != 0)
|
|
|
- {
|
|
|
- var match = matches[0];
|
|
|
- if (match.Groups.Count != 3)
|
|
|
- {
|
|
|
- return null;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return match.Groups[2].Value;
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|