-- telnet.jal bvwelch 02 june 2004 -- See RFC 854 for details -- TODO: many things. we ignore all the telnet options for right now. include ./javi_lib/telutils -- TODO: 16 bit version procedure telnet_task ( byte in conn_off ) is var byte hi , lo, rxlen, stat var byte txlen -- wait for a telnet command stat = tcp_status ( conn_off ) if stat != 1 then return end if tcp_recv ( conn_off , hi , lo ) rxlen = lo if rxlen == 0 then return end if -- ---- PARSE RX DATA if ( ( hi == 0 ) & ( lo < 4 ) ) then -- compare it with 0x0004 tel_val = tcomm_SynErr -- command too short else tel_val = telnet_app_command -- parse command text (4 chars) if tel_val == tcomm_Echo then -- echo text to serial while ( lo > 0 ) loop -- loop while > 0 (max 255 bytes) tarc_temp = MemNext2 -- skip space lo = lo - 1 if tarc_temp == 0xff then -- Telnet end. return end if if (tarc_temp & 0x80) == 0 then -- Only ASCII-7bit putc = tarc_temp end if end loop elsif tel_val == tcomm_User then -- free access asm nop elsif tel_val == tcomm_Quit then -- close telnet session asm nop elsif tel_val == tcomm_Peek then -- peek, return value tarc_temp = MemNext2 -- skip space tarc_temp = MemNext2 -- offset + 5 FSR0H = hex1bin ( tarc_temp ) FSR0L = hex2bin -- HEX2BIN uses data from MemNext2 tel_user_val = INDF0 -- we have here the desired value. elsif tel_val == tcomm_Poke then -- Poke, store value tarc_temp = MemNext2 -- skip space tarc_temp = MemNext2 -- offset + 5 FSR0H = hex1bin ( tarc_temp ) FSR0L = hex2bin tarc_temp = MemNext2 -- skip space INDF0 = hex2bin -- Data, offset + 8 = " " elsif tel_val == tcomm_IORA then -- read port_a FSR0H = 0x0F -- select SFR bank FSR0L = 0x80 -- 0xF80 porta tel_user_val = INDF0 elsif tel_val == tcomm_IORC then -- read port_C FSR0H = 0x0F -- select SFR bank FSR0L = 0x82 -- 0xF82 portc tel_user_val = INDF0 elsif tel_val == tcomm_IOWA then -- write port_A FSR0H = 0x0F -- select SFR bank FSR0L = 0x80 -- 0xF80 porta tarc_temp = MemNext2 -- skip space INDF0 = hex2bin elsif tel_val == tcomm_IOWC then -- write port_C FSR0H = 0x0F -- select SFR bank FSR0L = 0x82 -- 0xF82 portc tarc_temp = MemNext2 -- skip space INDF0 = hex2bin elsif tel_val == tcomm_IEPR then -- read internal eeprom tarc_temp = MemNext2 -- skip space eeadr = hex2bin eecon1_eepgd = low eecon1_rd = high tel_user_val = eedata elsif tel_val == tcomm_IEPW then -- write internal eeprom tarc_temp = MemNext2 -- skip space eeadr = hex2bin tarc_temp = MemNext2 -- skip space eedata = hex2bin eecon1_eepgd = low eecon1_wren = high assembler movlw 0x55 movwf eecon2 movlw 0xAA movwf eecon2 bsf eecon1_wr end assembler while eecon1_wr loop -- wait to write cycle end loop eecon1_wren = low elsif tel_val == tcomm_EEPR then -- read external eeprom if I2C_eeprom_active then tarc_temp = MemNext2 -- skip space tarc_temp = hex2bin tarc_temp1 = hex2bin I2C_Master_ON read_eeprom ( tarc_temp , tarc_temp1 , tel_user_val ) else tel_val = tcomm_ComErr -- output unable to proccess command end if elsif tel_val == tcomm_EEPW then -- write external eeprom if I2C_eeprom_active then tarc_temp = MemNext2 -- skip space tarc_temp = hex2bin tarc_temp1 = hex2bin tarc_temp = MemNext2 -- skip space tel_user_val = hex2bin I2C_Master_ON write_eeprom ( tarc_temp , tarc_temp1 , tel_user_val ) else tel_val = tcomm_ComErr -- output unable to proccess command end if elsif tel_val == tcomm_LADC then -- 8bit ADC tarc_temp = MemNext2 -- skip space tarc_temp = MemNext2 -- read channel tarc_temp = hex1bin ( tarc_temp ) make_adc_8 ( tarc_temp ) -- adc value in hadc:ladc elsif tel_val == tcomm_HADC then -- 10bit ADC tarc_temp = MemNext2 -- skip space tarc_temp = MemNext2 -- read channel tarc_temp = hex1bin ( tarc_temp ) make_adc_10 ( tarc_temp ) -- adc value in hadc:ladc elsif tel_val == tcomm_SERI then -- serial in if PIR1_RCIF then -- check empty buffer tel_user_val = getc else tel_val = tcomm_ComErr -- output unable to proccess command end if elsif tel_val == tcomm_SERO then -- serial out tarc_temp = MemNext2 -- skip space tel_user_val = hex2bin if PIR1_TXIF then -- check full buffer putc = tel_user_val else tel_val = tcomm_ComErr -- output unable to proccess command end if elsif tel_val == tcomm_telcom then -- telnet commands tel_val = tcomm_hello else tel_val = tcomm_SynErr end if end if -- send command result. tatc_temp = tcomm_200 LoadPointer_2 ( TCP_APP_OFF ) if (tel_val == tcomm_idle) then asm nop elsif (tel_val == tcomm_echo) then telnet_app_transmit_crlf elsif (tel_val == tcomm_Quit) then telnet_app_transmit_sctext ( tcomm_421 ) telnet_app_transmit_crlf telnet_rx = false tel_val = tcomm_hello -- Compute length hi = FSR2H lo = FSR2L -- Hi:Lo store the last data address LoadPointer_2 ( TCP_APP_OFF ) -- FSR2 store the first data address assembler -- 16bit SUB, (hi:lo) = (hi:lo) - (FSR2) movf FSR2L, w -- This is NOT an indirect addressing, subwf lo,f -- it's a direct SUB between addresses movf FSR2H, w subwfb hi,f end assembler -- Return with size in hi:lo -- tcp_send ( conn_off , hi , lo ) -- send packet tcp_send_close ( conn_off ) -- disconnect return elsif (tel_val == tcomm_user) then telnet_app_transmit_crlf tatc_temp = tcomm_230 elsif (tel_val == tcomm_peek) then MemNext2 = hex_to_ascii ( tel_user_val >> 4 ) MemNext2 = hex_to_ascii ( tel_user_val & 0x0F ) telnet_app_transmit_crlf elsif (tel_val == tcomm_poke) then telnet_app_transmit_crlf elsif (tel_val == tcomm_iora) then MemNext2 = hex_to_ascii ( tel_user_val >> 4 ) MemNext2 = hex_to_ascii ( tel_user_val & 0x0F ) telnet_app_transmit_crlf elsif (tel_val == tcomm_iorc) then MemNext2 = hex_to_ascii ( tel_user_val >> 4 ) MemNext2 = hex_to_ascii ( tel_user_val & 0x0F ) telnet_app_transmit_crlf elsif (tel_val == tcomm_iowa) then telnet_app_transmit_crlf elsif (tel_val == tcomm_iowc) then telnet_app_transmit_crlf elsif (tel_val == tcomm_IEPR) then MemNext2 = hex_to_ascii ( tel_user_val >> 4 ) MemNext2 = hex_to_ascii ( tel_user_val & 0x0F ) telnet_app_transmit_crlf elsif (tel_val == tcomm_IEPW) then telnet_app_transmit_crlf elsif (tel_val == tcomm_EEPR) then MemNext2 = hex_to_ascii ( tel_user_val >> 4 ) MemNext2 = hex_to_ascii ( tel_user_val & 0x0F ) telnet_app_transmit_crlf elsif (tel_val == tcomm_EEPW) then telnet_app_transmit_crlf elsif (tel_val == tcomm_LADC) then MemNext2 = hex_to_ascii ( ladc >> 4 ) MemNext2 = hex_to_ascii ( ladc & 0x0F ) telnet_app_transmit_crlf elsif (tel_val == tcomm_HADC) then MemNext2 = hex_to_ascii ( hadc >> 4 ) MemNext2 = hex_to_ascii ( hadc & 0x0F ) MemNext2 = hex_to_ascii ( ladc >> 4 ) MemNext2 = hex_to_ascii ( ladc & 0x0F ) telnet_app_transmit_crlf elsif (tel_val == tcomm_SERI) then MemNext2 = hex_to_ascii ( tel_user_val >> 4 ) MemNext2 = hex_to_ascii ( tel_user_val & 0x0F ) telnet_app_transmit_crlf elsif (tel_val == tcomm_SERO) then telnet_app_transmit_crlf elsif (tel_val == tcomm_ComErr) then telnet_app_transmit_crlf tatc_temp = tcomm_500 elsif (tel_val == tcomm_hello) then telnet_app_transmit_crlf tatc_temp = tcomm_220 else telnet_app_transmit_crlf tatc_temp = tcomm_502 end if telnet_app_transmit_sctext ( tatc_temp ) telnet_app_transmit_crlf telnet_app_transmit_prompt telnet_rx = false tel_val = tcomm_idle -- Compute length hi = FSR2H lo = FSR2L -- Hi:Lo store the last data address LoadPointer_2 ( TCP_APP_OFF ) -- FSR2 store the first data address assembler -- 16bit SUB, (hi:lo) = (hi:lo) - (FSR2) movf FSR2L, w -- This is NOT an indirect addressing, subwf lo,f -- it's a direct SUB between addresses movf FSR2H, w subwfb hi,f end assembler -- Return with size in hi:lo tcp_send ( conn_off , hi , lo ) -- send packet -- must wait before sending the reply while tcp_status ( conn_off ) != 2 loop -- let the networking "stack" run. tcp_yield stat = tcp_status ( conn_off ) -- bailout/abort if user closes the telnet session. -- or if someone tries a http connection at this time. if stat > 0xf0 then return end if -- unlikely, but we may get extra rx packets. just ignore them. if stat == 1 then tcp_recv ( conn_off , hi , lo ) end if end loop end procedure