The HomeAppliance Object is a Interface for home device .
public class myP2PBundle implements HomeApplianceInterface{ ... }Then, you have to implement the above functions:
/** * Key Learning function * @param object bundle object * @param protocol learning protocol{@link #Protocol433} {@link #Protocol315} {@link #ProtocolIR} {@link #ProtocolZigbee} {@link #ProtocolZWave} * @param HomeApplianceID Assign learning key code from which Home Appliance * @param ControllerId device id( or port or ...) of controller * @param key learning key {@link #Key_AV_xxx} {@link #Key_AC_xxx} {@link #Key_KTV_xxx} {@link #Key_DVD_xxx} * @param alias key alias * @return learning code, defined by developer of device */ public long Learning(Object object, String protocol, String HomeApplianceID, String ControllerId, String key, String alias); /** * Suspend learning process * @param object bundle object * @param HomeApplianceID Assign learning key code from which Home Appliance * @param ControllerId device id( or port or ...) of controller */ public void stopLearning(Object object, String HomeApplianceID, String ControllerId); /** * Get available protocol * @return protocol array, refer to * {@link com.infairy.cocina.SDK.P2P.HomeApplianceInterface#Protocol315} * {@link com.infairy.cocina.SDK.P2P.HomeApplianceInterface#Protocol433} * {@link com.infairy.cocina.SDK.P2P.HomeApplianceInterface#ProtocolIR} * {@link com.infairy.cocina.SDK.P2P.HomeApplianceInterface#ProtocolZigbee} * {@link com.infairy.cocina.SDK.P2P.HomeApplianceInterface#ProtocolZWave} */ public String[] getAvailableProtocol(); /** * Key control function * @param object bundle object * @param HomeApplianceID Assign learning key code from which Home Appliance * @param ControllerId device id( or port or ...) of controller * @param learningCode learning code of key, return by {@link #Learning(Object, String, int, String, String)} * @return true:success, false: fail */ public boolean Control(Object object, String HomeApplianceID, String ControllerId, long learningCode); /** * remove code function * @param object bundle object * @param HomeApplianceID Assign learning key code from which Home Appliance * @param learningCode learning code of key, return by {@link #Learning(Object, String, int, String, String)} * @return true"success, false: fail */ public boolean Remove(Object object, String HomeApplianceID,long learningCode); /** * get device brand name, this name was named by developer, to show the brand in other bundle * @return device brand name */ public String getDeviceBrand(); /** * Get Home appliance devices * @return home appliance devices */ public HomeApplianceDeviceImpl[] GetHomeAppliance(); public boolean EditCode(String ID);Then, please see the example of Geeklink which is a IR/433M/315M control device, we create a home appliance bundle to let all other bundle to control the home appliance via Geeklink.
First, GeekLink have p2p function, so..
package com.infairy.cocina.device.IR.wifi.GeekLink; ..... import com.infairy.cocina.SDK.P2P.P2PHandlerInterface; }Second, GeekLink is a home appliance device, we also implement HomeApplianceInterface,
package com.infairy.cocina.device.IR.wifi.GeekLink; ..... import com.infairy.cocina.SDK.P2P.HomeApplianceControlButton; import com.infairy.cocina.SDK.P2P.HomeApplianceDeviceImpl; import com.infairy.cocina.SDK.P2P.HomeApplianceInterface; }Finally, you can implement function of interface , you will be have a Infairy P2P devices.
Next, we will show you how the other bundle operate the GeekLink bundle to search device and control device.
The above code shows you how to get the P2P device in Infairy:
ArrayList p2p=device.getP2PDevice();Then, get the p2p device and filter you want:
private void getP2PDevice(){ ArrayList p2p=device.getP2PDevice(); for(int i=0; i < p2p.size(); i++){ Object[] data=(Object[])p2p.get(i); //get p2p object String id=(String)data[0]; //get id of p2p device String alias=(String)data[1]; //get id of p2p alias for special purpos2 String icon=(String)data[2]; //get icon file path Object p2pDevice=device.getP2PDeviceImpl(id); try{ HomeApplianceInterface hai=(HomeApplianceInterface)p2pDevice; //cast object to HomeApplianceDevice String[] protocol=hai.getAvailableProtocol(); //get home appliance protocol boolean rightProtocol=false; /* * We want to use the home device with IR/Zigbee/ZWave */ for(int j=0; j < protocol.length; j++){ if(protocol[j].equals(HomeApplianceInterface.ProtocolIR) || protocol[j].equals(HomeApplianceInterface.ProtocolZigbee) || protocol[j].equals(HomeApplianceInterface.ProtocolZWave) ){ rightProtocol=true; break; } } if(rightProtocol){ String brand=hai.getDeviceBrand(); //get device brand HomeApplianceDeviceImpl[] hadev= hai.GetHomeAppliance(); //get home appliance object String[] machineID=new String[hadev.length]; String[] machineAlias=new String[hadev.length]; for(int j=0; j < hadev.length; j++){ machineID[j]==(String)hadev[j].get(HomeApplianceDeviceImpl.MachineID); ; //get home appliance machine id, ex. ZWave's homeid machineAlias[j]=(String)hadev[j].get(HomeApplianceDeviceImpl.Alias); //get home device's alias } } }catch(Exception e){ } } }Fig-1-12-1.bundle and home appliance relationship
To learn the control code from the device's process as below:
HomeApplianceInterface hai=(HomeApplianceInterface)p2pDevice; //cast object to HomeApplianceDevice String controllerID="001"; /* * machineID is get from HomeApplianceDeviceImpl */ String machineID=(String)hadev[j].get(HomeApplianceDeviceImpl.MachineID); /* * Learning key's alias */ String alias="PowerOn"; /* * Learning key defined, pleaser refer to HomeApplianceInterface.KEY_xxx */ String key=HomeApplianceInterface.Key_AC_PowerOn; /* * Learning key and assign the learning protocol */ long learnCode=hai.Learning(this, HomeApplianceInterface.ProtocolIR, machineID, controllerID, alias, key);To control the device process as below:
HomeApplianceInterface hai=(HomeApplianceInterface)p2pDevice; //cast object to HomeApplianceDevice HomeApplianceDeviceImpl[] hadev= hai.GetHomeAppliance(); //get home appliance object /* * machineID is get from HomeApplianceDeviceImpl */ String machineID=(String)hadev[j].get(HomeApplianceDeviceImpl.MachineID); /* * controller id is defined by developer */ String controllerID="001"; /* * the control Code is response for learning process */ String controlCode=learnCode; /* * operate GeekLink device */ hai.Control(this, machineID, controllerID, controlCode);