private void History(int type) { // based on histlog2300.c WS2300base.timestamp time_last; DateTime time_lastrecord_tm, time_lastrecord; int interval, countdown, no_records; double pressure_term; #if noTread double t_in, t_out, press; int h_in, h_out; double w_speed, w_deg, rain, dew, w_chill; string strO; int next_record; h_in = -1; h_out = -1; w_speed = -1; w_deg = -1; rain = -1; dew = -1; w_chill = -1; t_in = -1; t_out = -1; press = -1; strO = ""; string[] directions = new string[] { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW" }; #endif time_last = new WS2300base.timestamp(); int current_record, lastlog_record, new_records; interval = -1; countdown = -1; no_records = -1; try { current_record = ws2300.read_history_info(ref interval, ref countdown, ref time_last, ref no_records); if (type != 2) { Display("HISTORY last=" + current_record.ToString() + " interval:" + interval.ToString() + " countdown:" + countdown.ToString() + " recno:" + no_records.ToString() + " timelast:" + Time(time_last)); } time_lastrecord_tm = new DateTime(time_last.year, time_last.month, time_last.day, time_last.hour, time_last.minute, 0); pressure_term = ws2300.pressure_correction(config.pressure_conv_factor); // da inizializzare con la data dell'ultima registrazione //time_lastrecord = new DateTime(1900, 1, 1, 0, 0, 0); time_lastrecord = new DateTime(2007, 4, 26, 14, 0, 0); //time_lastrecord_tm = new DateTime(2007, 4, 5, 7, 30, 0); DateTime dt = this.dateTimePicker1.Value; long s = dt.Minute * 60 + dt.Second; time_lastrecord = new DateTime(dt.Ticks - s * 10000000); DateTime d = new DateTime(time_lastrecord_tm.Ticks - time_lastrecord.Ticks); System.TimeSpan ds = time_lastrecord_tm.Subtract(time_lastrecord); new_records = (int)(ds.TotalMinutes / interval); if (new_records > 0xAF) { new_records = 0xAF; } if (new_records > no_records) { new_records = no_records; } lastlog_record = current_record - new_records; if (lastlog_record < 0) { lastlog_record = 0xAE + lastlog_record + 1; } time_lastrecord_tm = time_lastrecord_tm.Subtract(System.TimeSpan.FromMinutes(new_records * interval)); #if noTread for (int i = 1; i <= new_records; i++) { next_record = (i + lastlog_record) % 0xAF; ws2300.read_history_record(next_record, ref config, ref t_in, ref t_out, ref press, ref h_in, ref h_out, ref rain, ref w_speed, ref w_deg, ref dew, ref w_chill); time_lastrecord_tm = time_lastrecord_tm.AddMinutes((double)interval); if (type == 0) { strO = time(time_lastrecord_tm); strO += " T_in=" + t_in.ToString() + " T_out=" + t_out.ToString() + " P=" + (press + pressure_term).ToString() + " h_in=" + h_in.ToString() + " h_out=" + h_out.ToString() + " w=" + w_speed.ToString() + " " + w_deg.ToString() + " rain=" + rain.ToString() + " w_chill=" + w_chill.ToString() + " dew=" + dew.ToString("F"); System.Console.WriteLine(next_record.ToString() + " " + strO); } if (type == 1) { //1011,1 18,3 44 21,6 36 5,9 20,9 2,1 SSW 0,0 22:39 25.05.2006 strO = (press + pressure_term).ToString("F1") + '\t' + t_in.ToString("F1") + '\t' + h_in.ToString(); strO += '\t' + t_out.ToString("F1") + '\t' + h_out.ToString() + '\t' + dew.ToString("F1") + '\t' + w_chill.ToString("F1") + '\t' + w_speed.ToString() + '\t' + w_deg.ToString() + '\t' + rain.ToString("F1") + '\t' + time(time_lastrecord_tm); } if (type == 2) { strO = "INSERT INTO weather (timestamp, rec_date, rec_time, temp_in, temp_out, " + "dewpoint, rel_hum_in, rel_hum_out, windspeed, wind_angle, wind_direction, wind_chill, " + "rain_1h, rain_24h, rain_total, rel_pressure, tendency, forecast) VALUES ("; if (h_out > 100) { // out-of-range values: // outdoor values invalid due to communication error with external station strO += timeDB(time_lastrecord_tm, 0) + ",'" + timeDB(time_lastrecord_tm, 1) + "','" + timeDB(time_lastrecord_tm, 2) + "','" + decimalDB(t_in) + "',null" + ", null,'" + h_in.ToString() + "',null, null, null, null, null" + ",'0','0','" + decimalDB(rain) + "','" + decimalDB(press + pressure_term) + "','0','0');"; } else { strO += timeDB(time_lastrecord_tm, 0) + ",'" + timeDB(time_lastrecord_tm, 1) + "','" + timeDB(time_lastrecord_tm, 2) + "','" + decimalDB(t_in) + "','" + decimalDB(t_out) + "','" + decimalDB(dew) + "','" + h_in.ToString() + "','" + h_out.ToString() + "','" + decimalDB(w_speed) + "','" + decimalDB(w_deg) + "','','" + decimalDB(w_chill) + "','0','0','" + decimalDB(rain) + "','" + decimalDB(press + pressure_term) + "','0','0');"; } } display(strO); } #else Historybg(new_records, interval, lastlog_record, time_lastrecord_tm, pressure_term); #endif } catch (Exception ex) { Display("ERROR: " + ex.Message); } Display(""); }