github.com/boki/go-xmp@v1.0.1/models/dji/dji.go (about)

     1  // Copyright (c) 2017-2018 Alexander Eichhorn
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"): you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    11  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    12  // License for the specific language governing permissions and limitations
    13  // under the License.
    14  
    15  // Package dji implements metadata models written by video cameras on DJI drones.
    16  package dji
    17  
    18  import (
    19  	"fmt"
    20  	"trimmer.io/go-xmp/xmp"
    21  )
    22  
    23  var (
    24  	NsDJI = xmp.NewNamespace("drone-dji", "http://www.dji.com/drone-dji/1.0/", NewModel)
    25  )
    26  
    27  func init() {
    28  	xmp.Register(NsDJI, xmp.CameraMetadata)
    29  }
    30  
    31  func NewModel(name string) xmp.Model {
    32  	return &DJI{}
    33  }
    34  
    35  func MakeModel(d *xmp.Document) (*DJI, error) {
    36  	m, err := d.MakeModel(NsDJI)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	x, _ := m.(*DJI)
    41  	return x, nil
    42  }
    43  
    44  func FindModel(d *xmp.Document) *DJI {
    45  	if m := d.FindModel(NsDJI); m != nil {
    46  		return m.(*DJI)
    47  	}
    48  	return nil
    49  }
    50  
    51  func (m *DJI) Namespaces() xmp.NamespaceList {
    52  	return xmp.NamespaceList{NsDJI}
    53  }
    54  
    55  func (m *DJI) Can(nsName string) bool {
    56  	return nsName == NsDJI.GetName()
    57  }
    58  
    59  func (x *DJI) SyncModel(d *xmp.Document) error {
    60  	return nil
    61  }
    62  
    63  func (x *DJI) SyncFromXMP(d *xmp.Document) error {
    64  	return nil
    65  }
    66  
    67  func (x DJI) SyncToXMP(d *xmp.Document) error {
    68  	return nil
    69  }
    70  
    71  func (x *DJI) CanTag(tag string) bool {
    72  	_, err := xmp.GetNativeField(x, tag)
    73  	return err == nil
    74  }
    75  
    76  func (x *DJI) GetTag(tag string) (string, error) {
    77  	if v, err := xmp.GetNativeField(x, tag); err != nil {
    78  		return "", fmt.Errorf("%s: %v", NsDJI.GetName(), err)
    79  	} else {
    80  		return v, nil
    81  	}
    82  }
    83  
    84  func (x *DJI) SetTag(tag, value string) error {
    85  	if err := xmp.SetNativeField(x, tag, value); err != nil {
    86  		return fmt.Errorf("%s: %v", NsDJI.GetName(), err)
    87  	}
    88  	return nil
    89  }
    90  
    91  type DJI struct {
    92  	AbsoluteAltitude  float32 `drone-dji:"AbsoluteAltitude"  qt:"-"     xmp:"drone-dji:AbsoluteAltitude"`  //  "+543.44",
    93  	FlightPitchDegree float32 `drone-dji:"FlightPitchDegree" qt:"©fpt"  xmp:"drone-dji:FlightPitchDegree"` //  "+4.80",
    94  	FlightRollDegree  float32 `drone-dji:"FlightRollDegree"  qt:"©frl"  xmp:"drone-dji:FlightRollDegree"`  //  "+1.30",
    95  	FlightYawDegree   float32 `drone-dji:"FlightYawDegree"   qt:"©fyw"  xmp:"drone-dji:FlightYawDegree"`   //  "-1.90",
    96  	GimbalPitchDegree float32 `drone-dji:"GimbalPitchDegree" qt:"©gpt"  xmp:"drone-dji:GimbalPitchDegree"` //  "-90.00",
    97  	GimbalRollDegree  float32 `drone-dji:"GimbalRollDegree"  qt:"©grl"  xmp:"drone-dji:GimbalRollDegree"`  //  "+0.00",
    98  	GimbalYawDegree   float32 `drone-dji:"GimbalYawDegree"   qt:"©gyw"  xmp:"drone-dji:GimbalYawDegree"`   //  "-2.00",
    99  	RelativeAltitude  float32 `drone-dji:"RelativeAltitude"  qt:"-"     xmp:"drone-dji:RelativeAltitude"`  //  "+46.60"
   100  	SpeedX            float32 `drone-dji:"SpeedX"            qt:"©xsp"  xmp:"drone-dji:SpeedX"`
   101  	SpeedY            float32 `drone-dji:"SpeedY"            qt:"©ysp"  xmp:"drone-dji:SpeedY"` // - +0.00
   102  	SpeedZ            float32 `drone-dji:"SpeedZ"            qt:"©zsp"  xmp:"drone-dji:SpeedZ"` //  - +0.00,+0.40
   103  	Model             string  `drone-dji:"Model"             qt:"©mdl"  xmp:"tiff:Model"`
   104  }
   105  
   106  // unknown
   107  // "©dji"  UserData_dji
   108  // "©res"  UserData_res
   109  // "©uid"  UserData_uid