/[H8]/trunk/PIC/Demo trimmet/TFTPcDemo.c
ViewVC logotype

Diff of /trunk/PIC/Demo trimmet/TFTPcDemo.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 102 by hedin, Fri May 25 16:00:14 2007 UTC revision 106 by hedin, Mon May 28 08:26:29 2007 UTC
# Line 1  Line 1 
1  #define THIS_IS_STACK_APPLICATION  #define THIS_IS_STACK_APPLICATION
2    
3  #include "stacktsk.h"  #include "stacktsk.h"
 #include "dhcp.h"  
4  #include "tick.h"  #include "tick.h"
5  #include "delay.h"  #include "delay.h"
6  #include "udp.h"  #include "network.h"
 #include "arp.h"  
 #include "arptsk.h"  
 #include "tcp.h"  
7    
8  bit bIsDhcpUp = 0;  #include <string.h>
 char netlevel = 0;  
9    
 // All TFTP command statuts display will be done on first line of LCD.  
 //#define TFTP_COMMAND_DISPLAY_LINE       0  
10    
 // 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[] = "                ";  
 */  
11  /*  /*
12   * This is used by other stack elements.   * This is used by other stack elements.
13   * Main application must define this and initialize it with   * Main application must define this and initialize it with
# Line 69  static void InitAppConfig(void); Line 45  static void InitAppConfig(void);
45  static void InitializeBoard(void);  static void InitializeBoard(void);
46  static void SetConfig(void);  static void SetConfig(void);
47    
 /*****************************  
  Enummerations  
  ****************************/  
 typedef enum _NetworkState  
 {  
         off,  
         DhcpIsBound,  
         ArpIsTxReady,  
         ArpIsResolved,  
         SockOpening,  
         SockOpen,  
         TcpReadyToSend,  
         TcpSend,  
         HelloDone,  
         StregkodeDone,  
         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;  
 }        
   
   
 void network_worker(void)  
 {      
         TickGet();  
     StackTask();      
 }        
48    
 void network_wait(unsigned char n)  
 {  
         int i;  
         for (i=0; i<n; i++)  
         {  
                 network_worker();  
                 DelayMs(1);  
         }  
 }        
   
   
 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;  
   
 while( !DHCPIsBound() && isBound == 0 )  
         network_worker();  
   
 //      while( state != DhcpIsBound ){  
                 if ( DHCPIsBound() && isBound == 0 ){  
                         state = DhcpIsBound;  
                         isBound = 1;  
 //              }  
   
         }  
         while( state != HelloDone )  
         {  
                 switch (state)  
                 {  
                         case DhcpIsBound:  
                                 if ( ARPIsTxReady() && gotArp == 0 )  
                                         state = ArpIsTxReady;  
                                 else  
                                         state = ArpIsResolved;  
                                 break;  
                           
                         case ArpIsTxReady:  
                                 ARPResolve(&rnode.IPAddr);  
                                 gotArp = 1;  
                                 state = ArpIsResolved;  
                                 break;  
                                                   
                         case ArpIsResolved:  
                                 if ( ARPIsResolved(&rnode.IPAddr, &rnode.MACAddr) ){  
                                         state = SockOpening;  
                                 }  
                                 break;  
                           
                         case SockOpening:  
                                 tsock1 = TCPConnect (&rnode, 3000);  
                                 state = SockOpen;  
                                 break;  
                   
                         case SockOpen:  
                                 if ( TCPIsConnected(tsock1) && TCPIsPutReady(tsock1) )  
                                         state = TcpSend;  
                                 break;  
                           
                         case TcpSend:  
                                 TCPPut( tsock1, 0x00 );  
                                 TCPPut( tsock1, termid );  
                                 TCPFlush(tsock1);  
                                 //TCPDiscard( tsock1 );  
                                 state = HelloDone;  
                                 network_wait(5);  
                                 break;  
                 }  
                 network_worker();  
         }  
         return 0;  
 }  
   
 char network_send_scan_frame( unsigned char stregkode[], unsigned char buflen )  
 {  
         while( state != StregkodeDone )  
         {  
                 switch (state)  
                 {  
                         case HelloDone:  
                                 if ( TCPIsConnected(tsock1) && TCPIsPutReady(tsock1) )  
                                 state = TcpSend;  
                         case TcpSend:  
                                 TCPPut( tsock1, 0x01 );  
                                 for (i = 0; i < buflen; i++)  
                                 {  
                                         TCPPut(tsock1, stregkode[i] );  
                                 }  
                                 TCPFlush(tsock1);  
                                 state = StregkodeDone;  
                                 break;  
                 }  
                 network_worker();  
         }  
         return 0;  
 }        
 char network_send_goodbye(void)  
 {  
         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:  
                                 TCPDisconnect( tsock1 );  
                                 state = SockClosed;  
                                 break;  
                 }  
                 network_worker();  
         }  
         if( TCPIsConnected(tsock1) )  
                 return 3;                               // Didn't close the socket properly;  
         else  
                 return 0;  
           
 }        
 void network_wait_for_dhcp()  
 {  
         while (!DHCPIsBound())  
                 network_worker();  
 }        
49    
50  void main(void)  void main(void)
51  {  {
52      // Tick to blink SYSTEM led.      // Tick to blink SYSTEM led.
53      static TICK t = 0;      static TICK t = 0;
     TCP_SOCKET usock1;  
     char sock_state = 0;  
     char is_resolved = 0;  
     char has_arp = 0;  
     char a = 1;  
54    
55                    
56      TICK tick;      TICK tick;
# Line 307  void main(void) Line 102  void main(void)
102    
103      while(1)      while(1)
104      {      {
             unsigned char antal = 8;  
             unsigned char stregkode[] = "12345678";  
105          /*          /*
106           * Blink SYSTEM LED every second.           * Blink SYSTEM LED every second.
107           */           */
# Line 330  void main(void) Line 123  void main(void)
123           * configuration since last reset.           * configuration since last reset.
124           */           */
125                    
126                      a = network_send_hello( 0x01 );          
127                          a = network_send_scan_frame( stregkode, antal );                      network_send_hello( 0x01 );
128                          a = network_send_goodbye();                      
129                        strncpy(global_network_char, "12345678", 8);
130                            network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8
131                            
132                            strncpy(global_network_char, "87654444", 8);
133                            network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8
134                            
135                            network_send_calc_total();
136                            
137                            network_send_cash_payed(50000);
138                            
139                            network_send_cancel_last();
140                            
141                            network_send_cancel_all();
142                                                    
143                            network_send_goodbye();
144      }      }
145  }  }
146    
# Line 341  void interrupt HighISR(void) Line 149  void interrupt HighISR(void)
149      TickUpdate();      TickUpdate();
150  }  }
151    
152  #if defined(MCHP_C18)  
 #pragma code highVector=0x08  
 void HighVector (void)  
 {  
     _asm goto HighISR _endasm  
 }  
 #pragma code /* return to default code section */  
 #endif  
153    
154  /*********************************************************************  /*********************************************************************
155   * Function:        void InitializeBoard(void)   * Function:        void InitializeBoard(void)

Legend:
Removed from v.102  
changed lines
  Added in v.106

  ViewVC Help
Powered by ViewVC 1.1.20