--- trunk/PIC/Demo trimmet/TFTPcDemo.c 2007/05/22 14:45:39 98 +++ trunk/PIC/Demo trimmet/TFTPcDemo.c 2007/05/28 08:26:29 106 @@ -1,35 +1,12 @@ #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" -bit bIsDhcpUp = 0; +#include -// 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. @@ -68,145 +45,13 @@ static void InitializeBoard(void); static void SetConfig(void); -/***************************** - Enummerations - ****************************/ -typedef enum _NetworkState -{ - off, - DhcpIsBound, - ArpIsTxReady, - ArpIsResolved, - SockOpening, - SockOpen, - TcpReadyToSend, - TcpSend, - SockClosing, - SockClosed -} NetworkState; - -/***************************** - GLOBAL INIT - ****************************/ -NODE_INFO rnode; -NetworkState state; -TCP_SOCKET tsock1; - - -/***************************** - network funktions - ****************************/ -int net_INT = 13, i; -char *net_CHAR = "1234567890123"; - - -void network_init(void) -{ - state = off; -} - -char network_send_hello( unsigned char termid ) -{ -char gotArp = 0; // if gotArp is 0, the embedded haven't talked to the server since boot. -static char isBound = 0; - if ( DHCPIsBound() && isBound == 0 ){ - state = DhcpIsBound; - isBound = 1; - } - switch (state) - { - case DhcpIsBound: - if ( ARPIsTxReady() && gotArp == 0 ) - state = ArpIsTxReady; - else - state = ArpIsResolved; - return 0; - - case ArpIsTxReady: - ARPResolve(&rnode.IPAddr); - gotArp = 1; - state = ArpIsResolved; - return 0; - - case ArpIsResolved: - if (ARPIsResolved(&rnode.IPAddr, &rnode.MACAddr) ){ - state = SockOpening; - return 0; - } - else{ - state = ArpIsResolved; - return 2; // no arp resolved - } - - case SockOpening: - tsock1 = TCPConnect (&rnode, 3000); - state = SockOpen; - return 0; - - case SockOpen: - if ( TCPIsConnected(tsock1) && TCPIsPutReady(tsock1) ) - state = TcpSend; - return 0; - - case TcpSend: - TCPPut( tsock1, 0x00 ); - TCPPut( tsock1, termid ); - TCPFlush(tsock1); - TCPDiscard( tsock1 ); - - - state = TcpReadyToSend; - return 0; - } - return 1; -} - -char network_send_scan_frame( unsigned char stregkode, unsigned char buflen ) -{ - switch (state) - { - TCPPut( tsock1, 0x01 ); - for (i = buflen; i >= 0; i--) - { - TCPPut(tsock1, stregkode ); - } - TCPFlush(tsock1); - state = TcpReadyToSend; - return 1; - } -} -char network_send_goodbye(void) -{ - switch (state) - { - case TcpReadyToSend: - if ( TCPIsConnected(tsock1) && TCPIsPutReady(tsock1) ) - state = TcpSend; - - case TcpSend: - TCPPut( tsock1, 0x06 ); - TCPFlush( tsock1 ); - state = SockClosing; - return 0; - - case SockClosing: - TCPDisconnect( tsock1 ); - state = SockClosed; - return 1; - } - return 3; // Didn't close the socket properly; -} 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; - char a; + TICK tick; TICK lastTick; @@ -257,8 +102,6 @@ while(1) { - unsigned char antal = 8; - unsigned char stregkode[] = "12345678"; /* * Blink SYSTEM LED every second. */ @@ -279,40 +122,34 @@ * For DHCP information, display how many times we have renewed the IP * configuration since last reset. */ - - a = network_send_hello( 0x01 ); -// a = network_send_scan_frame( stregkode, antal ); - a = network_send_goodbye(); - + + + network_send_hello( 0x01 ); + + strncpy(global_network_char, "12345678", 8); + network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8 + + strncpy(global_network_char, "87654444", 8); + network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8 + + network_send_calc_total(); + + network_send_cash_payed(50000); + + network_send_cancel_last(); + + network_send_cancel_all(); + + network_send_goodbye(); } } -#if defined(MCHP_C18) - #pragma interrupt HighISR save=section(".tmpdata") - void HighISR(void) -#elif defined(HITECH_C18) - #if defined(STACK_USE_SLIP) - extern void MACISR(void); - #endif - void interrupt HighISR(void) -#endif +void interrupt HighISR(void) { TickUpdate(); -/* -#if defined(STACK_USE_SLIP) - MACISR(); -#endif -*/ } -#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)