# Copyright (c) 2016-2017 Anki, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License in the file LICENSE.txt or at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Autogenerated python message buffer code.
Source: clad/types/proxMessages.clad
Full command line: ../tools/message-buffers/emitters/Python_emitter.py -C ../robot/clad/src/ -o ../generated/cladPython// clad/types/proxMessages.clad
"""

from __future__ import absolute_import
from __future__ import print_function

def _modify_path():
  import inspect, os, sys
  search_paths = [
    '../..',
    '../../../../tools/message-buffers/support/python',
  ]
  currentpath = os.path.abspath(os.path.dirname(inspect.getfile(inspect.currentframe())))
  for search_path in search_paths:
    search_path = os.path.normpath(os.path.abspath(os.path.realpath(os.path.join(currentpath, search_path))))
    if search_path not in sys.path:
      sys.path.insert(0, search_path)
_modify_path()

import msgbuffers

Anki = msgbuffers.Namespace()
Anki.Cozmo = msgbuffers.Namespace()

class CliffSensor(object):
  "Automatically-generated uint_8 enumeration."
  CLIFF_FL    = 0
  CLIFF_FR    = 1
  CLIFF_BL    = 2
  CLIFF_BR    = 3
  CLIFF_COUNT = 4

Anki.Cozmo.CliffSensor = CliffSensor
del CliffSensor


class CliffEvent(object):
  "Generated message-passing message."

  __slots__ = (
    '_timestamp',       # uint_32
    '_detectedFlags',   # uint_8
    '_didStopForCliff', # bool
  )

  @property
  def timestamp(self):
    "uint_32 timestamp struct property."
    return self._timestamp

  @timestamp.setter
  def timestamp(self, value):
    self._timestamp = msgbuffers.validate_integer(
      'CliffEvent.timestamp', value, 0, 4294967295)

  @property
  def detectedFlags(self):
    "uint_8 detectedFlags struct property."
    return self._detectedFlags

  @detectedFlags.setter
  def detectedFlags(self, value):
    self._detectedFlags = msgbuffers.validate_integer(
      'CliffEvent.detectedFlags', value, 0, 255)

  @property
  def didStopForCliff(self):
    "bool didStopForCliff struct property."
    return self._didStopForCliff

  @didStopForCliff.setter
  def didStopForCliff(self, value):
    self._didStopForCliff = msgbuffers.validate_bool(
      'CliffEvent.didStopForCliff', value)

  def __init__(self, timestamp=0, detectedFlags=0, didStopForCliff=False):
    self.timestamp = timestamp
    self.detectedFlags = detectedFlags
    self.didStopForCliff = didStopForCliff

  @classmethod
  def unpack(cls, buffer):
    "Reads a new CliffEvent from the given buffer."
    reader = msgbuffers.BinaryReader(buffer)
    value = cls.unpack_from(reader)
    if reader.tell() != len(reader):
      raise msgbuffers.ReadError(
        ('CliffEvent.unpack received a buffer of length {length}, ' +
        'but only {position} bytes were read.').format(
        length=len(reader), position=reader.tell()))
    return value

  @classmethod
  def unpack_from(cls, reader):
    "Reads a new CliffEvent from the given BinaryReader."
    _timestamp = reader.read('I')
    _detectedFlags = reader.read('B')
    _didStopForCliff = bool(reader.read('b'))
    return cls(_timestamp, _detectedFlags, _didStopForCliff)

  def pack(self):
    "Writes the current CliffEvent, returning bytes."
    writer = msgbuffers.BinaryWriter()
    self.pack_to(writer)
    return writer.dumps()

  def pack_to(self, writer):
    "Writes the current CliffEvent to the given BinaryWriter."
    writer.write(self._timestamp, 'I')
    writer.write(self._detectedFlags, 'B')
    writer.write(int(self._didStopForCliff), 'b')

  def __eq__(self, other):
    if type(self) is type(other):
      return (self._timestamp == other._timestamp and
        self._detectedFlags == other._detectedFlags and
        self._didStopForCliff == other._didStopForCliff)
    else:
      return NotImplemented

  def __ne__(self, other):
    if type(self) is type(other):
      return not self.__eq__(other)
    else:
      return NotImplemented

  def __len__(self):
    return (msgbuffers.size(self._timestamp, 'I') +
      msgbuffers.size(self._detectedFlags, 'B') +
      msgbuffers.size(self._didStopForCliff, 'b'))

  def __str__(self):
    return '{type}(timestamp={timestamp}, detectedFlags={detectedFlags}, didStopForCliff={didStopForCliff})'.format(
      type=type(self).__name__,
      timestamp=self._timestamp,
      detectedFlags=self._detectedFlags,
      didStopForCliff=self._didStopForCliff)

  def __repr__(self):
    return '{type}(timestamp={timestamp}, detectedFlags={detectedFlags}, didStopForCliff={didStopForCliff})'.format(
      type=type(self).__name__,
      timestamp=repr(self._timestamp),
      detectedFlags=repr(self._detectedFlags),
      didStopForCliff=repr(self._didStopForCliff))

Anki.Cozmo.CliffEvent = CliffEvent
del CliffEvent


class PotentialCliff(object):
  "Generated message-passing message."

  __slots__ = ()

  def __init__(self):
    pass

  @classmethod
  def unpack(cls, buffer):
    "Reads a new PotentialCliff from the given buffer."
    reader = msgbuffers.BinaryReader(buffer)
    value = cls.unpack_from(reader)
    if reader.tell() != len(reader):
      raise msgbuffers.ReadError(
        ('PotentialCliff.unpack received a buffer of length {length}, ' +
        'but only {position} bytes were read.').format(
        length=len(reader), position=reader.tell()))
    return value

  @classmethod
  def unpack_from(cls, reader):
    "Reads a new PotentialCliff from the given BinaryReader."
    return cls()

  def pack(self):
    "Writes the current PotentialCliff, returning bytes."
    writer = msgbuffers.BinaryWriter()
    self.pack_to(writer)
    return writer.dumps()

  def pack_to(self, writer):
    "Writes the current PotentialCliff to the given BinaryWriter."

  def __eq__(self, other):
    if type(self) is type(other):
      return True
    else:
      return NotImplemented

  def __ne__(self, other):
    if type(self) is type(other):
      return not self.__eq__(other)
    else:
      return NotImplemented

  def __len__(self):
    return 0

  def __str__(self):
    return '{type}()'.format(type=type(self).__name__)

  def __repr__(self):
    return '{type}()'.format(type=type(self).__name__)

Anki.Cozmo.PotentialCliff = PotentialCliff
del PotentialCliff


