// HandleReadCommands triggers a protocol Read operation for the specified device.
HandleReadCommands triggers a protocol Read operation for the specified device.
// HandleReadCommands triggers a protocol Read operation for the specified device .
func (w *WebcamDriver) HandleReadCommands(deviceName string, protocols map[string]contract.ProtocolProperties, reqs []dsModels.CommandRequest) (res []*dsModels.CommandValue, err error) {
	w.lc.Debug("WebcamDriver.HandleReadCommand called")
	if len(reqs) != 1 && len(reqs) != 3 {
		err = fmt.Errorf("WebcamDriver.HandleReadCommands; either 1 or 3 command requests are supported")
		return
	}
	w.lc.Debug(fmt.Sprintf("WebcamDriver.HandleReadCommands: protocols: %v resource: %v attributes: %v", protocols, reqs[0].DeviceResourceName, reqs[0].Attributes))
	res = make([]*dsModels.CommandValue, len(reqs))
	if reqs[0].DeviceResourceName != "Frame" {
		err = fmt.Errorf("WebcamDriver.HandleReadCommands; Frame must be the first request")
		return
	}
	now := time.Now().UnixNano() / int64(time.Millisecond)
	buf := new(bytes.Buffer)
	err = getImageBytes("./res/sample_dog_416.jpg", buf)
	cvb, _ := dsModels.NewBinaryValue(reqs[0].DeviceResourceName, now, buf.Bytes())
	res[0] = cvb
	w.lc.Debug(fmt.Sprintf("WebcamDriver.HandleReadCommands: read frame %v", res[0]))
	if len(reqs) > 1 {
		hoomans, doggos, e := w.re.YOLODetect(buf.Bytes())
		if e != nil {
			err = e
			w.lc.Debug(fmt.Sprintf("WebcamDriver.HandleReadCommands: YOLODetect failed - %v", err))
			return 
		}
		cv, _ := dsModels.NewUint64Value(reqs[1].DeviceResourceName, now, hoomans)
		res[1] = cv
		cv, _ = dsModels.NewUint64Value(reqs[2].DeviceResourceName, now, doggos)
		res[2] = cv
	}
	w.lc.Debug("WebcamDriver.HandleReadCommand existed")
	return
}
func ( w * WebcamDriver ) HandleReadCommands ( deviceName string , protocols map [ string ] contract . ProtocolProperties , reqs [ ] dsModels . CommandRequest ) ( res [ ] * dsModels . CommandValue , err error ) { w . lc . Debug ( " " ) if len ( reqs ) != 1 && len ( reqs ) != 3 { err = fmt . Errorf ( " " ) return } w . lc . Debug ( fmt . Sprintf ( " " , protocols , reqs [ 0 ] . DeviceResourceName , reqs [ 0 ] . Attributes ) ) res = make ( [ ] * dsModels . CommandValue , len ( reqs ) ) if reqs [ 0 ] . DeviceResourceName != " " { err = fmt . Errorf ( " " ) return } now := time . Now ( ) . UnixNano ( ) / int64 ( time . Millisecond ) buf := new ( bytes . Buffer ) err = getImageBytes ( " " , buf ) cvb , _ := dsModels . NewBinaryValue ( reqs [ 0 ] . DeviceResourceName , now , buf . Bytes ( ) ) res [ 0 ] = cvb w . lc . Debug ( fmt . Sprintf ( " " , res [ 0 ] ) ) if len ( reqs ) > 1 { hoomans , doggos , e := w . re . YOLODetect ( buf . Bytes ( ) ) if e != nil { err = e w . lc . Debug ( fmt . Sprintf ( " " , err ) ) return } cv , _ := dsModels . NewUint64Value ( reqs [ 1 ] . DeviceResourceName , now , hoomans ) res [ 1 ] = cv cv , _ = dsModels . NewUint64Value ( reqs [ 2 ] . DeviceResourceName , now , doggos ) res [ 2 ] = cv } w . lc . Debug ( " " ) return }
HandleReadCommands triggers a protocol Read operation for the specified device.
HandleReadCommands triggers a protocol Read operation for the specified device .
// The first request should always be for a frame // TODO: get an actual video frame // Get detections