2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 * Stores a sequence of fixed-size (32 byte) chunks
23 * without splitting memory up into separate flights
27 #include "ao_product.h"
29 static struct ao_task ao_log_single_task;
31 uint8_t ao_log_running;
33 uint32_t ao_log_start_pos;
34 uint32_t ao_log_end_pos;
35 uint32_t ao_log_current_pos;
37 union ao_log_single ao_log_single_write_data;
38 union ao_log_single ao_log_single_read_data;
41 ao_log_single_write(void)
45 ao_mutex_get(&ao_log_mutex); {
46 if (ao_log_current_pos >= ao_log_end_pos && ao_log_running)
50 ao_storage_write(ao_log_current_pos,
51 &ao_log_single_write_data,
53 ao_log_current_pos += AO_LOG_SINGLE_SIZE;
55 } ao_mutex_put(&ao_log_mutex);
60 ao_log_single_valid(void)
62 uint8_t *d = ao_log_single_read_data.bytes;
64 for (i = 0; i < AO_LOG_SINGLE_SIZE; i++)
71 ao_log_single_read(uint32_t pos)
73 if (!ao_storage_read(pos, &ao_log_single_read_data, AO_LOG_SINGLE_SIZE))
75 return ao_log_single_valid();
79 ao_log_single_start(void)
81 if (!ao_log_running) {
83 ao_wakeup(&ao_log_running);
88 ao_log_single_stop(void)
96 ao_log_single_restart(void)
98 /* Find end of data */
99 ao_log_end_pos = ao_storage_config;
100 for (ao_log_current_pos = 0;
101 ao_log_current_pos < ao_storage_config;
102 ao_log_current_pos += ao_storage_block)
104 if (!ao_log_single_read(ao_log_current_pos))
107 if (ao_log_current_pos > 0) {
108 ao_log_current_pos -= ao_storage_block;
109 for (; ao_log_current_pos < ao_storage_config;
110 ao_log_current_pos += sizeof (struct ao_log_telescience))
112 if (!ao_log_single_read(ao_log_current_pos))
119 ao_log_single_set(void)
122 printf("Logging currently %s\n", ao_log_running ? "on" : "off");
124 if (ao_cmd_status == ao_cmd_success) {
126 printf("Logging from %ld to %ld\n", ao_log_current_pos, ao_log_end_pos);
127 ao_log_single_start();
129 printf ("Log stopped at %ld\n", ao_log_current_pos);
130 ao_log_single_stop();
133 ao_cmd_status = ao_cmd_success;
137 ao_log_single_delete(void)
140 uint16_t r = ao_cmd_hex();
141 if (ao_cmd_status != ao_cmd_success)
144 ao_cmd_status = ao_cmd_syntax_error;
145 printf("No such flight: %d\n", r);
148 ao_log_single_stop();
149 for (pos = 0; pos < ao_storage_config; pos += ao_storage_block) {
150 if (!ao_log_single_read(pos))
152 ao_storage_erase(pos);
154 ao_log_current_pos = ao_log_start_pos = 0;
156 printf("No such flight: %d\n", r);
164 return ao_log_current_pos >= ao_log_end_pos;
170 return ao_log_single_read(0);
174 ao_log_single_query(void)
176 printf("Logging enabled: %d\n", ao_log_running);
177 printf("Log start: %ld\n", ao_log_start_pos);
178 printf("Log cur: %ld\n", ao_log_current_pos);
179 printf("Log end: %ld\n", ao_log_end_pos);
180 ao_log_single_extra_query();
183 const struct ao_cmds ao_log_single_cmds[] = {
184 { ao_log_single_set, "L <0 off, 1 on>\0Set logging" },
185 { ao_log_single_list, "l\0List stored logs" },
186 { ao_log_single_delete, "d 1\0Delete all stored logs" },
187 { ao_log_single_query, "q\0Query log status" },
192 ao_log_single_init(void)
196 ao_cmd_register(&ao_log_single_cmds[0]);
198 ao_add_task(&ao_log_single_task, ao_log_single, "log");