diff --git a/mappers/gige/Dockerfile.arm64 b/mappers/gige/Dockerfile.arm64 index cc13e27e..006ca3e7 100644 --- a/mappers/gige/Dockerfile.arm64 +++ b/mappers/gige/Dockerfile.arm64 @@ -2,6 +2,7 @@ FROM ubuntu:16.04 WORKDIR /usr/local/bin COPY ./res /usr/local/res COPY ./bin /usr/local/bin +COPY ./bin/librcapi_aarch64.so /usr/local/bin/librcapi.so COPY ./baumer/Ubuntu-16.04/arm64 /usr/local/bin/cti ENV GENICAM_GENTL64_PATH /usr/local/bin/cti RUN apt update && apt install -y libpng16-dev libjpeg9-dev diff --git a/mappers/gige/Dockerfile.x64 b/mappers/gige/Dockerfile.x64 index 414c0215..d3f696c7 100644 --- a/mappers/gige/Dockerfile.x64 +++ b/mappers/gige/Dockerfile.x64 @@ -2,6 +2,7 @@ FROM ubuntu:16.04 WORKDIR /usr/local/bin COPY ./res /usr/local/res COPY ./bin /usr/local/bin +COPY ./bin/librcapi_linux_x64.so /usr/local/bin/librcapi.so COPY ./baumer/Ubuntu-16.04/x86_64 /usr/local/bin/cti ENV GENICAM_GENTL64_PATH /usr/local/bin/cti RUN apt update && apt install -y libpng16-dev libjpeg9-dev diff --git a/mappers/gige/crd_example/deviceinstance.yaml b/mappers/gige/crd_example/deviceinstance.yaml index f5d8d09a..e180efce 100644 --- a/mappers/gige/crd_example/deviceinstance.yaml +++ b/mappers/gige/crd_example/deviceinstance.yaml @@ -1,12 +1,12 @@ apiVersion: devices.kubeedge.io/v1alpha2 kind: Device metadata: - name: camera-instance + name: gige-camera-instance01 labels: model: camera-instance-model spec: deviceModelRef: - name: camera-instance-model + name: basler-ac5472 protocol: common: customizedValues: @@ -20,52 +20,52 @@ spec: operator: In values: - edge51 - propertyVisitors: - - propertyName: PixelFormat - collectCycle: 1000000000 - reportCycle: 1000000000 + propertyVisitors: + - propertyName: PixelFormat + collectCycle: 3000000000 + reportCycle: 3000000000 customizedProtocol: protocolName: GigEVision - configData: + configData: FeatureName: 'PixelFormat' - propertyName: ImageTrigger - collectCycle: -1 - reportCycle: -1 + collectCycle: 3000000000 + reportCycle: 3000000000 customizedProtocol: protocolName: GigEVision configData: FeatureName: 'ImageTrigger' - propertyName: ImageFormat - collectCycle: 1000000000 - reportCycle: 1000000000 + collectCycle: 3000000000 + reportCycle: 3000000000 customizedProtocol: protocolName: GigEVision configData: FeatureName: 'ImageFormat' - propertyName: ImageURL - collectCycle: 1000000000 - reportCycle: 1000000000 + collectCycle: 3000000000 + reportCycle: 3000000000 customizedProtocol: protocolName: GigEVision configData: FeatureName: 'ImageURL' - - propertyName: Width - collectCycle: 1000000000 - reportCycle: 1000000000 + - propertyName: Width + collectCycle: 3000000000 + reportCycle: 3000000000 customizedProtocol: protocolName: GigEVision configData: FeatureName: 'Width' - propertyName: Height - collectCycle: 1000000000 - reportCycle: 1000000000 + collectCycle: 3000000000 + reportCycle: 3000000000 customizedProtocol: protocolName: GigEVision configData: FeatureName: 'Height' - propertyName: OffsetX - collectCycle: 1000000000 - reportCycle: 1000000000 + collectCycle: 3000000000 + reportCycle: 3000000000 customizedProtocol: protocolName: GigEVision configData: @@ -78,29 +78,29 @@ spec: configData: FeatureName: 'OffsetY' - propertyName: AcquisitionFrameRateAbs - collectCycle: 1000000000 - reportCycle: 1000000000 + collectCycle: 3000000000 + reportCycle: 3000000000 customizedProtocol: protocolName: GigEVision configData: FeatureName: 'AcquisitionFrameRateAbs' - propertyName: AcquisitionFrameRateEnable - collectCycle: 1000000000 - reportCycle: 1000000000 + collectCycle: 3000000000 + reportCycle: 3000000000 customizedProtocol: protocolName: GigEVision configData: FeatureName: 'AcquisitionFrameRateEnable' - propertyName: ExposureTimeAbs - collectCycle: 1000000000 - reportCycle: 1000000000 + collectCycle: 3000000000 + reportCycle: 3000000000 customizedProtocol: protocolName: GigEVision configData: FeatureName: 'ExposureTimeAbs' - propertyName: AutoFunctionAOIUsageWhiteBalance - collectCycle: 1000000000 - reportCycle: 1000000000 + collectCycle: 3000000000 + reportCycle: 3000000000 customizedProtocol: protocolName: GigEVision configData: @@ -138,11 +138,11 @@ status: desired: metadata: type: string - value: '' + value: 'http://127.0.0.1:5000/v2/push/picture' reported: metadata: type: string - value: '192.168.137.61' + value: 'http://127.0.0.1:5000/v2/push/picture' - propertyName: Width desired: metadata: @@ -151,16 +151,16 @@ status: reported: metadata: type: integer - value: '659' + value: '600' - propertyName: Height desired: metadata: type: integer - value: '494' + value: '400' reported: metadata: type: integer - value: '494' + value: '400' - propertyName: OffsetX desired: metadata: diff --git a/mappers/gige/crd_example/devicemodel.yaml b/mappers/gige/crd_example/devicemodel.yaml index a57ce709..91a3ebe8 100644 --- a/mappers/gige/crd_example/devicemodel.yaml +++ b/mappers/gige/crd_example/devicemodel.yaml @@ -1,7 +1,7 @@ apiVersion: devices.kubeedge.io/v1alpha2 kind: DeviceModel metadata: - name: camera-instance-model + name: basler-ac5472 spec: properties: - name: PixelFormat @@ -10,29 +10,25 @@ spec: accessMode: ReadWrite defaultValue: 'Mono8' - name: ImageTrigger - type: - bytes: - accessMode: ReadOnly - - name: ImageFormat - type: - boolean: - accessMode: ReadWrite - defaultValue: "jpeg" - - name: ImageURL + description: imageproc type: string: accessMode: ReadWrite + defaultValue: 'stop' - name: AutoFunctionAOIUsageWhiteBalance + description: White Balance type: boolean: accessMode: ReadWrite defaultValue: false - - name: AcquisitionFrameRateEnable + - name: AcquisitionFrameRateEnable + description: Acquisition FrameRate type: boolean: accessMode: ReadWrite defaultValue: false - name: ExposureTimeAbs + description: Exposure Time type: float: accessMode: ReadWrite @@ -41,12 +37,14 @@ spec: maximum: 100000 unit: 'us' - name: AcquisitionFrameRateAbs + description: Acquisition Frame Rate type: float: accessMode: ReadWrite defaultValue: 10.0 unit: 'Hz' - name: Width + description: picture width type: int: accessMode: ReadWrite @@ -54,6 +52,7 @@ spec: minimum: 0 maximum: 659 - name: Height + description: picture height type: int: accessMode: ReadWrite @@ -61,12 +60,26 @@ spec: minimum: 0 maximum: 494 - name: OffsetX + description: offset of x type: int: accessMode: ReadWrite defaultValue: 0 - name: OffsetY + description: offset of Y type: int: accessMode: ReadWrite defaultValue: 0 + - name: ImageFormat + description: mage format, jpeg,png,pnm + type: + string: + accessMode: ReadWrite + defaultValue: "jpeg" + - name: ImageURL + description: url for post picture + type: + string: + accessMode: ReadWrite + defaultValue: "https://127.0.0.1/push/picture" diff --git a/mappers/gige/driver/gigeclient.go b/mappers/gige/driver/gigeclient.go index 61615811..bf2097e2 100644 --- a/mappers/gige/driver/gigeclient.go +++ b/mappers/gige/driver/gigeclient.go @@ -142,6 +142,30 @@ func (gigEClient *GigEVisionDevice) Set(DeviceSN string, value interface{}) (err return err } switch gigEClient.deviceMeta[DeviceSN].FeatureName { + case "ImageTrigger": + switch convertValue { + case "single": + //gigEClient.deviceMeta[DeviceSN].ImageTrigger = "single" // move to the funcion postImage + case "continuous": + //gigEClient.deviceMeta[DeviceSN].ImageTrigger = "continuous" // move to the funcion postImage + case "stop": + gigEClient.deviceMeta[DeviceSN].ImageTrigger = "stop" + default: + err = fmt.Errorf("set %s's ImageTrigger to %s failed, it only support single, continuous, stop", + DeviceSN, convertValue) + return err + } + + if convertValue != "stop" { + if gigEClient.deviceMeta[DeviceSN].imageURL != "" { + gigEClient.PostImage(DeviceSN, convertValue) + + } else { + klog.V(4).Infof("Device %v's imageURL is null, so do not post the image", DeviceSN) + } + } + return nil + case "ImageFormat": switch convertValue { case "png": @@ -151,7 +175,8 @@ func (gigEClient *GigEVisionDevice) Set(DeviceSN string, value interface{}) (err case "jpeg": gigEClient.deviceMeta[DeviceSN].imageFormat = "jpeg" default: - err = fmt.Errorf("set %s's image format failed, it only support format jpeg, png or pnm", DeviceSN) + err = fmt.Errorf("set %s's imageformat to %s failed, it only support format jpeg, png or pnm", + DeviceSN, convertValue) return err } case "ImageURL": @@ -162,7 +187,7 @@ func (gigEClient *GigEVisionDevice) Set(DeviceSN string, value interface{}) (err return err } gigEClient.deviceMeta[DeviceSN].imageURL = convertValue - gigEClient.PostImage(DeviceSN) + //gigEClient.PostImage(DeviceSN) default: var msg *C.char defer C.free(unsafe.Pointer(msg)) @@ -182,26 +207,13 @@ func (gigEClient *GigEVisionDevice) Set(DeviceSN string, value interface{}) (err func (gigEClient *GigEVisionDevice) Get(DeviceSN string) (results string, err error) { switch gigEClient.deviceMeta[DeviceSN].FeatureName { case "ImageTrigger": - var imageBuffer *byte - var size int - var msg *C.char - defer C.free(unsafe.Pointer(msg)) - signal := C.get_image(gigEClient.deviceMeta[DeviceSN].dev, C.CString(gigEClient.deviceMeta[DeviceSN].imageFormat), (**C.char)(unsafe.Pointer(&imageBuffer)), (*C.int)(unsafe.Pointer(&size)), &msg) - if signal != 0 { - err = fmt.Errorf("failed to get %s's images: %s", DeviceSN, (string)(C.GoString(msg))) - if signal >= 4 { - gigEClient.deviceMeta[DeviceSN].deviceStatus = false - go gigEClient.ReconnectDevice(DeviceSN) - } + if gigEClient.deviceMeta[DeviceSN].ImageTrigger != "" { + results = gigEClient.deviceMeta[DeviceSN].ImageTrigger + } else { + err = fmt.Errorf("maybe init %s's ImageTrigger failed, current value is null", DeviceSN) return "", err } - var buffer []byte - var bufferHdr = (*reflect.SliceHeader)(unsafe.Pointer(&buffer)) - bufferHdr.Data = uintptr(unsafe.Pointer(imageBuffer)) - bufferHdr.Len = size - bufferHdr.Cap = size - results = base64.StdEncoding.EncodeToString(buffer) - C.free_image((**C.char)(unsafe.Pointer(&imageBuffer))) + case "ImageFormat": if gigEClient.deviceMeta[DeviceSN].imageFormat != "" { results = gigEClient.deviceMeta[DeviceSN].imageFormat @@ -213,10 +225,9 @@ func (gigEClient *GigEVisionDevice) Get(DeviceSN string) (results string, err er if gigEClient.deviceMeta[DeviceSN].imageURL != "" { results = gigEClient.deviceMeta[DeviceSN].imageURL } else { - err = fmt.Errorf("maybe init %s's image format failed, it only support format png or pnm", DeviceSN) - return "", err + results = "" } - gigEClient.PostImage(DeviceSN) + return results, nil default: var msg *C.char @@ -275,7 +286,7 @@ func (gigEClient *GigEVisionDevice) NewClient(DeviceSN string) (err error) { return nil } -func (gigEClient *GigEVisionDevice) PostImage(DeviceSN string) { +func (gigEClient *GigEVisionDevice) PostImage(DeviceSN string, convertValue string) { var imageBuffer *byte var size int var p = &imageBuffer @@ -290,6 +301,7 @@ func (gigEClient *GigEVisionDevice) PostImage(DeviceSN string) { } return } + go func() { var buffer []byte var bufferHdr = (*reflect.SliceHeader)(unsafe.Pointer(&buffer)) @@ -297,10 +309,9 @@ func (gigEClient *GigEVisionDevice) PostImage(DeviceSN string) { bufferHdr.Data = uintptr(unsafe.Pointer(imageBuffer)) bufferHdr.Len = size bufferHdr.Cap = size - postStr := base64.URLEncoding.EncodeToString(buffer) - v := url.Values{} - v.Set("gigEImage", postStr) - body := ioutil.NopCloser(strings.NewReader(v.Encode())) + postStr := base64.StdEncoding.EncodeToString(buffer) + bufferSize := len(buffer) + body := strings.NewReader(`{"size":` + strconv.Itoa(bufferSize) + `,"value":"` + postStr + `"}`) req, _ := http.NewRequest(http.MethodPost, gigEClient.deviceMeta[DeviceSN].imageURL, body) if req == nil { klog.Errorf("Failed to post %s's images: URL can't POST.", DeviceSN) @@ -313,6 +324,8 @@ func (gigEClient *GigEVisionDevice) PostImage(DeviceSN string) { klog.Errorf("Failed to post %s's images: URL no reaction.", DeviceSN) return } + gigEClient.deviceMeta[DeviceSN].ImageTrigger = convertValue + defer func(Body io.ReadCloser) { err := Body.Close() if err != nil { @@ -364,4 +377,3 @@ func (gigEClient *GigEVisionDevice) convert(value interface{}) (convertValue str } return convertValue, nil } - diff --git a/mappers/gige/driver/gigedriver.go b/mappers/gige/driver/gigedriver.go index 85faa241..0b16cf24 100644 --- a/mappers/gige/driver/gigedriver.go +++ b/mappers/gige/driver/gigedriver.go @@ -44,12 +44,14 @@ type GigEVisionDevice struct { } type DeviceMeta struct { - dev *C.uint - FeatureName string - deviceStatus bool - imageFormat string - imageURL string - maxRetryTimes int + dev *C.uint + FeatureName string + deviceStatus bool + imageFormat string + imageURL string + ImageTrigger string + ImagePostingFlag bool + maxRetryTimes int } func (gigEClient *GigEVisionDevice) InitDevice(protocolCommon []byte) (err error) { @@ -165,4 +167,3 @@ func (gigEClient *GigEVisionDevice) ReconnectDevice(DeviceSN string) { } fmt.Printf("Device %s restart success!\n", DeviceSN) } - diff --git a/mappers/gige/res/config.yaml b/mappers/gige/res/config.yaml index 520e8c68..e2145a3f 100644 --- a/mappers/gige/res/config.yaml +++ b/mappers/gige/res/config.yaml @@ -1,5 +1,5 @@ mqtt: - server: mqtt://127.0.0.1:1883 + server: mqtt://127.0.0.1:1884 servername: 127.0.0.1 username: "" password: ""