emw3162 driver

Fork of emw3162-driver-mbed-os-5 by Maggie Mei

Revision:
2:fb6251306b21
Parent:
0:2d5090e1ceb4
--- a/emw3162/EMW3162.cpp	Fri Nov 04 02:14:19 2016 +0000
+++ b/emw3162/EMW3162.cpp	Mon Nov 14 02:30:49 2016 +0000
@@ -1,4 +1,4 @@
-/* ESP8266 Example
+/* EMW3162 Example
  * Copyright (c) 2015 ARM Limited
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +16,7 @@
 
 #include "EMW3162.h"
 
-ESP8266::ESP8266(PinName tx, PinName rx, bool debug)
+EMW3162::EMW3162(PinName tx, PinName rx, bool debug)
     : _serial(tx, rx, 1024), _parser(_serial)
     , _packets(0), _packets_end(&_packets)
 {
@@ -24,16 +24,16 @@
     _parser.debugOn(debug);
 }
 
-bool ESP8266::startup(void)
+bool EMW3162::startup(void)
 {
     bool success = reset("FACTORY");
 
-    _parser.oob("+EVENT=SOCKET", this, &ESP8266::_packet_handler);
+    _parser.oob("+EVENT=SOCKET", this, &EMW3162::_packet_handler);
 
     return success;
 }
 
-bool ESP8266::reset(const char *reset)
+bool EMW3162::reset(const char *reset)
 {
     for (int i = 0; i < 2; i++) {
         if (_parser.send("AT+%s", reset)
@@ -45,13 +45,13 @@
     return false;
 }
 
-bool ESP8266::dhcp(bool enabled)
+bool EMW3162::dhcp(bool enabled)
 {
     return _parser.send("AT+DHCP=%s", enabled ? "ON":"OFF")
         && _parser.recv("+OK");
 }
 
-bool ESP8266::connect(const char *ap, const char *passPhrase)
+bool EMW3162::connect(const char *ap, const char *passPhrase)
 {
     return _parser.send("AT+WSTA=%s,%s", ap, passPhrase)
         && _parser.recv("+OK")
@@ -60,7 +60,7 @@
         && _parser.recv("+EVENT=WIFI_LINK,STATION_UP");
 }
 
-bool ESP8266::disconnect(void)
+bool EMW3162::disconnect(void)
 {
     
     return _parser.send("AT+WLANF=STA,OFF")
@@ -70,7 +70,7 @@
         && _parser.recv("+OK");
 }
 
-const char *ESP8266::getIPAddress(void)
+const char *EMW3162::getIPAddress(void)
 {
     if (!(_parser.send("AT+IPCONFIG")
         && _parser.recv("%*[^,],%*[^,],%*[^,],%[^,]%*[^#]#", _ip_buffer))) {
@@ -80,7 +80,7 @@
     return _ip_buffer;
 }
 
-const char *ESP8266::getMACAddress(void)
+const char *EMW3162::getMACAddress(void)
 {
     if (!(_parser.send("AT+WMAC")
         && _parser.recv("%*[^=]=%[^#]#", _mac_buffer))) {
@@ -90,12 +90,12 @@
     return _mac_buffer;
 }
 
-bool ESP8266::isConnected(void)
+bool EMW3162::isConnected(void)
 {
     return getIPAddress() != 0;
 }
 
-int ESP8266::open(const char *type, int id, const char* addr, int port)
+int EMW3162::open(const char *type, int id, const char* addr, int port)
 {
     int state1 = 0, state2 = 0;
     state1 = _parser.send("AT+CON1=%s,%d,%d,%s", type, id, port, addr)
@@ -119,7 +119,7 @@
         return -1;
 }
 
-bool ESP8266::send(int id, const void *data, uint32_t amount)
+bool EMW3162::send(int id, const void *data, uint32_t amount)
 {
     //May take a second try if device is busy
     for (unsigned i = 0; i < 2; i++) {
@@ -135,7 +135,7 @@
     return false;
 }
 
-void ESP8266::_packet_handler()
+void EMW3162::_packet_handler()
 {
     int id;
     uint32_t amount;
@@ -165,7 +165,7 @@
     _packets_end = &packet->next;
 }
 
-int32_t ESP8266::recv(int id, void *data, uint32_t amount)
+int32_t EMW3162::recv(int id, void *data, uint32_t amount)
 {
     while (true) {
         // check if any packets are ready for us
@@ -202,7 +202,7 @@
     }
 }
 
-bool ESP8266::close(int id)
+bool EMW3162::close(int id)
 {
     //May take a second try if device is busy
     for (unsigned i = 0; i < 2; i++) {
@@ -219,22 +219,22 @@
     return false;
 }
 
-void ESP8266::setTimeout(uint32_t timeout_ms)
+void EMW3162::setTimeout(uint32_t timeout_ms)
 {
     _parser.setTimeout(timeout_ms);
 }
 
-bool ESP8266::readable()
+bool EMW3162::readable()
 {
     return _serial.readable();
 }
 
-bool ESP8266::writeable()
+bool EMW3162::writeable()
 {
     return _serial.writeable();
 }
 
-void ESP8266::attach(Callback<void()> func)
+void EMW3162::attach(Callback<void()> func)
 {
     _serial.attach(func);
 }