int rakmgr_open_cmdMode(void)
{
    int retval = RAK_SUCCESS;
    int retry_times = 0;
//  RAK_DEBUG_PORT_PIN=~RAK_DEBUG_PORT_PIN;

    if (rakmgr_module_work_mode == ASSIST_CMD_TYPE) {
        return retval;
    }
    
    while (1) {
        if (++ retry_times > 10) {
           retval = RAK_FAIL;
           break;
        }
        
        // Opening AT mode may get failed because unwanted network transmission can break in the process.
        // In every retry, purge all buffer data which should not appear in the process.
        rakmgr_uartbuf_init();
        rakmgr_sockdata_prg(-1);
        
        rak_UART_send((uint8_t *) RAK_OPEN_CMD_REQUEST, strlen(RAK_OPEN_CMD_REQUEST));
        rakmgr_sockdata_prg(-1);
        retval = rakmgr_sockdata_timeout(RAK_200MS_TIMEOUT, rakmgr_sockdata_poll_trn);
        if (retval < 0) {
            retval = RAK_SUCCESS;
            continue;
        }
        
        if (uCmdRspFrame.uCmdRspBuf[0] == RAK_ACK_FOR_REQUEST) {
            rak_UART_send((uint8_t *) RAK_CONFIRM_CMD_MODE, strlen(RAK_CONFIRM_CMD_MODE));
            rakmgr_sockdata_prg(-1);
            retval = rakmgr_sockdata_timeout(RAK_200MS_TIMEOUT, rakmgr_sockdata_poll_at_resp);
            if (retval < 0) {
                retval= RAK_SUCCESS;
                continue;
            }
            
            if (strncmp((char *) uCmdRspFrame.uCmdRspBuf, "OK", 2) == 0) {
                retval = RAK_SUCCESS;
                // FIXME
                rakmgr_module_work_mode = ASSIST_CMD_TYPE;
                break;
            }
            else {
                retval = RAK_SUCCESS;
                continue;
            }
        }
        else {
            retval = RAK_SUCCESS;
            continue;
        }
    }
//  RAK_DEBUG_PORT_PIN=~RAK_DEBUG_PORT_PIN;
    return retval;
}
 /*=============================================================================*/
int8 rak_query_constatus(void)
{
	int8	     retval=0;
	char rak_sendCmd[20]="";
	strcpy(rak_sendCmd,RAK_QUERY_CONSTATUS_CMD);
	strcat(rak_sendCmd,RAK_END);
    retval=rak_UART_send((uint8_t*)rak_sendCmd,strlen(rak_sendCmd));//发送打开模块命令接口请求
	return retval;
}
Exemplo n.º 3
0
 /*=============================================================================*/
int8 rak_copy_uConfig(void)
{
	int8	     retval=0;
	char rak_sendCmd[20]="";
	strcpy(rak_sendCmd,RAK_COPY_UCONFIG_CMD);
	strcat(rak_sendCmd,RAK_END);
    retval=rak_UART_send((uint8_t*)rak_sendCmd,strlen(rak_sendCmd));//发送打开模块命令接口请求
	return retval;
}
 /*=============================================================================*/
int8 rak_query_ipconifg(void)
{
	int8	     retval=0;
	char rak_sendCmd[20]="";
	strcpy(rak_sendCmd,RAK_QUERY_IPCONFIG_CMD);
	strcat(rak_sendCmd,RAK_END);
    retval=rak_UART_send((uint8_t*)rak_sendCmd,strlen(rak_sendCmd));//发送打开模块命令接口请求
	return retval;
}
 /*=============================================================================*/
int8 rak_read_restoreConfig(void)
{
	int8	     retval=0;
	char rak_sendCmd[30]="";
	strcpy(rak_sendCmd,RAK_READ_RCONFIG_CMD);
	strcat(rak_sendCmd,RAK_END);
    retval=rak_UART_send((uint8_t*)rak_sendCmd,strlen(rak_sendCmd));//发送打开模块命令接口请求
	return retval;
}
 /*=============================================================================*/
int8 rak_easy_txrxMode(void)
{
	int8	     retval=0;
	char rak_sendCmd[20]="";
	strcpy(rak_sendCmd,RAK_ENTER_EASYTXRX_CMD);
	strcat(rak_sendCmd,RAK_END);
    retval=rak_UART_send((uint8_t*)rak_sendCmd,strlen(rak_sendCmd));//发送打开模块命令接口请求
	return retval;
}
 /*=============================================================================*/
int8 rak_query_macaddr(void)
{
	int8	     retval=0;
	char rak_sendCmd[20]="";
	strcpy(rak_sendCmd,RAK_QUERY_MACADDR_CMD);
	strcat(rak_sendCmd,RAK_END);
    retval=rak_UART_send((uint8_t*)rak_sendCmd,strlen(rak_sendCmd));//发送打开模块命令接口请求
	return retval;
}
Exemplo n.º 8
0
int8 rak_write_restoreConfig(void)
{
	int8	retval=0;	
	char    rak_sendCmd[1000]="";
	char    rak_sendLenth[5]="";
	uint16  SendLength=0;
	uint16  SendHeadLen=0;
	uint16  WriteLength=0;
	uint16  AddLength=0;

	/**********模式 参数*************/
	AddLength=sprintf(rak_sendCmd,"%s%s%s",RAK_WLAN_MODE,RAK_AND,RAK_POWER_MODE);
	WriteLength+=AddLength;
	if(strcmp(RAK_WLAN_MODE, "wifi_mode=AP") == 0)
	{
	  /**********AP 参数*************/
	  AddLength=sprintf(&rak_sendCmd[WriteLength],"%s%s%s%s%s%s%s%s%s%s%s%s%s%s",RAK_AND,RAK_AP_SSID,
						                                 RAK_AND,RAK_AP_CHANNEL,
														 RAK_AND,RAK_AP_SECU_EN,
														 RAK_AND,RAK_AP_PSK,
														 RAK_AND,RAK_AP_IPADDR,
														 RAK_AND,RAK_AP_NETMASK,
														 RAK_AND,RAK_AP_BDCAST_EN
									                     );
	 WriteLength+=AddLength;
	}else
	{
	  /**********STA 参数*************/
	  AddLength=sprintf(&rak_sendCmd[WriteLength],"%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",RAK_AND,RAK_STA_SSID,
						                                 RAK_AND,RAK_STA_SECU_EN,
														 RAK_AND,RAK_STA_PSK,
														 RAK_AND,RAK_STA_DHCP_EN,
														 RAK_AND,RAK_STA_IPADDR,
														 RAK_AND,RAK_STA_NETMASK,
														 RAK_AND,RAK_STA_GATEWAY,
														 RAK_AND,RAK_STA_DNSS1,
														 RAK_AND,RAK_STA_DNSS2
									                     );
	 WriteLength+=AddLength;
	}
	/**********UART 参数*************/
	 AddLength=sprintf(&rak_sendCmd[WriteLength],"%s%s%s%s%s%s%s%s%s%s", RAK_AND,RAK_UART_BAUD,
						                                 RAK_AND,RAK_UART_DATALEN,
														 RAK_AND,RAK_UART_PARITYEN,
														 RAK_AND,RAK_UART_STOPLEN,
														 RAK_AND,RAK_UART_RTSCTSEN														
									                     );

	WriteLength+=AddLength;
	/**********Socket 参数*************/
	AddLength=sprintf(&rak_sendCmd[WriteLength],"%s%s",RAK_AND,RAK_SOCKET_BAUD);

	WriteLength+=AddLength;
	AddLength=sprintf(&rak_sendCmd[WriteLength],"%s%s%s%s%s%s%s%s%s%s",RAK_AND,RAK_SOCKETA_TYPE,
						                                 RAK_AND,RAK_SOCKETA_LPORT,
														 RAK_AND,RAK_SOCKETA_DESTIP,
														 RAK_AND,RAK_SOCKETA_DPORT,
														 RAK_AND,RAK_SOCKETA_TCPTIMEOUT														
									                     );
	 WriteLength+=AddLength;
	if(strcmp(RAK_SOCKET_BAUD, "socket_multi_en=1") == 0)
	{
	  AddLength=sprintf(&rak_sendCmd[WriteLength],"%s%s%s%s%s%s%s%s%s%s",RAK_AND,RAK_SOCKETB_TYPE,
						                                 RAK_AND,RAK_SOCKETB_LPORT,
														 RAK_AND,RAK_SOCKETB_DESTIP,
														 RAK_AND,RAK_SOCKETB_DPORT,
														 RAK_AND,RAK_SOCKETB_TCPTIMEOUT														
	 								                     );
	 WriteLength+=AddLength;
	}

	/**********Name 参数*************/
	AddLength=sprintf(&rak_sendCmd[WriteLength],"%s%s%s%s",RAK_AND,RAK_MODULE_NAME,RAK_AND,RAK_MODULE_GROUP);
   	WriteLength+=AddLength;

	/**********WEB 参数*************/
	AddLength=sprintf(&rak_sendCmd[WriteLength],"%s%s%s%s%s%s",RAK_AND,RAK_WEB_USERNAME,
	                                                           RAK_AND,RAK_WEB_PASSWORD,
															   RAK_AND,RAK_WEB_DLANGUAGE);
    WriteLength+=AddLength;

	/**********Function 选择*************/
    AddLength=sprintf(&rak_sendCmd[WriteLength],"%s%s%s%s%s%s",RAK_AND,RAK_WEB_FUNCEN,
	                                                           RAK_AND,RAK_UDP_FUNCEN,
															   RAK_AND,RAK_MODE_PIN
															   );
    WriteLength+=AddLength;

	//填充配置参数长度
	SendLength=WriteLength;
	sprintf(rak_sendLenth,"%d",SendLength);

	sprintf(&rak_sendCmd[WriteLength],"%s",RAK_END);

	SendHeadLen=sprintf((char *)uCmdRspFrame.uCmdRspBuf,"%s%s%s",RAK_WRITE_RCONFIG_CMD,rak_sendLenth,RAK_COMMA);

	sprintf((char *)&uCmdRspFrame.uCmdRspBuf[SendHeadLen],"%s",rak_sendCmd);

    retval=rak_UART_send(uCmdRspFrame.uCmdRspBuf,SendLength+SendHeadLen+2);//发送打开模块命令接口请求

	return retval;
}