/[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 96 by hedin, Tue May 22 06:41:06 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;  
 }        
 char network_send_hello( unsigned char termid )  
 {  
 char error = 0;  
 char gotArp = 0;  
 static char isBound = 0;  
   
 if ( DHCPIsBound() && isBound == 0 ){  
         state = DhcpIsBound;  
         isBound = 1;  
 }  
48    
         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:  
                         for (i = net_INT; i >= 0; i--)  
                         {  
                                 TCPPut(tsock1, termid );  
                         }  
                         TCPFlush(tsock1);  
                         state = TcpReadyToSend;  
                         return 0;  
         }  
         return 1;  
 }  
 /*  
 void network_send_hello( unsigned char termid )  
 {  
            if (DHCPIsBound())  
         {  
                 RA3 = 0;  
                 if (sock_open == 0)  
                 {  
                         if (ARPIsTxReady())  
                         {  
                                 ARPResolve( &rnode.IPAddr);  
                                 is_resolved = 1;  
                             }  
                                 else  
                                 {  
                                         if (ARPIsResolved( &rnode.IPAddr, &rnode.MACAddr))  
                                         //if (MyArp( &rnode))  
                                         {  
                                                 usock1=UDPOpen(2000,&rnode,3000); // socket to send UDP  
                                                 sock_open=1;  
                                         }  
                                 }        
                         }  
                 }  
                   
                 if (UDPIsPutReady(usock1) && datagrams_to_send>0)  
                 {  
                         UDPPut( rnode.MACAddr.v[0] );  
                         UDPPut( rnode.MACAddr.v[1] );  
                         UDPPut( rnode.MACAddr.v[2] );  
                         UDPPut( rnode.MACAddr.v[3] );  
                         UDPPut( rnode.MACAddr.v[4] );  
                         UDPPut( rnode.MACAddr.v[5] );  
                         UDPPut('D');  
                         UDPPut('a');  
                         UDPPut('w');  
                         UDPPut(0);  
                         UDPFlush();  
                         datagrams_to_send--;  
                 }  
                 }  
 }  
 */  
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 284  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( 1 );          
127     /*     if (DHCPIsBound())                      network_send_hello( 0x01 );
128          {                      
129                  RA3 =0;                      strncpy(global_network_char, "12345678", 8);
130                  if (has_arp == 0)                          network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8
131                  {                          
132                          if (ARPIsTxReady())                          strncpy(global_network_char, "87654444", 8);
133                          {                          network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8
134                                  if (is_resolved == 0)                          
135                                  {                          network_send_calc_total();
136                                          ARPResolve( &rnode.IPAddr);                          
137                                          is_resolved = 1;                          network_send_cash_payed(50000);
138                                  }                          
139                                  else                          network_send_cancel_last();
140                                  {                          
141                                          if (ARPIsResolved( &rnode.IPAddr, &rnode.MACAddr))                          network_send_cancel_all();
142                                          {                                                  
143                                                          has_arp = 1;                          network_send_goodbye();
                                         }  
                                 }  
           
                         }  
                 }  
                   
                 if (has_arp == 1)  
                 {  
                         if (sock_state == 0)  
                         {  
                         usock1=TCPConnect(&rnode,3000);  
                                 sock_state = 1;  
                         }  
                 /*      if (sock_state ==1 && TCPIsConnected(usock1) && TCPIsPutReady(usock1))  
                         {  
                                 TCPPut(usock1,'D');  
                                 TCPPut(usock1,'a');  
                                 TCPPut(usock1,'w');  
                                 TCPPut(usock1,0);  
                         TCPFlush(usock1);  
                                 sock_state = 2;  
                         }  
                   
                         if (sock_state == 2 && TCPIsPutReady(usock1))  
                     {  
                                 TCPDisconnect(usock1);  
                                 lastTick = TickGet();  
                                 sock_state =3;  
                         }  
                         tick = TickGet();  
                         diffTicks = TickGetDiff(tick, lastTick);  
                           
                         if ( sock_state == 3 && diffTicks > ((TICK)TICK_SECOND * (TICK)2) )  
                                 sock_state = 0;  
                                   
                     }  
         } */  
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.96  
changed lines
  Added in v.106

  ViewVC Help
Powered by ViewVC 1.1.20