use of org.openhab.binding.souliss.internal.network.typicals.SoulissT31 in project openhab1-addons by openhab.
the class UDPSoulissDecoder method decodeStateRequest.
private void decodeStateRequest(ArrayList<Short> mac) {
boolean bDecoded_forLOG = false;
int tgtnode = mac.get(3);
// QUI. AGGIORNAMENTO DEL TIMESTAMP PER OGNI NODO. DA FARE USANDO NODI
// FITTIZI
SoulissTServiceUpdater.updateTIMESTAMP(soulissTypicalsRecipients, tgtnode);
// leggo valore tipico in base allo slot
synchronized (this) {
Iterator<Entry<String, SoulissGenericTypical>> iteratorTypicals = soulissTypicalsRecipients.getIterator();
while (iteratorTypicals.hasNext()) {
SoulissGenericTypical typ = iteratorTypicals.next().getValue();
// se il tipico estratto appartiene al nodo che il frame deve
// aggiornare...
bDecoded_forLOG = false;
if (typ.getSoulissNodeID() == tgtnode) {
// ...allora controllo lo slot
int slot = typ.getSlot();
// ...ed aggiorno lo stato in base al tipo
int iNumBytes = 0;
try {
String sHex = Integer.toHexString(typ.getType());
String sRes = SoulissNetworkParameter.getPropTypicalBytes(sHex.toUpperCase());
if (sRes != null)
iNumBytes = Integer.parseInt(sRes);
} catch (NumberFormatException e) {
e.printStackTrace();
iNumBytes = 0;
}
float val = 0;
// ***** T1A *****
if (typ.getType() == 0x1A) {
short sVal = getByteAtSlot(mac, slot);
((SoulissT1A) typ).setState(sVal);
bDecoded_forLOG = true;
// ***** T19 *****
} else if (typ.getType() == 0x19) {
// set value of T19 at number of second slot
short sVal = getByteAtSlot(mac, slot + 1);
typ.setState(sVal);
bDecoded_forLOG = true;
} else if (iNumBytes == 1) {
// caso valori digitali
val = getByteAtSlot(mac, slot);
typ.setState(val);
bDecoded_forLOG = true;
} else if (iNumBytes == 2) {
// caso valori float
val = getFloatAtSlot(mac, slot);
typ.setState(val);
bDecoded_forLOG = true;
} else if (iNumBytes == 4) {
// ***** T16 RGB *****
val = getByteAtSlot(mac, slot);
typ.setState(val);
((SoulissT16) typ).setStateRED(getByteAtSlot(mac, slot + 1));
((SoulissT16) typ).setStateGREEN(getByteAtSlot(mac, slot + 2));
((SoulissT16) typ).setStateBLU(getByteAtSlot(mac, slot + 3));
bDecoded_forLOG = true;
} else if (iNumBytes == 5) {
// ***** T31 *****
// *******************
// SLOT 0: Control State
short sVal = getByteAtSlot(mac, slot);
((SoulissT31) typ).setRawCommandState(sVal);
/*
* The control state bit meaning follow as:
* BIT 0 Not used
* BIT 1 (0 Heating OFF , 1 Heating ON)
* BIT 2 (0 Cooling OFF , 1 Cooling ON)
* BIT 3 (0 Fan 1 OFF , 1 Fan 1 ON)
* BIT 4 (0 Fan 2 OFF , 1 Fan 2 ON)
* BIT 5 (0 Fan 3 OFF , 1 Fan 3 ON)
* BIT 6 (0 Manual Mode , 1 Automatic Mode for Fan)
* BIT 7 (0 Heating Mode, 1 Cooling Mode)
*/
((SoulissT31) typ).power.setState(getBitState(sVal, 0));
((SoulissT31) typ).heating.setState(getBitState(sVal, 1));
((SoulissT31) typ).cooling.setState(getBitState(sVal, 2));
((SoulissT31) typ).fanLow.setState(getBitState(sVal, 3));
((SoulissT31) typ).fanMed.setState(getBitState(sVal, 4));
((SoulissT31) typ).fanHigh.setState(getBitState(sVal, 5));
((SoulissT31) typ).fanAutoMode.setState(getBitState(sVal, 6));
((SoulissT31) typ).heatingCoolingModeValue.setState(getBitState(sVal, 7));
// SLOT 1-2: Temperature Measured Value
val = getFloatAtSlot(mac, slot + 1);
((SoulissT31) typ).setMeasuredValue(val);
// SLOT 3-4: Temperature Setpoint Value
val = getFloatAtSlot(mac, slot + 3);
((SoulissT31) typ).setSetpointValue(val);
bDecoded_forLOG = true;
}
// inserito in un altro punto del codice
if (typ.getType() != 152 && typ.getType() != 153)
if (iNumBytes == 4)
// RGB Log
logger.debug("decodeStateRequest: {} ({}) = {}. RGB= {}, {}, {}", typ.getName(), Short.valueOf(typ.getType()), ((SoulissT16) typ).getState(), ((SoulissT16) typ).getStateRED(), ((SoulissT16) typ).getStateGREEN(), ((SoulissT16) typ).getStateBLU());
else if (iNumBytes == 5) {
// T31 Thermostat
logger.debug("decodeStateRequest: {} ({}). Thermostat= {}, Temp.Measured= {}, Temp.SetPoint= {}", typ.getName(), Short.valueOf(typ.getType()), ((SoulissT31) typ).getRawCommandState(), ((SoulissT31) typ).getTemperatureMeasuredValue(), ((SoulissT31) typ).getSetpointValue());
} else if (bDecoded_forLOG) {
if (typ.getType() == 0x1A) {
logger.debug("decodeStateRequest: {} (0x{}) = {}", typ.getName(), Integer.toHexString(typ.getType()), Integer.toBinaryString(((SoulissT1A) typ).getRawState()));
} else
logger.debug("decodeStateRequest: {} (0x{}) = {}", typ.getName(), Integer.toHexString(typ.getType()), Float.valueOf(val));
}
}
}
}
}
use of org.openhab.binding.souliss.internal.network.typicals.SoulissT31 in project openhab1-addons by openhab.
the class SoulissBinding method receiveCommand.
@Override
public /**
* Get the souliss's typical from the hash table and send a command
*
* @author Tonino Fazio
* @since 1.7.0
*/
void receiveCommand(String itemName, Command command) {
// Get the typical defined in the hash table
SoulissGenericTypical T = SoulissGenericBindingProvider.SoulissTypicalsRecipients.getTypicalFromItem(itemName);
logger.info("receiveCommand - {} = {} - Typical: 0x{}", itemName, command, Integer.toHexString(T.getType()));
switch(T.getType()) {
case Constants.Souliss_T11:
SoulissT11 T11 = (SoulissT11) T;
T11.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.toString()));
break;
case Constants.Souliss_T12:
SoulissT12 T12 = (SoulissT12) T;
if (itemName.equals(T12.getsItemNameAutoModeValue())) {
T12.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T12_Use_Of_Slot_AUTOMODE + "_" + command.toString()));
} else if (itemName.equals(T12.getsItemNameSwitchValue())) {
T12.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T12_Use_Of_Slot_SWITCH + "_" + command.toString()));
}
break;
case Constants.Souliss_T14:
SoulissT14 T14 = (SoulissT14) T;
T14.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.toString()));
break;
case Constants.Souliss_T18:
SoulissT18 T18 = (SoulissT18) T;
T18.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.toString()));
break;
case Constants.Souliss_T16:
SoulissT16 T16 = (SoulissT16) T;
String cmd = command.getClass().getSimpleName();
if (cmd.equals(Constants.Openhab_RGB_TYPE)) {
String[] HSB = command.toString().split(",");
short[] RGB = HSBtoRGB(Float.parseFloat(HSB[0]), Float.parseFloat(HSB[1]), Float.parseFloat(HSB[2]));
T16.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.getClass().getSimpleName()), RGB[0], RGB[1], RGB[2]);
} else {
T16.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.toString()));
}
break;
case Constants.Souliss_T19:
SoulissT19 T19 = (SoulissT19) T;
if (command instanceof PercentType) {
int percentToShort = (((PercentType) command).shortValue() * 254 / 100);
T19.commandSEND(Constants.Souliss_T1n_Set, Short.parseShort(String.valueOf(percentToShort)));
} else if (command instanceof DecimalType) {
int decimalToShort = (((DecimalType) command).shortValue() * 254 / 100);
T19.commandSEND(Constants.Souliss_T1n_Set, Short.parseShort(String.valueOf(decimalToShort)));
} else {
T19.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.toString()));
}
break;
case Constants.Souliss_T21:
SoulissT21 T21 = (SoulissT21) T;
T21.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.toString()));
break;
case Constants.Souliss_T22:
SoulissT22 T22 = (SoulissT22) T;
T22.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.toString()));
break;
case Constants.Souliss_T31:
SoulissT31 T31 = (SoulissT31) T;
// Setpoint
if (itemName.equals(T31.getsItemNameSetpointValue())) {
if (command instanceof DecimalType) {
int uu = HalfFloatUtils.fromFloat(((DecimalType) command).floatValue());
byte B2 = (byte) (uu >> 8);
byte B1 = (byte) uu;
// setpoint command
T31.CommandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_SETPOINT_COMMAND), B1, B2);
}
} else // Set As Measured
if (itemName.equals(T31.setAsMeasured.getName())) {
T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_SETASMEASURED + "_" + command.toString()));
} else if (itemName.equals(T31.heatingCoolingModeValue.getName())) {
T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_HEATING_COOLING + "_" + command.toString()));
} else if (itemName.equals(T31.fanAutoMode.getName())) {
T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_FANAUTOMODE + "_" + command.toString()));
} else if (itemName.equals(T31.fanOff.getName())) {
T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_FANOFF + "_" + command.toString()));
} else if (itemName.equals(T31.fanLow.getName())) {
T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_FANLOW + "_" + command.toString()));
} else if (itemName.equals(T31.fanMed.getName())) {
T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_FANMED + "_" + command.toString()));
} else if (itemName.equals(T31.fanHigh.getName())) {
T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_FANHIGH + "_" + command.toString()));
} else if (itemName.equals(T31.power.getName())) {
T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_POWER + "_" + command.toString()));
}
break;
default:
logger.debug("Typical Unknown");
}
}
use of org.openhab.binding.souliss.internal.network.typicals.SoulissT31 in project openhab1-addons by openhab.
the class SoulissGenericBindingProvider method processBindingConfiguration.
/**
* This method create typicals and add it to hastable
*
* @author Tonino Fazio
* @since 1.7.0
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
// Create Souliss Typicals
//
// ...from wiki of Dario De Maio
// In Souliss the logics that drive your lights, curtains, LED, and
// others are pre-configured into so called Typicals. A Typical is a
// logic with a predefined set of inputs and outputs and a know
// behavior, are used to standardize the user interface and have a
// configuration-less behavior.
final String itemName = item.getName();
logger.trace("Starting to load Souliss config for item {}", itemName);
super.processBindingConfiguration(context, item, bindingConfig);
String[] sNameArray = bindingConfig.split("\\:");
String sTypical = sNameArray[0];
int iNodeID = Integer.parseInt(sNameArray[1]);
int iSlot = Integer.parseInt(sNameArray[2]);
byte iBit = 0;
String sUseSlot = "";
// parametro
if (sNameArray.length > 3) {
if ((StateTraslator.stringToSOULISSTypicalCode(sTypical) == Constants.Souliss_T31) || (StateTraslator.stringToSOULISSTypicalCode(sTypical) == Constants.Souliss_T12)) {
sUseSlot = sNameArray[3];
} else {
iBit = Byte.parseByte(sNameArray[3]);
}
}
String sNote = item.getClass().getSimpleName();
SoulissGenericTypical soulissTypicalNew = null;
// Tipico Souliss
if ((StateTraslator.stringToSOULISSTypicalCode(sTypical) == Constants.Souliss_T31) || (StateTraslator.stringToSOULISSTypicalCode(sTypical) == Constants.Souliss_T12)) {
soulissTypicalNew = SoulissTypicalsRecipients.getTypicalFromAddress(iNodeID, iSlot, 0);
// creazione tipico, solo se non si tratta di un T31 al quale è stato aggiunto un parametro
if (soulissTypicalNew == null) {
soulissTypicalNew = TypicalFactory.getClass(StateTraslator.stringToSOULISSTypicalCode(sTypical), SoulissNetworkParameter.datagramsocket, SoulissNetworkParameter.IPAddressOnLAN, iNodeID, iSlot, sNote, iBit, sUseSlot);
}
if (soulissTypicalNew != null) {
// in base al campo use slot inserisco nel tipico il nome item di riferimento
switch(sUseSlot) {
case Constants.Souliss_T12_Use_Of_Slot_AUTOMODE:
((SoulissT12) soulissTypicalNew).setsItemNameAutoModeValue(item.getName());
((SoulissT12) soulissTypicalNew).setsItemTypeAutoModeValue(sNote);
break;
case Constants.Souliss_T12_Use_Of_Slot_SWITCH:
((SoulissT12) soulissTypicalNew).setsItemNameSwitchValue(item.getName());
((SoulissT12) soulissTypicalNew).setsItemTypeSwitchValue(sNote);
break;
case Constants.Souliss_T31_Use_Of_Slot_SETPOINT:
((SoulissT31) soulissTypicalNew).setsItemNameSetpointValue(item.getName());
((SoulissT31) soulissTypicalNew).setsItemTypeSetpointValue(sNote);
break;
case Constants.Souliss_T31_Use_Of_Slot_MEASURED:
((SoulissT31) soulissTypicalNew).setsItemNameMeasuredValue(item.getName());
((SoulissT31) soulissTypicalNew).setsItemTypeMeasuredValue(sNote);
break;
case Constants.Souliss_T31_Use_Of_Slot_SETASMEASURED:
((SoulissT31) soulissTypicalNew).setAsMeasured.setName(item.getName());
((SoulissT31) soulissTypicalNew).setAsMeasured.setNote(sNote);
break;
case Constants.Souliss_T31_Use_Of_Slot_HEATING:
((SoulissT31) soulissTypicalNew).heating.setName(item.getName());
((SoulissT31) soulissTypicalNew).heating.setNote(sNote);
break;
case Constants.Souliss_T31_Use_Of_Slot_COOLING:
((SoulissT31) soulissTypicalNew).cooling.setName(item.getName());
((SoulissT31) soulissTypicalNew).cooling.setNote(sNote);
break;
case Constants.Souliss_T31_Use_Of_Slot_FANOFF:
((SoulissT31) soulissTypicalNew).fanOff.setName(item.getName());
((SoulissT31) soulissTypicalNew).fanOff.setNote(sNote);
break;
case Constants.Souliss_T31_Use_Of_Slot_FANLOW:
((SoulissT31) soulissTypicalNew).fanLow.setName(item.getName());
((SoulissT31) soulissTypicalNew).fanLow.setNote(sNote);
break;
case Constants.Souliss_T31_Use_Of_Slot_FANMED:
((SoulissT31) soulissTypicalNew).fanMed.setName(item.getName());
((SoulissT31) soulissTypicalNew).fanMed.setNote(sNote);
break;
case Constants.Souliss_T31_Use_Of_Slot_FANHIGH:
((SoulissT31) soulissTypicalNew).fanHigh.setName(item.getName());
((SoulissT31) soulissTypicalNew).fanHigh.setNote(sNote);
break;
case Constants.Souliss_T31_Use_Of_Slot_HEATING_COOLING:
((SoulissT31) soulissTypicalNew).heatingCoolingModeValue.setName(item.getName());
((SoulissT31) soulissTypicalNew).heatingCoolingModeValue.setNote(sNote);
break;
case Constants.Souliss_T31_Use_Of_Slot_FANAUTOMODE:
((SoulissT31) soulissTypicalNew).fanAutoMode.setName(item.getName());
((SoulissT31) soulissTypicalNew).fanAutoMode.setNote(sNote);
break;
case Constants.Souliss_T31_Use_Of_Slot_POWER:
((SoulissT31) soulissTypicalNew).power.setName(item.getName());
((SoulissT31) soulissTypicalNew).power.setNote(sNote);
break;
}
logger.info("Add parameter to T31/T12 : " + sUseSlot);
}
}
// creazione tipico, solo se non si tratta di un T31 / T12 al quale è stato aggiunto un parametro
if (soulissTypicalNew == null) {
soulissTypicalNew = TypicalFactory.getClass(StateTraslator.stringToSOULISSTypicalCode(sTypical), SoulissNetworkParameter.datagramsocket, SoulissNetworkParameter.IPAddressOnLAN, iNodeID, iSlot, sNote, iBit, sUseSlot);
}
if (soulissTypicalNew != null) {
SoulissTypicalsRecipients.addTypical(item.getName(), soulissTypicalNew);
SoulissNetworkParameter.nodes = SoulissTypicalsRecipients.getNodeNumbers();
}
}
Aggregations