- return -sum;
-}
-
-static uint8_t
-ao_log_telescience_write(void)
-{
- uint8_t wrote = 0;
-
- ao_log_store.csum = 0;
- ao_log_store.csum = ao_log_csum((__xdata uint8_t *) &ao_log_store);
- ao_mutex_get(&ao_log_mutex); {
- if (ao_log_current_pos >= ao_log_end_pos && ao_log_running)
- ao_log_stop();
- if (ao_log_running) {
- wrote = 1;
- ao_storage_write(ao_log_current_pos,
- (__xdata uint8_t *) &ao_log_store,
- sizeof (struct ao_log_telescience));
- ao_log_current_pos += sizeof (struct ao_log_telescience);
- }
- } ao_mutex_put(&ao_log_mutex);
- return wrote;
-}
-
-static uint8_t
-ao_log_valid(struct ao_log_telescience *log)
-{
- uint8_t *d;
- uint8_t i;
- d = (uint8_t *) log;
- for (i = 0; i < sizeof (struct ao_log_telescience); i++)
- if (d[i] != 0xff)
- return 1;
- return 0;
-}
-
-static uint8_t
-ao_log_telescience_read(uint32_t pos)
-{
- if (!ao_storage_read(pos, &ao_log_fetch, sizeof (struct ao_log_telescience)))
- return 0;
- return ao_log_valid(&ao_log_fetch);
-}
-
-void
-ao_log_start(void)
-{
- if (!ao_log_running) {
- ao_log_running = 1;
- ao_wakeup(&ao_log_running);
- }
-}
-
-void
-ao_log_stop(void)
-{
- if (ao_log_running) {
- ao_log_running = 0;
- }
-}
-
-void
-ao_log_restart(void)
-{
- /* Find end of data */
- ao_log_end_pos = ao_storage_config;
- for (ao_log_current_pos = 0;
- ao_log_current_pos < ao_storage_config;
- ao_log_current_pos += ao_storage_block)
- {
- if (!ao_log_telescience_read(ao_log_current_pos))
- break;
- }
- if (ao_log_current_pos > 0) {
- ao_log_current_pos -= ao_storage_block;
- for (; ao_log_current_pos < ao_storage_config;
- ao_log_current_pos += sizeof (struct ao_log_telescience))
- {
- if (!ao_log_telescience_read(ao_log_current_pos))
- break;
- }
- }