Exemplo n.º 1
0
 @Override
 public ValueResponse read(int resourceid) {
   log.info("[{}] Read on resource: {}", this.getClass().getName(), resourceid);
   switch (resourceid) {
     case 0:
       return new ValueResponse(
           ResponseCode.CONTENT,
           new LwM2mResource(resourceid, Value.newFloatValue(this.getSensorValue())));
     case 1:
       return new ValueResponse(
           ResponseCode.CONTENT,
           new LwM2mResource(resourceid, Value.newFloatValue(this.getPreviousAltitude())));
     default:
       return super.read(resourceid);
   }
 }
Exemplo n.º 2
0
 @Override
 public ValueResponse read(int resourceid) {
   try {
     switch (resourceid) {
       case 0:
         return new ValueResponse(
             ResponseCode.CONTENT,
             new LwM2mResource(resourceid, Value.newIntegerValue(attacker.getFly_mode())));
       case 1:
         return new ValueResponse(
             ResponseCode.CONTENT,
             new LwM2mResource(resourceid, Value.newIntegerValue(attacker.getIndex())));
       case 2:
         return new ValueResponse(
             ResponseCode.CONTENT,
             new LwM2mResource(
                 resourceid,
                 Value.newStringValue(gson.toJson(attacker.getTarget_indicated_by_role()))));
       case 3:
         return new ValueResponse(
             ResponseCode.CONTENT,
             new LwM2mResource(resourceid, Value.newBooleanValue(attacker.isVisible())));
       case 4:
         return new ValueResponse(
             ResponseCode.CONTENT,
             new LwM2mResource(
                 resourceid, Value.newStringValue(gson.toJson(attacker.getCenter_coordinates()))));
       case 5:
         return new ValueResponse(
             ResponseCode.CONTENT,
             new LwM2mResource(
                 resourceid,
                 Value.newStringValue(
                     gson.toJson(World.assignUAVPortInBase(attacker.getIndex())))));
       case 9:
         return new ValueResponse(
             ResponseCode.CONTENT,
             new LwM2mResource(resourceid, Value.newBooleanValue(attacker.isLockedToThreat())));
       case 12:
         return new ValueResponse(
             ResponseCode.CONTENT,
             new LwM2mResource(resourceid, Value.newFloatValue(attacker.getRemained_energy())));
       case 13:
         return new ValueResponse(
             ResponseCode.CONTENT,
             new LwM2mResource(
                 resourceid, Value.newStringValue(attacker.getAttackerType().toString())));
       case 14:
         return new ValueResponse(
             ResponseCode.CONTENT,
             new LwM2mResource(resourceid, Value.newBooleanValue(attacker.isThreatDestroyed())));
       case 15:
         return new ValueResponse(
             ResponseCode.CONTENT,
             new LwM2mResource(
                 resourceid, Value.newIntegerValue(attacker.getJustDestroyedThreatIndex())));
       default:
         return super.read(resourceid);
     }
   } catch (Exception e) {
     logger.error("ERROR: {}", e.getMessage());
     return super.read(resourceid);
   }
 }
Exemplo n.º 3
0
 protected Value<?> createDefaultOpaqueValue(
     ObjectModel objectModel, ResourceModel resourceModel) {
   return Value.newBinaryValue(new String("Default " + resourceModel.name).getBytes());
 }
Exemplo n.º 4
0
 protected Value<?> createDefaultFloatValue(ObjectModel objectModel, ResourceModel resourceModel) {
   return Value.newFloatValue((float) Math.random() * 100);
 }
Exemplo n.º 5
0
 protected Value<?> createDefaultDateValue(ObjectModel objectModel, ResourceModel resourceModel) {
   return Value.newDateValue(new Date());
 }
Exemplo n.º 6
0
 protected Value<Boolean> createDefaultBooleanValue(
     ObjectModel objectModel, ResourceModel resourceModel) {
   return Value.newBooleanValue(Math.random() * 100 % 2 == 0);
 }
Exemplo n.º 7
0
 protected Value<Integer> createDefaultIntegerValue(
     ObjectModel objectModel, ResourceModel resourceModel) {
   return Value.newIntegerValue((int) (Math.random() * 100 % 101));
 }
Exemplo n.º 8
0
 protected Value<String> createDefaultStringValue(
     ObjectModel objectModel, ResourceModel resourceModel) {
   return Value.newStringValue(resourceModel.name);
 }