--- trunk/PIC/Demo trimmet/TFTPcDemo.c 2007/05/27 16:32:30 105 +++ trunk/PIC/Demo trimmet/TFTPcDemo.c 2007/05/28 10:13:48 109 @@ -1,39 +1,13 @@ #define THIS_IS_STACK_APPLICATION #include "stacktsk.h" -#include "dhcp.h" #include "tick.h" #include "delay.h" -#include "udp.h" -#include "arp.h" -#include "arptsk.h" -#include "tcp.h" - +#include "network.h" +#include "barcode.h" #include -bit bIsDhcpUp = 0; -char netlevel = 0; - -// All TFTP command statuts display will be done on first line of LCD. -//#define TFTP_COMMAND_DISPLAY_LINE 0 - -// Result will be displayed at y = 15. -#define TFTP_COMMAND_RESULT_POSITION 15 - - -/*#define STARTUP_MSG "G1_Build_0x00" - -ROM char StartupMsg[] = STARTUP_MSG; - -#if defined(STACK_USE_DHCP) || defined(STACK_USE_IP_GLEANING) -ROM char DHCPMsg[] = "DHCP/Gleaning..."; -#endif - -ROM char SetupMsg[] = "Board Setup..."; -// 1234567890123456 -//ROM char blankLCDLine[] = " "; -*/ /* * This is used by other stack elements. * Main application must define this and initialize it with @@ -71,398 +45,12 @@ static void InitializeBoard(void); static void SetConfig(void); -/***************************** - Enummerations - ****************************/ -typedef enum _NetworkState -{ - off, - DhcpIsBound, - ArpIsTxReady, - ArpIsResolved, - SockOpening, - SockOpen, - TcpReadyToSend, - TcpSend, - HelloDone, - StregkodeSendDone, - ReadyToRecieve, - StregkodeRecieveDone, - TotalRequested, - TotalRequestedDone, - ChangeRequested, - ChangeRequestedDone, - Acknowledged, - CancelDone, - SockClosing, - SockClosed -} NetworkState; - -/***************************** - GLOBAL INIT - ****************************/ -NODE_INFO rnode; -NetworkState state; -TCP_SOCKET tsock1; - - -/***************************** - network funktions - ****************************/ -unsigned long global_network_amount; -unsigned char global_network_char[16]; -unsigned char global_network_charlen; - - -void network_init(void) -{ - state = off; -} - - -void network_worker(void) -{ - TickGet(); - StackTask(); -} - -void network_parse_amount(unsigned char buf[]) -{ - global_network_amount = buf[0]<<24 + buf[1]<<16 + buf[2]<<8 + buf[3]; -} - -void network_read_amount(void) -{ - unsigned char buf[4]; - TCPGetArray(tsock1, buf,4); - network_parse_amount(buf); -} - -void network_wait(unsigned char n) -{ - int i; - for (i=0; i>24); - TCPPut(tsock1, amount>>16); - TCPPut(tsock1, amount>>8); - TCPPut(tsock1, amount); - TCPFlush(tsock1); - state = ChangeRequested; - break; - } - network_worker(); - } - - while (state != ChangeRequestedDone) - { - if (TCPIsGetReady(tsock1)) - { - TCPGet(tsock1, &ack); - if (ack == 0) - { - TCPFlush(tsock1); - state = TcpReadyToSend; - return 4; - } - network_read_amount(); - TCPFlush(tsock1); - state = ChangeRequestedDone; - - } - network_worker(); - } - state = TcpReadyToSend; - return 0; -} -//request 4+5 -char network_send_cancel_generic(char id) -{ - while(state != CancelDone) - { - switch (state) - { - case TcpReadyToSend: - if ( TCPIsConnected(tsock1) && TCPIsPutReady(tsock1) ) - state = TcpSend; - break; - case TcpSend: - TCPPut(tsock1, id); - TCPFlush(tsock1); - state = CancelDone; - - } - network_worker(); - } - return network_read_ack(); -} - -//Request ID 4 -char network_send_cancel_last(void) -{ - return network_send_cancel_generic(0x04); -} - -//Request ID 5 -char network_send_cancel_all(void) -{ - return network_send_cancel_generic(0x05); -} - -//Request ID 6 -char network_send_goodbye(void) -{ - char ack; - while( state != SockClosed) - { - switch (state) - { - case TcpReadyToSend: - if ( TCPIsConnected(tsock1) && TCPIsPutReady(tsock1) ) - state = TcpSend; - break; - - case TcpSend: - TCPPut( tsock1, 0x06 ); - TCPFlush( tsock1 ); - state = SockClosing; - break; - - case SockClosing: - ack = network_read_ack(); - TCPDisconnect( tsock1 ); - state = SockClosed; - break; - } - network_worker(); - } - if( TCPIsConnected(tsock1)) - return 3; // Didn't close the socket properly; - else - return ack; - -} -void network_wait_for_dhcp() -{ - while (!DHCPIsBound()) - network_worker(); -} void main(void) { // Tick to blink SYSTEM led. static TICK t = 0; - TCP_SOCKET usock1; - char sock_state = 0; - char is_resolved = 0; - char has_arp = 0; TICK tick; @@ -506,7 +94,7 @@ */ - // Defines the IP add. on the server machine + // Defines the IP add. on the server machine (rnode is defined in network.h) rnode.IPAddr.v[0] = 192; rnode.IPAddr.v[1] = 168; rnode.IPAddr.v[2] = 1; @@ -514,8 +102,6 @@ while(1) { - unsigned char antal = 8; - unsigned char stregkode[] = "12345678"; /* * Blink SYSTEM LED every second. */ @@ -560,17 +146,13 @@ void interrupt HighISR(void) { - TickUpdate(); + if (RCIF == 1) + barcode_interrupt(); + else + TickUpdate(); } -#if defined(MCHP_C18) -#pragma code highVector=0x08 -void HighVector (void) -{ - _asm goto HighISR _endasm -} -#pragma code /* return to default code section */ -#endif + /********************************************************************* * Function: void InitializeBoard(void)