Representation of one log configuration that enables logging from the Crazyflie
| 140 | |
| 141 | |
| 142 | class LogConfig(object): |
| 143 | """Representation of one log configuration that enables logging |
| 144 | from the Crazyflie""" |
| 145 | |
| 146 | def __init__(self, name, period_in_ms): |
| 147 | """Initialize the entry""" |
| 148 | self.data_received_cb = Caller() |
| 149 | self.error_cb = Caller() |
| 150 | self.started_cb = Caller() |
| 151 | self.added_cb = Caller() |
| 152 | self.err_no = 0 |
| 153 | |
| 154 | # These 3 variables are set by the log subsystem when the bock is added |
| 155 | self.id = 0 |
| 156 | self.cf = None |
| 157 | self.useV2 = False |
| 158 | |
| 159 | self.period = int(period_in_ms / 10) |
| 160 | self.period_in_ms = period_in_ms |
| 161 | self._added = False |
| 162 | self._started = False |
| 163 | self.valid = False |
| 164 | self.variables = [] |
| 165 | self.default_fetch_as = [] |
| 166 | self.name = name |
| 167 | |
| 168 | def add_variable(self, name, fetch_as=None): |
| 169 | """Add a new variable to the configuration. |
| 170 | |
| 171 | name - Complete name of the variable in the form group.name |
| 172 | fetch_as - String representation of the type the variable should be |
| 173 | fetched as (i.e uint8_t, float, FP16, etc) |
| 174 | |
| 175 | If no fetch_as type is supplied, then the stored as type will be used |
| 176 | (i.e the type of the fetched variable is the same as it's stored in the |
| 177 | Crazyflie).""" |
| 178 | if fetch_as: |
| 179 | self.variables.append(LogVariable(name, fetch_as)) |
| 180 | else: |
| 181 | # We cannot determine the default type until we have connected. So |
| 182 | # save the name and we will add these once we are connected. |
| 183 | self.default_fetch_as.append(name) |
| 184 | |
| 185 | def add_memory(self, name, fetch_as, stored_as, address): |
| 186 | """Add a raw memory position to log. |
| 187 | |
| 188 | name - Arbitrary name of the variable |
| 189 | fetch_as - String representation of the type of the data the memory |
| 190 | should be fetch as (i.e uint8_t, float, FP16) |
| 191 | stored_as - String representation of the type the data is stored as |
| 192 | in the Crazyflie |
| 193 | address - The address of the data |
| 194 | """ |
| 195 | self.variables.append(LogVariable(name, fetch_as, LogVariable.MEM_TYPE, |
| 196 | stored_as, address)) |
| 197 | |
| 198 | def _set_added(self, added): |
| 199 | if added != self._added: |
no outgoing calls