-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeensyOTA1.ttl
192 lines (163 loc) · 6.32 KB
/
TeensyOTA1.ttl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
16 October 2021 G. Frank Paynter
Tera Term macro to connect to Teensy and send latest .HEX file
Tera Term is called via a post-build command in VS2019/VMicro
like <path_to_ttpmacro.exe> /v <path_to_TeensyOTA1.ttl> <build_path>\<project_name>.hex> <COM port>
The actual post-build command is contained in the 'board.txt' file as follows:
recipe.hooks.postbuild.1.pattern=cmd.exe /c "c:\Program Files (x86)\teraterm\ttpmacro.exe" /v "c:\users\Frank\Documents\Arduino\Teensy Projects\TeensyOTADemo\Test2.ttl" "{vm.runtime.build.final_output_path}" {serial.port} {build.project_name}
When this is passed to tera term the arguments appear as follows:
param1 = macro filename (TeensyOTA1.TTL)
param2 = BuildPath ; used to find the .HEX file to transfer, like "C:\Ussers\Frank\Arduino\Teensy Projects\TeensyOTADemo\Release\"
param3 = COMportstr ;"COMx" where 'x' is the actual number assigned
param4 = INOfilename ;project file name like "TeensyOTADemo.ino"
Notes:
10/16/21: for verbose output, set VERBOSE = 1 (default is 0)
10/30/21: modified to remove hard-coded paths & filenames
01/02/22: revised to support multiple connection tries
*/
/*-----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------*/
VERBOSE = 0; set this to 1 for verbose progress indications
BuildPath = param2
strlen BuildPath
if result > 0 then
pathlen = result
strremove BuildPath pathlen 1;remove trailing '\'
;messagebox BuildPath 'file'
else
messagebox 'BuildPath has zero length - aborting' "Error"
goto ERROR ;error exit - closes COM connection and TT
endif
COMportstr = param3
strtrim COMportstr ' ' /*remove any leading/trailing spaces*/
ComPortNumStr = COMportstr
;messagebox ComPortNumStr 'info'
strremove ComPortNumStr 1 3 /*isolate the com port number*/
/*generate hex filename*/
INOfilename = param4
strlen INOfilename
if result > 0 then
INOfilenameLen = result
strcopy INOfilename 0 INOfilenameLen-3 HEXfilename/* hex filename minus extension*/
strconcat HEXfilename 'HEX'
else
messagebox 'INOfilename has zero length - aborting' "Error"
goto ERROR /*error exit - closes COM connection and TT*/
endif
if VERBOSE then
sprintf2 msgstr2 "path to HEX file: %s\n" BuildPath
sprintf2 msgstr3 "COM port number: %s\n" ComPortNumStr
sprintf2 msgstr4 "INO filename: %s\n" INOfilename
sprintf2 msgstr "%s%s%s" msgstr2 msgstr3 msgstr4
strspecial msgstr/*converts '\n's into real crlf actions*/
messagebox msgstr 'Calling Arguments'
endif
:COMCONNECT
/*connect to Teensy via COM <param2>*/
sprintf2 cnct_str "/C=%s" ComPortNumStr /* actual string used by TT*/
if VERBOSE then
sprintf2 msgstr "attempting to connnect to Teensy on COM%s using %s" ComPortNumStr cnct_str
messagebox msgstr 'info'
messagebox result 'result before testlink'
endif
testlink /* TT could already be connected*/
if VERBOSE then
messagebox result 'result after testlink'
endif
/*if result = 0 then*/
if result <> 2 then
connect cnct_str/* actually launch TT and make the connection. <result> = 2 for success*/
endif
if VERBOSE then
messagebox result 'result after connect try'
endif
/*01/02/22 now supports multiple connection tries (maybe you forgot to power up the other end?)*/
if result <> 2 then
sprintf2 errstr "unable to connect to Teensy on %s - Try Again?" COMportstr
yesnobox errstr "Error"
if result <> 1 then
goto ERROR /*error exit - closes COM connection and TT*/
else
result = 0
goto COMCONNECT
endif
else
/*if we get to here, we have a valid COM port connection*/
if VERBOSE then
sprintf2 msgstr "sending trigger command (%s) and waiting for %s" "U" "waiting"
messagebox msgstr "info"
endif
send 'U' /*actually send the trigger character*/
timeout = 5 /* seconds*/
wait 'waiting' /*on success, result = 1*/
if result <> 1 then
sprintf2 errstr "Oops - timed out waiting for 'waiting' from Teensy - Try Again?"
yesnobox errstr "Error"
if result <> 1 then
goto ERROR /*error exit - closes COM connection and TT*/
else
result = 0
goto COMCONNECT
endif
else /* OK, got 'waiting'...*/
if VERBOSE then
msgstr = "got 'waiting' string - sending file"
messagebox msgstr 'info'
endif
/*10/30/21 chg to use constructed filename vs hard-coded*/
sprintf2 hexfilestr '%s\%s' BuildPath HEXfilename/* 01/02/2022 add trailing '\' back to BuildPath*/
if VERBOSE then
messagebox hexfilestr 'sendfile'
endif
sendfile hexfilestr 0 /*actually send the file. Note the 0 is required to make it work*/
/*now we have to extract the number of lines from the 'enter xxxx to flash...' string*/
wait 'enter' /*get the next line from Teensy*/
if result = 0 then
messagebox "Oops - timed out waiting for 'enter' from Teensy" "Error"
goto ERROR /*error exit - closes COM connection and TT*/
else /* OK, got 'enter'...*/
if VERBOSE then
msgstr = "got string containing 'enter'"
messagebox msgstr 'info'
endif
recvln/* this puts received line into 'inputstr'*/
if result = 1 then
/* ; if VERBOSE then
; messagebox inputstr 'From Teensy'
; endif
*/
/*now extract number of lines from inputstr*/
strsplit inputstr ' ' /*puts numlines string into <groupmatchstr2>*/
strtrim groupmatchstr2 ' '/*trim any leading/trailing spaces*/
if result <> 0 then
if VERBOSE then
sprintf2 msgstr '%s lines received' groupmatchstr2
messagebox msgstr 'From Teensy'
endif
/*now send <groupmatchstr2> to Teensy to confirm update*/
if VERBOSE then
sprintf2 msgstr "sending '%s' to Teensy" groupmatchstr2
messagebox msgstr 'To Teensy'
endif
sendln groupmatchstr2/* actually sends the <numlines> value*/
else
messagebox 'groupmatchstr2 send failed' 'error'
goto ERROR /*error exit - closes COM connection and TT*/
endif
else
messagebox "nothing received from Teensy" info
goto ERROR /*error exit - closes COM connection and TT*/
endif
endif
endif
endif
:ERROR
if VERBOSE then
messagebox "closing COM port and Tera Term" "info"
endif
testlink /*TT may or may not be connnected*/
if result <> 0 then
disconnect 1 /*closes the COM port connection*/
closett /* closes teraterm*/
endif
end