feat(api): cwmp SetParameterValues message
This commit is contained in:
parent
bb7b1a4f50
commit
42b657f4b9
|
|
@ -59,6 +59,7 @@ func (a *Api) StartApi() {
|
|||
iot.HandleFunc("/auth", a.deviceAuth).Methods("GET", "POST", "DELETE")
|
||||
iot.HandleFunc("/cwmp/{sn}/getParameterNames", a.cwmpGetParameterNamesMsg).Methods("PUT")
|
||||
iot.HandleFunc("/cwmp/{sn}/getParameterValues", a.cwmpGetParameterValuesMsg).Methods("PUT")
|
||||
iot.HandleFunc("/cwmp/{sn}/setParameterValues", a.cwmpSetParameterValuesMsg).Methods("PUT")
|
||||
iot.HandleFunc("", a.retrieveDevices).Methods("GET")
|
||||
iot.HandleFunc("/{id}", a.retrieveDevices).Methods("GET")
|
||||
iot.HandleFunc("/{sn}/{mtp}/get", a.deviceGetMsg).Methods("PUT")
|
||||
|
|
|
|||
|
|
@ -81,3 +81,38 @@ func (a *Api) cwmpGetParameterValuesMsg(w http.ResponseWriter, r *http.Request)
|
|||
|
||||
w.Write(data)
|
||||
}
|
||||
|
||||
func (a *Api) cwmpSetParameterValuesMsg(w http.ResponseWriter, r *http.Request) {
|
||||
sn := getSerialNumberFromRequest(r)
|
||||
|
||||
payload, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write(utils.Marshall(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
data, err := bridge.NatsCwmpInteraction(
|
||||
nats.NATS_CWMP_ADAPTER_SUBJECT_PREFIX+sn+".api",
|
||||
payload,
|
||||
w,
|
||||
a.nc,
|
||||
)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var response cwmp.SetParameterValuesResponse
|
||||
err = xml.Unmarshal(data, &response)
|
||||
if err != nil {
|
||||
err = json.Unmarshal(data, &response)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write(utils.Marshall(err))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(data)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,6 +180,10 @@ func GetParameterMultiValues(leaves []string) string {
|
|||
return msg
|
||||
}
|
||||
|
||||
type SetParameterValuesResponse struct {
|
||||
Status int `xml:"Body>SetParameterValuesResponse>Status"`
|
||||
}
|
||||
|
||||
func SetParameterValues(leaf string, value string) string {
|
||||
return `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<soap:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:schemaLocation="urn:dslforum-org:cwmp-1-0 ..\schemas\wt121.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user