I have also made code for switching a klikonklickoff unit with a raw the S and T command and that works lke a char;
Code: Select all
private void button1_Click(object sender, EventArgs e)
{
int iHouse = 0;
int iUnit = 0;
int iCommand = 6; // 6 off 14 on
TelldusNETWrapper.tdSendRawCommand(MakeRawCommand(360, 1070, iHouse + (iUnit << 4) + (iCommand << 8), 12), 0);
}
private void button2_Click(object sender, EventArgs e)
{
int iHouse = 0;
int iUnit = 0;
int iCommand = 14; // 6 off 14 on
TelldusNETWrapper.tdSendRawCommand(MakeRawCommand(360, 1070, iHouse + (iUnit << 4) + (iCommand << 8), 12), 0);
}
private void button3_Click(object sender, EventArgs e)
{
int iHouse = 0;
int iUnit = 0;
int iCommand = 6; // 6 off 14 on
TelldusNETWrapper.tdSendRawCommand(MakeRawLongCommand(360, 1070, 360, 1070, iHouse + (iUnit << 4) + (iCommand << 8), 12), 0);
}
private void button4_Click(object sender, EventArgs e)
{
int iHouse = 0;
int iUnit = 0;
int iCommand = 14; // 6 off 14 on
TelldusNETWrapper.tdSendRawCommand(MakeRawLongCommand(360, 1070, 360, 1070, iHouse + (iUnit << 4) + (iCommand << 8), 12), 0);
}
string MakeRawCommand(int tOn, int tOff, int iCommand, int length) {
string sCommand = "";
for( int i=0; i<length; i++ ) {
sCommand += String.Format("{0}{1}", (char)(tOn / 10), (char)(tOff/ 10));
sCommand += String.Format("{0}{1}", (char)(((iCommand % 2) != 0 ? tOff : tOn) / 10), (char)(((iCommand % 2) != 0 ? tOn : tOff) / 10));
Debug.WriteLine((iCommand % 2).ToString());
iCommand /= 2;
}
return String.Format("S{0}{1}{2}+", sCommand, (char) (tOn / 10), (char) (tOff / 10));
}
string MakeRawLongCommand(int t1On, int t1Off, int t2On, int t2Off, int iCommand, int length)
{
char[] sCommand = new char[length+1];
char slsl = (char)17;
char slls = (char)20;
for (int i = 0; i < length; i++)
{
sCommand[i] = ((iCommand % 2) != 0 ? slls : slsl);
Debug.WriteLine((iCommand % 2) != 0 ? "slls" : "slsl");
iCommand /= 2;
}
sCommand[length] = slsl;
string result = new string(sCommand);
return String.Format("T{0}{1}{2}{3}{4}{5}+", (char)(t1On / 10), (char)(t1Off / 10), (char)(t2On / 10), (char)(t2Off / 10), (char)((length * 4)+2), result);
}
The HE EU units have a verry poor to find protocol description on the internet but there are some sources from witch i understand a bit;
Preamble 275us high, 2675us low (just over the 255 max pulsewitdth)
26 bits housecode,
2 bits group, on/of,
4 bits unit code
0 pulse 275us high and 275us high,
1 pulse 275us high and 1300us low
0 pulse is send as a 01 RF pulse
1 pulse is send as a 10 RF pulse
There are some unknown/unspecified enhancements with a dim command (dim command and dim value).
I have written the code to generate the raw command that should produce tis RF sequence but in does not work;
Code: Select all
string MakeRawPattern(int iCommand, int length, int iT0, int iT1, int iT2, int iT3, char i0Pattern, char i1Pattern)
{
char[] sCommand = new char[length+1];
for (int i = 0; i < length; i++)
{
sCommand[i] = ((iCommand % 2) != 0 ? i1Pattern :i0Pattern);
iCommand /= 2;
}
sCommand[length] = i1Pattern;
string result = new string(sCommand);
result = String.Format("T{0}{1}{2}{3}{4}{5}+", (char)(iT0 / 10), (char)(iT1 / 10), (char)(iT2 / 10), (char)(iT3 / 10), (char)((length * 4) + 2), result);
char[] cresult = result.ToCharArray();
for (int i = 0; i < cresult.Length; i++)
{
Debug.Write(String.Format("[0x{0:X2}],", (int)cresult[i]));
// debug output output for a on command in raw format
// [0x54],[0x1B],[0x7B],[0x1B],[0x7B],[0x82],[0x01],[0x01],
// [0x01],[0x01],[0x01],[0x01],[0x01],[0x01],[0x01],[0x01],
// [0x01],[0x01],[0x01],[0x01],[0x01],[0x01],[0x01],[0x01],
// [0x01],[0x01],[0x01],[0x01],[0x01],[0x01],[0x01],[0x01],
// [0x01],[0x10],[0x01],[0x01],[0x01],[0x01],[0x10],[0x2B]
}
return result;
}
private void button5_Click(object sender, EventArgs e)
{
int iHouse = 0;
int iUnit = 0;
int iCommand = 0; // 0 off 2 on
TelldusNETWrapper.tdSendRawCommand(String.Format("S{0}{1}{2}{3}+", (char)26, (char)255, (char)1, (char)12), 0);
TelldusNETWrapper.tdSendRawCommand(MakeRawPattern(iHouse + (iCommand << 26) + (iUnit << 28), 32, 270, 1230, 270, 1230, (char)1, (char)16), 0);
}
private void button6_Click(object sender, EventArgs e)
{
int iHouse = 0;
int iUnit = 0;
int iCommand = 2; // 0 off 2 on
TelldusNETWrapper.tdSendRawCommand(String.Format("S{0}{1}{2}{3}+", (char)26, (char)255, (char)1, (char)12), 0);
TelldusNETWrapper.tdSendRawCommand(MakeRawPattern(iHouse + (iCommand << 26) + (iUnit << 28), 32, 270, 1230, 270, 1230, (char)1, (char)16), 0);
}
THX in advanced for any of your reactions,
Wim