Add two threads into the IOT WIFIDemo for test_JacobShi

Dependencies:   C12832 HTTPClient wifiontros wifirtos mbed

Fork of frdm_rtos by Freescale

Files at this revision

API Documentation at this revision

Comitter:
shiyilei
Date:
Fri Dec 05 02:14:44 2014 +0000
Parent:
3:5f921ff0868d
Commit message:
wifibasedonrtos

Changed in this revision

WiflyInterface.lib Show annotated file Show diff for this revision Revisions of this file
baseinterface.cpp Show annotated file Show diff for this revision Revisions of this file
baseinterface.h Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
sysinterface.cpp Show annotated file Show diff for this revision Revisions of this file
sysinterface.h Show annotated file Show diff for this revision Revisions of this file
diff -r 5f921ff0868d -r 242715d40e54 WiflyInterface.lib
--- a/WiflyInterface.lib	Fri Nov 28 12:52:56 2014 +0000
+++ b/WiflyInterface.lib	Fri Dec 05 02:14:44 2014 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/mbed/code/WiflyInterface/#a27cf731e79a
+http://developer.mbed.org/teams/ARM-Shanghai-IoT-Team/code/wifiontros/#8a57e2ed20a4
diff -r 5f921ff0868d -r 242715d40e54 baseinterface.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/baseinterface.cpp	Fri Dec 05 02:14:44 2014 +0000
@@ -0,0 +1,82 @@
+#include <algorithm>
+#include "baseinterface.h"
+
+Wifly*wifi;
+/********************************************
+*function:wifi get instance
+*
+********************************************/
+bool base_level_getinstance(void)
+{
+    wifi=Wifly::getInstance();
+    if (wifi == NULL)
+            return 0;
+        return 1;
+}
+
+/***********************************
+*function: wifi close
+* 
+**********************************/
+bool base_level_close()
+{
+    return (wifi->close())?0:-1;
+}
+
+/*************************
+*function:wifi connect
+*
+************************/
+bool base_level_connect(const char* host, const int port)
+{
+    if(!wifi->connect(host,port))
+        return -1;
+    wifi->flush();
+            return 0;
+}
+
+/*******************************
+*function:if wifi is connected?
+*
+*********************************/
+bool base_level_is_connected(void)
+{
+    return wifi->is_connected();
+}
+
+/*****************************
+*function:wifi send_data
+*
+******************************/
+int baselevel_send_data(char *data,int length)
+{
+        int idx =0;
+        idx +=wifi->send(data, length);
+      return idx;
+}
+
+/********************************
+*function:receive_data
+*
+* 
+********************************/
+int baselevel_receive_data(char *data,int length)
+{
+     //while(!wifi->readable());
+int idx=0;
+    int nb_available = wifi->readable();
+      for (int i = 0; i < min(nb_available, length); i++) {
+       data[idx++] = wifi->getc();
+            }   
+        return idx;
+}
+/****************************************
+*function:wifi->readable()
+*
+*****************************************/
+int  baselevel_is_readable()
+{
+        int nb_available=wifi->readable();
+    
+        return nb_available;
+}
diff -r 5f921ff0868d -r 242715d40e54 baseinterface.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/baseinterface.h	Fri Dec 05 02:14:44 2014 +0000
@@ -0,0 +1,13 @@
+#ifndef __BASELEVEL_H
+#define __BASELEVEL_H
+#include "Wifly.h"
+extern Wifly*wifi;   //·ÀÖ¹UDP±¨´í
+bool base_level_getinstance(void);
+bool base_level_close();
+bool base_level_connect(const char* host, const int port);
+bool base_level_is_connected(void);
+int baselevel_send_data(char *data,int length);
+int baselevel_receive_data(char *data,int length);
+int baselevel_is_readable();
+
+#endif
\ No newline at end of file
diff -r 5f921ff0868d -r 242715d40e54 mbed-rtos.lib
--- a/mbed-rtos.lib	Fri Nov 28 12:52:56 2014 +0000
+++ b/mbed-rtos.lib	Fri Dec 05 02:14:44 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#cb1d43beeb70
+http://developer.mbed.org/teams/ARM-Shanghai-IoT-Team/code/wifirtos/#eb9dfc662874
diff -r 5f921ff0868d -r 242715d40e54 sysinterface.cpp
--- a/sysinterface.cpp	Fri Nov 28 12:52:56 2014 +0000
+++ b/sysinterface.cpp	Fri Dec 05 02:14:44 2014 +0000
@@ -1,29 +1,46 @@
+#include "sysinterface.h"
 
-#include "sysinterface.h"
-//GLOBAL_DATA globaldata;
+PUBLICDATA globaldata;
+    
+DigitalOut threadled(LED1);
 void send_task(void const *args)
 {
-    
     while(1)
-    {   
-//      if(globaldata.send_ready==1)
-//      {
-//          globaldata.send_ready=0;
-//          int idx=baselevel_send_data(globaldata.send_buffer,globaldata.send_length);
-//          globaldata.send_length_over=idx;
-//          globaldata.send_completed=1;
-//      }
-        int a=0;
-        Thread::wait(40);
+    {
+        if(globaldata.send_ready==1)
+        {
+                globaldata.send_ready=0;
+                short idx=baselevel_send_data(globaldata.send_buffer,globaldata.send_length);
+                    globaldata.send_length_over=idx;
+                    globaldata.send_completed=1;    
+        }
+        
+        
+        threadled=!threadled;
+        Thread::wait(20);
     }
 }
 
+
 void recv_task(void const *args)
 {
+    
+    int lengthtemp;
     while(1)
     {
-        int b=0;
-        Thread::wait(40);
+        //recv_app();
+            if(globaldata.receive_start==1)
+    {
+            globaldata.receive_length=baselevel_receive_data(globaldata.receive_buffer,globaldata.need_receive);
+            if(globaldata.receive_length>0)
+            {
+                globaldata.receive_start=0;
+                globaldata.receive_completed=1;
+            }
     }
 
-}
\ No newline at end of file
+    
+        Thread::wait(20);
+    }
+
+}
diff -r 5f921ff0868d -r 242715d40e54 sysinterface.h
--- a/sysinterface.h	Fri Nov 28 12:52:56 2014 +0000
+++ b/sysinterface.h	Fri Dec 05 02:14:44 2014 +0000
@@ -2,8 +2,22 @@
 #define __SYSINTERFACE_H
 #include "mbed.h"
 #include "rtos.h"
-//#include "globaldata.h"
-//#include "baseinterface.h"
+#include "baseinterface.h"
+typedef struct publicdata{  
+    bool send_ready;
+    bool send_completed;
+    bool receive_completed;
+    short send_length;
+    short send_length_over;
+    char send_buffer[600];
+    char receive_buffer[600];
+    int receive_length;
+    int need_receive;
+    short need_send; 
+    bool receive_start;
+    bool readable;
+} PUBLICDATA;
+extern PUBLICDATA globaldata;
 void send_task(void const *args);
 void recv_task(void const *args);
 #define sys_thread_new(taskname,function)    Thread taskname(function)