Measure system

Dependencies:   EthernetNetIf mbed RF12B

Revision:
3:799d8c61fb03
Parent:
2:afe5826411e3
--- a/MeasureSystem.cpp	Sun Mar 27 07:56:59 2011 +0000
+++ b/MeasureSystem.cpp	Tue May 17 16:49:23 2011 +0000
@@ -1,14 +1,13 @@
 #define MEASURE_C
-
+#include "mbed.h"
 #include "EthernetNetIf.h"
 #include "HTTPServer.h"
 #include "SDFileSystem.h"
 #include "TextLCD.h"
 #include "DS1820.h"
 #include "MeasureSystem.h"
-#include "NTPClient.h"
 #include "WatchDog.h"
-#include "HTTPClient.h"
+//#include "HTTPClient.h"
 #include "AvailableMemory.h"
 
 //-------------------Defines--------------------------------
@@ -18,11 +17,10 @@
 EthernetNetIf *eth;            //Network IP stack
 HTTPServer svr;                //HTTP server
 Serial pc(USBTX, USBRX);       // Serial debug usb port
-DigitalIn dhcpOn(p30);         // Button
-DigitalOut led1(LED1, "led1"); //Led 1
-DigitalOut led2(LED2, "led2"); //Led 2
-DigitalOut led3(LED3, "led3"); //Led 3
-DigitalOut led4(LED4, "led4"); //Led 4
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
 LocalFileSystem local("local");//Internal flash
 SDFileSystem sd(p5, p6, p7, p8, "sd"); // // External sd card
 TextLCD lcd(p21, p22, p23, p24, p25, p26,  TextLCD::LCD20x4 );  //Char lcd
@@ -35,6 +33,7 @@
 char localIP[18];
 int fileindex =0;
 bool getIPfromDHCP;
+bool localmode;
 Timer timerMeasure;
 int ipConfig[4];
 int maskConfig[4];
@@ -190,11 +189,11 @@
     //-------------------MAIN LOOP--------------------
     while (true) {
         Net::poll(); // Network listen
-
         if (tm.read()>1) {
         //RESET REQUIED
         if (reset)
         {
+        wait(1);
         mbed_reset();
         }
         
@@ -211,7 +210,7 @@
             
             //Refress LCD
             UpdateLCD(counter); 
-            
+            /*
             //If no network detected aat startup then try to connect every 30 sec
             if ( (wanIP[0]==0 & (counter%30)==0) | (wanIP[0]!=0 & (counter)==0)) {      
                 GetMyIP();
@@ -220,7 +219,7 @@
                     UpdateTime();
                 }
             }
-
+*/
             //DEADLOCK PREVENTER
             if (HandlerActive) {
                 handlerCounter++;
@@ -234,7 +233,7 @@
 
             //Logger
             if (logging == 1 ) {
-                MeasureLogger();
+                MeasureLogger(0);
             }
 
 
@@ -252,6 +251,7 @@
 
 //---------------------------Functions--------------------------
 
+
 void InitDS1820() {
 
     int i;
@@ -282,15 +282,22 @@
 }
 
 //-------------------Get WAN IP adress-------------------------
+
 void GetMyIP() {
+/*
     HTTPClient http;
     HTTPText txt;
-    HTTPResult r = http.get("http://www.whatismyip.com/automation/n09230945NL.asp", &txt);
+    HTTPResult r
+    //r = http.get("http://www.whatismyip.com/automation/n09230945NL.asp", &txt);
     if (r==HTTP_OK) {
         sprintf(wanIP,"%s", txt.gets());
     } else {
         sprintf(wanIP,NOINTERNET);
-    }
+    }   
+
+*/
+sprintf(wanIP,NOINTERNET);
+
 }
 
 //-----------------Create Index HTM in local-------------------
@@ -341,7 +348,7 @@
         }
 
         if (j==12) { //Change to find string element search by char.
-            if (wanIP[0]!=0) {
+            if (/*wanIP[0]!=0 &*/ !localmode) {
             fprintf(fs_tgt,"      <param name=\"ServerAddress\" value=\"%s\">",myUrl.c_str());
             }
             else
@@ -391,7 +398,7 @@
             if (IPshowflag) {
                 lcd.printf("IP: %s        ", localIP);
             } else {
-                lcd.printf("IP: %s        ", wanIP);
+                lcd.printf("IP: %s        ", myUrl.c_str());
             }
             IPshowflag = !IPshowflag;
         } else {
@@ -412,13 +419,17 @@
 
 //----------------Update time---------------------
 void UpdateTime() {
+/*
     NTPClient * ntp = new NTPClient(); //NTP client
     time_t ctTime;
     ctTime = time(NULL);
+    printf("Current time is (UTC): %s\n", ctime(&ctTime));
     Host server(IpAddr(), 123, "0.hu.pool.ntp.org");
     ntp->setTime(server);
     ctTime = time(NULL);
     ctTime += (clockoffset*3600); //set jst time
+    printf("\nTime is now (UTC): %s\n", ctime(&ctTime)); 
+    */
 }
 
 //-------------Get file name---------------------
@@ -448,7 +459,6 @@
     fs_src    = fopen( CONFIG_FILE, "rb" );
     while (fgets(buffer, 100, fs_src)) {
         linecounter++;
-
         switch (linecounter) {
             case 2 :
                 sscanf(buffer,"%d.%d.%d.%d",&ipConfig[0],&ipConfig[1],&ipConfig[2],&ipConfig[3]);
@@ -466,13 +476,17 @@
                 if (buffer[0]=='t' | buffer[0]=='T') getIPfromDHCP= true;
                 else getIPfromDHCP = false;
                 break;
-            case 13:
+            case 12:
+                if (buffer[0]=='t' | buffer[0]=='T') localmode= true;
+                else localmode = false;
+                break;               
+            case 15:
                 sscanf(buffer,"%d",&interval);
                 break;
-            case 15:
+            case 17:
                 sscanf(buffer,"%d",&clockoffset);
                 break;
-            case 18:
+            case 20:
                 myUrl = buffer;
                 break;
         }
@@ -505,6 +519,15 @@
 {
 fprintf(fs_src,"False\r\n");
 }
+fprintf(fs_src,"%s\r\n","Local only mode (true/false)");
+if (localmode)
+{
+fprintf(fs_src,"True\r\n");
+}
+else
+{
+fprintf(fs_src,"False\r\n");
+}
 fprintf(fs_src,"%s\r\n","---------------");
 fprintf(fs_src,"%s\r\n","Interval (sec)");
 fprintf(fs_src,"%d\r\n",interval);
@@ -586,8 +609,8 @@
 
         printf ("Printing header into log file: %s\r\n",logfile);
 
-        sdcardWriteFile (logfile,WRITEFILE,"Measure Start\r\n");
-        
+        sdcardWriteFile (logfile,WRITEFILE,"");
+        MeasureLogger(1);
     }
     
     
@@ -637,21 +660,32 @@
 
 
 //---------- Logger method------------------------------------------------
-void MeasureLogger() {
+void MeasureLogger(int force) {
 
-    if (timerMeasure.read() >= (interval-1)) {
+    if (timerMeasure.read() >= (interval-1) | force==1) {
         led2 = 1;
         char buf[50];
         ctTime = time(NULL);
         ctTime += (clockoffset*3600);
-        strftime(buf,sizeof(buf), "%Y.%m.%d / %H:%M:%S", localtime(&ctTime));
+        strftime(buf,sizeof(buf), "%Y.%m.%d\t%H:%M:%S", localtime(&ctTime));
 
         char resp[100] = "";
         strcat(resp,buf);
         char temp[32] ;
         probe[0]->convert_temperature(DS1820::all_devices);
         for (int i=0; i<devices_found; i++) {
-            sprintf(temp," / %3.1f",(probe[i]->temperature('c')));
+            sprintf(temp,"\t%3.1f",(probe[i]->temperature('c')));
+            
+                 for(int i = 0; i <strlen(temp); i++)
+     {
+          switch(temp[i])
+          {
+               case '.':
+               temp[i] = ',';
+               break;
+          }
+     }
+     
             strcat(resp,temp);
         }
         sprintf( temp , "\r\n");
@@ -690,7 +724,7 @@
 //------------------Prints out free ram space----------------------
 void PrintRAM()
 {
-printf("Available memory (exact bytes) : %d\r\n", AvailableMemory(1));
+//printf("Available memory (exact bytes) : %d\r\n", AvailableMemory(1));
 }
 //-----------------Update List-------------------------------------
 void UpdateList()