Ejemplo n.º 1
0
/* AT command callback, which will be called after the AT command is sent from the Monitor tool */
static void at_callback(vm_cmd_command_t* param, void* user_data)
{
  VMINT result;

  if(strcmp("Test01",(char*)param->command_buffer) == 0)
  {
     /* Opens the cell when receiving AT command: AT+[1000]Test01 */
     result = vm_gsm_cell_open();
     vm_log_info("open result = %d",result);
  }
  else if(strcmp("Test02",(char*)param->command_buffer) == 0)
  {
    /* Gets the current cell info when receiving AT command: AT+[1000]Test02 */
    vm_gsm_cell_get_current_cell_info(&g_info);
    vm_log_info("ar=%d, bsic=%d, rxlev=%d, mcc=%d, mnc=%d, lac=%d, ci=%d", g_info.arfcn, g_info.bsic, g_info.rxlev, g_info.mcc, g_info.mnc, g_info.lac, g_info.ci);
  }
  else if(strcmp("Test03",(char*)param->command_buffer) == 0)
  {
    /* Gets the neighboring cell info when receiving AT command: AT+[1000]Test03 */
    int i, count;
    count = vm_gsm_cell_get_neighbor_number();
    vm_log_info("neighbor count=%d", count);
    for(i=0; i<count; i++)
    {
      vm_gsm_cell_get_neighbor_cell_info(&g_info, i);
      vm_log_info("ar=%d, bsic=%d, rxlev=%d, mcc=%d, mnc=%d, lac=%d, ci=%d", g_info.arfcn, g_info.bsic, g_info.rxlev, g_info.mcc, g_info.mnc, g_info.lac, g_info.ci);
    }
  }
  else if(strcmp("Test04",(char*)param->command_buffer) == 0)
  {
    /* Closes the cell when receiving AT command: AT+[1000]Test04 */
    vm_gsm_cell_close();
  }
}
Ejemplo n.º 2
0
static void onWifiConnected(void *user_data, vm_wlan_conn_res_struct *conn_res)
{
  vm_log_info("onWifiConnected (MMI)");
  LWiFiConnectContext *pContext = (LWiFiConnectContext*)user_data;

  // connect result
  pContext->result = *conn_res;

  vm_log_info("onWifiConnected result=%d", conn_res->result);

  if (VM_WLAN_RESULT_SUCCESS != pContext->result.result)
  {
    vm_log_info("FAILED ret=%d cause=%d", conn_res->result, conn_res->cause);
    // connect fail,
    // wakeup Arduino thread directly
    LTask.post_signal();
  }
  else
  {
    // connect OK,
    // retrieve AP & IP info.
    // in DHCP case, we may need to wait for IP ready
    vm_wlan_get_connected_ap_info((void*)&pContext->connectedInfo, VM_WLAN_AP_INFO_ALL);

    // We should then wait for IP info, which will be callbacked
  }
  return;
}
Ejemplo n.º 3
0
static void onWiFiSnifferOn(void *userData, vm_wlan_sniffer_on_res_struct *res)
{
    LWiFiConnectContext *pContext = (LWiFiConnectContext*)userData;

    vm_log_info("onWiFiSnifferOn result=%d, cb_type=%d", res->result, res->cb_type);
    if(VM_WLAN_SNIFFER_SUCCESS == res->result)
    {
        if(VM_WLAN_SNIFFER_ON_RES == res->cb_type)
        {
            
        }
        else if(VM_WLAN_SNIFFER_ON_AP_INFO == res->cb_type)
        {
            vm_wlan_prof_struct prof;
            memset(&prof, 0, sizeof(vm_wlan_prof_struct));
            memcpy(&prof, &(res->profile), sizeof(vm_wlan_prof_struct));
            pContext->apInfo.auth_mode = prof.auth_mode;
            strncpy((char*)pContext->apInfo.ssid, (char*)prof.ssid, VM_WLAN_PROF_MAX_SSID_LEN);
            strncpy((char*)pContext->apInfo.password, (char*)prof.password, VM_WLAN_PROF_PSWD_MAX_LEN);
            
            vm_log_info("auth_mode: %d", res->profile.auth_mode);            
            vm_log_info("ssid: %s", (char*)pContext->apInfo.ssid);
            vm_log_info("password: %s", (char*)pContext->apInfo.password);
            vm_wlan_sniffer_off(onWiFiSnifferOff, pContext);
        }
    }
    else
    {
        vm_log_info("vm_wlan_sniffer_on fails, result=%d", res->result);
        pContext->result.result = VM_WLAN_RESULT_FAILED;
        LTask.post_signal();
    }
}
Ejemplo n.º 4
0
int LGPRSClass::hostByName(const char* aHostname, IPAddress& aResult)
{
	vm_log_info("hostByName");
	LGPRSResolveContext context;
	// no memory copy since we're blocking call
	context.domainName = aHostname;
	LTask.remoteCall(&gprsResolveDomainName, (void*)&context);

	vm_log_info("context.resolveState = %d", context.resolveState);
	unsigned char* ipArray = (unsigned char*)&context.dns.address[0];
	vm_log_info("Arduino DNS resolve callback, cause=%d, num=%d, address=%d.%d.%d.%d", 
				context.dns.error_cause, 
				context.dns.num,
				ipArray[0],
				ipArray[1],
				ipArray[2],
				ipArray[3]);
	// parse result
	if (VM_E_SOC_SUCCESS == context.resolveState)
	{
		// There may have multiple ip addresses. We take the 1st one.
		aResult = context.dns.address[0];
		
		vm_log_info("get IP=%d.%d.%d.%d", 
					aResult[0],
					aResult[1],
					aResult[2],
					aResult[3]);
		return 1;
	}
	else
	{
		return 0;
	}
}
Ejemplo n.º 5
0
static boolean gprsResolveDomainName(void *userData)
{
	LGPRSResolveContext *pContext = (LGPRSResolveContext*)userData;

	vm_log_info("vm_soc_get_host_by_name_ex: %s", pContext->domainName);
	pContext->resolveState = vm_soc_get_host_by_name_ex(VM_TCP_APN_CMNET, 
														pContext->domainName, 
														&pContext->dns, 
														&gprsResolveCallback, 
														pContext);
	vm_log_info("vm_soc_get_host_by_name_ex ret = %d", pContext->resolveState);

	if (pContext->resolveState > 0)
	{
		// not done yet
		return false;
	}
	
	switch(pContext->resolveState)
	{
	case VM_E_SOC_SUCCESS:  // Get IP address successfully, result is filled.
  		return true;
	case VM_E_SOC_WOULDBLOCK:  // wait response from network, result could be gotten from callback.
		// need to wait, return directly
		// so MMI message loop may continue.
		return false;
	case VM_E_SOC_INVAL:  // invalid arguments: null domain_name, etc.
	case VM_E_SOC_ERROR:  // unspecified error
	case VM_E_SOC_LIMIT_RESOURCE:  // socket resources not available
	case VM_E_SOC_INVALID_ACCOUNT:  // invalid data account id  
		return true;
	}
}
Ejemplo n.º 6
0
boolean LTcpClient::wifiRead(void *userData)
{
	LTcpReadWriteContext *pContext = (LTcpReadWriteContext*)userData;
	LTcpClient *pThis = pContext->pInst;

	pContext->lenProcessed = 0;
	
	// parameter check
	if(pContext->len <= 0)
	{	
		return true;
	}

	vm_log_info("wifiRead len=%d", pContext->len);

	// check peek state
	if(pThis->m_peekBuffered)
	{	
		// insert the peeked byte
		*((VMINT8*)pContext->buf) = pThis->m_peekByte;
		pContext->lenProcessed += 1;
		pContext->len--;
		// clear peek state
		pThis->m_peekByte = -1;
		pThis->m_peekBuffered = false;
	}

	VMINT readResult = VM_TCP_READ_EOF;
	
	// actually read from TCP socket
	if (pContext->serverHandle != -1)
	{
		readResult = vm_soc_svr_read(pContext->serverHandle,
									 pContext->handle, 
									 pContext->buf, 
									 pContext->len);
	}
	else
	{
		readResult = vm_tcp_read(pContext->handle, 
								 pContext->buf, 
								 pContext->len);
	}

	if (readResult > 0)
	{
		pContext->lenProcessed += readResult;
	}
	
	if (readResult == VM_TCP_READ_EOF)
	{
		// we may cache a peek byte even if the socket is disconnected
		vm_log_info("wifiRead socket disconnected");
	}
	
	vm_log_info("wifiRead %d bytes", pContext->lenProcessed);
	return true;
}
Ejemplo n.º 7
0
int8_t LWiFiClass::scanNetworks()
{
  vm_log_info("scanNetworks");
  LWiFiScanContext context;
  LTask.remoteCall(&LWiFiScanContext::mmiCall, &context);
  m_scanInfo = context.result;
  vm_log_info("scanNetworks ret=%d", m_scanInfo.ap_list_num);
  return m_scanInfo.ap_list_num;
}
Ejemplo n.º 8
0
boolean LUDP::udpSend(void* userdata)
{
	LUDPSendContext *pCntx = (LUDPSendContext*)userdata;
	LUDP* pThis = pCntx->pThis;
	VMINT remainBuffer = pThis->m_writePos;
	VMUINT8 *pBuf = &pThis->m_writeBuffer[0];

	vm_sockaddr_struct sendto = {0};
	sendto.addr[0] = pThis->m_sendToIP[0];
	sendto.addr[1] = pThis->m_sendToIP[1];
	sendto.addr[2] = pThis->m_sendToIP[2];
	sendto.addr[3] = pThis->m_sendToIP[3];
	sendto.addr_len = 4;
	sendto.port = pThis->m_sendToPort;

	vm_log_info("send packet len:%d to %d.%d.%d.%d:%d",
				remainBuffer,
				sendto.addr[0],
				sendto.addr[1],
				sendto.addr[2],
				sendto.addr[3],
				sendto.port);

	while(remainBuffer > 0)
	{
		VMINT sentBytes = 0;
		sentBytes = vm_udp_sendto(pThis->m_serverHandle,
								  pBuf,
								  remainBuffer,
								  &sendto);
		
		vm_log_info("vm_udp_sendto returns %d", sentBytes);


		if(sentBytes <= 0)
		{
			vm_log_error("vm_udp_sendto sent no content");
			break;
		}	

		pBuf += sentBytes;
		remainBuffer -= sentBytes;
	}

	// check if buffer is completely sent
	if(remainBuffer <= 0)
	{
		pCntx->sentComplete = 1;
	}
	else
	{
		pCntx->sentComplete = 0;
	}

	return true;
}
Ejemplo n.º 9
0
/* The callback to be invoked by the system engine. */
void handle_sysevt(VMINT message, VMINT param) {
    switch (message) {
        case VM_EVENT_CREATE:
        vm_log_info("reboot test create");
        reboot_test_main();
        break;

        case VM_EVENT_QUIT:
        vm_log_info("reboot test quit");
        break;
    }
}
Ejemplo n.º 10
0
VMUINT8 gsm_sms_get_unread(void* userdata)
{
	sms_unread_msg_struct *dest = (sms_unread_msg_struct*)userdata;
    VMINT16 message_id;
    vm_gsm_sms_read_message_data_t* message_data = NULL;
    VMWCHAR* content_buff;
    VMINT res;

    //message_id = vm_gsm_sms_get_message_id(VM_GSM_SMS_BOX_INBOX, 0);
	//dest -> id = message_id;
    message_id = dest->id;

    if(message_id >= 0)
    {
		// Allocates memory for the message data
		message_data = (vm_gsm_sms_read_message_data_t*)vm_calloc(sizeof(vm_gsm_sms_read_message_data_t));
		if(message_data == NULL)
		{
			vm_log_info("sms read malloc message data fail");
			return FALSE;
		}

		// Allocates memory for the content buffer of the message
		content_buff = (VMWCHAR*)vm_calloc((500+1)*sizeof(VMWCHAR));
		if(content_buff == NULL)
		{
			vm_free(message_data);
			vm_log_info("sms read malloc content fail");
			return FALSE;

		}
		message_data->content_buffer = content_buff;
		message_data->content_buffer_size = 500;

		// Reads the message
		res = vm_gsm_sms_read_message(message_id, VM_TRUE, message_data, sms_read_callback, NULL);
    	//vm_log_info("vm_gsm_sms_read_message message_id is %d", message_id);

		if(res != VM_GSM_SMS_RESULT_OK)
		{
			vm_free(content_buff);
			vm_free(message_data);

			vm_log_info("register read callback fail");
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}
}
Ejemplo n.º 11
0
static void onWiFiEnabled(void *userData, vm_wlan_req_res_enum result)
{
  LWiFiConnectContext *pContext = (LWiFiConnectContext*)userData;

  vm_log_info("onWiFiEnabled result=%d", result);

  do
  {
    if (VM_WLAN_REQ_RES_DONE != result)
    {
      vm_log_info("wifi status change error=%d", result);
      break;
    }

    if(true == pContext->isWaitApInfo)
    {
        VMINT snifferOnRet = vm_wlan_sniffer_on(NULL, &onWiFiSnifferOn, pContext);
        if(VM_WLAN_RESULT_PROCESSING != snifferOnRet)
        {
            vm_log_info("wlan sniffer on fails ret=%d", snifferOnRet);
            break;
        }
        vm_log_info("start waiting AP info");
        return;
    }

    vm_log_info("vm_wlan_reg_noti");

    // register IP callback
    vm_wlan_reg_noti(VM_WLAN_NOTI_IP_AVAILABLE, &onWiFiIPReady, pContext);

    vm_log_info("vm_wlan_connect");
    // connect to AP
    VMINT connectRet = vm_wlan_connect(&pContext->apInfo, &onWifiConnected, pContext);

    vm_log_info("vm_wlan_connect ret =%d", connectRet);
    if (connectRet != VM_WLAN_RESULT_PROCESSING)
    {
      vm_log_info("vm_wlan_connect fails ret=%d", connectRet);
      break;
    }

    vm_log_info("start waiting connect & IP address");
    return;
  }
  while (0);

  // fail and allow arduino thread to keep going
  vm_log_info("vm_wlan_mode_set cb result=%d", result);
  pContext->result.result = VM_WLAN_RESULT_FAILED;
  LTask.post_signal();
}
Ejemplo n.º 12
0
boolean LTcpClient::connectIP(void *userData)
{
	LTcpConnectContext *pContext = (LTcpConnectContext*)userData;
	// async api
	vm_log_info("connectIP, IP=%s, port=%d", pContext->ipAddr, pContext->port);
	VMINT clientHandle = vm_tcp_connect_ex(pContext->ipAddr, 
										   pContext->port, 
										   pContext->pInstance->getAPN(),
										   pContext->pInstance,
										   &connectCallback);
	vm_log_info("vm_tcp_connect returns %d", clientHandle);
	return false;
}
Ejemplo n.º 13
0
int LTcpClient::connect(IPAddress ip, uint16_t port)
{
	vm_log_info("connect(IPAddress)");
	char ipAddr[50] = {0};
	sprintf(ipAddr, 
			"%d.%d.%d.%d", 
			ip[0],
			ip[1], 
			ip[2], 
			ip[3]);
	vm_log_info("connect to %s", ipAddr);
	return connect(ipAddr, port); 
}
Ejemplo n.º 14
0
static boolean wifiMacAddress(void* userData)
{
  vm_log_info("wifiMacAddress called");
  LWiFiClass *pThis = (LWiFiClass*)userData;
  vm_wlan_prof_str_info_qry_struct qry;
  qry.dest = pThis->m_macAddress;
  qry.dest_len = VM_WLAN_WNDRV_MAC_ADDRESS_LEN;
  qry.req_len = VM_WLAN_WNDRV_MAC_ADDRESS_LEN;
  pThis->m_lastError = vm_wlan_get_mac_address(&qry);
  vm_log_info("wifiMacAddress called, result = %d", pThis->m_lastError);
  vm_log_info("req_len=%d", qry.req_len);
  return true;
}
Ejemplo n.º 15
0
size_t LTcpClient::write(uint8_t b)
{
	vm_log_info("wifiWrite arduino (byte)");
	LTcpReadWriteContext c;
	c.handle = m_handle.m_handle;
	c.serverHandle = m_handle.m_serverHandle;
	c.buf = &b;
	c.len = 1;
	c.pInst = this;
	LTask.remoteCall(&wifiWrite, &c);

	vm_log_info("written %d bytes", c.lenProcessed);
	return c.lenProcessed;
}
Ejemplo n.º 16
0
size_t LTcpClient::write(const uint8_t *buf, size_t size)
{
	vm_log_info("wifiWrite arduino (buffered)");
	LTcpReadWriteContext c;
	c.handle = m_handle.m_handle;
	c.serverHandle = m_handle.m_serverHandle;
	c.buf = (void*)buf;
	c.len = size;
	c.pInst = this;
	LTask.remoteCall(&wifiWrite, &c);

	vm_log_info("written %d bytes", c.lenProcessed);
	return c.lenProcessed;
}
Ejemplo n.º 17
0
int LTcpClient::read(uint8_t *buf, size_t size)
{
	// read a single byte
	LTcpReadWriteContext c;
	uint8_t ret = 0;
	c.handle = m_handle.m_handle;
	c.serverHandle = m_handle.m_serverHandle;
	c.buf = buf;
	c.len = size;
	c.pInst = this;
	vm_log_info("wifiRead call with buf=%d, size=%d", c.buf, c.len);
	LTask.remoteCall(&wifiRead, &c);
	vm_log_info("LTcpClient::read return %d", c.lenProcessed);
	return c.lenProcessed;
}
Ejemplo n.º 18
0
SharedHandle::SharedHandle(VMINT clientHandle, VMINT serverHandle):
	m_handle(clientHandle),
	m_serverHandle(serverHandle),
	m_pSharedCount(new VMINT(1))
{
	vm_log_info("SharedHandle create: c:%d, s:%d", m_handle, m_serverHandle);
}
Ejemplo n.º 19
0
void UartIrqHandler(void* parameter, VM_DCL_EVENT event, VM_DCL_HANDLE device_handle)
{
    if(event == VM_UART_READY_TO_READ)
    {
        char data[SERIAL_BUFFER_SIZE];
        int i;
        VM_DCL_STATUS status;
        VM_DCL_BUFF_LEN returned_len;

        status = vm_dcl_read(device_handle,(VM_DCL_BUFF*)data,SERIAL_BUFFER_SIZE,&returned_len,vm_dcl_get_ownerid());
        if(status<VM_DCL_STATUS_OK)
        {
            vm_log_info((char*)"read failed");
        }  
        if(device_handle == g_APinDescription[0].ulHandle)
        {
            for(i=0;i<returned_len;i++)
            {
                Serial1._rx_buffer->store_char(data[i]);
            }
        }
        else
        {
            for(i=0;i<returned_len;i++)
            {
                Serial._rx_buffer->store_char(data[i]);
            }
        }
    }
    else
    {
    }
}
Ejemplo n.º 20
0
uint8_t TwoWire::endTransmission(uint8_t sendStop) {
	vm_i2c_ctrl_config_t conf_data;
	vm_i2c_ctrl_single_write_t write_data;
	VM_DCL_STATUS ret = 0;
	int32_t sent = 0;

	if(i2c_handle==-1)
	{
		vm_log_info("endTransmission,i2c handle is invalid.i2c_handle:%d",i2c_handle);
		return 0;
	}
    
    if(0 < txBufferLength) {
		conf_data.Reserved0 =  (VM_DCL_I2C_OWNER)0;
		conf_data.eTransactionMode = VM_DCL_I2C_TRANSACTION_FAST_MODE;
		conf_data.fgGetHandleWait = 0;
		conf_data.Reserved1 = 0;
		conf_data.u1DelayLen = 0;
		conf_data.u1SlaveAddress = txAddress;

		conf_data.u4FastModeSpeed = 100;
		conf_data.u4HSModeSpeed = 0;
		ret = vm_dcl_control(i2c_handle,VM_I2C_CMD_CONFIG,(void *)&conf_data);
	
		write_data.pu1Data = &(txBuffer[0]);
		write_data.u4DataLen = txBufferLength;
        ret = vm_dcl_control(i2c_handle,VM_I2C_CMD_SINGLE_WRITE,(void *)&write_data);
		sent = txBufferLength;
	}
  
	txBufferLength = 0;

	status = MASTER_IDLE;
	return sent;
}
Ejemplo n.º 21
0
void TwoWire::beginTransmission(uint8_t address) {
	if(i2c_handle==-1)
	{
		vm_log_info("[TwoWire]beginTransmission:i2c handle is invalid,return");
		return;
	}
	status = MASTER_SEND;

	// save address of target and empty buffer
	txAddress = address<<1;

    // frist transfer
    if (txBufferLength == 0)
    {
        bytes_per_transfer = 0;
        num_transfer = 1;
    }
    else
    {
        // conut the number of repeated start signal
        num_transfer++;
    }

    rxBufferLength = 0;
    bytes_per_read = 0;
    num_read = 0;
}
Ejemplo n.º 22
0
SharedHandle::SharedHandle(VMINT handle):
	m_handle(handle),
	m_serverHandle(INVALID_HANDLE),
	m_pSharedCount(new VMINT(1))
{
	vm_log_info("SharedHandle create: c:%d, s:%d", m_handle, m_serverHandle);
}
Ejemplo n.º 23
0
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop) {

	// perform blocking read into buffer
	int readed = 0;
	VM_DCL_STATUS ret = 0;
	vm_i2c_ctrl_config_t conf_data;
	vm_i2c_ctrl_single_read_t  read_data;
	
	if(i2c_handle==-1)
	{
		vm_log_info("requestFrom,i2c handle is invalid.i2c_handle:%d",i2c_handle);
		return 0;
	}
	
	if (quantity > BUFFER_LENGTH)
		quantity = BUFFER_LENGTH;
	conf_data.Reserved0 = (VM_DCL_I2C_OWNER)0;
	conf_data.eTransactionMode = VM_DCL_I2C_TRANSACTION_FAST_MODE;
	conf_data.fgGetHandleWait = 0;
	conf_data.Reserved1 = 0;
	conf_data.u1DelayLen = 0;
	conf_data.u1SlaveAddress = address<<1;
	conf_data.u4FastModeSpeed = 100;
	conf_data.u4HSModeSpeed = 0;
	ret = vm_dcl_control(i2c_handle,VM_I2C_CMD_CONFIG,(void *)&conf_data);
	read_data.pu1Data = &(rxBuffer[0]);
	read_data.u4DataLen = quantity;
	ret = vm_dcl_control(i2c_handle,VM_I2C_CMD_SINGLE_READ,(void *)&read_data);
	rxBufferIndex = 0;
	rxBufferLength = quantity;

	return quantity;
}
Ejemplo n.º 24
0
static void
call_voiceCall_callback(vm_gsm_tel_call_actions_callback_data_t *data) {
  vm_log_info("call_voiceCall_callback");

  if (data->type_action == VM_GSM_TEL_CALL_ACTION_DIAL) {

    if (data->data_act_rsp.result_info.result == VM_GSM_TEL_OK) {
      g_call_status = CALLING;
    } else {
      g_call_status = IDLE_CALL;
    }
  }

  else if (data->type_action == VM_GSM_TEL_CALL_ACTION_ACCEPT) {
    if (data->data_act_rsp.result_info.result == VM_GSM_TEL_OK) {
      g_call_status = TALKING;
    } else {
      g_call_status = IDLE_CALL;
    }
  }

  else if (data->type_action == VM_GSM_TEL_CALL_ACTION_HOLD) {

  }

  else if (data->type_action == VM_GSM_TEL_CALL_ACTION_END_SINGLE) {
    g_call_status = IDLE_CALL;
  } else {
  }
}
Ejemplo n.º 25
0
void adc_callback(void* parameter, VM_DCL_EVENT event, VM_DCL_HANDLE device_handle)
{
    vm_dcl_callback_data_t *data;
    vm_dcl_adc_measure_done_confirm_t * result;
    vm_dcl_adc_control_send_stop_t stop_data;
    VMINT status = 0;

    if(parameter!=NULL)
      {
        data = ( vm_dcl_callback_data_t*)parameter;
        result = (vm_dcl_adc_measure_done_confirm_t *)(data->local_parameters);

        if( result != NULL )
        {
            double *p;

            p =(double*)&(result->value);
            g_adc_result = (unsigned int)*p;
            vm_log_info("get adc data is %d",g_adc_result);
        }
     }

    // Stop ADC
    stop_data.owner_id = vm_dcl_get_owner_id();
    status = vm_dcl_control(g_adc_handle,VM_DCL_ADC_COMMAND_SEND_STOP,(void *)&stop_data);

    vm_dcl_close(g_adc_handle);
}
Ejemplo n.º 26
0
void LTcpClient::connectCallback(VMINT handle, VMINT event, void *userData)
{
	LTcpClient *pThis = (LTcpClient*)userData;
	vm_log_info("connectCallback handle=%d event=%d userData=%d", handle, event, userData);
	switch(event)
	{
	case VM_TCP_EVT_CONNECTED:
		pThis->m_handle = SharedHandle(handle);
		LTask.post_signal();
		break;
	case VM_TCP_EVT_CAN_WRITE:
		break;
	case VM_TCP_EVT_CAN_READ:
		break;
	case VM_TCP_EVT_PIPE_BROKEN:
		pThis->m_handle.invalidateHandle();
		LTask.post_signal();
		break;
	case VM_TCP_EVT_HOST_NOT_FOUND:
		pThis->m_handle.invalidateHandle();
		LTask.post_signal();
		break;
	case VM_TCP_EVT_PIPE_CLOSED:
		pThis->m_handle.invalidateHandle();
		LTask.post_signal();
		break;
	}
	return;
}
Ejemplo n.º 27
0
static boolean wifiBegin(void* userData)
{
  vm_log_info("wifiBegin (in MMI)");


  LWiFiConnectContext *pContext = (LWiFiConnectContext*)userData;

  const VMINT wlanStatus = vm_wlan_status();
  // check if we already connected
  if (wlanStatus & VM_WLAN_STA_STATUS_CONNECTED)
  {
    pContext->result.result = VM_WLAN_RESULT_STATE_ERROR;
    return true;
  }

  // first we enable WiFi and wait for callback
  if (VM_WLAN_SET_MODE_STA != vm_wlan_mode_get())
  {
    vm_wlan_mode_set(VM_WLAN_SET_MODE_STA, &onWiFiEnabled, pContext);
  }
  else
  {
    onWiFiEnabled(pContext, VM_WLAN_REQ_RES_DONE);
  }

  // block Arduino thread
  return false;
}
extern caddr_t _sbrk ( int incr )
{
    static void* heap = NULL ;
    static void* base = NULL ;
    void* prev_heap ;

    if ( heap == NULL )
    {
        base = (unsigned char *)g_base_address; 
				if(base == NULL)
				{
					vm_log_fatal("malloc failed");
				}
				else
				{
					heap = base;
					vm_log_info("init memory success");
				}
    }
    
    if (heap + incr > g_base_address + g_memory_size) 
    {
        vm_log_fatal("memory not enough");
    }
    
    prev_heap = heap;

    heap += incr ;

    return (caddr_t) prev_heap ;
}
Ejemplo n.º 29
0
int LTcpClient::connect(const char *host, uint16_t port)
{
	vm_log_info("LTcpClient::connect(char) to %s:%d", host, port);

	if(connected())
	{
		vm_log_info("LTcpClient::connect() while already connected. stop() first.");
		stop();
	}
	
	LTcpConnectContext context;
	context.ipAddr = host;
	context.port = port;
	context.pInstance = this;
	LTask.remoteCall(&connectIP, &context);	
	return connected();
}
Ejemplo n.º 30
0
void handle_sysevt(VMINT message, VMINT param)
{
	switch (message)
	{
	case VM_EVENT_CREATE:
		/* delay for catch logs */
		vm_thread_sleep(8000);
		vm_log_info("Sample of FS list file - Start.");
		fs_demo_find_files();

		break;

	case VM_EVENT_QUIT:
		vm_log_info("Sample of FS list file - End.");
		break;
	}
}