SNIC UART Interface library: Serial to Wi-Fi library for Murata TypeYD Wi-Fi module. For more information about TypeYD: http://www.murata.co.jp/products/microwave/module/lbwb1zzydz/index.html
Dependents: SNIC-xively-jumpstart-demo SNIC-FluentLogger-example TCPEchoServer murataDemo ... more
Fork of YDwifiInterface by
Revision 31:15c22824cc46, committed 2014-05-29
- Comitter:
- kishino
- Date:
- Thu May 29 03:23:21 2014 +0000
- Parent:
- 30:944b8c04b5ff
- Child:
- 32:ae95309643aa
- Commit message:
- Created a command of IP address settings.
Changed in this revision
--- a/SNIC/SNIC_Core.h Tue May 27 01:33:04 2014 +0000
+++ b/SNIC/SNIC_Core.h Thu May 29 03:23:21 2014 +0000
@@ -109,6 +109,27 @@
unsigned char buf_size[2];
}tagSNIC_INIT_REQ_T;
+ /** SNIC_IP_CONFIG_REQ */
+ typedef struct
+ {
+ unsigned char cmd_sid;
+ unsigned char seq;
+ unsigned char interface;
+ unsigned char dhcp;
+ }tagSNIC_IP_CONFIG_REQ_DHCP_T;
+
+ /** SNIC_IP_CONFIG_REQ */
+ typedef struct
+ {
+ unsigned char cmd_sid;
+ unsigned char seq;
+ unsigned char interface;
+ unsigned char dhcp;
+ unsigned char ip_addr[4];
+ unsigned char netmask[4];
+ unsigned char gateway[4];
+ }tagSNIC_IP_CONFIG_REQ_STATIC_T;
+
/** SNIC_TCP_CREATE_SOCKET_REQ */
typedef struct
{
--- a/SNIC/SNIC_UartMsgUtil.cpp Tue May 27 01:33:04 2014 +0000
+++ b/SNIC/SNIC_UartMsgUtil.cpp Thu May 29 03:23:21 2014 +0000
@@ -141,4 +141,53 @@
}
return response_len;
+}
+
+int C_SNIC_UartMsgUtil::addrToInteger( const char *addr_p )
+{
+ if( addr_p == NULL )
+ {
+ printf("addrToInteger parameter error\r\n");
+ return 0;
+ }
+
+ unsigned char ipadr[4];
+ unsigned char temp= 0;
+ int i,j,k;
+
+ /* convert to char[4] */
+ k=0;
+ for(i=0; i<4; i ++)
+ {
+ for(j=0; j<4; j ++)
+ {
+ if((addr_p[k] > 0x2F)&&(addr_p[k] < 0x3A))
+ {
+ temp = (temp * 10) + addr_p[k]-0x30;
+ }
+ else if((addr_p[k] == 0x20)&&(temp == 0))
+ {
+ }
+ else
+ {
+ ipadr[i]=temp;
+ temp = 0;
+ k++;
+ break;
+ }
+ k++;
+ }
+ }
+
+ int addr = ( (ipadr[0]<<24) | (ipadr[1]<<16) | (ipadr[2]<<8) | ipadr[3] );
+
+ return addr;
+}
+
+void C_SNIC_UartMsgUtil::convertIntToByteAdday( int addr, char *addr_array_p )
+{
+ addr_array_p[0] = ((addr & 0xFF000000) >> 24 );
+ addr_array_p[1] = ((addr & 0xFF0000) >> 16 );
+ addr_array_p[2] = ((addr & 0xFF00) >> 8 );
+ addr_array_p[3] = ( addr & 0xFF);
}
\ No newline at end of file
--- a/SNIC/SNIC_UartMsgUtil.h Tue May 27 01:33:04 2014 +0000
+++ b/SNIC/SNIC_UartMsgUtil.h Thu May 29 03:23:21 2014 +0000
@@ -133,6 +133,7 @@
class C_SNIC_UartMsgUtil: public C_MurataObject
{
friend class C_SNIC_Core;
+friend class C_SNIC_WifiInterface;
private:
C_SNIC_UartMsgUtil();
@@ -164,6 +165,19 @@
*/
static unsigned int getResponsePayload( unsigned int recvdata_len, unsigned char *recvdata_p
, unsigned char *command_id_p, unsigned char *payload_p );
+
+ /** Convert a string to number of ip address.
+ @param recvdata_p Pointer of string of IP address
+ @return Number of ip address
+ */
+ static int addrToInteger( const char *addr_p );
+
+ /** Convert a integer to byte array of ip address.
+ @param recvdata_p Pointer of string of IP address
+ @return Number of ip address
+ */
+ static void convertIntToByteAdday( int addr, char *addr_array_p );
+
protected:
};
--- a/SNIC_WifiInterface.cpp Tue May 27 01:33:04 2014 +0000
+++ b/SNIC_WifiInterface.cpp Thu May 29 03:23:21 2014 +0000
@@ -559,3 +559,87 @@
snic_core_p->freeCmdBuf( payload_buf );
return 0;
}
+
+int C_SNIC_WifiInterface::setIPConfig( bool is_DHCP
+ , const char *ip_p, const char *mask_p, const char *gateway_p )
+{
+ // Parameter check
+ if( is_DHCP == false )
+ {
+ if( (ip_p == NULL) || (mask_p == NULL) ||(gateway_p == NULL) )
+ {
+ printf("setIPConfig parameter error\r\n");
+ return -1;
+ }
+ }
+
+ C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
+ C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
+
+ // Get buffer for response payload from MemoryPool
+ tagMEMPOOL_BLOCK_T *payload_buf = snic_core_p->allocCmdBuf();
+ if( payload_buf == NULL )
+ {
+ printf("setIPConfig payload_buf NULL\r\n");
+ return -1;
+ }
+
+ unsigned char *command_array = snic_core_p->getCommandBuf();
+ unsigned int command_len;
+ if( is_DHCP == true )
+ {
+ C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_DHCP_T req;
+ // Make request
+ req.cmd_sid = UART_CMD_SID_SNIC_IP_CONFIG_REQ;
+ req.seq = mUartRequestSeq++;
+ req.interface = 0;
+ req.dhcp = 1;
+
+ // Preparation of command
+ command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
+ , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_DHCP_T), payload_buf->buf, command_array );
+ }
+ else
+ {
+ C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_STATIC_T req;
+ // Make request
+ req.cmd_sid = UART_CMD_SID_SNIC_IP_CONFIG_REQ;
+ req.seq = mUartRequestSeq++;
+ req.interface = 0;
+ req.dhcp = 0;
+
+ // Set paramter of address
+ int addr_temp;
+ addr_temp = C_SNIC_UartMsgUtil::addrToInteger( ip_p );
+ C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.ip_addr );
+ addr_temp = C_SNIC_UartMsgUtil::addrToInteger( mask_p );
+ C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.netmask );
+ addr_temp = C_SNIC_UartMsgUtil::addrToInteger( gateway_p );
+ C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.gateway );
+
+ // Preparation of command
+ command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
+ , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_STATIC_T), payload_buf->buf, command_array );
+ }
+ // Send uart command request
+ snic_core_p->sendUart( command_len, command_array );
+
+ int ret;
+ // Wait UART response
+ ret = uartCmdMgr_p->wait();
+ if( ret != 0 )
+ {
+ printf( "setIPConfig failed\r\n" );
+ snic_core_p->freeCmdBuf( payload_buf );
+ return -1;
+ }
+
+ if( uartCmdMgr_p->getCommandStatus() != 0 )
+ {
+ printf("setIPConfig status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
+ ret = -1;
+ }
+
+ snic_core_p->freeCmdBuf( payload_buf );
+ return 0;
+}
--- a/SNIC_WifiInterface.h Tue May 27 01:33:04 2014 +0000
+++ b/SNIC_WifiInterface.h Thu May 29 03:23:21 2014 +0000
@@ -30,6 +30,7 @@
/** Interface class for using SNIC UART.
*/
class C_SNIC_WifiInterface : public C_MurataObject {
+
public:
/** Constructor
@param tx mbed pin to use for tx line of Serial interface
@@ -121,27 +122,16 @@
*/
int getWifiStatus( tagWIFI_STATUS_T *status_p);
-#if 0
- /** 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
+ /** Set IP configuration
+ @param is_DHCP true:DHCP false:static IP.
+ @param ip_p Pointer of strings of IP address.(null terminate).
+ @param mask_p Pointer of strings of Netmask.(null terminate).
+ @param gateway_p Pointer of strings of gateway address.(null terminate).
+ @return 0 on success, a negative number on failure
+ @note This function is blocked until a returns.
+ When you use it by UI thread, be careful.
+ */
+ int setIPConfig( bool is_DHCP, const char *ip_p=NULL, const char *mask_p=NULL, const char *gateway_p=NULL );
private:
PinName mUART_tx;
--- a/Socket/Socket.cpp Tue May 27 01:33:04 2014 +0000
+++ b/Socket/Socket.cpp Thu May 29 03:23:21 2014 +0000
@@ -170,47 +170,6 @@
return 0;
}
-int Socket::addrToInteger( const char *addr_p )
-{
- if( addr_p == NULL )
- {
- printf("addrToInteger parameter error\r\n");
- return 0;
- }
-
- unsigned char ipadr[4];
- unsigned char temp= 0;
- int i,j,k;
-
- /* convert to char[4] */
- k=0;
- for(i=0; i<4; i ++)
- {
- for(j=0; j<4; j ++)
- {
- if((addr_p[k] > 0x2F)&&(addr_p[k] < 0x3A))
- {
- temp = (temp * 10) + addr_p[k]-0x30;
- }
- else if((addr_p[k] == 0x20)&&(temp == 0))
- {
- }
- else
- {
- ipadr[i]=temp;
- temp = 0;
- k++;
- break;
- }
- k++;
- }
- }
-
- int addr = ( (ipadr[0]<<24) | (ipadr[1]<<16) | (ipadr[2]<<8) | ipadr[3] );
-
- return addr;
-}
-
int Socket::resolveHostName( const char *host_p )
{
C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
--- a/Socket/Socket.h Tue May 27 01:33:04 2014 +0000
+++ b/Socket/Socket.h Thu May 29 03:23:21 2014 +0000
@@ -80,8 +80,6 @@
int createSocket( unsigned char bind = 0, unsigned int local_addr = 0, unsigned short port = 0 );
protected:
- int addrToInteger( const char *addr_p );
-
int resolveHostName( const char *host_p );
protected:
muRata

Murata TypeYD