ARM Shanghai IoT Team (Internal) / Mbed 2 deprecated WifiaddThread

Dependencies:   C12832 HTTPClient wifiontros wifirtos mbed

Fork of frdm_rtos by Freescale

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers baseinterface.cpp Source File

baseinterface.cpp

00001 #include <algorithm>
00002 #include "baseinterface.h"
00003 
00004 Wifly*wifi;
00005 /********************************************
00006 *function:wifi get instance
00007 *
00008 ********************************************/
00009 bool base_level_getinstance(void)
00010 {
00011     wifi=Wifly::getInstance();
00012     if (wifi == NULL)
00013             return 0;
00014         return 1;
00015 }
00016 
00017 /***********************************
00018 *function: wifi close
00019 * 
00020 **********************************/
00021 bool base_level_close()
00022 {
00023     return (wifi->close())?0:-1;
00024 }
00025 
00026 /*************************
00027 *function:wifi connect
00028 *
00029 ************************/
00030 bool base_level_connect(const char* host, const int port)
00031 {
00032     if(!wifi->connect(host,port))
00033         return -1;
00034     wifi->flush();
00035             return 0;
00036 }
00037 
00038 /*******************************
00039 *function:if wifi is connected?
00040 *
00041 *********************************/
00042 bool base_level_is_connected(void)
00043 {
00044     return wifi->is_connected();
00045 }
00046 
00047 /*****************************
00048 *function:wifi send_data
00049 *
00050 ******************************/
00051 int baselevel_send_data(char *data,int length)
00052 {
00053         int idx =0;
00054         idx +=wifi->send(data, length);
00055       return idx;
00056 }
00057 
00058 /********************************
00059 *function:receive_data
00060 *
00061 * 
00062 ********************************/
00063 int baselevel_receive_data(char *data,int length)
00064 {
00065      //while(!wifi->readable());
00066 int idx=0;
00067     int nb_available = wifi->readable();
00068       for (int i = 0; i < min(nb_available, length); i++) {
00069        data[idx++] = wifi->getc();
00070             }   
00071         return idx;
00072 }
00073 /****************************************
00074 *function:wifi->readable()
00075 *
00076 *****************************************/
00077 int  baselevel_is_readable()
00078 {
00079         int nb_available=wifi->readable();
00080     
00081         return nb_available;
00082 }