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; 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.
19 #include "sky_flash.h"
28 static const struct option options[] = {
29 { .name = "tty", .has_arg = 1, .val = 'T' },
30 { .name = "device", .has_arg = 1, .val = 'D' },
31 { .name = "loader", .has_arg = 1, .val = 'l' },
32 { .name = "firmware", .has_arg = 1, .val = 'f' },
33 { .name = "query", .has_arg = 0, .val = 'q' },
34 { .name = "raw", .has_arg = 0, .val = 'r' },
35 { .name = "quiet", .has_arg = 0, .val = 'Q' },
39 static uint8_t query_version[] = {
40 0xa0, 0xa1, 0x00, 0x02, 0x02, 0x01, 0x03, 0x0d, 0x0a
47 "usage: %s [--tty <tty-name>]\n"
48 " [--device <device-name>]\n"
49 " [--loader <srec bootloader file>]\n"
50 " [--firmware <binary firmware file>]\n"
53 " [--raw]\n", program);
58 skytraq_expect(int fd, uint8_t want, int timeout) {
61 c = skytraq_waitchar(fd, timeout);
70 skytraq_wait_reply(int fd, uint8_t reply, uint8_t *buf, uint8_t reply_len) {
74 uint8_t cksum_computed, cksum_read;
76 switch (skytraq_expect(fd, 0xa0, 10000)) {
84 switch (skytraq_expect(fd, 0xa1, 1000)) {
90 a = skytraq_waitchar(fd, 1000);
91 b = skytraq_waitchar(fd, 1000);
92 switch (skytraq_expect(fd, reply, 1000)) {
103 cksum_computed = reply;
105 a = skytraq_waitchar(fd, 1000);
111 switch (skytraq_expect(fd, cksum_computed, 1000)) {
117 switch (skytraq_expect(fd, 0x0d, 1000)) {
123 switch (skytraq_expect(fd, 0x0a, 1000)) {
135 main(int argc, char **argv)
147 char *loader = "srec_115200.bin";
152 while ((c = getopt_long(argc, argv, "T:D:l:f:qQr", options, NULL)) != -1) {
182 tty = cc_usbdevs_find_by_arg(device, "TeleMetrum");
184 tty = getenv("ALTOS_TTY");
187 fd = skytraq_open(tty);
192 /* Set the baud rate to 115200 */
193 skytraq_setcomm(fd, 115200);
195 skytraq_setspeed(fd, 115200);
197 /* Connect TM to the device */
198 skytraq_write(fd, "U\n", 2);
201 /* Wait for the device to stabilize after baud rate changes */
202 for (c = 0; c < 6; c++) {
208 uint8_t query_reply[14];
210 uint8_t software_type;
211 uint32_t kernel_version;
212 uint32_t odm_version;
215 skytraq_write(fd, query_version, 9);
216 if (skytraq_wait_reply(fd, 0x80, query_reply, sizeof (query_reply)) != 0) {
217 fprintf(stderr, "query reply failed\n");
221 #define i8(o) query_reply[(o)-1]
222 #define i32(o) ((i8(o) << 24) | (i8(o+1) << 16) | (i8(o+2) << 8) | (i8(o+3)))
223 software_type = i8(2);
224 kernel_version = i32(3);
225 odm_version = i32(7);
227 skytraq_dbg_printf(0, "\n");
228 printf ("Software Type %d. Kernel Version %d.%d.%d. ODM Version %d.%d.%d. Revision %d.%d.%d.\n",
230 kernel_version >> 16 & 0xff,
231 kernel_version >> 8 & 0xff,
232 kernel_version >> 0 & 0xff,
233 odm_version >> 16 & 0xff,
234 odm_version >> 8 & 0xff,
235 odm_version >> 0 & 0xff,
236 revision >> 16 & 0xff,
237 revision >> 8 & 0xff,
238 revision >> 0 & 0xff);
245 ret = skytraq_send_srec(fd, "srec_115200.bin");
246 skytraq_dbg_printf (0, "srec ret %d\n", ret);
252 // ret = skytraq_send_bin(fd, "STI_01.04.42-01.10.23_4x_9600_Bin_20100901.bin");
253 ret = skytraq_send_bin(fd, "STI_01.06.10-01.07.23_balloon_CRC_7082_9600_20120913.bin");
255 printf ("bin ret %d\n", ret);