easycwmp解读(1.3.1)-添加自定的数据模型

TR069协议中规定,自定义的节点都是以"X"开头的,本文我们以添加"X_ATM_Server"节点为例。

节点设计

节点 名称 类型
节点名 InternetGatewayDevice.X_ATM_Server. obj
子节点 InternetGatewayDevice.X_ATM_Server.Enable xsd:boolean
子节点 InternetGatewayDevice.X_ATM_Server.Status xsd:String
子节点 InternetGatewayDevice.X_ATM_Server.RunTime xsd:dateTime
子节点 InternetGatewayDevice.X_ATM_Server.Interval xsd:unsignedInt
子节点 InternetGatewayDevice.X_ATM_Server.KeyWord xsd:String
子节点 InternetGatewayDevice.X_ATM_Server.Version xsd:String

节点定义实现

entry_execute_method_root_X_ATM_Server() {
        case "$1" in ""|"$DMROOT."|"$DMROOT.X_ATM_Server."*)
                common_execute_method_obj "$DMROOT.X_ATM_Server." "0"
                common_execute_method_param "$DMROOT.X_ATM_Server.Enable" "1" "$UCI_GET easycwmp.@atm[0].enable" "x_atm_server_set easycwmp.@atm[0].enable" "xsd:boolean"
                common_execute_method_param "$DMROOT.X_ATM_Server.Status" "0" "Running" "" "" ""
                common_execute_method_param "$DMROOT.X_ATM_Server.RunTime" "0" "$UCI_GET easycwmp.@atm[0].runtime" "" "xsd:dateTime"
                common_execute_method_param "$DMROOT.X_ATM_Server.Interval" "1" "$UCI_GET easycwmp.@atm[0].interval" "x_atm_server_set easycwmp.@atm[0].interval" "xsd:unsignedInt"
                common_execute_method_param "$DMROOT.X_ATM_Server.KeyWord" "0" "$UCI_GET easycwmp.@atm[0].keyword" "" "" "1"
                common_execute_method_param "$DMROOT.X_ATM_Server.Version" "0" "$UCI_GET easycwmp.@atm[0].version" "" "" "0"
        return 0;
        ;;
        esac
        return $E_INVALID_PARAMETER_NAME;
}

子节点的定义,实现就是调动common_execute_method_param 函数设置不同的参数,改函数的入参说明如下:

入参 说明 样例 类型
$1 节点名称 InternetGatewayDevice.X_ATM_Server.Status 字符串
$2 权限permission 0 0:只读R 1: 读写RW
$3 GET方法 $UCI_GET easycwmp.@atm[0].runtime 函数
$4 SET方法 x_atm_server_set easycwmp.@atm[0].interval 函数
$5 数据类型 xsd:unsignedInt 数据类型表
$6 inform上报 0 0:不上报 1:上报

加入到表中

#节点加到根节点
prefix_list="$prefix_list $DMROOT.X_ATM_Server."
#节点加到 entry_execute_method_list 支持GET SET操作
entry_execute_method_list="$entry_execute_method_list entry_execute_method_root_X_ATM_Server"
# 如果有需要Inoform的节点则加入到 entry_execute_method_list_forcedinform
entry_execute_method_list_forcedinform="$entry_execute_method_list_forcedinform entry_execute_method_root_X_ATM_Server"

其他函数

x_atm_server_set() {
        local cfg=$1
        local val=$2
        echo "cfg:$cfg val:$val"
        $UCI_SET $cfg="$val"
        return 0
}

加入到软件包或者设备中

源码路径:ext/openwrt/scripts/functions/common/common
设备路径: /usr/share/easycwmp/functions/tr098/

测试

查看所有节点

# easycwmp get value InternetGatewayDevice.X_ATM_Server.
{ "parameter": "InternetGatewayDevice.X_ATM_Server.Enable", "value": "", "type": "xsd:boolean" }
{ "parameter": "InternetGatewayDevice.X_ATM_Server.Status", "value": "" }
{ "parameter": "InternetGatewayDevice.X_ATM_Server.RunTime", "value": "", "type": "xsd:dateTime" }
{ "parameter": "InternetGatewayDevice.X_ATM_Server.Interval", "value": "102", "type": "xsd:unsignedInt" }
{ "parameter": "InternetGatewayDevice.X_ATM_Server.KeyWord", "value": "" }
{ "parameter": "InternetGatewayDevice.X_ATM_Server.Version", "value": "" }

SET操作

# easycwmp set value InternetGatewayDevice.X_ATM_Server.Interval 1002
# easycwmp get value InternetGatewayDevice.X_ATM_Server.Interval
{ "parameter": "InternetGatewayDevice.X_ATM_Server.Interval", "value": "1002", "type": "xsd:unsignedInt" }

全部源码

#!/bin/sh
#       DIY
#       Author: Guiyuan Duan <[email protected]>

#############################
#   My Define param         #
#############################

# 节点加到根节点
prefix_list="$prefix_list $DMROOT.X_ATM_Server."
# 节点加到 entry_execute_method_list 支持GET SET操作
entry_execute_method_list="$entry_execute_method_list entry_execute_method_root_X_ATM_Server"
# 如果有需要Inoform的节点则加入到 entry_execute_method_list_forcedinform
entry_execute_method_list_forcedinform="$entry_execute_method_list_forcedinform entry_execute_method_root_X_ATM_Server"

entry_execute_method_root_X_ATM_Server() {
        case "$1" in ""|"$DMROOT."|"$DMROOT.X_ATM_Server."*)
                common_execute_method_obj "$DMROOT.X_ATM_Server." "0"
                common_execute_method_param "$DMROOT.X_ATM_Server.Enable" "1" "$UCI_GET easycwmp.@atm[0].enable" "x_atm_server_set easycwmp.@atm[0].enable" "xsd:boolean"
                common_execute_method_param "$DMROOT.X_ATM_Server.Status" "0" "Running" "" "" ""
                common_execute_method_param "$DMROOT.X_ATM_Server.RunTime" "0" "$UCI_GET easycwmp.@atm[0].runtime" "" "xsd:dateTime"
                common_execute_method_param "$DMROOT.X_ATM_Server.Interval" "1" "$UCI_GET easycwmp.@atm[0].interval" "x_atm_server_set easycwmp.@atm[0].interval" "xsd:unsignedInt"
                common_execute_method_param "$DMROOT.X_ATM_Server.KeyWord" "0" "$UCI_GET easycwmp.@atm[0].keyword" "" "" "1"
                common_execute_method_param "$DMROOT.X_ATM_Server.Version" "0" "$UCI_GET easycwmp.@atm[0].version" "" "" "0"
        return 0;
        ;;
        esac
        return $E_INVALID_PARAMETER_NAME;
}

x_atm_server_set() {
        local cfg=$1
        local val=$2
        echo "cfg:$cfg val:$val"
        $UCI_SET $cfg="$val"
        return 0
}

你可能感兴趣的:(easycwmpd-解读)