2 * Copyright © 2012 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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 #include "sky_flash.h"
27 static const struct option options[] = {
28 { .name = "tty", .has_arg = 1, .val = 'T' },
29 { .name = "device", .has_arg = 1, .val = 'D' },
30 { .name = "loader", .has_arg = 1, .val = 'l' },
31 { .name = "firmware", .has_arg = 1, .val = 'f' },
32 { .name = "query", .has_arg = 0, .val = 'q' },
33 { .name = "raw", .has_arg = 0, .val = 'r' },
34 { .name = "quiet", .has_arg = 0, .val = 'Q' },
38 static uint8_t query_version[] = {
39 0xa0, 0xa1, 0x00, 0x02, 0x02, 0x01, 0x03, 0x0d, 0x0a
46 "usage: %s [--tty <tty-name>]\n"
47 " [--device <device-name>]\n"
48 " [--loader <srec bootloader file>]\n"
49 " [--firmware <binary firmware file>]\n"
52 " [--raw]\n", program);
57 skytraq_expect(int fd, uint8_t want, int timeout) {
60 c = skytraq_waitchar(fd, timeout);
69 skytraq_wait_reply(int fd, uint8_t reply, uint8_t *buf, uint8_t reply_len) {
73 uint8_t cksum_computed, cksum_read;
75 switch (skytraq_expect(fd, 0xa0, 10000)) {
83 switch (skytraq_expect(fd, 0xa1, 1000)) {
89 a = skytraq_waitchar(fd, 1000);
90 b = skytraq_waitchar(fd, 1000);
91 switch (skytraq_expect(fd, reply, 1000)) {
102 cksum_computed = reply;
104 a = skytraq_waitchar(fd, 1000);
110 switch (skytraq_expect(fd, cksum_computed, 1000)) {
116 switch (skytraq_expect(fd, 0x0d, 1000)) {
122 switch (skytraq_expect(fd, 0x0a, 1000)) {
134 main(int argc, char **argv)
146 char *loader = "srec_115200.bin";
151 while ((c = getopt_long(argc, argv, "T:D:l:f:qQr", options, NULL)) != -1) {
181 tty = cc_usbdevs_find_by_arg(device, "TeleMetrum");
183 tty = getenv("ALTOS_TTY");
186 fd = skytraq_open(tty);
191 /* Set the baud rate to 115200 */
192 skytraq_setcomm(fd, 115200);
194 skytraq_setspeed(fd, 115200);
196 /* Connect TM to the device */
197 skytraq_write(fd, "U\n", 2);
200 /* Wait for the device to stabilize after baud rate changes */
201 for (c = 0; c < 6; c++) {
207 uint8_t query_reply[14];
209 uint8_t software_type;
210 uint32_t kernel_version;
211 uint32_t odm_version;
214 skytraq_write(fd, query_version, 9);
215 if (skytraq_wait_reply(fd, 0x80, query_reply, sizeof (query_reply)) != 0) {
216 fprintf(stderr, "query reply failed\n");
220 #define i8(o) query_reply[(o)-1]
221 #define i32(o) ((i8(o) << 24) | (i8(o+1) << 16) | (i8(o+2) << 8) | (i8(o+3)))
222 software_type = i8(2);
223 kernel_version = i32(3);
224 odm_version = i32(7);
226 skytraq_dbg_printf(0, "\n");
227 printf ("Software Type %d. Kernel Version %d.%d.%d. ODM Version %d.%d.%d. Revision %d.%d.%d.\n",
229 kernel_version >> 16 & 0xff,
230 kernel_version >> 8 & 0xff,
231 kernel_version >> 0 & 0xff,
232 odm_version >> 16 & 0xff,
233 odm_version >> 8 & 0xff,
234 odm_version >> 0 & 0xff,
235 revision >> 16 & 0xff,
236 revision >> 8 & 0xff,
237 revision >> 0 & 0xff);
244 ret = skytraq_send_srec(fd, "srec_115200.bin");
245 skytraq_dbg_printf (0, "srec ret %d\n", ret);
251 // ret = skytraq_send_bin(fd, "STI_01.04.42-01.10.23_4x_9600_Bin_20100901.bin");
252 ret = skytraq_send_bin(fd, "STI_01.06.10-01.07.23_balloon_CRC_7082_9600_20120913.bin");
254 printf ("bin ret %d\n", ret);