blob: 1f1ff8da2c51312c5402d3bf6e10beba4772f274 [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2020 Ericsson Telecom AB
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v2.0
// which accompanies this distribution, and is available at
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
///////////////////////////////////////////////////////////////////////////////
// File: EPTF_LwM2M_Object_Functions.ttcn
// Description:
// Rev: R1A
// Prodnr: CNL 113 859
// Updated: 2020-03-04
// Contact: http://ttcn.ericsson.se
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Module: EPTF_LwM2M_Object_Functions
//
// Purpose:
// This module contains the functions of the smart object definitions for the LWM2M load generator component
//
// See also:
// <EPTF_COAP_LGen_Definitions>
///////////////////////////////////////////////////////////////
module EPTF_LwM2M_Object_Functions {
import from LightweightM2M_Types all;
import from EPTF_LwM2M_Object_Definitions all;
import from EPTF_CLL_HashMapInt2Int_Functions all;
import from EPTF_CLL_HashMapStr2Int_Functions all;
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectSpecificationDB_init
//
// Purpose:
// Initializes the <LwM2M_ObjectSpecificationDB> database
//
// Parameters:
// p_db - *inout* <LwM2M_ObjectSpecificationDB> - DB instance
// p_id - *in integer* - unique id for the instance
//
// Related Type:
// <LwM2M_ObjectSpecificationDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectSpecificationDB_init(inout LwM2M_ObjectSpecificationDB p_db, in integer p_id)
{
p_db := c_LwM2M_ObjectSpecificationDB_init;
p_db.id := p_id;
p_db.hashRef := f_EPTF_int2int_HashMap_New("EPTF_LwM2M_ObjectSpecificationDB_"&int2str(p_id)&"_Hash");
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectSpecificationDB_cleanUp
//
// Purpose:
// Cleans up the reserved resources of the <LwM2M_ObjectSpecificationDB> database
//
// Parameters:
// p_db - *inout* <LwM2M_ObjectSpecificationDB> - DB instance
//
// Related Type:
// <LwM2M_ObjectSpecificationDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectSpecificationDB_cleanUp(inout LwM2M_ObjectSpecificationDB p_db)
{
f_EPTF_int2int_HashMap_Delete("EPTF_LwM2M_ObjectSpecificationDB_"&int2str(p_db.id)&"_Hash");
p_db := c_LwM2M_ObjectSpecificationDB_init;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectSpecificationDB_add
//
// Purpose:
// Adds a new <LwM2M_ObjectSpecification> element to the <LwM2M_ObjectSpecificationDB> database
//
// Parameters:
// p_db - *inout* <LwM2M_ObjectSpecificationDB> - DB instance
// p_spec - <LwM2M_ObjectSpecification> - new element
//
// Related Type:
// <LwM2M_ObjectSpecificationDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectSpecificationDB_add(inout LwM2M_ObjectSpecificationDB p_db, LwM2M_ObjectSpecification p_spec)
return integer
{
var integer vl_idx := -1;
if (not f_EPTF_int2int_HashMap_Find(p_db.hashRef, p_spec.id, vl_idx))
{
vl_idx := sizeof(p_db.specs);
p_db.specs[vl_idx] := p_spec;
f_EPTF_int2int_HashMap_Insert(p_db.hashRef, p_spec.id, vl_idx);
}
return vl_idx;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectSpecificationDB_lookUp
//
// Purpose:
// Gets the index of a <LwM2M_ObjectSpecification> element in the <LwM2M_ObjectSpecificationDB> database
//
// Parameters:
// p_db - *inout* <LwM2M_ObjectSpecificationDB> - DB instance
// p_objId - *integer* - obj id of the <LwM2M_ObjectSpecification> to be retrieved
//
// Returns:
// *integer* - the index of the looked up element in the database, or -1 if not found
//
// Related Type:
// <LwM2M_ObjectSpecificationDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectSpecificationDB_lookUp(in LwM2M_ObjectSpecificationDB p_db, in integer p_objId)
return integer
{
var integer vl_idx := -1;
if (f_EPTF_int2int_HashMap_Find(p_db.hashRef, p_objId, vl_idx)) {
return vl_idx;
}
return -1;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectSpecificationDB_getResourceSpecification
//
// Purpose:
// Retrieves a <LwM2M_ResourceSpecification> element in the <LwM2M_ObjectSpecificationDB> database
//
// Parameters:
// p_spec_db - *inout* <LwM2M_ObjectSpecificationDB> - DB instance
// p_objId - *integer* - obj id of the <LwM2M_ResourceSpecification> to be retrieved
// p_resId - *integer* - resource id of the <LwM2M_ResourceSpecification> to be retrieved
// p_spec - *inout* <LwM2M_ResourceSpecification> - the returned specification
//
// Returns:
// *boolean* - true, in case the specification was found
//
// Related Type:
// <LwM2M_ObjectSpecificationDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectSpecificationDB_getResourceSpecification(
LwM2M_ObjectSpecificationDB p_spec_db,
integer p_objId,
integer p_resId,
inout LwM2M_ResourceSpecification p_spec
)
return boolean
{
if (p_objId >=0 and p_resId >= 0)
{
var integer p_objSpecIdx := f_LwM2M_ObjectSpecificationDB_lookUp(p_spec_db, p_objId);
if (p_objSpecIdx >=0)
{
for (var integer i:=0; i<sizeof(p_spec_db.specs[p_objSpecIdx].resourcedefs); i:=i+1)
{
if (p_spec_db.specs[p_objSpecIdx].resourcedefs[i].id == p_resId)
{
p_spec := p_spec_db.specs[p_objSpecIdx].resourcedefs[i];
return true;
}
}
}
}
return false;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectSpecificationDB_fillInOmaSpecs
//
// Purpose:
// Loads known OMA related <LwM2M_ObjectSpecification> elements into the <LwM2M_ObjectSpecificationDB> database
//
// Parameters:
// p_db - *inout* <LwM2M_ObjectSpecificationDB> - DB instance
//
// Related Type:
// <LwM2M_ObjectSpecificationDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectSpecificationDB_fillInOmaSpecs(inout LwM2M_ObjectSpecificationDB p_db)
{
f_LwM2M_ObjectSpecificationDB_add(p_db, c_LwM2M_Security_spec);
f_LwM2M_ObjectSpecificationDB_add(p_db, c_LwM2M_Server_spec);
f_LwM2M_ObjectSpecificationDB_add(p_db, c_LwM2M_Device_spec);
f_LwM2M_ObjectSpecificationDB_add(p_db, c_LwM2M_Location_spec);
f_LwM2M_ObjectSpecificationDB_add(p_db, c_LwM2M_FirmwareUpdate_spec);
f_LwM2M_ObjectSpecificationDB_add(p_db, c_LwM2M_IPSO_Temperature_spec);
f_LwM2M_ObjectSpecificationDB_add(p_db, c_LwM2M_PowerMeasurement_spec);
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectDB_init
//
// Purpose:
// Initializes the <LwM2M_ObjectDB> database
//
// Parameters:
// p_db - *inout* <LwM2M_ObjectDB> - DB instance
// p_id - *in integer* - unique id for the instance
//
// Related Type:
// <LwM2M_ObjectDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectDB_init(inout LwM2M_ObjectDB p_db, in integer p_id)
{
p_db := c_LwM2M_ObjectDB_init;
p_db.id := p_id;
p_db.objHashRef := f_EPTF_int2int_HashMap_New("EPTF_LwM2M_ObjectDB_"&int2str(p_db.id)&"_objHash");
p_db.resHashRef := f_EPTF_str2int_HashMap_New("EPTF_LwM2M_ObjectDB_"&int2str(p_db.id)&"_resHash");
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectDB_cleanUp
//
// Purpose:
// Cleans up the reserved resources of the <LwM2M_ObjectDB> database
//
// Parameters:
// p_db - *inout* <LwM2M_ObjectDB> - DB instance
//
// Related Type:
// <LwM2M_ObjectDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectDB_cleanUp(inout LwM2M_ObjectDB p_db)
{
if (p_db.id >= 0)
{
f_EPTF_int2int_HashMap_Delete("EPTF_LwM2M_ObjectDB_"&int2str(p_db.id)&"_objHash");
f_EPTF_str2int_HashMap_Delete("EPTF_LwM2M_ObjectDB_"&int2str(p_db.id)&"_resHash");
p_db := c_LwM2M_ObjectDB_init;
}
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectDB_createObject
//
// Purpose:
// Creates a new instance of a <LwM2M_Object> and adds it to the <LwM2M_ObjectDB> database
//
// Parameters:
// p_db - *inout* <LwM2M_ObjectDB> - DB instance
// p_spec - *in* <LwM2M_ObjectSpecification> - specification of the smart object to be instantiated
//
// Returns:
// *integer* - the index of the <LwM2M_Object> instance in the database
//
// Related Type:
// <LwM2M_ObjectDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectDB_createObject(inout LwM2M_ObjectDB p_db, in LwM2M_ObjectSpecification p_spec)
return integer
{
var integer vl_idx := -1;
if (not f_EPTF_int2int_HashMap_Find(p_db.objHashRef, p_spec.id, vl_idx))
{
vl_idx := sizeof(p_db.objs);
f_EPTF_int2int_HashMap_Insert(p_db.objHashRef, p_spec.id, vl_idx);
p_db.objs[vl_idx] := c_LwM2M_Object_init;
p_db.objs[vl_idx].id := p_spec.id;
}
return vl_idx;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectDB_getObject
//
// Purpose:
// Retrieves an instance of a <LwM2M_Object> from a <LwM2M_ObjectDB> database
//
// Parameters:
// p_db - *in* <LwM2M_ObjectDB> - DB instance
// p_id - *in integer* - id of the smart object to be retrieved
//
// Returns:
// p_obj - *inout* <LwM2M_Object> - the retrieved <LwM2M_Object> instance
// *boolean* - true if the instance was found, false otherwise
//
// Related Type:
// <LwM2M_ObjectDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectDB_getObject(in LwM2M_ObjectDB p_db, in integer p_id, inout LwM2M_Object p_obj)
return boolean
{
var integer vl_idx := f_LwM2M_ObjectDB_getObjectIdx(p_db, p_id);
if (vl_idx >= 0)
{
p_obj := p_db.objs[vl_idx];
return true;
}
return false;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectDB_getObjectIdx
//
// Purpose:
// Retrieves the index of an instance of a <LwM2M_Object> from a <LwM2M_ObjectDB> database
//
// Parameters:
// p_db - *in* <LwM2M_ObjectDB> - DB instance
// p_id - *in integer* - id of the smart object to be retrieved
//
// Returns:
// integer - index of an instance of a <LwM2M_Object> in a <LwM2M_ObjectDB> database
//
// Related Type:
// <LwM2M_ObjectDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectDB_getObjectIdx(in LwM2M_ObjectDB p_db, in integer p_id)
return integer
{
var integer vl_idx := -1;
if (f_EPTF_int2int_HashMap_Find(p_db.objHashRef, p_id, vl_idx))
{
return vl_idx;
}
return -1;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectDB_createObjectInstance
//
// Purpose:
// Creates an <LwM2M_ObjectInstance> of a <LwM2M_Object> in a <LwM2M_ObjectDB> database
//
// Parameters:
// p_db - *in* <LwM2M_ObjectDB> - DB instance
// p_id - *in integer* - id of the smart object to be instantiated
// p_spec_db - *in* <LwM2M_ObjectSpecificationDB> - object specification DB
// p_createResources - *in boolean* - should the func create the resource instances as well?
//
// Returns:
// integer - index of an instance of a <LwM2M_ObjectInstance> in a <LwM2M_ObjectDB> database
//
// Related Type:
// <LwM2M_ObjectDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectDB_createObjectInstance(inout LwM2M_ObjectDB p_db, in LwM2M_ObjectSpecificationDB p_spec_db, in integer p_id, in boolean p_createResources := true)
return integer
{
var integer vl_objIdx := -1
var integer vl_objInstIdx := -1;
var integer vl_objSpecIdx := -1;
vl_objIdx := f_LwM2M_ObjectDB_getObjectIdx(p_db, p_id);
if (vl_objIdx >= 0)
{
vl_objSpecIdx := f_LwM2M_ObjectSpecificationDB_lookUp(p_spec_db, p_id);
if (vl_objSpecIdx >= 0)
{
vl_objInstIdx := sizeof(p_db.objs[vl_objIdx].instances);
p_db.objs[vl_objIdx].instances[vl_objInstIdx] := c_LwM2M_ObjectInstance_init;
p_db.objs[vl_objIdx].instances[vl_objInstIdx].id := vl_objInstIdx;
p_db.objs[vl_objIdx].instances[vl_objInstIdx].objId := p_spec_db.specs[vl_objSpecIdx].id;
// Creating resources according to spec
if (p_createResources) {
var LwM2M_Resource v_res;
for (var integer i:=0; i<sizeof(p_spec_db.specs[vl_objSpecIdx].resourcedefs); i:=i+1)
{
v_res := f_LwM2M_createResource(p_db.objs[vl_objIdx].instances[vl_objInstIdx], p_spec_db.specs[vl_objSpecIdx].resourcedefs[i]);
v_res.spec.objSpecIdx := vl_objSpecIdx;
v_res.spec.resSpecIdx := i;
f_LwM2M_ObjectDB_addResource(p_db, v_res);
}
}
}
}
return vl_objInstIdx;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectDB_createObjectInstance
//
// Purpose:
// Links in an <LwM2M_Resource> in a <LwM2M_ObjectDB> database
//
// Parameters:
// p_db - *in* <LwM2M_ObjectDB> - DB instance
// p_resource - *in* <LwM2M_Resource> - smart resource instance
//
// Returns:
// boolean - true if it was succesful
//
// Related Type:
// <LwM2M_ObjectDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectDB_addResource(inout LwM2M_ObjectDB p_db, in LwM2M_Resource p_resource)
return boolean
{
var integer vl_resIdx;
if (not f_EPTF_str2int_HashMap_Find(p_db.resHashRef, f_LwM2M_resourceHash_forResource(p_resource), vl_resIdx))
{
var integer vl_objIdx := f_LwM2M_ObjectDB_getObjectIdx(p_db, p_resource.objId);
if (vl_objIdx >= 0)
{
// Adding to resource array
vl_resIdx := sizeof(p_db.resources);
p_db.resources[vl_resIdx] := p_resource;
// Linking it under the object instance
var integer vl_resIdxInObjInst := sizeof(p_db.objs[vl_objIdx].instances[p_resource.objInstId].resources);
p_db.objs[vl_objIdx].instances[p_resource.objInstId].resources[vl_resIdxInObjInst] := vl_resIdx;
// Adding it to the hash
f_EPTF_str2int_HashMap_Insert(p_db.resHashRef, f_LwM2M_resourceHash_forResource(p_resource), vl_resIdx);
return true;
}
}
return false;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectDB_getObjectInstance
//
// Purpose:
// Retrieves an <LwM2M_ObjectInstance> from a <LwM2M_ObjectDB> database
//
// Parameters:
// p_db - *in* <LwM2M_ObjectDB> - DB instance
// p_objId - *in integer* - object id
// p_objInstId - *in integer* - object instance id
//
// Returns:
// p_objInst - *inout* <LwM2M_ObjectInstance> - object instance
// boolean - if the instance was found
//
// Related Type:
// <LwM2M_ObjectDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectDB_getObjectInstance(in LwM2M_ObjectDB p_db,
in integer p_objId, in integer p_objInstId, inout LwM2M_ObjectInstance p_objInst)
return boolean
{
var integer vl_objIdx := f_LwM2M_ObjectDB_getObjectIdx(p_db, p_objId);
if (vl_objIdx >= 0) {
if (sizeof(p_db.objs[vl_objIdx].instances) > p_objInstId and p_objInstId >= 0) {
p_objInst := p_db.objs[vl_objIdx].instances[p_objInstId];
return true;
}
}
return false;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectDB_getResource
//
// Purpose:
// Retrieves an <LwM2M_Resource> from a <LwM2M_ObjectDB> database
//
// Parameters:
// p_db - *in* <LwM2M_ObjectDB> - DB instance
// p_objId - *in integer* - object id
// p_objInstId - *in integer* - object instance id
// p_resourceId - *in integer* - resource id
//
// Returns:
// p_resource - *inout* <LwM2M_Resource> - object instance
// boolean - if the instance was found
//
// Related Type:
// <LwM2M_ObjectDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectDB_getResource(in LwM2M_ObjectDB p_db,
in integer p_objId, in integer p_objInstId, in integer p_resourceId, inout LwM2M_Resource p_resource)
return boolean
{
var integer vl_resIdx;
if (f_EPTF_str2int_HashMap_Find(p_db.resHashRef, f_LwM2M_resourceHash_forIds(p_objId, p_objInstId, p_resourceId), vl_resIdx))
{
p_resource := p_db.resources[vl_resIdx];
return true;
}
return false;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectDB_setResource
//
// Purpose:
// Updates the contents of an already linked in <LwM2M_Resource> in a <LwM2M_ObjectDB> database
//
// Parameters:
// p_db - *in* <LwM2M_ObjectDB> - DB instance
// p_objId - *in integer* - object id
// p_objInstId - *in integer* - object instance id
// p_resourceId - *in integer* - resource id
// p_resource - *in* <LwM2M_Resource> - resource instance
//
// Returns:
// boolean - if the instance was found
//
// Related Type:
// <LwM2M_ObjectDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectDB_setResource(inout LwM2M_ObjectDB p_db,
in integer p_objId, in integer p_objInstId, in integer p_resourceId, in LwM2M_Resource p_resource)
return boolean
{
var integer vl_resIdx;
if (f_EPTF_str2int_HashMap_Find(p_db.resHashRef, f_LwM2M_resourceHash_forIds(p_objId, p_objInstId, p_resourceId), vl_resIdx))
{
p_db.resources[vl_resIdx] := p_resource;
return true;
}
return false;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectDB_getResourceValue
//
// Purpose:
// Retrieves the <LwM2M_ResourceValue> of a <LwM2M_Resource> in a <LwM2M_ObjectDB> database
//
// Parameters:
// p_db - *in* <LwM2M_ObjectDB> - DB instance
// p_objId - *in integer* - object id
// p_objInstId - *in integer* - object instance id
// p_resourceId - *in integer* - resource id
//
// Returns:
// p_value - *inout* <LwM2M_ResourceValue> - resource value
// boolean - if the instance was found
//
// Related Type:
// <LwM2M_ObjectDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectDB_getResourceValue(in LwM2M_ObjectDB p_db,
in integer p_objId, in integer p_objInstId, in integer p_resourceId, inout LwM2M_ResourceValue p_value)
return boolean
{
var integer vl_resIdx;
if (f_EPTF_str2int_HashMap_Find(p_db.resHashRef, f_LwM2M_resourceHash_forIds(p_objId, p_objInstId, p_resourceId), vl_resIdx))
{
p_value := p_db.resources[vl_resIdx].val;
return true;
}
return false;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectDB_setResourceValue
//
// Purpose:
// Sets the <LwM2M_ResourceValue> of an already linked in <LwM2M_Resource> in a <LwM2M_ObjectDB> database
//
// Parameters:
// p_db - *in* <LwM2M_ObjectDB> - DB instance
// p_objId - *in integer* - object id
// p_objInstId - *in integer* - object instance id
// p_resourceId - *in integer* - resource id
// p_value - *in* <LwM2M_ResourceValue> - resource instance
//
// Returns:
// boolean - if the instance was found
//
// Related Type:
// <LwM2M_ObjectDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectDB_setResourceValue(inout LwM2M_ObjectDB p_db,
in integer p_objId, in integer p_objInstId, in integer p_resourceId, in LwM2M_ResourceValue p_value)
return boolean
{
var integer vl_resIdx;
if (f_EPTF_str2int_HashMap_Find(p_db.resHashRef, f_LwM2M_resourceHash_forIds(p_objId, p_objInstId, p_resourceId), vl_resIdx))
{
p_db.resources[vl_resIdx].val := p_value;
return true;
}
return false;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectDB_setResourceObserved
//
// Purpose:
// Sets the observation flag of an already linked in <LwM2M_Resource> in a <LwM2M_ObjectDB> database
//
// Parameters:
// p_db - *in* <LwM2M_ObjectDB> - DB instance
// p_objId - *in integer* - object id
// p_objInstId - *in integer* - object instance id
// p_resourceId - *in integer* - resource id
// p_observed - *in boolean* - observation flag
// p_contentFormat - *in integer optional* - preferred content format
//
// Returns:
// boolean - if the instance was found
//
// Related Type:
// <LwM2M_ObjectDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectDB_setResourceObserved(inout LwM2M_ObjectDB p_db,
in integer p_objId, in integer p_objInstId, in integer p_resourceId, in boolean p_observed, in template integer p_contentFormat := omit)
return boolean
{
var integer vl_resIdx;
if (f_EPTF_str2int_HashMap_Find(p_db.resHashRef, f_LwM2M_resourceHash_forIds(p_objId, p_objInstId, p_resourceId), vl_resIdx))
{
p_db.resources[vl_resIdx].observed := p_observed;
if (ispresent(p_contentFormat))
{
p_db.resources[vl_resIdx].contentFormat := valueof(p_contentFormat);
}
else
{
p_db.resources[vl_resIdx].contentFormat := omit;
}
return true;
}
return false;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_ObjectDB_getObjectPaths
//
// Purpose:
// Retrieves all the object paths <ObjectPath_List> that are stored in the <LwM2M_ObjectDB>
//
// Parameters:
// p_db - *in* <LwM2M_ObjectDB> - DB instance
//
// Returns:
// p_paths - *inout* <ObjectPath_List> - the pathes of the objects stored in the DB
//
// Related Type:
// <LwM2M_ObjectDB>
///////////////////////////////////////////////////////////
function f_LwM2M_ObjectDB_getObjectPaths(in LwM2M_ObjectDB p_db, inout ObjectPath_List p_paths)
{
if (p_db.id != -1) {
for (var integer i:=0; i<sizeof(p_db.objs); i:=i+1) {
// No instances for object
if (sizeof(p_db.objs[i].instances)==0) {
p_paths[sizeof(p_paths)] := {
objectId := p_db.objs[i].id,
objectInstanceId := omit,
resourceId := omit
}
}
// There are object instances
else {
for (var integer j:=0; j<sizeof(p_db.objs[i].instances); j:=j+1) {
p_paths[sizeof(p_paths)] := {
objectId := p_db.objs[i].id,
objectInstanceId := p_db.objs[i].instances[j].id,
resourceId := omit
}
}
}
}
}
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_resourceHash_forResource
//
// Purpose:
// Function to generate a unique key for the <LwM2M_Resource> instance
//
// Parameters:
// p_res - *in* <LwM2M_Resource> - resource instance
//
// Returns:
// charstring - unique hash for the <LwM2M_Resource>
//
// Related Type:
// <LwM2M_Resource>
///////////////////////////////////////////////////////////
function f_LwM2M_resourceHash_forResource(in LwM2M_Resource p_res)
return charstring
{
return int2str(p_res.objId) & "/" & int2str(p_res.objInstId) & "/" & int2str(p_res.id);
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_resourceHash_forIds
//
// Purpose:
// Function to generate a unique key for <LwM2M_Resource> IDs
//
// Parameters:
// p_objId - *in integer* - object id
// p_objInstId - *in integer* - object instance id
// p_resId - *in integer* - resource id
//
// Returns:
// charstring - unique hash for the reource IDs
//
// Related Type:
// <LwM2M_Resource>
///////////////////////////////////////////////////////////
function f_LwM2M_resourceHash_forIds(in integer p_objId, in integer p_objInstId, in integer p_resId)
return charstring
{
return int2str(p_objId) & "/" & int2str(p_objInstId) & "/" & int2str(p_resId);
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_createResource
//
// Purpose:
// Function to create an <LwM2M_Resource> instance based on a <LwM2M_ResourceSpecification> and link it into an <LwM2M_ObjectInstance>
//
// Parameters:
// p_oi - *inout* <LwM2M_ObjectInstance> - object instance, where the rousrce will be added
// p_spec - *in* <LwM2M_ResourceSpecification> - resource specification for the instantiation
//
// Returns:
// <LwM2M_Resource> - the create resource instance
//
// Related Type:
// <LwM2M_Resource>
///////////////////////////////////////////////////////////
function f_LwM2M_createResource(inout LwM2M_ObjectInstance p_oi, in LwM2M_ResourceSpecification p_spec)
return LwM2M_Resource
{
var LwM2M_Resource v_ret := c_LwM2M_Resource_init;
v_ret.id := p_spec.id;
v_ret.objId := p_oi.objId;
v_ret.objInstId := p_oi.id;
if (p_spec.type_ == FLOAT or p_spec.type_ == TIME) {
v_ret.val.floatValue := 0.0;
}
else if (p_spec.type_ == INTEGER) {
v_ret.val.intValue := 0;
}
else if (p_spec.type_ == STRING) {
v_ret.val.strValue := "";
}
else if (p_spec.type_ == OPAQUE) {
v_ret.val.opaqueValue := ''O;
}
else if (p_spec.type_ == BOOLEAN) {
v_ret.val.boolValue := false;
}
return v_ret;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_Resource_getSpecification
//
// Purpose:
// Function to look up the specification of a <LwM2M_Resource> instance
//
// Parameters:
// p_res - *in* <LwM2M_Resource> - the resource
// p_spec_db - *in* <LwM2M_ObjectSpecificationDB> - object specification database
// p_spec - *inout* <LwM2M_ResourceSpecification> - resource specification for the instantiation
//
// Returns:
// *boolean* - true if the specification was found
//
// Related Type:
// <LwM2M_Resource>
///////////////////////////////////////////////////////////
function f_LwM2M_Resource_getSpecification(in LwM2M_Resource p_res, in LwM2M_ObjectSpecificationDB p_spec_db, inout LwM2M_ResourceSpecification p_spec)
return boolean
{
if (p_res.spec.objSpecIdx >=0 and sizeof(p_spec_db.specs) > p_res.spec.objSpecIdx)
{
if (p_res.spec.resSpecIdx >= 0 and sizeof(p_spec_db.specs[p_res.spec.objSpecIdx].resourcedefs) > p_res.spec.resSpecIdx)
{
p_spec := p_spec_db.specs[p_res.spec.objSpecIdx].resourcedefs[p_res.spec.resSpecIdx]
return true;
}
}
return false;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_Resource_checkSpecification
//
// Purpose:
// Function to check the specification of a <LwM2M_Resource> instance against a template
//
// Parameters:
// p_res - *in* <LwM2M_Resource> - the resource
// p_spec_db - *in* <LwM2M_ObjectSpecificationDB> - object specification database
// p_spec - *in* <LwM2M_ResourceSpecification> - resource specification for the instantiation
//
// Returns:
// *boolean* - true if the specifications were matching
//
// Related Type:
// <LwM2M_Resource>
///////////////////////////////////////////////////////////
function f_LwM2M_Resource_checkSpecification(in LwM2M_Resource p_res, in LwM2M_ObjectSpecificationDB p_spec_db, template LwM2M_ResourceSpecification p_spec)
return boolean
{
if (p_res.spec.objSpecIdx >=0 and sizeof(p_spec_db.specs) > p_res.spec.objSpecIdx)
{
if (p_res.spec.resSpecIdx >= 0 and sizeof(p_spec_db.specs[p_res.spec.objSpecIdx].resourcedefs) > p_res.spec.resSpecIdx)
{
if (match(p_spec_db.specs[p_res.spec.objSpecIdx].resourcedefs[p_res.spec.resSpecIdx], p_spec))
{
return true;
}
}
}
return false;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_Resource_setNextDataSample
//
// Purpose:
// In case the <LwM2M_Resource> instance is associated with a <LwM2M_DataSamples> it will set its value to the next from the samples
//
// Parameters:
// p_res - *inout* <LwM2M_Resource> - resource instance, where the value will be updated
// p_db - *in out* <LwM2M_DataSamples_DB> - DB where the samples are stored
//
// Returns:
// <LwM2M_Resource> - with the updated value
//
// Related Type:
// <LwM2M_Resource>
///////////////////////////////////////////////////////////
function f_LwM2M_Resource_setNextDataSample(inout LwM2M_Resource p_res, inout LwM2M_DataSamples_DB p_db)
{
if (ispresent(p_res.dataSample)) {
// Init samplesPointer
if (p_res.dataSample.samplesPointer == -1) {
p_res.dataSample.samplesPointer := f_LwM2M_DataSamples_DB_lookUp(p_db, p_res.dataSample.samplesName);
}
// We found the dataSamples
if (p_res.dataSample.samplesPointer >=0 and p_res.dataSample.samplesPointer < sizeof(p_db.data)) {
// We have values
if (sizeof(p_db.data[p_res.dataSample.samplesPointer].values)>0) {
// Check value pointer boundaries
if (p_res.dataSample.valuePointer < 0 or
p_res.dataSample.valuePointer >= sizeof(p_db.data[p_res.dataSample.samplesPointer].values))
{
// Outside of boundaries, set it to zero
p_res.dataSample.valuePointer := 0;
}
// Set the value
p_res.val := p_db.data[p_res.dataSample.samplesPointer].values[p_res.dataSample.valuePointer];
// Step value pointer
p_res.dataSample.valuePointer := p_res.dataSample.valuePointer+1;
}
}
}
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_DataSamples_DB_init
//
// Purpose:
// Initializes a <LwM2M_DataSamples_DB> database
//
// Parameters:
// p_db - *inout* <LwM2M_DataSamples_DB> - DB instance
// p_name - *in charstring* - name for the DB instance
//
// Related Type:
// <LwM2M_DataSamples_DB>
///////////////////////////////////////////////////////////
function f_LwM2M_DataSamples_DB_init(inout LwM2M_DataSamples_DB p_db, in charstring p_name)
{
p_db.name := p_name;
p_db.data := {};
p_db.hashRef := f_EPTF_str2int_HashMap_New(p_name);
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_DataSamples_DB_add
//
// Purpose:
// Adds a new <LwM2M_DataSamples> element to a <LwM2M_DataSamples_DB> database
//
// Parameters:
// p_db - *inout* <LwM2M_DataSamples_DB> - DB instance
// p_samples - *in* <LwM2M_DataSamples> - element to be added
//
// Related Type:
// <LwM2M_DataSamples_DB>
///////////////////////////////////////////////////////////
function f_LwM2M_DataSamples_DB_add(inout LwM2M_DataSamples_DB p_db, in LwM2M_DataSamples p_samples)
return integer
{
var integer p_idx := f_LwM2M_DataSamples_DB_lookUp(p_db, p_samples.name);
if (p_idx == -1)
{
p_idx := sizeof(p_db.data);
f_EPTF_str2int_HashMap_Insert(p_db.hashRef, p_samples.name, p_idx);
p_db.data[p_idx] := p_samples;
}
return p_idx;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_DataSamples_DB_lookUp
//
// Purpose:
// Looks up a <LwM2M_DataSamples> element from a <LwM2M_DataSamples_DB> database based on the samples' name
//
// Parameters:
// p_db - *inout* <LwM2M_DataSamples_DB> - DB instance
// p_sampleName - *in charstring* - name of the sample to look up
//
// Related Type:
// <LwM2M_DataSamples_DB>
///////////////////////////////////////////////////////////
function f_LwM2M_DataSamples_DB_lookUp(inout LwM2M_DataSamples_DB p_db, in charstring p_sampleName)
return integer
{
var integer vl_idx := -1;
f_EPTF_str2int_HashMap_Find(p_db.hashRef, p_sampleName, vl_idx);
return vl_idx;
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_DataSamples_DB_get
//
// Purpose:
// Retrieves a <LwM2M_DataSamples> element from a <LwM2M_DataSamples_DB> database based on its internal index
//
// Parameters:
// p_db - *inout* <LwM2M_DataSamples_DB> - DB instance
// p_idx - *in integer* - index of the sample to be fetched
//
// Returns:
// p_samples - *inout* <LwM2M_DataSamples> - retrieved element
//
// Related Type:
// <LwM2M_DataSamples_DB>
///////////////////////////////////////////////////////////
function f_LwM2M_DataSamples_DB_get(inout LwM2M_DataSamples_DB p_db, in integer p_idx, inout LwM2M_DataSamples p_samples)
{
if (p_idx < sizeof(p_db.data))
{
p_samples := p_db.data[p_idx];
}
}
///////////////////////////////////////////////////////////
// Function: f_LwM2M_DataSamples_DB_cleanUp
//
// Purpose:
// Cleans up the reserved resources of a <LwM2M_DataSamples_DB> database
//
// Parameters:
// p_db - *inout* <LwM2M_DataSamples_DB> - DB instance
//
// Related Type:
// <LwM2M_DataSamples_DB>
///////////////////////////////////////////////////////////
function f_LwM2M_DataSamples_DB_cleanUp(inout LwM2M_DataSamples_DB p_db)
{
p_db.data := {};
f_EPTF_str2int_HashMap_Delete(p_db.name);
}
}