public ShellViewModel() { // Init a probe probe = new ProbeModel { TotalElements = 64, UsedElementsPerBeam = 4, Frequency = 5, Pitch = 1, }; // Init a gate gate = new GateModel { Start = 10, Length = 50, Threshold = 20, }; GateStart = gate.Start.ToString(); GateLength = gate.Length.ToString(); GateThreshold = gate.Threshold.ToString(); // Init Ascan InitAscan(); PlotGate(); // Init Cscan InitCscan(); }
public static void SaveProbe(ProbeModel probe) { using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString())) { cnn.Execute("insert or replace into Probe (Id, DeviceId, Name, Active, Min, Max, Marker) values (@Id, @DeviceId, @Name, @Active, @Min, @Max, @Marker)", probe); } }
public ProbeModel GetProbeData(SensorEntity <TKey> sensorEntity) { try { var url = sensorEntity.SensorApiAddress; var client = new WebClient(); var responseString = client.DownloadString(url); var response = JsonConvert.DeserializeObject <SuplaResponseModel>(responseString); if (response.Connected) { var probe = new ProbeModel { ProbeDate = DateTime.Now, TemperatureCelcius = response.Temperature, HumidityPercent = response.Humidity }; return(probe); } } catch (Exception ex) { logger.LogError(ex, "Error during load data."); } return(null); }
private static ProbeEntity <TKey> GetEntityModel(ProbeModel data, SensorEntity <TKey> sensorEntity) { var probe = new ProbeEntity <TKey> { SensorId = sensorEntity.Id, ProbeDate = DateTime.Now, TemperatureCelcius = data.TemperatureCelcius, Pm1 = data.Pm1, Pm2_5 = data.Pm2_5, Pm10 = data.Pm10, HumidityPercent = data.HumidityPercent }; return(probe); }
private void btnProbe_Click(object sender, EventArgs e) { try { ProbeModel probe = new ProbeModel(Convert.ToInt32(cmbProbeId.Text), Convert.ToInt32(txtProbeDeviceId.Text), txtProbeName.Text, chkProbeActive.Checked, Convert.ToInt32(numMin.Value), Convert.ToInt32(numMax.Value), Convert.ToInt32(numMarker.Value)); SqliteDataAccess.SaveProbe(probe); List <ProbeModel> data = SqliteDataAccess.LoadProbes(); dataGridView1.DataSource = data; } catch (Exception err) { MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private static ProbeModel GetTemperature(string responseString) { var response = JsonConvert.DeserializeObject <BleboxTemperatureModel>(responseString); var value = response?.TempSensor?.Sensors?.FirstOrDefault(); if (value != null) { var probe = new ProbeModel { ProbeDate = DateTime.Now.AddSeconds(-value.ElapsedTimeS), TemperatureCelcius = ((decimal)value.Value) / 100 }; return(probe); } return(null); }
private void cmbProbeId_SelectedIndexChanged(object sender, EventArgs e) { try { ProbeModel probe = SqliteDataAccess.LoadProbe(Convert.ToInt32(cmbProbeId.Text)); txtProbeDeviceId.Text = probe.DeviceId.ToString(); chkProbeActive.Checked = probe.Active; txtProbeName.Text = probe.Name; numMin.Value = probe.Min; numMax.Value = probe.Max; numMarker.Value = probe.Marker; } catch (Exception err) { MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private static bool IsModelChanged(ProbeEntity <TKey> latestData, ProbeModel data) { if (data == null) { return(false); } if (latestData == null) { return(true); } if (IsValueChanched(latestData.CAQI, data.CAQI)) { return(true); } if (IsValueChanched(latestData.HumidityPercent, data.HumidityPercent)) { return(true); } if (IsValueChanched(latestData.Pm1, data.Pm1)) { return(true); } if (IsValueChanched(latestData.Pm2_5, data.Pm2_5)) { return(true); } if (IsValueChanched(latestData.Pm10, data.Pm10)) { return(true); } if (IsValueChanched(latestData.TemperatureCelcius, data.TemperatureCelcius)) { return(true); } return(false); }
public GraphDataModel AssembleGraphDataModel(int i) { ProbeModel probe = new ProbeModel { Id = i, DeviceId = ((i - 1) / 8) + 1, Name = groupBoxes[i - 1].Text, Active = true, Min = Convert.ToInt32(numMins[i - 1].Value), Max = Convert.ToInt32(numMaxs[i - 1].Value), Marker = Convert.ToInt32(numMarkers[i - 1].Value) }; return(new GraphDataModel { Company = lblCompany.Text, Probe = probe, Date = dateTimePickers[i - 1].Value.ToShortDateString(), StartHour = Convert.ToInt32(numStartHours[i - 1].Value), HourCount = Convert.ToInt32(numHourCounts[i - 1].Value) }); }
/****************************************** * Allows a controller to recieve a probe and detect deadlock. *******************************************/ public async Task <Dictionary <string, ControllerModel> > Probe(ProbeModel model) { ControllerModel ThisController = model.AllControllers[model.SendToController]; ThisController.ControllerName = model.SendToController; ThisController.WaitingFor = ThisController.WaitingFor ?? new List <string>(); if (ThisController.ControllerName == model.InitiatedBy) { model.AllControllers[model.SendToController].Deadlock = true; } else { foreach (string Table in ThisController.WaitingFor) { string ProbeController = model.AllControllers.FirstOrDefault(x => x.Value.TablesOwned.Contains(Table)).Key; model.AllControllers = await Probe(new ProbeModel(ProbeController, model.InitiatedBy, model.SendToController, model.AllControllers)); } } return(model.AllControllers); }
private static ProbeModel GetAirData(string responseString) { var response = JsonConvert.DeserializeObject <BleboxAirModel>(responseString); var airData = response?.Air?.Sensors; var info = airData.FirstOrDefault(); if (info != null) { var probe = new ProbeModel { ProbeDate = DateTime.Now.AddSeconds(-info.ElapsedTimeS) }; var pm1 = airData.FirstOrDefault(b => b.Type == "pm1"); if (pm1 != null) { probe.Pm1 = pm1.Value; } var pm10 = airData.FirstOrDefault(b => b.Type == "pm10"); if (pm10 != null) { probe.Pm10 = pm10.Value; } var pm2_5 = airData.FirstOrDefault(b => b.Type == "pm2.5"); if (pm2_5 != null) { probe.Pm2_5 = pm2_5.Value; } return(probe); } return(null); }
public static string getDeviceInfoCommon(int userid) { //http://localhost:59519/Service/rilservlet.ashx?action=getDevice&userid=1 DeviceManager device = new DeviceManager(); string data = ""; string json = ""; JavaScriptSerializer js = new JavaScriptSerializer(); List <DeviceModel> lstoutinfo = new List <DeviceModel>(); DeviceModel outinfo = null; using (SqlConnection con = DBhelp.conn()) { con.Open(); string sql = "select* from device_tb where userid = @userid"; SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.AddWithValue(@"userid", userid); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { outinfo = new DeviceModel(); outinfo.Deviceid = int.Parse(dr["deviceid"].ToString()); outinfo.Userid = int.Parse(dr["userid"].ToString()); outinfo.Devicecode = dr["devicecode"].ToString(); outinfo.Devicename = dr["devicename"].ToString(); outinfo.Deviceaddre = dr["deviceaddre"].ToString(); outinfo.Devicetime = dr["devicetime"].ToString(); outinfo.Deviceonline = int.Parse(dr["deviceonline"].ToString()); outinfo.Deviceinfo = dr["deviceinfo"].ToString(); lstoutinfo.Add(outinfo); } dr.Close(); con.Close(); } using (SqlConnection con = DBhelp.conn()) { con.Open(); for (int i = 0; i < lstoutinfo.Count; i++) { lstoutinfo[i].Plist = new List <ProbeModel>(); outinfo.Plist = new List <ProbeModel>(); ProbeModel pb = null; string sql = "select * from probe_tb where deviceid='" + lstoutinfo[i].Deviceid + "'"; SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { pb = new ProbeModel(); pb.Probename = dr["probename"].ToString(); pb.Probeid = int.Parse(dr["probeid"].ToString()); pb.Deviceid = int.Parse(dr["deviceid"].ToString()); pb.Probetemp = dr["probetemp"].ToString(); lstoutinfo[i].Plist.Add(pb); } dr.Close(); } con.Close(); } data = js.Serialize(lstoutinfo); if (data != null && data != "") { json = "{" + "\"code\"" + ":" + 200 + "," + "\"message\"" + ":" + "\"success\"" + "," + "\"device\"" + ":" + data + "}"; } else { json = "{" + "\"code\"" + ":" + 0 + "," + "\"message\"" + ":" + "\"error\"" + "}"; } return(json); }