Beispiel #1
0
        public static int SendData2ABRP(tlm objTLM)
        {
            int Counter = 0;

            // Just Continue if GPS coordinates are different from 0
            if (objTLM.lat == 0 && objTLM.lon == 0 && objTLM.alt == 0)
            {
                // There is no GPS data yet
                return(0);
            }

            // Fill utc and car model
            objTLM.car_model = Program.AppConfig.CAR_MODEL;
            // utc is comming from tlm
            //objTLM.utc = Convert.ToInt32(DateTime.UtcNow.Subtract(DateTime.MinValue.AddYears(1969)).TotalMilliseconds / 1000);

            // Reparse TLM
            var    returnTLM          = new returnTLM(objTLM);
            string stringTLMParameter = SerializeReturnTLM(returnTLM);

            // Send data to ABRP (read from config)
            var URL = Program.AppConfig.ABRPUrl;

            var urljson = URL += "?";

            urljson += "api_key=" + Program.AppConfig.ABRP_api_key;
            urljson += "&";
            urljson += "token=" + Program.AppConfig.ABRP_token;
            urljson += "&";
            urljson += "tlm=" + stringTLMParameter;

            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(urljson);
                    //HTTP GET
                    var responseTask = client.GetAsync("");
                    responseTask.Wait();

                    var result = responseTask.Result;
                    var log    = result.Version + " | " + result.ReasonPhrase + " | " + result.RequestMessage;
                    if (result.IsSuccessStatusCode)
                    {
                        // Ha ido bien
                        Counter = Models.Tools.AddCount();
                    }
                    if (Program.AppConfig.DebugMode)
                    {
                        Models.Tools.guardarLog(log);
                        // Guardar en log los datos enviados
                        // Models.Tools.guardarLog(stringTLMParameter);
                    }
                }
                // Guardar los datos en InfluxDB
                Models.Tools.SaveDataIntoInfluxDB(objTLM);
            }
            catch (Exception ex)
            {
                string msg = "Source: " + ex.Source + " | " + ex.Message;
                if (ex.InnerException != null)
                {
                    msg += " | " + ex.InnerException.Message;
                }
                Models.Tools.guardarLog(msg);
            }

            return(Counter);
        }
Beispiel #2
0
        public static string SerializeReturnTLM(returnTLM tlm)
        {
            string newTLM = JsonConvert.SerializeObject(tlm);

            return(newTLM);
        }