# Path: avatar2/targets/target.py
# class TargetStates(IntEnum):
#     """
#     A simple Enum for the different states a target can be in.
#     """
#     CREATED = 0x1
#     INITIALIZED = 0x2
#     STOPPED = 0x4
#     RUNNING = 0x8
#     SYNCING = 0x10
#     EXITED = 0x20
#     NOT_RUNNING = INITIALIZED | STOPPED
#     BREAKPOINT = SYNCING | STOPPED
# 
# Path: avatar2/message.py
# class AvatarMessage(object):
#     def __init__(self, origin):
#         self.origin = origin
# 
#     def __str__(self):
#         if self.origin:
#             return "%s from %s" % (self.__class__.__name__, self.origin.name)
#         else:
#             return "%s from unkown origin" % self.__class__.__name__
# 
# class UpdateStateMessage(AvatarMessage):
#     def __init__(self, origin, new_state):
#         super(UpdateStateMessage, self).__init__(origin)
#         self.state = new_state
# 
# class BreakpointHitMessage(UpdateStateMessage):
#     def __init__(self, origin, breakpoint_number, address):
#         super(BreakpointHitMessage, self).__init__(origin, TargetStates.BREAKPOINT)
#         self.breakpoint_number = breakpoint_number
#         self.address = address


import sys
import subprocess
import telnetlib
import logging
import distutils
import binascii
import re
    import Queue as queue
    import queue
from codecs import encode
from threading import Thread, Lock, Event
from struct import pack, unpack
from time import sleep
from os.path import abspath
from avatar2.targets import TargetStates
from avatar2.message import AvatarMessage, UpdateStateMessage, BreakpointHitMessage
            reset_type = mreset.group(1)
            self.log.debug("Got reset event type %s" % reset_type)
            if reset_type == "halt":
                avatar_msg = UpdateStateMessage(self._origin, TargetStates.STOPPED)
                self.avatar.fast_queue.put(avatar_msg)
        elif mtrace:
            # DOn't log anything here.  If we do, our IO will be exhausted by the sheer volume of trace packets.
            self.trace_queue.put(str)
        elif mstate:
            # Do a state update!
            state = mstate.group(1)
            if "halted" in state:
                self.log.debug("Target has halted")
                avatar_msg = UpdateStateMessage(self._origin, TargetStates.STOPPED)
                self.avatar.fast_queue.put(avatar_msg)
            elif "running" in state:
                self.log.debug("Target is now running")
                avatar_msg = UpdateStateMessage(self._origin, TargetStates.RUNNING)
                self.avatar.fast_queue.put(avatar_msg)
            else:
                self.log.warning("Weird target state %s" % state)
        elif mevent:
            #TODO handle these
            event = mevent.group(1)
            self.log.debug("Target event: %s " % event)
            # TODO handle these
            if event == 'halted':
                avatar_msg = UpdateStateMessage(self._origin, TargetStates.STOPPED)
                self.avatar.fast_queue.put(avatar_msg)
            elif event == 'resumed':

# Path: avatar2/targets/target.py
# class TargetStates(IntEnum):
#     """
#     A simple Enum for the different states a target can be in.
#     """
#     CREATED = 0x1
#     INITIALIZED = 0x2
#     STOPPED = 0x4
#     RUNNING = 0x8
#     SYNCING = 0x10
#     EXITED = 0x20
#     NOT_RUNNING = INITIALIZED | STOPPED
#     BREAKPOINT = SYNCING | STOPPED
# 
# Path: avatar2/message.py
# class AvatarMessage(object):
#     def __init__(self, origin):
#         self.origin = origin
# 
#     def __str__(self):
#         if self.origin:
#             return "%s from %s" % (self.__class__.__name__, self.origin.name)
#         else:
#             return "%s from unkown origin" % self.__class__.__name__
# 
# class UpdateStateMessage(AvatarMessage):
#     def __init__(self, origin, new_state):
#         super(UpdateStateMessage, self).__init__(origin)
#         self.state = new_state
# 
# class BreakpointHitMessage(UpdateStateMessage):
#     def __init__(self, origin, breakpoint_number, address):
#         super(BreakpointHitMessage, self).__init__(origin, TargetStates.BREAKPOINT)
#         self.breakpoint_number = breakpoint_number
#         self.address = address


# Path: avatar2/protocols/openocd.py
import sys
import subprocess
import telnetlib
import logging
import distutils
import binascii
import re
    import Queue as queue
    import queue
from codecs import encode
from threading import Thread, Lock, Event
from struct import pack, unpack
from time import sleep
from os.path import abspath
from avatar2.targets import TargetStates
from avatar2.message import AvatarMessage, UpdateStateMessage, BreakpointHitMessage

            reset_type = mreset.group(1)
            self.log.debug("Got reset event type %s" % reset_type)
            if reset_type == "halt":
                avatar_msg = UpdateStateMessage(self._origin, TargetStates.STOPPED)
                self.avatar.fast_queue.put(avatar_msg)
        elif mtrace:
            # DOn't log anything here.  If we do, our IO will be exhausted by the sheer volume of trace packets.
            self.trace_queue.put(str)
        elif mstate:
            # Do a state update!
            state = mstate.group(1)
            if "halted" in state:
                self.log.debug("Target has halted")
                avatar_msg = UpdateStateMessage(self._origin, TargetStates.STOPPED)
                self.avatar.fast_queue.put(avatar_msg)
            elif "running" in state:
                self.log.debug("Target is now running")
                avatar_msg = UpdateStateMessage(self._origin, TargetStates.RUNNING)
                self.avatar.fast_queue.put(avatar_msg)
            else:
                self.log.warning("Weird target state %s" % state)
        elif mevent:
            #TODO handle these
            event = mevent.group(1)
            self.log.debug("Target event: %s " % event)
            # TODO handle these
            if event == 'halted':
                avatar_msg = UpdateStateMessage(self._origin, TargetStates.STOPPED)
                self.avatar.fast_queue.put(avatar_msg)
            elif event == 'resumed':

                avatar_msg = UpdateStateMessage(self._origin, TargetStates.RUNNING)