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"
29 static const struct option options[] = {
30 { .name = "tty", .has_arg = 1, .val = 'T' },
31 { .name = "device", .has_arg = 1, .val = 'D' },
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 " [--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;
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)
145 while ((c = getopt_long(argc, argv, "T:D:l:f:qQr", options, NULL)) != -1) {
172 tty = cc_usbdevs_find_by_arg(device, "TeleMetrum");
174 tty = getenv("ALTOS_TTY");
177 fd = skytraq_open(tty);
182 /* Set the baud rate to 115200 */
183 skytraq_setcomm(fd, 115200);
185 skytraq_setspeed(fd, 115200);
187 /* Connect TM to the device */
188 skytraq_write(fd, "U\n", 2);
191 /* Wait for the device to stabilize after baud rate changes */
192 for (c = 0; c < 6; c++) {
198 uint8_t query_reply[14];
200 uint8_t software_type;
201 uint32_t kernel_version;
202 uint32_t odm_version;
205 skytraq_write(fd, query_version, 9);
206 if (skytraq_wait_reply(fd, 0x80, query_reply, sizeof (query_reply)) != 0) {
207 fprintf(stderr, "query reply failed\n");
211 #define i8(o) query_reply[(o)-1]
212 #define i32(o) ((i8(o) << 24) | (i8(o+1) << 16) | (i8(o+2) << 8) | (i8(o+3)))
213 software_type = i8(2);
214 kernel_version = i32(3);
215 odm_version = i32(7);
217 skytraq_dbg_printf(0, "\n");
218 printf ("Software Type %d. Kernel Version %d.%d.%d. ODM Version %d.%d.%d. Revision %d.%d.%d.\n",
220 kernel_version >> 16 & 0xff,
221 kernel_version >> 8 & 0xff,
222 kernel_version >> 0 & 0xff,
223 odm_version >> 16 & 0xff,
224 odm_version >> 8 & 0xff,
225 odm_version >> 0 & 0xff,
226 revision >> 16 & 0xff,
227 revision >> 8 & 0xff,
228 revision >> 0 & 0xff);
235 ret = skytraq_send_srec(fd, "srec_115200.bin");
236 skytraq_dbg_printf (0, "srec ret %d\n", ret);
242 // ret = skytraq_send_bin(fd, "STI_01.04.42-01.10.23_4x_9600_Bin_20100901.bin");
243 ret = skytraq_send_bin(fd, "STI_01.06.10-01.07.23_balloon_CRC_7082_9600_20120913.bin");
245 printf ("bin ret %d\n", ret);