private void x10_ReceivedX10(object sender, X10EventArgs e) { X10Event2XPLMsg(e, false); }
private void x10_SendX10Result(object sender, X10EventArgs e) { if (e.ResultCode == 0) //OK { X10Event2XPLMsg(e, true); } else //error { xPLMessage x = new xPLMessage(); x.Source = xL.Address; x.MsgType = xPL_Base.xPLMessageTypeEnum.Trigger; x.Target = "*"; x.Schema = "log.basic"; x.KeyValueList.Add("type", "err"); x.KeyValueList.Add("code", "x10"); x.KeyValueList.Add("text", "error " + e.Devices + " " + X10Enum2String(e.X10Command)); x.Send(xL); // string xplMsg = "type=err" + '\n' + "code=x10" + '\n' + "text=error " + e.Devices + " " + X10Enum2String(e.X10Command) + '\n'; // xL.SendMessage("xpl-cmnd", "*", "log.basic", xplMsg); } }
private void X10Event2XPLMsg(X10EventArgs e, bool confirmation) { //string xplMsg = string.Empty; xPLMessage x = new xPLMessage(); x.MsgType = xPL_Base.xPLMessageTypeEnum.Trigger; x.Target = "*"; if (e.Devices.Length==1) //housecode, no devices { //xplMsg = "command=" + X10Enum2String(e.X10Command) + '\n' + "house=" + e.Devices + '\n'; x.KeyValueList.Add("command", X10Enum2String(e.X10Command)); x.KeyValueList.Add("house", e.Devices); if (e.X10Command == X10_COMMANDS.BRIGHT || e.X10Command == X10_COMMANDS.DIM || e.X10Command == X10_COMMANDS.PRESET_DIM1 || e.X10Command == X10_COMMANDS.PRESET_DIM2) //xplMsg += "level=" + e.Brightness.ToString() + '\n'; x.KeyValueList.Add("level", e.Brightness.ToString()); else if (e.X10Command == X10_COMMANDS.EXTENDED) { //xplMsg += "data1=" + e.Data1.ToString() + '\n' + "data2=" + e.Data2.ToString() + '\n'; x.KeyValueList.Add("data1", e.Data1.ToString()); x.KeyValueList.Add("data2", e.Data2.ToString()); } if (confirmation) //xL.SendMessage("xpl-trig", "*", "x10.confirm", xplMsg); x.Schema = "x10.confirm"; else //xL.SendMessage("xpl-trig", "*", "x10.basic", xplMsg); x.Schema = "x10.basic"; xL.Send(x); } else //devices, send an xpl msg per device { string[] ardev = e.Devices.Split(','); for (int i=0; i<ardev.Length; i++) { //xplMsg = "command=" + X10Enum2String(e.X10Command) + '\n' + "device=" + (i>0?ardev[0].Substring(0,1):"") + ardev[i] + '\n'; x.KeyValueList.Add("command", X10Enum2String(e.X10Command)); x.KeyValueList.Add("device", (i > 0 ? ardev[0].Substring(0, 1) : "") + ardev[i]); if (e.X10Command == X10_COMMANDS.BRIGHT || e.X10Command == X10_COMMANDS.DIM || e.X10Command == X10_COMMANDS.PRESET_DIM1 || e.X10Command == X10_COMMANDS.PRESET_DIM2) //xplMsg += "level=" + e.Brightness.ToString() + '\n'; x.KeyValueList.Add("level", e.Brightness.ToString()); else if (e.X10Command == X10_COMMANDS.EXTENDED) { //xplMsg += "data1=" + e.Data1.ToString() + '\n' + "data2=" + e.Data2.ToString() + '\n'; x.KeyValueList.Add("data1", e.Data1.ToString()); x.KeyValueList.Add("data2", e.Data2.ToString()); } if (confirmation) //xL.SendMessage("xpl-trig", "*", "x10.confirm", xplMsg); x.Schema = "x10.confirm"; else //xL.SendMessage("xpl-trig", "*", "x10.basic", xplMsg); x.Schema = "x10.basic"; xL.Send(x); } } }