-
Notifications
You must be signed in to change notification settings - Fork 0
/
TXTest.spin
115 lines (89 loc) · 3.57 KB
/
TXTest.spin
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
{
--------------------------------------------
Filename: TXTest.spin
Author: Jesse Burt
Description: ZModem transmit from Propeller test
Send a file 'p1rom.bin' containing the
Propeller's ROM to the remote device
Copyright (c) 2022
Started Nov 28, 2021
Updated Nov 15, 2022
See end of file for terms of use.
--------------------------------------------
}
CON
_clkmode = xtal1+pll16x
_xinfreq = 5_000_000
OBJ
com : "com.serial.terminal" ' remote device
ser : "com.serial.terminal.ansi" ' debug/terminal output
time: "time"
pub main | ptr_data, st_pos, frm_end, xfer, pos
ser.startrxtx(31, 30, 0, 115_200)
com.startrxtx(23, 22, 0, 115_200)
time.msleep(30)
ser.clear
_subpsz := 1024
bytemove(@_f_name, string("p1rom.bin"), 9)
_f_sz := 32768
ptr_data := $8000 ' P1 ROM start
st_pos := 0
ser.printf1(string("Filename: %s\n\r"), @_f_name)
ser.printf1(string("Size : %u\n\r"), _f_sz)
zmtx_hex_header(ZRQINIT, 0)
repeat until (zget_hdr{} == ZRINIT)
ser.strln(string("got ZRINIT"))
_txflags[ZF0] := 0
_txflags[ZF1] := 0
_txflags[ZF2] := 0
_txflags[ZF3] := 0
zmtx_bin_header(ZBIN32, ZFILE, @_txflags)
zmtx_file_info{}
repeat until (zget_hdr{} == ZRPOS)
ser.strln(string("got ZRPOS"))
zmtx_bin_header(ZBIN32, ZDATA, @st_pos) ' start position
xfer := 0
repeat pos from st_pos to (_f_sz-1) step _subpsz
if (pos < (_f_sz-_subpsz)) ' before last subpacket?
frm_end := ZCRCQ ' Q: ACK, G: no ACK
else
frm_end := ZCRCE ' frame ends
xfer += zmtx_data_subpkt(ptr_data, pos, _subpsz, frm_end)
if (frm_end == ZCRCQ)
if (zget_hdr{} <> ZACK)
ser.fgcolor(ser#red)
ser.strln(string("error from receiver - aborting"))
ser.fgcolor(ser#white)
repeat
ser.pos_xy(0, 3)
ser.printf2(string("transferred %d/%d bytes\n\r"), xfer, _f_sz)
zmtx_bin_header(ZBIN32, ZEOF, @_f_sz)
repeat until (zget_hdr{} == ZRINIT)
zmtx_hex_header(ZFIN, 0)
repeat until (zget_hdr{} == ZFIN)
ser.strln(string("Transfer complete"))
putchar("O") ' over and out
putchar("O")
repeat
PUB putchar(ch)
com.putchar(ch)
PUB getchar: ch
return com.getchar{}
#include "zmodem.common.spinh"
#include "protocol.file-xfer.zmodem.spinh"
DAT
{
Copyright 2022 Jesse Burt
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}