コード例 #1
0
  private void getUserStructs() {
    for (Struct struct : userStructs) {
      List<FieldDescription> fieldDescs = new ArrayList<FieldDescription>();

      List<Field> fields = struct.getFields();
      for (Field field : fields) {
        Srl srlType = Srl.valueOf(field.getType().getId());
        switch (srlType) {
          case t_srl_I32:
            fieldDescs.add(new FieldDescription(field.getName(), FieldType.INT64));
            break;
          case t_srl_U32:
            fieldDescs.add(new FieldDescription(field.getName(), FieldType.INT64));
            break;
          default:
        }
      }
      client.typeDescRead(new TypeDescription(struct.getId(), struct.getName(), fieldDescs));
    }
  }
コード例 #2
0
  private void getUserEvent(TypedCircularMessage message, long ts) {
    Struct struct = message.getStruct();
    userStructs.add(struct);

    int structId = struct.getId();
    FieldValues values = new FieldValues();
    List<Field> fields = struct.getFields();
    for (Field field : fields) {
      String fieldName = field.getName();
      Object value = message.getValue(fieldName);
      Type type = field.getType();
      if (field.isNullTerminated()) {
        if (type.getId() == Type.Srl.t_char.getId()) {
          String s = (String) value;
          values.addStringValue(s);
        } else {
          throw new UnsupportedOperationException(
              "Only null terminated 'char' sequences are currently supported, type is " + type);
        }
      } else if (field.getNumElements() == 1) {
        Srl srlType = Srl.valueOf(type.getId());
        switch (srlType) {
          case t_srl_I32:
          case t_srl_U32:
            Long i = (Long) value;
            values.addLongValue(i);
            break;
          default:
            throw new UnsupportedOperationException("Unsupported type: " + type);
        }

      } else {
        throw new UnsupportedOperationException(
            "Arrays are currently not supported, type is " + type);
      }
    }
    client.eventRead(new GenericEventInfo(ts, structId, values));
  }
コード例 #3
0
  /**
   * A hack to fix the problem with swapped ids in SRL in the mentor delivery 08032?
   *
   * @param typedCircularMessages
   */
  private void correctMessageIds(final Collection<TypedCircularMessage> typedCircularMessages) {
    for (TypedCircularMessage typedCircularMessage : typedCircularMessages) {
      Struct struct = typedCircularMessage.getStruct();

      /*
       * Detect id - name mismatch
       */
      if (struct.getId() == Message.UML_SEND.srlTypeId()) {
        if (struct.getName().equals("srl_UmlSignalReceive")) {
          struct.setId(Message.UML_RECEIVE.srlTypeId());
        }
      } else if (struct.getId() == Message.UML_RECEIVE.srlTypeId()) {
        if (struct.getName().equals("srl_UmlSignalSend")) {
          struct.setId(Message.UML_SEND.srlTypeId());
        }
      }
    }
  }