|
Code Example |
Top Previous Next |
Here is a simple example of using the PPPOE library. Pppoe_start() is called on boot(). Once the PPPoE link is established, the device will open an outgoing TCP connection to a certain remote IP and port.
Green status LED is used to indicate the TCP connection status: it will be on when the TCP connection is established.
To test the TCP connection, the code will periodically send a small string of data to the remote end of the connection. If any reply is received, the green status LED will momentarily turn off.
Before running the code, do not forget to change ADSL_NAME, ADSL_LOGIN, REMOTE_IP, and REMOTE_PORT constants.
global.tbh: |
'DEFINES------------------------------------------------------------- #define PPPOE_DEBUG_PRINT 1
'INCLUDES------------------------------------------------------------ include "sock\trunk\sock.tbh" include "pppoe\trunk\pppoe.tbh"
'DECLARATIONS-------------------------------------------------------- declare tcp_sock_o as byte
|
main.tbs: |
include "global.tbh"
'-------------------------------------------------------------------- const ADSL_NAME="correct_name" '<----- CHANGE THIS AS NEEDED const ADSL_PASSWORD="correct_password" '<----- CHANGE THIS AS NEEDED const REMOTE_IP="59.120.32.27" '<----- CHANGE THIS AS NEEDED const REMOTE_PORT=40000 '<----- CHANGE THIS AS NEEDED
'-------------------------------------------------------------------- dim tcp_sock_o as byte
'==================================================================== sub on_sys_init() dim res as en_pppoe_status_codes
'----- this is for the outgoing test connection tcp_sock_o=sock_get("TCPA") sock.num=tcp_sock_o sock.txbuffrq(1) sock.rxbuffrq(1) sys.buffalloc sock.protocol=PL_SOCK_PROTOCOL_TCP sock.targetip=REMOTE_IP sock.targetport=REMOTE_PORT sock.targetinterface=PL_SOCK_INTERFACE_PPPOE '----- end
res=pppoe_start(ADSL_NAME,ADSL_PASSWORD) end sub
'-------------------------------------------------------------------- sub on_sock_data_arrival() dim s as string(32)
pppoe_proc_data()
'----- this is for the outgoing test connection if sock.num=tcp_sock_o then s=sock.getdata(255) pat.play("-***",PL_PAT_CANINT) end if '----- end end sub
'-------------------------------------------------------------------- sub on_sys_timer() pppoe_proc_timer()
'----- this is for the outgoing test connection sock.num=tcp_sock_o if sock.statesimple=PL_SSTS_EST then sock.setdata("ABC") sock.send end if '----- end end sub
'-------------------------------------------------------------------- sub on_sock_event(newstate as pl_sock_state, newstatesimple as pl_sock_state_simple) '----- this is for the outgoing test connection if sock.num=tcp_sock_o then pat.play("-***",PL_PAT_CANINT) end if '----- end end sub
'-------------------------------------------------------------------- sub on_pat() '----- this is for the outgoing test connection sock.num=tcp_sock_o if sock.statesimple=PL_SSTS_EST then pat.play("G~",PL_PAT_CANINT) end if '----- end end sub
|
device.tbs: |
include "global.tbh"
'==================================================================== sub callback_pppoe_ok() sock.num=tcp_sock_o sock.connect end sub
'-------------------------------------------------------------------- sub callback_pppoe_failure(pppoe_code as en_pppoe_status_codes) sock.num=tcp_sock_o sock.discard end sub
'-------------------------------------------------------------------- sub callback_pppoe_pre_buffrq(required_buff_pages as byte) end sub
|