UDPversion

Dependencies:   XBee mbed NetServicesMin

Revision:
0:84a3b029656e
Child:
1:3a46d2725374
diff -r 000000000000 -r 84a3b029656e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Apr 14 03:53:45 2012 +0000
@@ -0,0 +1,142 @@
+#include "mbed.h"
+#include "xbee_lib.h"
+#include "EthernetNetIf.h"
+#include "config.h"
+#include "tcp_server.h"
+#include "tcp_client.h"
+#include "xbee_rec_route.h"
+
+#include "leds.h"
+
+Serial pc(USBTX, USBRX);
+
+volatile PrefServer pref;
+
+EthernetNetIf eth ;   
+
+Ticker connectCheck;
+
+//#ifdef _SERVER_TEST_MODE_
+
+#include "data_models.h"
+
+DigitalIn  recSw(p20);
+Timeout chatter;
+bool isPressed;
+
+extern bool healthiPad;
+
+
+class Watchdog {  
+public:
+    void kick(float s) {
+        LPC_WDT->WDCLKSEL = 0x1;                // Set CLK src to PCLK
+        uint32_t clk = SystemCoreClock / 16;    // WD has a fixed /4 prescaler, PCLK default is /4 
+        LPC_WDT->WDTC = s * (float)clk;         
+        LPC_WDT->WDMOD = 0x3;                   // Enabled and Reset        
+        kick();
+    }
+    
+    void kick() {
+        LPC_WDT->WDFEED = 0xAA;
+        LPC_WDT->WDFEED = 0x55;
+    }
+};
+
+Watchdog w;
+
+
+
+
+
+
+void testModeInit(void)
+{
+    recSw.mode(PullUp);
+}
+
+void testSendRecieveData()
+{
+
+   Payload payload;
+   initTestPayloadData(&payload);
+
+   udpSendPayload(&payload); 
+   
+}
+
+
+//#endif
+
+
+
+int main() {
+
+    
+    
+    pc.baud(115200);
+
+//    #ifdef _SERVER_TEST_MODE_
+    testModeInit();
+//    #endif
+    
+    uint8_t tmpip[4]={kSserverIp};
+    uint8_t tmpsubnet[4]={kSubnetMask};
+    uint8_t tmprt[4]={kRouterIp};
+        
+    EthernetNetIf eth( //  -- static IP address
+        IpAddr(kSserverIp),     // IP Address
+        IpAddr(kSubnetMask),   // Subnet Mask
+        IpAddr(kRouterIp),     // Default Gateway
+        IpAddr(kRouterIp)      // DNS Server
+    ) ;
+
+    if( eth.setup() != ETH_OK )
+    {
+        pc.printf("Ether Setup Error\r\n");
+        return -1;
+    }
+    pc.printf("Ether Setup OK\r\n");
+
+    memcpy((void*)pref.serverAddress,tmpip,4);
+    pc.printf("mbed IP Address is [%d.%d.%d.%d]\r\n", pref.serverAddress[0], pref.serverAddress[1], pref.serverAddress[2], pref.serverAddress[3]) ;
+    
+    memcpy((void*)pref.subnetMask,tmpsubnet,4);
+    pc.printf("mbed subnet Address is [%d.%d.%d.%d]\r\n", pref.subnetMask[0], pref.subnetMask[1], pref.subnetMask[2], pref.subnetMask[3]) ;
+    
+    memcpy((void*)pref.routerAddress,tmprt,4);
+    pc.printf("mbed router Address is [%d.%d.%d.%d]\r\n", pref.routerAddress[0], pref.routerAddress[1], pref.routerAddress[2], pref.routerAddress[3]) ;
+
+    ;
+    
+    xbeeInit();
+
+    serverInit();
+    clientInit();
+    
+    startLed();
+    
+    connectCheckStart();
+ 
+//    w.kick(2.5); //watch dog timer set
+
+    while(1) {
+    
+        w.kick();
+        
+        Net::poll();
+       
+        
+  //      #ifdef _SERVER_TEST_MODE_
+        if(!recSw){
+            testSendRecieveData();
+            wait(0.5);
+        }
+  //     #else
+        xbeeRecieveRouting();
+  //       #endif
+        if(healthiPad)  ledTcpConnect(false);
+        else            ledTcpConnect(true);
+
+    }
+}