Fan Control Demo

Dependencies:   mbed-rtos mbed

Fork of mbed_fota by KIM HyoengJun

Revision:
6:8dd20294b2aa
Parent:
5:e11b23f9aacc
Child:
9:fcf91f563147
--- a/ext_fota/SerialManager.cpp	Mon Jul 13 06:32:05 2015 +0000
+++ b/ext_fota/SerialManager.cpp	Fri Jul 17 14:04:12 2015 +0000
@@ -159,43 +159,57 @@
     return ret;   
 }
 
+void SerialManager::DataReceive(uint8_t *databuf, unsigned short size)
+{
+    int i;
+    
+    for(i=0;i<size;i++)
+    {
+        databuf[i] = (uint8_t)device->getc();
+    }
+}
+
 void SerialManager::ReceiveToSerialTest(void) 
 {
     unsigned char tmp;
     int pos = 0;
-    char buff[128];
-    memset(buff,'K',127);
-    buff[127] = '\0';
+    char buff[1024];
+    memset(buff,'K',1023);
+    buff[1023] = '\0';
     hostpc->printf("\n pos = %d FIRST <%s> \n",pos,buff);
     tmp = device->getc();
-    tmp = device->getc();
-    tmp = device->getc();
-    tmp = device->getc();
-    tmp = device->getc();
+    if( tmp == 0x80 ){
+        tmp = device->getc();
+        if( tmp == 0x46 )
+        {
+            hostpc->printf("\n FIRMWARE DATA CONFIRM!! \n");
+        }
+    }
+    tmp = device->getc();//reserved value
+    tmp = device->getc();//reserved value
+    tmp = device->getc();//reserved value
     while(1)
     {
         if(device->readable())
         {
             tmp = device->getc();
-            hostpc->printf("%d ==> 0x%X\n",pos,tmp);
+            //hostpc->printf("%d ==> 0x%X\n",pos,tmp);
             buff[pos] = tmp;
-            pos++;
-            if( pos == 128 ){
-                pos = 0;
-                memset(buff,'Z',127);
-                buff[127] = '\0';
+            pos++;    
+            if( pos%512 == 0 ){
+                buff[1023] = '\0';
+                hostpc->printf("\n pos = %d CHECK <%s> \n",pos,buff);
             }
-            if( pos%16 == 0 ){
-                hostpc->printf("\n pos = %d ERROR <%s> \n",pos,buff);
-                if(device->writeable()){
-                    hostpc->printf("writeable!!\n");
-                    device->putc(0x80);
-                    device->putc(0x44);
-                }
+            if( pos == 1024 ){
+                pos = 0;
+                memset(buff,'Z',1023);
+                buff[1023] = '\0';
             }
         }
         
     }
+    
+    
 }
 
 }//namespace