Add two threads into the IOT WIFIDemo for test_JacobShi

Dependencies:   C12832 HTTPClient wifiontros wifirtos mbed

Fork of frdm_rtos by Freescale

Committer:
shiyilei
Date:
Fri Dec 05 02:14:44 2014 +0000
Revision:
4:242715d40e54
wifibasedonrtos

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shiyilei 4:242715d40e54 1 #include <algorithm>
shiyilei 4:242715d40e54 2 #include "baseinterface.h"
shiyilei 4:242715d40e54 3
shiyilei 4:242715d40e54 4 Wifly*wifi;
shiyilei 4:242715d40e54 5 /********************************************
shiyilei 4:242715d40e54 6 *function:wifi get instance
shiyilei 4:242715d40e54 7 *
shiyilei 4:242715d40e54 8 ********************************************/
shiyilei 4:242715d40e54 9 bool base_level_getinstance(void)
shiyilei 4:242715d40e54 10 {
shiyilei 4:242715d40e54 11 wifi=Wifly::getInstance();
shiyilei 4:242715d40e54 12 if (wifi == NULL)
shiyilei 4:242715d40e54 13 return 0;
shiyilei 4:242715d40e54 14 return 1;
shiyilei 4:242715d40e54 15 }
shiyilei 4:242715d40e54 16
shiyilei 4:242715d40e54 17 /***********************************
shiyilei 4:242715d40e54 18 *function: wifi close
shiyilei 4:242715d40e54 19 *
shiyilei 4:242715d40e54 20 **********************************/
shiyilei 4:242715d40e54 21 bool base_level_close()
shiyilei 4:242715d40e54 22 {
shiyilei 4:242715d40e54 23 return (wifi->close())?0:-1;
shiyilei 4:242715d40e54 24 }
shiyilei 4:242715d40e54 25
shiyilei 4:242715d40e54 26 /*************************
shiyilei 4:242715d40e54 27 *function:wifi connect
shiyilei 4:242715d40e54 28 *
shiyilei 4:242715d40e54 29 ************************/
shiyilei 4:242715d40e54 30 bool base_level_connect(const char* host, const int port)
shiyilei 4:242715d40e54 31 {
shiyilei 4:242715d40e54 32 if(!wifi->connect(host,port))
shiyilei 4:242715d40e54 33 return -1;
shiyilei 4:242715d40e54 34 wifi->flush();
shiyilei 4:242715d40e54 35 return 0;
shiyilei 4:242715d40e54 36 }
shiyilei 4:242715d40e54 37
shiyilei 4:242715d40e54 38 /*******************************
shiyilei 4:242715d40e54 39 *function:if wifi is connected?
shiyilei 4:242715d40e54 40 *
shiyilei 4:242715d40e54 41 *********************************/
shiyilei 4:242715d40e54 42 bool base_level_is_connected(void)
shiyilei 4:242715d40e54 43 {
shiyilei 4:242715d40e54 44 return wifi->is_connected();
shiyilei 4:242715d40e54 45 }
shiyilei 4:242715d40e54 46
shiyilei 4:242715d40e54 47 /*****************************
shiyilei 4:242715d40e54 48 *function:wifi send_data
shiyilei 4:242715d40e54 49 *
shiyilei 4:242715d40e54 50 ******************************/
shiyilei 4:242715d40e54 51 int baselevel_send_data(char *data,int length)
shiyilei 4:242715d40e54 52 {
shiyilei 4:242715d40e54 53 int idx =0;
shiyilei 4:242715d40e54 54 idx +=wifi->send(data, length);
shiyilei 4:242715d40e54 55 return idx;
shiyilei 4:242715d40e54 56 }
shiyilei 4:242715d40e54 57
shiyilei 4:242715d40e54 58 /********************************
shiyilei 4:242715d40e54 59 *function:receive_data
shiyilei 4:242715d40e54 60 *
shiyilei 4:242715d40e54 61 *
shiyilei 4:242715d40e54 62 ********************************/
shiyilei 4:242715d40e54 63 int baselevel_receive_data(char *data,int length)
shiyilei 4:242715d40e54 64 {
shiyilei 4:242715d40e54 65 //while(!wifi->readable());
shiyilei 4:242715d40e54 66 int idx=0;
shiyilei 4:242715d40e54 67 int nb_available = wifi->readable();
shiyilei 4:242715d40e54 68 for (int i = 0; i < min(nb_available, length); i++) {
shiyilei 4:242715d40e54 69 data[idx++] = wifi->getc();
shiyilei 4:242715d40e54 70 }
shiyilei 4:242715d40e54 71 return idx;
shiyilei 4:242715d40e54 72 }
shiyilei 4:242715d40e54 73 /****************************************
shiyilei 4:242715d40e54 74 *function:wifi->readable()
shiyilei 4:242715d40e54 75 *
shiyilei 4:242715d40e54 76 *****************************************/
shiyilei 4:242715d40e54 77 int baselevel_is_readable()
shiyilei 4:242715d40e54 78 {
shiyilei 4:242715d40e54 79 int nb_available=wifi->readable();
shiyilei 4:242715d40e54 80
shiyilei 4:242715d40e54 81 return nb_available;
shiyilei 4:242715d40e54 82 }