private void SerialEvent(byte[] baPayload) { //byte bType = baPayload[0]; string sPayload = StringHelper.GetString(baPayload); int iStartIndex = sPayload.IndexOf("#"); //4 int iEndIndex = sPayload.IndexOf(","); //6 string sJoin = sPayload.Substring(iStartIndex + 1, iEndIndex - iStartIndex - 1); //4,1 - 3 ushort idx = Convert.ToUInt16(sJoin); ushort iStartV = (ushort)(iEndIndex + (iEndIndex - iStartIndex) + 3); //11 ushort ilen = (ushort)(baPayload.Length - iStartV - 1); //1 string val = sPayload.Substring(iStartV, ilen); OnSerial?.Invoke(idx, val); OnDebug(eDebugEventType.Info, "Serial event on join={0} to {1}", idx.ToString(), val.ToString()); }
private void SendForecast(ForecastTime fr, int num) { ushort tempJoin = (ushort)(1 + num - 1); ushort weatherJoin = (ushort)(2 + num - 1); ushort iconJoin = (ushort)(5 + num - 1); ushort timeJoin = (ushort)(5 + num - 1); ushort tempSJoin = (ushort)(9 + num); OnAnalog?.Invoke(tempJoin, (ushort)(fr.Temperature.Value * 10)); OnSerial?.Invoke(weatherJoin, fr.Symbol.Name); OnAnalog?.Invoke(iconJoin, IconToCrestronVT(fr.Symbol.Var, fr.To)); string sTime = fr.To.ToString("t") + (fr.To.Day == DateTime.Now.Day ? "" : " (+1)"); OnSerial?.Invoke(timeJoin, sTime); OnSerial?.Invoke(tempSJoin, Math.Round(fr.Temperature.Value, 1).ToString() + "°"); }
private async void GetForecast() { OnDigital?.Invoke(1, false); try { var cw = await owmClient.CurrentWeather.GetByName(Settings.City, MetricSystem.Metric, OpenWeatherMapLanguage.RU); var fw = await owmClient.Forecast.GetByName(Settings.City, false, MetricSystem.Metric, OpenWeatherMapLanguage.RU); SunRise = fw.Sun.Rise.ToLocalTime().TimeOfDay; SunSet = fw.Sun.Set.ToLocalTime().TimeOfDay; OnAnalog?.Invoke(4, IconToCrestronVT(cw.Weather.Icon, DateTime.Now)); OnSerial?.Invoke(1, cw.Weather.Value); OnSerial?.Invoke(8, SunRise.ToString(@"h\:mm")); OnSerial?.Invoke(9, SunSet.ToString(@"h\:mm")); OnAnalog?.Invoke(8, (ushort)cw.Humidity.Value); OnAnalog?.Invoke(9, (ushort)cw.Wind.Speed.Value); DateTime fr1; DateTime fr2; DateTime fr3; DateTime curr = DateTime.Now; int hr = curr.Hour; if (hr < 5) { fr1 = new DateTime(curr.Year, curr.Month, curr.Day, 6, 0, 0); fr2 = new DateTime(curr.Year, curr.Month, curr.Day, 12, 0, 0); fr3 = new DateTime(curr.Year, curr.Month, curr.Day, 18, 0, 0); } else if (hr < 8) { fr1 = new DateTime(curr.Year, curr.Month, curr.Day, 9, 0, 0); fr2 = new DateTime(curr.Year, curr.Month, curr.Day, 12, 0, 0); fr3 = new DateTime(curr.Year, curr.Month, curr.Day, 18, 0, 0); } else if (hr < 11) { fr1 = new DateTime(curr.Year, curr.Month, curr.Day, 12, 0, 0); fr2 = new DateTime(curr.Year, curr.Month, curr.Day, 15, 0, 0); fr3 = new DateTime(curr.Year, curr.Month, curr.Day, 18, 0, 0); } else if (hr < 14) { fr1 = new DateTime(curr.Year, curr.Month, curr.Day, 15, 0, 0); fr2 = new DateTime(curr.Year, curr.Month, curr.Day, 18, 0, 0); fr3 = new DateTime(curr.Year, curr.Month, curr.Day, 21, 0, 0); } else if (hr < 17) { fr1 = new DateTime(curr.Year, curr.Month, curr.Day, 18, 0, 0); fr2 = new DateTime(curr.Year, curr.Month, curr.Day, 21, 0, 0); fr3 = (new DateTime(curr.Year, curr.Month, curr.Day, 0, 0, 0)).AddDays(1); } else if (hr < 20) { fr1 = new DateTime(curr.Year, curr.Month, curr.Day, 21, 0, 0); fr2 = (new DateTime(curr.Year, curr.Month, curr.Day, 9, 0, 0)).AddDays(1); fr3 = (new DateTime(curr.Year, curr.Month, curr.Day, 12, 0, 0)).AddDays(1); } else { fr1 = (new DateTime(curr.Year, curr.Month, curr.Day, 9, 0, 0)).AddDays(1); fr2 = (new DateTime(curr.Year, curr.Month, curr.Day, 12, 0, 0)).AddDays(1); fr3 = (new DateTime(curr.Year, curr.Month, curr.Day, 18, 0, 0)).AddDays(1); } var fw1 = fw.Forecast.FirstOrDefault(o => o.To == fr1); var fw2 = fw.Forecast.FirstOrDefault(o => o.To == fr2); var fw3 = fw.Forecast.FirstOrDefault(o => o.To == fr3); SendForecast(fw1, 1); SendForecast(fw2, 2); SendForecast(fw3, 3); } catch { OnDigital?.Invoke(1, true); } }