private static JObject FromVariableValue(VariableValue vv, MqttVarPub config) { var obj = new JObject(); obj["ID"] = vv.Variable.Object.LocalObjectID; VTQ vtq = vv.Value; if (config.TimeAsUnixMilliseconds) { obj["T"] = vtq.T.JavaTicks; } else { obj["T"] = vtq.T.ToString(); } if (config.QualityNumeric) { obj["Q"] = MapQualityToNumber(vtq.Q); } else { obj["Q"] = vtq.Q.ToString(); } obj["V"] = JToken.Parse(vtq.V.JSON); return(obj); }
private static VariableValues Filter(VariableValues values, MqttVarPub config) { bool numsOnly = config.NumericTagsOnly; bool sendNull = config.SendTagsWithNull; if (!numsOnly && sendNull) { return(values); } var res = new VariableValues(values.Count); foreach (var vv in values) { if (numsOnly && !sendNull) { double?dbl = vv.Value.V.AsDouble(); if (dbl.HasValue) { res.Add(vv); } } else if (numsOnly && sendNull) { double?dbl = vv.Value.V.AsDouble(); if (dbl.HasValue || vv.Value.V.IsEmpty) { res.Add(vv); } } else if (!numsOnly && !sendNull) { if (!vv.Value.V.IsEmpty) { res.Add(vv); } } } return(res); }
public RegCache(MqttVarPub varPub, string topic) { this.varPub = varPub; this.topic = topic; }