|
@@ -4,6 +4,7 @@ import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"errors"
|
|
"errors"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
|
|
+ "log"
|
|
"net/http"
|
|
"net/http"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
@@ -58,6 +59,7 @@ func (h *Handler) Scan() ([]*iot.Device, error) {
|
|
status, err := getStatusForDevice(&thisDevice)
|
|
status, err := getStatusForDevice(&thisDevice)
|
|
if err != nil {
|
|
if err != nil {
|
|
//This might be not a valid HDSv2 device. Skip this
|
|
//This might be not a valid HDSv2 device. Skip this
|
|
|
|
+ log.Println("*HDSv2* Get status failed for device: ", host.HostName, err.Error())
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
thisDevice.Status = status
|
|
thisDevice.Status = status
|
|
@@ -66,6 +68,7 @@ func (h *Handler) Scan() ([]*iot.Device, error) {
|
|
eps, err := getEndpoints(&thisDevice)
|
|
eps, err := getEndpoints(&thisDevice)
|
|
if err != nil {
|
|
if err != nil {
|
|
//This might be not a valid HDSv2 device. Skip this
|
|
//This might be not a valid HDSv2 device. Skip this
|
|
|
|
+ log.Println("*HDSv2* Get endpoints failed for device: ", host.HostName, err.Error())
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
thisDevice.ControlEndpoints = eps
|
|
thisDevice.ControlEndpoints = eps
|
|
@@ -90,7 +93,7 @@ func (h *Handler) Connect(device *iot.Device) error {
|
|
}
|
|
}
|
|
|
|
|
|
//Same rules also apply to disconnect
|
|
//Same rules also apply to disconnect
|
|
-func Disconnect(device *iot.Device) error {
|
|
|
|
|
|
+func (h *Handler) Disconnect(device *iot.Device) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
@@ -120,19 +123,21 @@ func getEndpoints(device *iot.Device) ([]*iot.Endpoint, error) {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
- //Check if the resp is json
|
|
|
|
- if !isJSON(strings.TrimSpace(string(content))) {
|
|
|
|
- return nil, errors.New("Invalid HDSv2 protocol")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//Convert the results to Endpoints
|
|
//Convert the results to Endpoints
|
|
- endpoints := []*iot.Endpoint{}
|
|
|
|
|
|
+ endpoints := []iot.Endpoint{}
|
|
err = json.Unmarshal(content, &endpoints)
|
|
err = json.Unmarshal(content, &endpoints)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
- return endpoints, nil
|
|
|
|
|
|
+ //Convert the structure to array pointers
|
|
|
|
+ results := []*iot.Endpoint{}
|
|
|
|
+ for _, ep := range endpoints {
|
|
|
|
+ thisEp := ep
|
|
|
|
+ results = append(results, &thisEp)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return results, nil
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|