|
@@ -16,6 +16,7 @@ import (
|
|
func SetOptions(options Options) {
|
|
func SetOptions(options Options) {
|
|
snapUrl = fmt.Sprintf("http://%s/api/v1/plc-current", options.GtServerIp)
|
|
snapUrl = fmt.Sprintf("http://%s/api/v1/plc-current", options.GtServerIp)
|
|
ctlUrl = fmt.Sprintf("http://%s/api/v1/plc/set-var-values", options.GtServerIp)
|
|
ctlUrl = fmt.Sprintf("http://%s/api/v1/plc/set-var-values", options.GtServerIp)
|
|
|
|
+ plcItemUrl = fmt.Sprintf("http://%s/api/v1/plc-list/", options.GtServerIp)
|
|
|
|
|
|
if options.Cache != nil {
|
|
if options.Cache != nil {
|
|
cache = options.Cache
|
|
cache = options.Cache
|
|
@@ -494,3 +495,35 @@ func getAdjustStringVal(projectId int64, item string) (string, error) {
|
|
}
|
|
}
|
|
return scmd.String(), nil
|
|
return scmd.String(), nil
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func (v *VirtualPlcItem) GetVirtualPlcItems() (*VirtualPlcItemResp, error) {
|
|
|
|
+
|
|
|
|
+ plcItemUrl = fmt.Sprintf("%s%d", plcItemUrl, v.ProjectId)
|
|
|
|
+
|
|
|
|
+ req := httplib.Get(plcItemUrl)
|
|
|
|
+ req.Param("project_id", fmt.Sprintf("%d", v.ProjectId))
|
|
|
|
+ req.Param("pageSize", fmt.Sprintf("%d", v.PageSize))
|
|
|
|
+ req.Param("is_virtual", fmt.Sprintf("%d", v.IsVirtual))
|
|
|
|
+
|
|
|
|
+ r, err := req.Response()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ defer r.Body.Close()
|
|
|
|
+
|
|
|
|
+ if r.StatusCode == 200 {
|
|
|
|
+ resp, err := req.Bytes()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ res := &VirtualPlcItemResp{}
|
|
|
|
+ err = json.Unmarshal(resp, res)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ return res, nil
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil, errors.New(fmt.Sprintf("request statusCode: %d", r.StatusCode))
|
|
|
|
+}
|