for EthernetInterface library compatibility.\\ ** Unoffical fix. may be a problem. **
Dependents: SNIC-httpclient-example SNIC-ntpclient-example
Fork of SNICInterface by
Revision 0:61c402886fbb, committed 2014-03-06
- Comitter:
- kishino
- Date:
- Thu Mar 06 11:13:00 2014 +0000
- Child:
- 1:c6e5f49dce5f
- Commit message:
- The common method which creates a UART command request was created.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/YDwifi/YDwifi.cpp Thu Mar 06 11:13:00 2014 +0000
@@ -0,0 +1,67 @@
+#include "mbed.h"
+#include "YDwifi.h"
+#include "YDwifi_uartmsg.h"
+#include <string>
+//#include <algorithm>
+
+C_YDwifi *C_YDwifi::mInstance_p;
+
+C_YDwifi::C_YDwifi(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud):
+ mUart(tx, rx), mModuleReset(reset)
+{
+ mUartRecvThread_p = NULL;
+ mInstance_p = this;
+ mUartRequestSeq = 0;
+
+ printf("baud:%d\r\n", baud);
+ mUart.baud( baud );
+}
+
+int C_YDwifi::initUart()
+{
+ // Create UART recv thread
+ mUartRecvThread_p = new Thread( C_YDwifi::uartRecvThread );
+ if( mUartRecvThread_p == NULL )
+ {
+ printf("[C_YDwifi::initUart] thread cread failed\r\n");
+ return -1;
+ }
+
+ // set intr callback function
+ mUart.attach( this, &C_YDwifi::uartIntr_callback, Serial::RxIrq );
+
+ return 0;
+}
+
+void C_YDwifi::uartIntr_callback( void )
+{
+#if 0
+ C_YDwifi *instance = C_YDwifi::getInstance();
+ instance->mUart.putc('G');
+ instance->mUartRecvThread_p->signal_set(1);
+#else
+ mUart.putc('G');
+ mUartRecvThread_p->signal_set(1);
+#endif
+}
+
+void C_YDwifi::uartRecvThread (void const *args_p) {
+ C_YDwifi *instance_p = C_YDwifi::getInstance();
+ if ( instance_p == NULL )
+ {
+ printf("Socket constructor error: no wifly instance available!\r\n");
+ }
+
+ int recvdata = 0;
+ printf("uartRecvThread\r\n");
+
+ /* UART recv thread main loop */
+ for (;;)
+ {
+ Thread::signal_wait(1);
+// wait(0.1);
+ recvdata = instance_p->mUart.getc();
+ printf( "[thread]%02x\r\n", recvdata );
+ }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/YDwifi/YDwifi.h Thu Mar 06 11:13:00 2014 +0000
@@ -0,0 +1,58 @@
+#ifndef _YD_WIFI_H_
+#define _YD_WIFI_H_
+
+#include "mbed.h"
+#include "rtos.h"
+#include "RawSerial.h"
+//#include "CBuffer.h"
+
+/** C_YDwifi class
+ */
+class C_YDwifi
+{
+
+public:
+ /** Wi-Fi security
+ */
+ typedef enum SECURITY {
+ e_SEC_OPEN = 0x00,
+ e_SEC_WEP = 0x01,
+ e_SEC_WPA_TKIP = 0x02,
+ e_SEC_WPA2_AES = 0x04,
+ e_SEC_WPA2_MIXED = 0x06,
+ e_SEC_WPA_AES = 0x07
+ }E_SECURITY;
+
+ // ----- YDwifi.cpp -----
+ /** Constructor
+ * \param tx mbed pin to use for tx line of Serial interface
+ * \param rx mbed pin to use for rx line of Serial interface
+ * \param cts mbed pin to use for cts line of Serial interface
+ * \param rts mbed pin to use for rts line of Serial interface
+ * \param reset reset pin of the wifi module
+ * \param alarm alarm pin of the wifi module
+ * \param baud baud rate of Serial interface
+ */
+ C_YDwifi (PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud);
+
+ int initUart();
+
+ static C_YDwifi * getInstance() {
+ return mInstance_p;
+ };
+ Thread *mUartRecvThread_p;
+
+protected:
+ static C_YDwifi *mInstance_p;
+
+ Mutex mUartMutex;
+// RawSerial mUart;
+ Serial mUart;
+ DigitalInOut mModuleReset;
+
+ /* Function */
+ void uartIntr_callback( void );
+ static void uartRecvThread( void const *args_p );
+};
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/YDwifi/YDwifi_uartmsg.cpp Thu Mar 06 11:13:00 2014 +0000
@@ -0,0 +1,80 @@
+#include "YDwifi_uartmsg.h"
+
+C_YD_UartMsg::C_YD_UartMsg()
+{
+}
+
+unsigned short C_YD_UartMsg::makePayload( unsigned int cmd_len, unsigned char *cmd_p, unsigned char *payload_p )
+{
+ unsigned short payload_len = 0;
+ int i;
+
+ for( i = 0; i < cmd_len; i++, payload_p++, payload_len++ )
+ {
+ /* check Escape code */
+ if( ( cmd_p[i] == UART_CMD_SOM ) || ( cmd_p[i] == UART_CMD_EOM ) || ( cmd_p[i] == UART_CMD_ESC ) )
+ {
+ /* Add ESC */
+ *payload_p = UART_CMD_ESC;
+ payload_len++;
+
+ payload_p++;
+ *payload_p = (0x80 | cmd_p[i]);
+ }
+ else
+ {
+ *payload_p = cmd_p[i];
+ }
+ }
+
+ return payload_len;
+}
+
+unsigned int C_YD_UartMsg::makeRequest( unsigned char cmd_id,unsigned char *payload_p
+ , unsigned short payload_len, unsigned char *uart_command_p )
+{
+ unsigned char check_sum = 0; // Check Sum
+ unsigned int uart_cmd_len = 0;
+ int i;
+
+ // set SOM
+ *uart_command_p = UART_CMD_SOM;
+ uart_command_p++;
+ uart_cmd_len++;
+
+ // set payload length L0
+ *uart_command_p = (0x80 | (payload_len & 0x007f));
+ check_sum += *uart_command_p;
+ uart_command_p++;
+ uart_cmd_len++;
+
+ // set payload length L1
+ *uart_command_p = (0x80 | ( (payload_len >> 7) & 0x003f));
+ check_sum += *uart_command_p;
+ uart_command_p++;
+ uart_cmd_len++;
+
+ // set Command ID
+ *uart_command_p = (0x80 | cmd_id);
+ check_sum += *uart_command_p;
+ uart_command_p++;
+ uart_cmd_len++;
+
+ // set Payload
+ for( i = 0; i < payload_len; i++, uart_command_p++, uart_cmd_len++ )
+ {
+ *uart_command_p = payload_p[i];
+ check_sum += *uart_command_p;
+ }
+
+ // set Check sum
+ *uart_command_p = (0x80 | check_sum);
+ uart_command_p++;
+ uart_cmd_len++;
+
+ // set EOM
+ *uart_command_p = UART_CMD_EOM;
+ uart_cmd_len++;
+
+ return uart_cmd_len;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/YDwifi/YDwifi_uartmsg.h Thu Mar 06 11:13:00 2014 +0000
@@ -0,0 +1,104 @@
+#ifndef _YD_WIFI_UART_MSG_H_
+#define _YD_WIFI_UART_MSG_H_
+
+#include "mbed.h"
+#include "rtos.h"
+#include "RawSerial.h"
+
+#define UART_CMD_SOM 0x02
+#define UART_CMD_EOM 0x04
+#define UART_CMD_ESC 0x10
+
+/* SNIC UART Command ID */
+#define UART_CMD_ID_GEN 0x01 //General command
+#define UART_CMD_ID_WIFI 0x50 //Wi-Fi command
+
+/* SNIC UART Subcommand ID */
+#define UART_CMD_SID_GEN_PWR_UP_IND 0x00 //Power up indication
+#define UART_CMD_SID_GEN_FW_VER_GET_REQ 0x08 //Get firmware version string
+
+#define UART_CMD_SID_WIFI_ON_REQ 0x00 // Turn on Wifi
+#define UART_CMD_SID_WIFI_OFF_REQ 0x01 // Turn off Wifi
+#define UART_CMD_SID_WIFI_JOIN_REQ 0x02 // Associate to a network
+#define UART_CMD_SID_WIFI_DISCONNECT_REQ 0x03 // Disconnect from a network
+#define UART_CMD_SID_WIFI_GET_STATUS_REQ 0x04 // Get WiFi status
+#define UART_CMD_SID_WIFI_SCAN_REQ 0x05 // Scan WiFi networks
+#define UART_CMD_SID_WIFI_GET_STA_RSSI_REQ 0x06 // Get STA signal strength (RSSI)
+#define UART_CMD_SID_WIFI_AP_CTRL_REQ 0x07 // Soft AP on-off control
+#define UART_CMD_SID_WIFI_WPS_REQ 0x08 // Start WPS process
+#define UART_CMD_SID_WIFI_AP_GET_CLIENT_REQ 0x0A // Get clients that are associated to the soft AP.
+#define UART_CMD_SID_WIFI_NETWORK_STATUS_IND 0x10 // Network status indication
+#define UART_CMD_SID_WIFI_SCAN_RESULT_IND 0x11 // Scan result indication
+
+/* SNIC UART Command response status code */
+#define UART_CMD_RES_SNIC_SUCCESS 0x00
+#define UART_CMD_RES_SNIC_FAIL 0x01
+#define UART_CMD_RES_SNIC_INIT_FAIL 0x02
+#define UART_CMD_RES_SNIC_CLEANUP_FAIL 0x03
+#define UART_CMD_RES_SNIC_GETADDRINFO_FAIL 0x04
+#define UART_CMD_RES_SNIC_CREATE_SOCKET_FAIL 0x05
+#define UART_CMD_RES_SNIC_BIND_SOCKET_FAIL 0x06
+#define UART_CMD_RES_SNIC_LISTEN_SOCKET_FAIL 0x07
+#define UART_CMD_RES_SNIC_ACCEPT_SOCKET_FAIL 0x08
+#define UART_CMD_RES_SNIC_PARTIAL_CLOSE_FAIL 0x09
+#define UART_CMD_RES_SNIC_SOCKET_PARTIALLY_CLOSED 0x0A
+#define UART_CMD_RES_SNIC_SOCKET_CLOSED 0x0B
+#define UART_CMD_RES_SNIC_CLOSE_SOCKET_FAIL 0x0C
+#define UART_CMD_RES_SNIC_PACKET_TOO_LARGE 0x0D
+#define UART_CMD_RES_SNIC_SEND_FAIL 0x0E
+#define UART_CMD_RES_SNIC_CONNECT_TO_SERVER_FAIL 0x0F
+#define UART_CMD_RES_SNIC_NOT_ENOUGH_MEMORY 0x10
+#define UART_CMD_RES_SNIC_TIMEOUT 0x11
+#define UART_CMD_RES_SNIC_CONNECTION_UP 0x12
+#define UART_CMD_RES_SNIC_GETSOCKOPT_FAIL 0x13
+#define UART_CMD_RES_SNIC_SETSOCKOPT_FAIL 0x14
+#define UART_CMD_RES_SNIC_INVALID_ARGUMENT 0x15
+#define UART_CMD_RES_SNIC_SEND_ARP_FAIL 0x16
+#define UART_CMD_RES_SNIC_INVALID_SOCKET 0x17
+#define UART_CMD_RES_SNIC_COMMAND_PENDING 0x18
+#define UART_CMD_RES_SNIC_SOCKET_NOT_BOUND 0x19
+#define UART_CMD_RES_SNIC_SOCKET_NOT_CONNECTED 0x1A
+#define UART_CMD_RES_SNIC_NO_NETWORK 0x20
+#define UART_CMD_RES_SNIC_INIT_NOT_DONE 0x21
+#define UART_CMD_RES_SNIC_NET_IF_FAIL 0x22
+#define UART_CMD_RES_SNIC_NET_IF_NOT_UP 0x23
+#define UART_CMD_RES_SNIC_DHCP_START_FAIL 0x24
+
+#define UART_CMD_RES_WIFI_SUCCESS 0x00
+#define UART_CMD_RES_WIFI_ERR_UNKNOWN_COUNTRY 0x01
+#define UART_CMD_RES_WIFI_ERR_INIT_FAIL 0x02
+#define UART_CMD_RES_WIFI_ERR_ALREADY_JOINED 0x03
+#define UART_CMD_RES_WIFI_ERR_AUTH_TYPE 0x04
+#define UART_CMD_RES_WIFI_ERR_JOIN_FAIL 0x05
+#define UART_CMD_RES_WIFI_ERR_NOT_JOINED 0x06
+#define UART_CMD_RES_WIFI_ERR_LEAVE_FAILED 0x07
+#define UART_CMD_RES_WIFI_COMMAND_PENDING 0x08
+#define UART_CMD_RES_WIFI_WPS_NO_CONFIG 0x09
+#define UART_CMD_RES_WIFI_NETWORK_UP 0x10
+#define UART_CMD_RES_WIFI_NETWORK_DOWN 0x11
+#define UART_CMD_RES_WIFI_FAIL 0xFF
+
+/** UART Command sequence number
+*/
+static unsigned char mUartRequestSeq;
+
+/** C_YD_UartMsg class
+ */
+class C_YD_UartMsg
+{
+
+public:
+ C_YD_UartMsg();
+
+ /** Make SNIC UART command payload.
+ */
+ static unsigned short makePayload( unsigned int cmd_len, unsigned char *cmd_p, unsigned char *payload_p );
+
+ /** Make SNIC UART command.
+ */
+ static unsigned int makeRequest( unsigned char cmd_id,unsigned char *payload_p, unsigned short payload_len, unsigned char *uart_command_p );
+
+protected:
+
+};
+#endif /* _YD_WIFI_UART_MSG_H_ */
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/YDwifiInterface.cpp Thu Mar 06 11:13:00 2014 +0000
@@ -0,0 +1,14 @@
+#include "YDwifiInterface.h"
+
+
+C_YDwifiInterface::C_YDwifiInterface( PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud):
+ C_YDwifi(tx, rx, cts, rts, reset, alarm, baud)
+{
+}
+
+int C_YDwifiInterface::init()
+{
+ /* Initialize UART */
+ initUart();
+ return 0;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/YDwifiInterface.h Thu Mar 06 11:13:00 2014 +0000
@@ -0,0 +1,67 @@
+#ifndef _YD_WIFIINTERFACE_H_
+#define _YD_WIFIINTERFACE_H_
+
+#include "YDwifi.h"
+
+class C_YDwifiInterface: public C_YDwifi {
+public:
+
+ /**
+ * Constructor
+ *
+ * \param tx mbed pin to use for tx line of Serial interface
+ * \param rx mbed pin to use for rx line of Serial interface
+ * \param cts mbed pin to use for cts line of Serial interface
+ * \param rts mbed pin to use for rts line of Serial interface
+ * \param reset reset pin of the wifi module
+ * \param alarm alarm pin of the wifi module (default: NC)
+ * \param baud baud rate of Serial interface (default: 9600)
+ */
+ C_YDwifiInterface(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm = NC, int baud = 9600);
+
+ /** Initialize the interface with DHCP.
+ * Initialize the interface and configure it to use DHCP (no connection at this point).
+ * \return 0 on success, a negative number on failure
+ */
+ int init();
+
+#if 0
+ /** Connect
+ * Bring the interface up, start DHCP if needed.
+ * \param sec the Wi-Fi security type
+ * \param ssid the Wi-Fi SSID
+ * \param phrase the Wi-Fi passphrase or security key
+ * \param mode the Wi-Fi mode
+ * \return 0 on success, a negative number on failure
+ */
+ int connect(Security sec, const char* ssid, const char* phrase, WiFiMode mode = WM_INFRASTRUCTURE);
+
+ /** Disconnect
+ * Bring the interface down
+ * \return 0 on success, a negative number on failure
+ */
+ int disconnect();
+
+ /** Get the MAC address of your Ethernet interface
+ * \return a pointer to a string containing the MAC address
+ */
+ char* getMACAddress();
+
+ /** Get the IP address of your Ethernet interface
+ * \return a pointer to a string containing the IP address
+ */
+ char* getIPAddress();
+
+ /** Get the Gateway address of your Ethernet interface
+ * \return a pointer to a string containing the Gateway address
+ */
+ char* getGateway();
+
+ /** Get the Network mask of your Ethernet interface
+ * \return a pointer to a string containing the Network mask
+ */
+ char* getNetworkMask();
+#endif
+};
+
+#endif /* _YD_WIFIINTERFACE_H_ */
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Thu Mar 06 11:13:00 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#f88660a9bed1
ban4jp -
