THE ONE OF IoT,YOUR ONLY CHOICE!
Health DNA
 

Health


Health interface define many health measure item, please refer to com.infairy.cocina.SDK.gene.HealthInterface.
If you are a health device maker, and want to write a bundle to broadcast your measure data, please follow the above step:
        package yourBundle;

        import com.infairy.cocina.SDK.gene.HealthInterface;
        import com.infairy.cocina.SDK.gene.HealthDNA;
        ...

        public class WeightMeter implements BundleActivator{
            ....

        }

        public void tellOthers(int kg){

          /*
           * Use HealthDNA object to 
           */
          HealthDNA health=new HealthDNA();
          health.Brand="MyBrand";
          health.Model="Weight001k";
          health.DataType=HealthInterface.Data_Type_Weight_Kg;
          health.DeviceKind=HealthInterface.Device_Kind_BodyWeight;
          health.Value=String.valueOf(kg);
          device.SensorBroadcast(health);

        }

      
Ok, your weight is easy to tell all others in Infairy.

Now, how can i get the weight data from Weight001k?
First, listen sensor broadcast:
        public class weightAssistant  implements BundleActivator,EventHandler{
          .....


          public void start(BundleContext context) throws Exception {

            /*
             *  Listen Sensor's broadcast data
             */
            device.ListenBroadcast(context, this, device.BROADCAST_CHANNEL_SENSOR);

              .....
          }


      
Second, implement handleEvent function:
      public void handleEvent(Event evnt) {
          if(evnt==null) return;
          
          /*
           * cast event to HealthDNA
           */
          HealthDNA health=(HealthDNA)evnt.getProperty(device.BROADCAST_HEALTH_EVENTOBJECT);
          if(health==null) return;
          
          /*
           * check the DeviceKind, please refer to  com.infairy.cocina.SDK.gete.HealthInterface.Device_Kind_xxxx
           */
          String Kind=health.DeviceKind;

          /*
           * check the DeviceKind, please refer to  com.infairy.cocina.SDK.gene.HealthInterface.Data_Type_xxxx
           */
          String DataType=health.DataType;

          /*
           * Value
           */
           String value=hrealth.Value;

           ...

      }