| /////////////////////////////////////////////////////////////////////////////// |
| // |
| // Copyright (c) 2000-2017 Ericsson Telecom AB |
| // |
| // All rights reserved. This program and the accompanying materials |
| // are made available under the terms of the Eclipse Public License v1.0 |
| // which accompanies this distribution, and is available at |
| // http://www.eclipse.org/legal/epl-v10.html |
| /////////////////////////////////////////////////////////////////////////////// |
| // File: LightweightM2M_Types.ttcn |
| // Description: |
| // Rev: R1A |
| // Prodnr: LPA 108 661 |
| // Updated: 2017-09-01 |
| // Contact: http://ttcn.ericsson.se |
| /////////////////////////////////////////////////////////////////////////////// |
| module LightweightM2M_Types |
| { |
| type universal charstring URN; |
| type record of universal charstring Location; |
| type record of integer Integer_List; |
| |
| type union LWM2M_PDU |
| { |
| // ----- |
| LWM2M_Register Register, |
| LWM2M_Update Update, |
| LWM2M_Deregister Deregister, |
| LWM2M_Response Response, |
| // ----- |
| LWM2M_Read Read_, |
| LWM2M_Write Write, |
| LWM2M_Execute Execute, |
| // ----- |
| LWM2M_Create Create, |
| LWM2M_Delete Delete |
| } |
| |
| type record LWM2M_Register |
| { |
| URN endpointClientName, |
| integer lifetime optional, |
| charstring version optional, |
| BindingMode bindingMode optional, |
| integer smsNumber optional, |
| ObjectPath_List objectsAndObjectInstances |
| } |
| |
| const LWM2M_PDU c_LWM2M_Register_init := |
| { |
| Register := { |
| endpointClientName := "", |
| lifetime := omit, |
| version := omit, |
| bindingMode := omit, |
| smsNumber := omit, |
| objectsAndObjectInstances := {} |
| } |
| } |
| |
| type record LWM2M_Update |
| { |
| Location location, |
| integer lifetime optional, |
| BindingMode bindingMode optional, |
| integer smsNumber optional, |
| ObjectPath_List objectsAndObjectInstances |
| } |
| |
| const LWM2M_PDU c_LWM2M_Update_init := |
| { |
| Update := { |
| location := {}, |
| lifetime := omit, |
| bindingMode := omit, |
| smsNumber := omit, |
| objectsAndObjectInstances := {} |
| } |
| } |
| |
| type record LWM2M_Read |
| { |
| ObjectPath path, |
| Integer_List accept, |
| LwM2M_Observe_Information observe optional |
| } |
| |
| const LWM2M_PDU c_LWM2M_Read_init := |
| { |
| Read_ := { |
| path := {-1, omit, omit}, |
| accept := {}, |
| observe := omit |
| } |
| } |
| |
| type record LWM2M_Write |
| { |
| ObjectPath path, |
| integer contentFormat, |
| LwM2M_Resource_List resources |
| } |
| |
| const LWM2M_PDU c_LWM2M_Write_init := |
| { |
| Write := { |
| path := { -1, omit, omit}, |
| contentFormat := -1, |
| resources := {} |
| } |
| } |
| |
| type record LWM2M_Execute |
| { |
| ObjectPath path |
| } |
| |
| const LWM2M_PDU c_LWM2M_Execute_init := |
| { |
| Execute := { |
| path := { -1, omit, omit} |
| } |
| } |
| |
| type record LWM2M_Create |
| { |
| ObjectPath path |
| } |
| |
| const LWM2M_PDU c_LWM2M_Create_init := |
| { |
| Create := { |
| path := { -1, omit, omit} |
| } |
| } |
| |
| type record LWM2M_Delete |
| { |
| ObjectPath path |
| } |
| |
| const LWM2M_PDU c_LWM2M_Delete_init := |
| { |
| Delete := { |
| path := { -1, omit, omit} |
| } |
| } |
| |
| type record LWM2M_Deregister |
| { |
| Location location |
| } |
| |
| type record LWM2M_Response |
| { |
| Location location, |
| integer code, |
| integer contentFormat optional, |
| LwM2M_Observe_Information observe optional, |
| LwM2M_Resource_List resources |
| } |
| |
| const LWM2M_PDU c_LWM2M_Response_init := |
| { |
| Response := { |
| location := {}, |
| code := 0, |
| contentFormat := omit, |
| observe := omit, |
| resources := {} |
| } |
| } |
| |
| type enumerated BindingMode |
| { |
| U, UQ, S, SQ, US, UQS |
| } |
| |
| type record ObjectPath |
| { |
| integer objectId, |
| integer objectInstanceId optional, |
| integer resourceId optional |
| } |
| |
| type record of ObjectPath ObjectPath_List; |
| |
| type record LwM2M_Resource |
| { |
| integer id, |
| integer objId, |
| integer objInstId, |
| LwM2M_Observe_Information observe optional, |
| LwM2M_DataSample_Information dataSample optional, |
| LwM2M_ResourceValue val |
| } |
| |
| type record LwM2M_Observe_Information |
| { |
| integer observe, |
| octetstring token |
| } |
| |
| const LwM2M_Observe_Information c_LwM2M_Observe_Information_init := |
| { |
| observe := -1, |
| token := ''O |
| } |
| |
| type record LwM2M_DataSample_Information |
| { |
| charstring samplesName, |
| integer samplesPointer, |
| integer valuePointer |
| } |
| |
| const LwM2M_DataSample_Information c_LwM2M_DataSample_Information_init := |
| { |
| samplesName := "", |
| samplesPointer := -1, |
| valuePointer := -1 |
| } |
| |
| const LwM2M_Resource c_LwM2M_Resource_init := |
| { |
| id := -1, |
| objId := -1, |
| objInstId := -1, |
| observe := omit, |
| dataSample := omit, |
| val := { boolValue := false } |
| } |
| |
| type union LwM2M_ResourceValue |
| { |
| integer intValue, |
| charstring strValue, |
| float floatValue, |
| octetstring opaqueValue, |
| boolean boolValue |
| } |
| |
| type record of LwM2M_ResourceValue LwM2M_ResourceValue_List; |
| |
| type record of LwM2M_Resource LwM2M_Resource_List; |
| |
| function f_LwM2M_ObjectPath_isResource(in ObjectPath p_path) |
| return boolean |
| { |
| return ispresent(p_path.objectInstanceId) and ispresent(p_path.resourceId) |
| } |
| |
| function f_LwM2M_ObjectPath_isObjectInstance(in ObjectPath p_path) |
| return boolean |
| { |
| return ispresent(p_path.objectInstanceId) and not ispresent(p_path.resourceId) |
| } |
| |
| function f_LwM2M_ObjectPath_isObject(in ObjectPath p_path) |
| return boolean |
| { |
| return not ispresent(p_path.objectInstanceId) and not ispresent(p_path.resourceId) |
| } |
| |
| /////////////////////////////////////// |
| // JSON representation and enc/dec |
| /////////////////////////////////////// |
| function f_enc_LwM2M_Resources_to_JSON(in LwM2M_Resource_List p_res_list) return octetstring |
| { |
| var charstring v_result := |
| "{\"bn\":\"/\",\n"& |
| "\"e\":[\n"; |
| |
| for (var integer i:=0; i<sizeof(p_res_list); i:=i+1) |
| { |
| v_result := v_result & f_enc_LwM2M_Resource_to_JSON(p_res_list[i]); |
| if (i != sizeof(p_res_list)-1) { v_result := v_result & ",\n"} |
| else { v_result := v_result & "\n"} |
| } |
| |
| v_result := v_result & "]}"; |
| |
| return char2oct(v_result); |
| } |
| |
| function f_enc_LwM2M_Resource_to_JSON(in LwM2M_Resource p_res) return charstring |
| { |
| var charstring v_ret := ""; |
| |
| // "n":"65/3/3" |
| var charstring v_name := ""; |
| |
| if (p_res.objId != -1) { |
| v_name := v_name & int2str(p_res.objId) |
| } |
| if (p_res.objInstId != -1) { |
| if (lengthof(v_name) > 0) { v_name := v_name & "/" & int2str(p_res.objInstId) } |
| else { v_name := int2str(p_res.objInstId) } |
| } |
| if (p_res.id != -1) { |
| if (lengthof(v_name) > 0) { v_name := v_name & "/" & int2str(p_res.id) } |
| else { v_name := int2str(p_res.id) } |
| } |
| v_name := "\"n\":\"" & v_name & "\""; |
| |
| var charstring v_value := ""; |
| |
| if (ischosen(p_res.val.intValue)) { |
| v_value := "\"v\":" & int2str(p_res.val.intValue); |
| } |
| else if (ischosen(p_res.val.floatValue)) { |
| v_value := "\"v\":" & float2str(p_res.val.floatValue); |
| } |
| else if (ischosen(p_res.val.strValue)) { |
| v_value := "\"sv\":" & "\"" & p_res.val.strValue & "\""; |
| } |
| else if (ischosen(p_res.val.boolValue)) { |
| v_value := "\"bv\":" & "\"" & f_bool2str(p_res.val.boolValue) & "\""; |
| } |
| else if (ischosen(p_res.val.opaqueValue)) { |
| v_value := "\"ov\":" & "\"" & oct2str(p_res.val.opaqueValue) & "\""; |
| } |
| |
| v_ret := "{" & v_name & ", " & v_value & "}"; |
| |
| return v_ret; |
| } |
| |
| function f_bool2str(in boolean p_b) return charstring { if (p_b) {return "true"} else {return "false" }} |
| |
| function f_enc_LwM2M_Resources_to_JSON_old(in LwM2M_Resource_List p_res_list) return octetstring |
| { |
| var LwM2M_JSON_Resources v_json_res_list; |
| v_json_res_list.e := {}; |
| |
| for (var integer i:=0; i<sizeof(p_res_list); i:=i+1) |
| { |
| v_json_res_list.e[sizeof(v_json_res_list.e)] := f_LwM2M_Resource_toJSONStructure(p_res_list[i]); |
| } |
| |
| return f_enc_LwM2M_JSON_Resources(v_json_res_list); |
| } |
| |
| function f_LwM2M_Resource_toJSONStructure(in LwM2M_Resource p_in) |
| return LwM2M_JSON_Resource |
| { |
| var LwM2M_JSON_Resource v_out; |
| |
| v_out.n := ""; |
| |
| if (p_in.objId != -1) { |
| v_out.n := int2str(p_in.objId) |
| } |
| if (p_in.objInstId != -1) { |
| if (lengthof(v_out.n) > 0) { v_out.n := v_out.n & "/" & int2str(p_in.objInstId) } |
| else { v_out.n := int2str(p_in.objInstId) } |
| } |
| if (p_in.id != -1) { |
| if (lengthof(v_out.n) > 0) { v_out.n := v_out.n & "/" & int2str(p_in.id) } |
| else { v_out.n := int2str(p_in.id) } |
| } |
| |
| if (ischosen(p_in.val.intValue)) { v_out.v := int2float(p_in.val.intValue) } |
| else if (ischosen(p_in.val.floatValue)) { v_out.v := p_in.val.floatValue } |
| else if (ischosen(p_in.val.strValue)) { v_out.sv := p_in.val.strValue } |
| else if (ischosen(p_in.val.boolValue)) { v_out.bv := p_in.val.boolValue } |
| else if (ischosen(p_in.val.opaqueValue)) { v_out.sv := oct2str(p_in.val.opaqueValue) } |
| |
| return v_out; |
| } |
| |
| function f_LwM2M_JSON_Resources_toResources(in LwM2M_JSON_Resources p_json_res_list) |
| return LwM2M_Resource_List |
| { |
| var LwM2M_Resource_List v_ret := {}; |
| |
| for (var integer i:=0; i<sizeof(p_json_res_list.e); i:=i+1) { |
| v_ret[sizeof(v_ret)] := f_LwM2M_JSON_Resource_toResource(p_json_res_list.e[i]); |
| } |
| |
| return v_ret; |
| } |
| |
| function f_LwM2M_JSON_Resource_toResource(in LwM2M_JSON_Resource p_json_res) |
| return LwM2M_Resource |
| { |
| var LwM2M_Resource v_ret := c_LwM2M_Resource_init; |
| |
| if (ispresent(p_json_res.bv)) { v_ret.val.boolValue := p_json_res.bv; } |
| if (ispresent(p_json_res.sv)) { v_ret.val.strValue := p_json_res.sv; } |
| if (ispresent(p_json_res.v)) { v_ret.val.floatValue := p_json_res.v; } |
| |
| return v_ret; |
| } |
| |
| external function f_enc_LwM2M_JSON_Resources(in LwM2M_JSON_Resources p_res) return octetstring |
| with { extension "prototype(convert) encode(JSON) printing(pretty)" } |
| |
| external function f_dec_LwM2M_JSON_Resources(in octetstring p_res) return LwM2M_JSON_Resources |
| with { extension "prototype(convert) decode(JSON)" } |
| |
| type record LwM2M_JSON_Resources |
| { |
| LwM2M_JSON_Resource_List e |
| } |
| with { encode "JSON" } |
| |
| type record of LwM2M_JSON_Resource LwM2M_JSON_Resource_List |
| with { encode "JSON" } |
| |
| type record LwM2M_JSON_Resource |
| { |
| charstring n, |
| float v optional, |
| boolean bv optional, |
| charstring sv optional |
| } |
| with { |
| encode "JSON" |
| optional "implicit omit" |
| } |
| } |