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
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章