annotate loadtools/labaud.c @ 52:b015036286f3

fc-loadtool: fast-baud communication with loadagent implemented, works!
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 23 Jun 2013 04:34:22 +0000
parents
children 604648026e9c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module handles the switching of serial baud rates
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * in coordination with loadagent.
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdlib.h>
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <termios.h>
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <unistd.h>
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "baudrate.h"
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 extern int target_fd;
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 extern struct baudrate *current_baud_rate;
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 extern struct baudrate *find_baudrate_by_name();
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 loadagent_switch_baud(newbr)
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 struct baudrate *newbr;
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 {
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 char *argv[3];
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 static char U = 'U';
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 argv[0] = "baud";
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 argv[1] = newbr->name;
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 argv[2] = 0;
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 tpinterf_make_cmd(argv);
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 if (tpinterf_send_cmd() < 0)
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 return(-1);
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 switch_baud_rate(newbr);
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 usleep(150000);
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 write(target_fd, &U, 1);
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 return tpinterf_pass_output(1);
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 }
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 cmd_baud(argc, argv)
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 char **argv;
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 {
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 struct baudrate *br;
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 if (argc < 2) {
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 printf("Current baud rate is %s\n", current_baud_rate->name);
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 return(0);
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 }
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 br = find_baudrate_by_name(argv[1]);
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 if (!br)
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 return(-1); /* error msg already printed */
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 return loadagent_switch_baud(br);
b015036286f3 fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 }