/[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 98 by hedin, Tue May 22 14:45:39 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>
9    
 // 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[] = "                ";  
10    
11  /*  /*
12   * This is used by other stack elements.   * This is used by other stack elements.
# Line 68  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,  
         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;  
 }        
   
48    
 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;  
 }        
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;
54      TCP_SOCKET usock1;  
     char sock_state = 0;  
     char is_resolved = 0;  
     char has_arp = 0;  
     char a;  
55                    
56      TICK tick;      TICK tick;
57      TICK lastTick;      TICK lastTick;
# Line 257  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 279  void main(void) Line 122  void main(void)
122           * For DHCP information, display how many times we have renewed the IP           * For DHCP information, display how many times we have renewed the IP
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    
147  #if defined(MCHP_C18)  void interrupt HighISR(void)
     #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  
148  {  {
149      TickUpdate();      TickUpdate();
 /*  
 #if defined(STACK_USE_SLIP)  
     MACISR();  
 #endif  
 */  
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.98  
changed lines
  Added in v.106

  ViewVC Help
Powered by ViewVC 1.1.20