private static uint SetSystemCode(uint code, DipswitchSystemCode systemCode) { // A LOW switch is binary 10 and a HIGH switch is binary 00. // The values of the DIP switches are inverted. if (!systemCode.HasFlag(DipswitchSystemCode.Switch1)) { code |= 1U << 22; } if (!systemCode.HasFlag(DipswitchSystemCode.Switch2)) { code |= 1U << 20; } if (!systemCode.HasFlag(DipswitchSystemCode.Switch3)) { code |= 1U << 18; } if (!systemCode.HasFlag(DipswitchSystemCode.Switch4)) { code |= 1U << 16; } if (!systemCode.HasFlag(DipswitchSystemCode.Switch5)) { code |= 1U << 14; } return(code); }
public DipswitchCode(DipswitchSystemCode system, DipswitchUnitCode unit, RemoteSocketCommand command) { System = system; Unit = unit; Command = command; _code = GetCode(this); }
private static int CheckNextSystem(ref DipswitchSystemCode parsedCode, int mask, uint code, DipswitchSystemCode systemCode) { mask = mask << 2; var maskedSysten = code & mask; if (maskedSysten == 0) { parsedCode |= systemCode; } return(mask); }
public static Lpd433MhzCode GetCode(DipswitchSystemCode systemCode, DipswitchUnitCode unitCode, RemoteSocketCommand command) { // Examples: // System Code = 11111 //00000000|00000000000|0010101|010001 = 1361 A ON //00000000|00000000000|0010101|010100 = 1364 A OFF //00000000|00000000000|1000101|010001 = 4433 B ON //00000000|00000000000|1000101|010100 = 4436 B OFF //00000000|00000000000|1010001|010001 = 5201 C ON //00000000|00000000000|1010001|010100 = 5204 C OFF //00000000|00000000000|1010100|010001 = 5393 D ON //00000000|00000000000|1010100|010100 = 5396 D OFF // System Code = 00000 //00000000|01010101010|0010101|010001 = 5588305 A ON //00000000|01010101010|0010101|010100 = 5588308 A OFF //00000000|01010101010|1000101|010001 = 5591377 B ON //00000000|01010101010|1000101|010100 = 5591380 B OFF //00000000|01010101010|1010001|010001 = 5592145 C ON //00000000|01010101010|1010001|010100 = 5592148 C OFF //00000000|01010101010|1010100|010001 = 5592337 D ON //00000000|01010101010|1010100|010100 = 5592340 D OFF // System Code = 10101 //00000000|00010001000|0010101|010001 = 1115473 A ON //00000000|00010001000|0010101|010100 = 1115476 A OFF //00000000|00010001000|1000101|010001 = 1118545 B ON //00000000|00010001000|1000101|010100 = 1118548 B OFF //00000000|00010001000|1010001|010001 = 1119313 C ON //00000000|00010001000|1010001|010100 = 1119316 C OFF //00000000|00010001000|1010100|010001 = 1119505 D ON //00000000|00010001000|1010100|010100 = 1119508 D OFF var code = 0U; code = SetSystemCode(code, systemCode); code = SetUnitCode(code, unitCode); code = SetCommand(code, command); return(new Lpd433MhzCode { Value = code, Length = 24, Protocol = 1, Repeats = 3 }); }
private static DipswitchSystemCode ParseSystem(uint code) { DipswitchSystemCode parsedCode = DipswitchSystemCode.AllOff; var systemMask = "00000000 00000000 00011000 00000000"; systemMask = systemMask.Replace(" ", ""); var systemMaskValue = Convert.ToInt32(systemMask, 2); systemMaskValue = CheckNextSystem(ref parsedCode, systemMaskValue, code, DipswitchSystemCode.Switch1); systemMaskValue = CheckNextSystem(ref parsedCode, systemMaskValue, code, DipswitchSystemCode.Switch2); systemMaskValue = CheckNextSystem(ref parsedCode, systemMaskValue, code, DipswitchSystemCode.Switch3); systemMaskValue = CheckNextSystem(ref parsedCode, systemMaskValue, code, DipswitchSystemCode.Switch4); systemMaskValue = CheckNextSystem(ref parsedCode, systemMaskValue, code, DipswitchSystemCode.Switch5); return(parsedCode); }
public static Lpd433MhzCodePair GetCodePair(DipswitchSystemCode systemCode, DipswitchUnitCode unitCode) { return(new Lpd433MhzCodePair( GetCode(systemCode, unitCode, RemoteSocketCommand.TurnOn), GetCode(systemCode, unitCode, RemoteSocketCommand.TurnOff))); }