Search in sources :

Example 1 with SoulissT16

use of org.openhab.binding.souliss.internal.network.typicals.SoulissT16 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));
                    }
            }
        }
    }
}
Also used : SoulissT31(org.openhab.binding.souliss.internal.network.typicals.SoulissT31) Entry(java.util.Map.Entry) SoulissT1A(org.openhab.binding.souliss.internal.network.typicals.SoulissT1A) SoulissT16(org.openhab.binding.souliss.internal.network.typicals.SoulissT16) SoulissGenericTypical(org.openhab.binding.souliss.internal.network.typicals.SoulissGenericTypical)

Example 2 with SoulissT16

use of org.openhab.binding.souliss.internal.network.typicals.SoulissT16 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");
    }
}
Also used : SoulissT21(org.openhab.binding.souliss.internal.network.typicals.SoulissT21) SoulissT31(org.openhab.binding.souliss.internal.network.typicals.SoulissT31) SoulissT12(org.openhab.binding.souliss.internal.network.typicals.SoulissT12) SoulissT11(org.openhab.binding.souliss.internal.network.typicals.SoulissT11) SoulissT22(org.openhab.binding.souliss.internal.network.typicals.SoulissT22) PercentType(org.openhab.core.library.types.PercentType) SoulissT18(org.openhab.binding.souliss.internal.network.typicals.SoulissT18) DecimalType(org.openhab.core.library.types.DecimalType) SoulissT19(org.openhab.binding.souliss.internal.network.typicals.SoulissT19) SoulissT14(org.openhab.binding.souliss.internal.network.typicals.SoulissT14) SoulissT16(org.openhab.binding.souliss.internal.network.typicals.SoulissT16) SoulissGenericTypical(org.openhab.binding.souliss.internal.network.typicals.SoulissGenericTypical)

Aggregations

SoulissGenericTypical (org.openhab.binding.souliss.internal.network.typicals.SoulissGenericTypical)2 SoulissT16 (org.openhab.binding.souliss.internal.network.typicals.SoulissT16)2 SoulissT31 (org.openhab.binding.souliss.internal.network.typicals.SoulissT31)2 Entry (java.util.Map.Entry)1 SoulissT11 (org.openhab.binding.souliss.internal.network.typicals.SoulissT11)1 SoulissT12 (org.openhab.binding.souliss.internal.network.typicals.SoulissT12)1 SoulissT14 (org.openhab.binding.souliss.internal.network.typicals.SoulissT14)1 SoulissT18 (org.openhab.binding.souliss.internal.network.typicals.SoulissT18)1 SoulissT19 (org.openhab.binding.souliss.internal.network.typicals.SoulissT19)1 SoulissT1A (org.openhab.binding.souliss.internal.network.typicals.SoulissT1A)1 SoulissT21 (org.openhab.binding.souliss.internal.network.typicals.SoulissT21)1 SoulissT22 (org.openhab.binding.souliss.internal.network.typicals.SoulissT22)1 DecimalType (org.openhab.core.library.types.DecimalType)1 PercentType (org.openhab.core.library.types.PercentType)1