예제 #1
0
// test :AT+TEST=1,"abc"<,3>
void ICACHE_FLASH_ATTR
at_setupCmdTest(uint8_t id, char *pPara)
{
    int result = 0, err = 0, flag = 0;
    uint8 buffer[32] = {0};
    pPara++; // skip '='

    //get the first parameter
    // digit
    flag = at_get_next_int_dec(&pPara, &result, &err);

    // flag must be ture because there are more parameter
    if (flag == FALSE) {
        at_response_error();
        return;
    }

    if (*pPara++ != ',') { // skip ','
        at_response_error();
        return;
    }

    os_sprintf(buffer, "the first parameter:%d\r\n", result);
    at_port_print(buffer);

    //get the second parameter
    // string
    at_data_str_copy(buffer, &pPara, 10);
    at_port_print("the second parameter:");
    at_port_print(buffer);
    at_port_print("\r\n");

    if (*pPara == ',') {
        pPara++; // skip ','
        result = 0;
        //there is the third parameter
        // digit
        flag = at_get_next_int_dec(&pPara, &result, &err);
        // we donot care of flag
        os_sprintf(buffer, "the third parameter:%d\r\n", result);
        at_port_print(buffer);
    }

    if (*pPara != '\r') {
        at_response_error();
        return;
    }

    at_response_ok();
}
예제 #2
0
void ICACHE_FLASH_ATTR
at_queryCmdNTP(uint8_t id)
{
    uint8 buffer[255] = {0};
    time_t tim = (time_t)sntp_get_current_timestamp();
    struct tm *t;
    if (tim > 0) {
	t = localtime(&tim);
	os_sprintf(buffer, "NTP Time: %02d:%02d:%02d %02d.%02d.%04d %s (%d)sec\r\n", t->tm_hour,t->tm_min, t->tm_sec, t->tm_mday, t->tm_mon + 1, t->tm_year + 1900, weekday[t->tm_wday], tim);
	at_port_print(buffer);
	at_response_ok();
    } else {
	os_sprintf(buffer, "NTP Error: (0)\r\n");
	at_port_print(buffer);
	at_response_error();
    }
}
예제 #3
0
static inline int at_response (pvt_t* pvt, int iovcnt, at_res_t at_res)
{
	char*		str;
	size_t		len;
	at_queue_t*	e;

	if (iovcnt > 0)
	{
		len = pvt->d_read_iov[0].iov_len + pvt->d_read_iov[1].iov_len - 1;

		if (iovcnt == 2)
		{
			ast_debug (5, "[%s] iovcnt == 2\n", pvt->id);

			if (len > sizeof (pvt->d_parse_buf) - 1)
			{
				ast_debug (1, "[%s] buffer overflow\n", pvt->id);
				return -1;
			}

			str = pvt->d_parse_buf;

			memmove (str,					pvt->d_read_iov[0].iov_base, pvt->d_read_iov[0].iov_len);
			memmove (str + pvt->d_read_iov[0].iov_len,	pvt->d_read_iov[1].iov_base, pvt->d_read_iov[1].iov_len);
		}
		else
		{
			str = pvt->d_read_iov[0].iov_base;
		}

		str[len] = '\0';

//		ast_debug (5, "[%s] [%.*s]\n", pvt->id, (int) len, str);

		switch (at_res)
		{
			case RES_BOOT:
			case RES_CONF:
			case RES_CSSI:
			case RES_CSSU:
			case RES_RING:
			case RES_SRVST:
				break;

			case RES_OK:
				return at_response_ok (pvt);

			case RES_RSSI:
				return at_response_rssi (pvt, str, len);

			case RES_MODE:
				/* An error here is not fatal. Just keep going. */
				at_response_mode (pvt, str, len);
				break;

			case RES_ORIG:
				return at_response_orig (pvt, str, len);

			case RES_CEND:
				return at_response_cend (pvt, str, len);

			case RES_CONN:
				return at_response_conn (pvt);

			case RES_CREG:
				/* An error here is not fatal. Just keep going. */
				at_response_creg (pvt, str, len);
				break;

			case RES_COPS:
				/* An error here is not fatal. Just keep going. */
				at_response_cops (pvt, str, len);
				break;



			case RES_CSQ:
				return at_response_csq (pvt, str, len);

			case RES_CMS_ERROR:
			case RES_ERROR:
				return at_response_error (pvt);

			case RES_SMMEMFULL:
				return at_response_smmemfull (pvt);

			case RES_CLIP:
				return at_response_clip (pvt, str, len);

			case RES_CMTI:
				return at_response_cmti (pvt, str, len);

			case RES_CMGR:
				return at_response_cmgr (pvt, str, len);

			case RES_SMS_PROMPT:
				return at_response_sms_prompt (pvt);

			case RES_CUSD:
				return at_response_cusd (pvt, str, len);

			case RES_BUSY:
				return at_response_busy (pvt);

			case RES_NO_DIALTONE:
				return at_response_no_dialtone (pvt);

			case RES_NO_CARRIER:
				return at_response_no_carrier (pvt);

			case RES_CPIN:
				return at_response_cpin (pvt, str, len);

			case RES_CNUM:
				/* An error here is not fatal. Just keep going. */
				at_response_cnum (pvt, str, len);
				break;

			case RES_PARSE_ERROR:
				ast_log (LOG_ERROR, "[%s] Error parsing result\n", pvt->id);
				return -1;

			case RES_UNKNOWN:
				if ((e = at_fifo_queue_head (pvt)))
				{
					switch (e->cmd)
					{
						case CMD_AT_CGMI:
							ast_debug (1, "[%s] Got AT_CGMI data (manufacturer info)\n", pvt->id);
							return at_response_cgmi (pvt, str, len);

						case CMD_AT_CGMM:
							ast_debug (1, "[%s] Got AT_CGMM data (model info)\n", pvt->id);
							return at_response_cgmm (pvt, str, len);

						case CMD_AT_CGMR:
							ast_debug (1, "[%s] Got AT+CGMR data (firmware info)\n", pvt->id);
							return at_response_cgmr (pvt, str, len);

						case CMD_AT_CGSN:
							ast_debug (1, "[%s] Got AT+CGSN data (IMEI number)\n", pvt->id);
							return at_response_cgsn (pvt, str, len);

						case CMD_AT_CIMI:
							ast_debug (1, "[%s] Got AT+CIMI data (IMSI number)\n", pvt->id);
							return at_response_cimi (pvt, str, len);

						default:
							ast_debug (1, "[%s] Ignoring unknown result: '%.*s'\n", pvt->id, (int) len, str);
							break;
					}
				}
				else
				{
					ast_debug (1, "[%s] Ignoring unknown result: '%.*s'\n", pvt->id, (int) len, str);
				}

				break;
		}
	}

	return 0;
}
예제 #4
0
int CardDevice::at_response(char* str, at_res_t at_res)
{
    size_t len = strlen(str);

    switch(at_res)
    {
	case RES_BOOT:
	case RES_CONF:
	case RES_CSSI:
	case RES_CSSU:
	case RES_SRVST:
	    return 0;

	case RES_OK:
	    return at_response_ok();

	case RES_RSSI:
	    return at_response_rssi(str, len);

	case RES_MODE:
	    /* An error here is not fatal. Just keep going. */
	    at_response_mode(str, len);
	    return 0;

	case RES_ORIG:
	    return at_response_orig(str, len);

	case RES_CEND:
	    return at_response_cend(str, len);

	case RES_CONN:
	    return at_response_conn(str, len);

	case RES_CREG:
	    /* An error here is not fatal. Just keep going. */
	    at_response_creg(str, len);
	    return 0;

	case RES_COPS:
	    /* An error here is not fatal. Just keep going. */
	    at_response_cops(str, len);
	    return 0;

	case RES_CSQ:
	    return at_response_csq(str, len);

	case RES_CMS_ERROR:
	case RES_ERROR:
	    return at_response_error();

	case RES_RING:
	    return at_response_ring();

	case RES_SMMEMFULL:
	    return at_response_smmemfull();

	case RES_CLIP:
	    return at_response_clip(str, len);

	case RES_CMTI:
	    return at_response_cmti(str, len);

	case RES_CMGR:
	    return at_response_cmgr(str, len);

	case RES_SMS_PROMPT:
	    return at_response_sms_prompt();

	case RES_CUSD:
	    return at_response_cusd(str, len);

	case RES_BUSY:
	    return at_response_busy();

	case RES_NO_DIALTONE:
	    return at_response_no_dialtone();

	case RES_NO_CARRIER:
	    return at_response_no_carrier();

	case RES_CPIN:
	    return at_response_cpin(str, len);

	case RES_CNUM:
	    /* An error here is not fatal. Just keep going. */
	    at_response_cnum(str, len);
	    return 0;

	case RES_PARSE_ERROR:
	    Debug(DebugAll, "[%s] Error parsing result", c_str());
	    return -1;

	case RES_UNKNOWN:
	    if (m_lastcmd)
	    {
		switch(m_lastcmd->m_cmd)
		{
		    case CMD_AT_CGMI:
			Debug(DebugAll,  "[%s] Got AT_CGMI data (manufacturer info)", c_str());
			return at_response_cgmi(str, len);
		    case CMD_AT_CGMM:
			Debug(DebugAll,  "[%s] Got AT_CGMM data (model info)", c_str());
			return at_response_cgmm(str, len);
		    case CMD_AT_CGMR:
			Debug(DebugAll,  "[%s] Got AT+CGMR data (firmware info)", c_str());
			return at_response_cgmr(str, len);
		    case CMD_AT_CGSN:
			Debug(DebugAll,  "[%s] Got AT+CGSN data (IMEI number)", c_str());
			return at_response_cgsn (str, len);
		    case CMD_AT_CIMI:
			Debug(DebugAll,  "[%s] Got AT+CIMI data (IMSI number)", c_str());
			return at_response_cimi(str, len);
		    case CMD_AT_CMGR:
			Debug(DebugAll,  "[%s] Got AT+CMGR data (SMS PDU data)", c_str());
			return at_response_pdu(str, len);
		    default:
			Debug(DebugAll, "[%s] Ignoring unknown result: '%.*s'", c_str(), (int) len, str);
			break;
		}
	    }
	    else
	    {
		Debug(DebugAll, "[%s] Ignoring unknown result: '%.*s'", c_str(), (int) len, str);
	    }
	    break;
	}
	return 0;
}
// pinMode([pin], [direction])
void ICACHE_FLASH_ATTR
at_setupPinModeCmd(uint8_t id, char *pPara)
{
    int result = 0, err = 0, flag = 0;
    uint8 buffer[32] = {0};
    pPara++; // skip '='

    //get the first parameter (uint8_t)
    // digit
    flag = at_get_next_int_dec(&pPara, &result, &err);

    // flag must be true because there are more parameters
    if ((flag == FALSE) && (result > 0) )
	{
        at_response_error();
        return;
    }
	
	uint8_t pin = result;
	
	// Don't go any further if the pin is un-usable or non-existant
	if (!pinValid(pin))
	{
		at_response_error();
		return;
	}
	
	if (*pPara++ != ',') { // skip ','
		at_response_error();
		return;
	}
	
	char mode = *pPara++;
	
	if ((mode == 'i') || (mode == 'I'))
	{
		if (pin == STATUS_LED_PIN)
		{
			wifi_status_led_uninstall();
		}
		PIN_FUNC_SELECT(pinMap[pin], pinFunction[pin]);
		GPIO_DIS_OUTPUT(pin);
		PIN_PULLUP_DIS(pinMap[pin]);
		os_sprintf(buffer, "%d=INPUT\r\n", pin);
	}
	else if ((mode == 'o') || (mode == 'O'))
	{
		if (pin == STATUS_LED_PIN)
		{
			wifi_status_led_uninstall();
		}
		PIN_FUNC_SELECT(pinMap[pin], pinFunction[pin]);
		GPIO_OUTPUT_SET(pin, 0);
		os_sprintf(buffer, "%d=OUTPUT\r\n", pin);
	}
	else if ((mode == 'p') || (mode == 'P'))
	{
		if (pin == STATUS_LED_PIN)
		{
			wifi_status_led_uninstall();
		}
		PIN_FUNC_SELECT(pinMap[pin], pinFunction[pin]);
		GPIO_DIS_OUTPUT(pin);
		PIN_PULLUP_EN(pinMap[pin]);
		os_sprintf(buffer, "%d=INPUT_PULLUP\r\n", pin);
	}
	else
	{
		at_response_error();
		return;
	}
	
	at_port_print(buffer);
	at_response_ok();
}