-
Notifications
You must be signed in to change notification settings - Fork 0
/
raspiServer.spin
142 lines (112 loc) · 2.99 KB
/
raspiServer.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
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
CON
_clkmode = xtal1 + pll16x ' Feedback and PLL multiplier
_xinfreq = 5_000_000 ' External oscillator = 5 MHz
OBJ
rpi: "Parallax Serial Terminal"
pc: "Parallax Serial Terminal"
CON
lineMax=64
skipBoot=true
skipLogin=true
VAR
byte lineIn[lineMax+1]
PUB raspiServer | op, s, e, stringStart
setup
repeat
rpi.StrInMax(@lineIn,lineMax)
stringStart:=@lineIn
if lineIn[0]==$0A
stringStart++
op:=StrToBase(stringStart+1,8,16)
pc.Char(lineIn)
pc.NewLine
pc.Hex(op,8)
pc.NewLine
case byte[stringStart]
"D":
s:=op&$ff
e:=(op>>8) & $ff
dira[s..e]:=op>>16
"O":
s:=op&$ff
e:=(op>>8) & $ff
outa[s..e]:=op>>16
"I":
rpi.Hex(ina,8)
rpi.NewLine
"C":
ctra:=op
"c":
ctrb:=op
"F":
frqa:=op
"f":
frqb:=op
"P":
phsa:=op
"p":
phsb:=op
"Q":
rpi.Hex(frqa,8)
rpi.NewLine
"q":
rpi.Hex(frqb,8)
rpi.NewLine
"H":
rpi.Hex(phsa,8)
rpi.NewLine
"h":
rpi.Hex(phsb,8)
rpi.NewLine
"N":
rpi.Hex(cnt,8)
rpi.NewLine
PUB setup
pc.start(115200)
rpi.startRxTx(12,13,%0100,115200)
ifnot skipBoot
waitPrompt(@bootDonePrompt)
rpi.NewLine
ifnot skipLogin
waitPrompt(@loginPrompt)
rpi.RxFlush
rpi.str(@username)
rpi.NewLine
waitPrompt(@passwordPrompt)
rpi.RxFlush
rpi.str(@password)
rpi.NewLine
waitPrompt(@commandPrompt)
rpi.str(@command)
rpi.NewLine
waitcnt(cnt+clkfreq>>4)
rpi.RxFlush
PUB waitPrompt(prompt) | c,foundTo
foundTo:=0
repeat while byte[prompt][foundTo]<>0
c:=rpi.CharIn
if (c==byte[prompt][foundTo])
foundTo++
else
foundTo:=0
pc.str(string("Found prompt: "))
pc.str(prompt)
pc.NewLine
PRI StrToBase(stringptr, count, base) : value | chr, index
{Converts a zero terminated string representation of a number to a value in the designated base.
Ignores all non-digit characters (except negative (-) when base is decimal (10)).}
value := index := 0
repeat until ((chr := byte[stringptr][index++]) == 0) or index>count
chr := -15 + --chr & %11011111 + 39*(chr > 56) 'Make "0"-"9","A"-"F","a"-"f" be 0 - 15, others out of range
if (chr > -1) and (chr < base) 'Accumulate valid values into result; ignore others
value := value * base + chr
if (base == 10) and (byte[stringptr] == "-") 'If decimal, address negative sign; ignore otherwise
value := - value
DAT
bootDonePrompt byte "Debian GNU/Linux wheezy/sid raspberrypi ttyAMA0",0
loginPrompt byte "raspberrypi login: ", 0
passwordPrompt byte "Password: ",0
commandPrompt byte "michael@raspberrypi:~$ ",0
username byte "michael",0
password byte "hexais10",0
command byte "stty icrnl -echo; nc -klU /var/tmp/propSocket",0