| | |
| | | } |
| | | |
| | | if len(camerasPerPage.Data) > 0 { |
| | | for i, v := range camerasPerPage.Data { |
| | | if v.ResType == 2 { |
| | | log.Println("v.restype == 2") |
| | | for i := 0; i < len(camerasPerPage.Data); i++ { |
| | | if camerasPerPage.Data[i].ResType == 2 { |
| | | camerasPerPage.Data = append(camerasPerPage.Data[:i], camerasPerPage.Data[i+1:]...) |
| | | i-- |
| | | } |
| | | } |
| | | } |
| | |
| | | return cameraSlice, true |
| | | } |
| | | |
| | | //getAllGroupBygroupIDAndpage get all group by groupID ang page 按页和组id获取下属分组 |
| | | func (api Gb28181Api) getAllGroupBygroupIDAndpage(groupID string, pageNo int) ([]DomainUnit, bool) { |
| | | url := BASIC_URL + DATA_URL_PREFIX + "/get_all_channel/" + groupID + "/node/" + strconv.Itoa(pageNo) |
| | | client := NewClient() |
| | | |
| | | var camerasPerPage CamerasInOnePage |
| | | body, err := client.DoGetRequest(url, nil, nil) |
| | | if err != nil { |
| | | log.Println("err:", err) |
| | | return nil, false |
| | | } |
| | | |
| | | if camerasPerPage.ErrCode != 0 { |
| | | log.Println("errcode: ", camerasPerPage.ErrCode, " errdesc: ", camerasPerPage.ErrDesc) |
| | | return nil, false |
| | | } |
| | | |
| | | //解析 cameras |
| | | //log.Println("body:", body) |
| | | if err = json.Unmarshal(body, &camerasPerPage); err != nil { |
| | | log.Println("jsonErr:", err) |
| | | return nil, false |
| | | } |
| | | |
| | | //cameraInfo 转 DomainUnit |
| | | var dmUnits []DomainUnit |
| | | var tmpUnit DomainUnit |
| | | for _, cam := range camerasPerPage.Data { |
| | | if cam.ResType == 2 { |
| | | tmpUnit.Name = cam.Name |
| | | tmpUnit.DevPubID = cam.DevPubID |
| | | tmpUnit.OnlineNum = 0 |
| | | tmpUnit.ParentID = cam.ParentID |
| | | tmpUnit.PublicID = cam.PublicID |
| | | tmpUnit.ResType = cam.ResType |
| | | tmpUnit.TotalNum = 0 |
| | | dmUnits = append(dmUnits, tmpUnit) |
| | | } |
| | | } |
| | | |
| | | return dmUnits, true |
| | | } |
| | | |
| | | //GetAllGroupByDevID 按组id获取下属分组 |
| | | func (api Gb28181Api) getAllGroupByGroupID(groupID string) []DomainUnit { |
| | | var dmUnitAll []DomainUnit |
| | | pageNo := 1 |
| | | for { |
| | | dmUnitsPerPage, flag := api.getAllGroupBygroupIDAndpage(groupID, pageNo) |
| | | if !flag || dmUnitsPerPage == nil { |
| | | break |
| | | } |
| | | dmUnitAll = append(dmUnitAll, dmUnitsPerPage...) |
| | | pageNo++ |
| | | } |
| | | |
| | | return dmUnitAll |
| | | } |
| | | |
| | | // |
| | | func (api Gb28181Api) getGroupsByGroupID(groupID string, groupsAll *[]DomainUnit) { |
| | | if groupID != "" { |
| | | groups := api.getAllGroupByGroupID(groupID) |
| | | if groups == nil { |
| | | return |
| | | } |
| | | if len(groups) > 0 { |
| | | *groupsAll = append(*groupsAll, groups...) |
| | | for _, groupid := range groups { |
| | | api.getGroupsByGroupID(groupid.PublicID, groupsAll) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //GetAllGroupByDevID get all group by devid 按设备id获取分组 |
| | | func (api Gb28181Api) GetAllGroupBydevID(devID string) []DomainUnit { |
| | | var dmUnitAll []DomainUnit |
| | | |
| | | api.getGroupsByGroupID(devID, &dmUnitAll) |
| | | |
| | | return dmUnitAll |
| | | } |
| | | |
| | | //getAllCamerasByGroupIDAndPage 按分组和页获取摄像机列表 |
| | | func (api Gb28181Api) getAllCamerasByGroupIDAndPage(groupID string, pageNo int) (CamerasInOnePage, bool) { |
| | | url := BASIC_URL + DATA_URL_PREFIX + "/get_all_channel/" + groupID + "/node/" + strconv.Itoa(pageNo) |
| | | client := NewClient() |
| | | |
| | | var camerasPerPage CamerasInOnePage |
| | | body, err := client.DoGetRequest(url, nil, nil) |
| | | if err != nil { |
| | | log.Println("err:", err) |
| | | return camerasPerPage, false |
| | | } |
| | | |
| | | //解析 cameras |
| | | if err = json.Unmarshal(body, &camerasPerPage); err != nil { |
| | | log.Println("jsonErr:", err) |
| | | return camerasPerPage, false |
| | | } |
| | | |
| | | if len(camerasPerPage.Data) > 0 { |
| | | for i := 0; i < len(camerasPerPage.Data); i++ { |
| | | if camerasPerPage.Data[i].ResType == 2 { |
| | | camerasPerPage.Data = append(camerasPerPage.Data[:i], camerasPerPage.Data[i+1:]...) |
| | | i-- |
| | | } |
| | | } |
| | | } |
| | | |
| | | return camerasPerPage, true |
| | | } |
| | | |
| | | //GetAllGroupByDevID get all group by devid 按设备id获取分组 |
| | | func (api Gb28181Api) GetAllCamerasByGroupID(groupID string) ([]CameraInfo, bool) { |
| | | |
| | | var cameraSlice []CameraInfo |
| | | camerasPerPage, flag := api.getAllCamerasByGroupIDAndPage(groupID, 1) |
| | | if !flag { |
| | | log.Println("GetCamsByDevAndPage Error, deviceSlice is nil") |
| | | return cameraSlice, false |
| | | } |
| | | cameraSlice = camerasPerPage.Data |
| | | |
| | | for i := 1; i < camerasPerPage.TotalPage; i++ { |
| | | camerasPerPage, flag := api.getAllCamerasByGroupIDAndPage(groupID, i+1) |
| | | if !flag { |
| | | log.Println("getAllCamerasByGroupIDAndPage Error! devID:" + groupID + ",type:all,pageno:" + strconv.Itoa(i+1) + " ,cameraSlice is not completed") |
| | | return cameraSlice, false |
| | | } |
| | | cameraSlice = append(cameraSlice, camerasPerPage.Data...) |
| | | } |
| | | |
| | | return cameraSlice, true |
| | | } |
| | | |
| | | //SetCameraPtz 2.3 PTZ云台控制 |
| | | //"channelid": (字符串) 通道20位编号 |
| | | //"ptztype": (字符串) 控制类型:上"up",下"down",左"left",右"right",左上"leftup",左下"leftdown",右上"rightup",右下"rightdown",镜头近"zoomin",镜头远"zoomout", |