| 35 | |
| 36 | |
| 37 | class SyncLogger: |
| 38 | DISCONNECT_EVENT = 'DISCONNECT_EVENT' |
| 39 | |
| 40 | def __init__(self, crazyflie, log_config): |
| 41 | """ |
| 42 | Construct an instance of a SyncLogger |
| 43 | |
| 44 | Takes an Crazyflie or SyncCrazyflie instance and one log configuration |
| 45 | or an array of log configurations |
| 46 | """ |
| 47 | if isinstance(crazyflie, SyncCrazyflie): |
| 48 | self._cf = crazyflie.cf |
| 49 | else: |
| 50 | self._cf = crazyflie |
| 51 | |
| 52 | if isinstance(log_config, list): |
| 53 | self._log_config = log_config |
| 54 | else: |
| 55 | self._log_config = [log_config] |
| 56 | |
| 57 | self._queue = Queue() |
| 58 | |
| 59 | self._is_connected = False |
| 60 | |
| 61 | def connect(self): |
| 62 | if self._is_connected: |
| 63 | raise Exception('Already connected') |
| 64 | |
| 65 | self._cf.disconnected.add_callback(self._disconnected) |
| 66 | for config in self._log_config: |
| 67 | self._cf.log.add_config(config) |
| 68 | config.data_received_cb.add_callback(self._log_callback) |
| 69 | config.start() |
| 70 | |
| 71 | self._is_connected = True |
| 72 | |
| 73 | def disconnect(self): |
| 74 | if self._is_connected: |
| 75 | for config in self._log_config: |
| 76 | config.stop() |
| 77 | config.delete() |
| 78 | |
| 79 | config.data_received_cb.remove_callback( |
| 80 | self._log_callback) |
| 81 | |
| 82 | self._cf.disconnected.remove_callback(self._disconnected) |
| 83 | |
| 84 | self._is_connected = False |
| 85 | |
| 86 | def is_connected(self): |
| 87 | return self._is_connected |
| 88 | |
| 89 | def __iter__(self): |
| 90 | return self |
| 91 | |
| 92 | def next(self): |
| 93 | return self.__next__() |
| 94 |
no outgoing calls