I'm trying my best to get a network status monitor running and i've run into a road block.
How do you generate an ICMP packet using the driver_socket library? I cannot specify a source or destination port because ICMP does not use one. This puts the connect object right out.
Here is how my code looks right now... Apologies to Robert and Ada, I've totally jacked a lot of their code.
Code: Select all
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
term : "tv_text"
settings : "settings"
subsys : "subsys"
tel : "api_telnet_serial"
websocket : "api_telnet_serial"
Var
long stack[8]
byte status
long statusstack[200]
Dat
ProductName byte "Network Status Monitor",0
ping1 byte 192,168,4,30
PUB start | i
dira[0]~~ 'Set direction on reset pin
outa[0]~ 'Set state on reset pin to LOW
cognew(buttonwatch, @stack) 'Set a Cog to watch the reset switch
term.start(12) 'Init the terminal
TopBanner 'Display The top banner thing.
outa[0]~~ ' Pull ethernet reset pin high, ending the reset condition.
if not \tel.start(1,2,3,4,6,7)
showMessage(string("Unable to start networking!"))
subsys.StatusFatalError
SadChirp
waitcnt(clkfreq*10000 + cnt)
reboot
if settings.getData(settings#NET_MAC_ADDR,@statusstack,6)
term.str(string("MAC: "))
repeat i from 0 to 5
if i
term.out("-")
term.hex(byte[@statusstack][i],2)
term.out(13)
if NOT settings.getData(settings#NET_IPv4_ADDR,@statusstack,4)
term.str(string("IPv4 ADDR: DHCP..."))
repeat while NOT settings.getData(settings#NET_IPv4_ADDR,@statusstack,4)
if ina[subsys#BTTNPin]
reboot
delay_ms(500)
term.out($0A)
term.out($00)
term.str(string("IPv4 ADDR: "))
repeat i from 0 to 3
if i
term.out(".")
term.dec(byte[@statusstack][i])
term.out(13)
term.str(String("Pinging: "))
repeat i from 0 to 3
if i
term.out(".")
term.dec(byte[@ping1][i])
term.str(string("... ")
repeat
PUB buttonwatch
repeat
if ina[subsys#BTTNPin]
reboot
PUB Topbanner
term.str(@ProductName)
term.out(13)
term.out($0c)
term.out(2)
repeat term#cols/2
term.out($8E)
term.out($88)
term.out($0c)
term.out(0)
PUB HappyChirp
subsys.chirpHappy
PUB SadChirp
subsys.chirpSad
PUB showMessage(str)
term.str(string($1,$B,12,$C,$1))
term.str(str)
term.str(string($C,$8))
PRI delay_ms(Duration)
waitcnt(((clkfreq / 1_000 * Duration - 3932)) + cnt)