Exemplo n.º 1
0
bool imu_send_command(uint8_t *cmd, uint8_t cmd_length, uint8_t *response, uint8_t response_length) {
	
	uint16_t tx_buffer_length;
	uint16_t rx_buffer_length;
		
	// Send command
	tx_buffer_length = uart_tx_data(&imu_port, cmd, cmd_length);

	if (tx_buffer_length<cmd_length) {
		return false;
	}	
	
	// Receive data
	rx_buffer_length = 0;
	while (rx_buffer_length<response_length) {
		rx_buffer_length += uart_rx_data(&imu_port,response+rx_buffer_length,response_length-rx_buffer_length);
	}
	
	// Verify checksum
	if (response_length>0) {
		return (rx_buffer_length==response_length) && (response[0]==cmd[0]) && imu_verify_checksum(response,response_length); 
	}	
	else {
		return true;
	}	
}
Exemplo n.º 2
0
/*
 * send formatted string to uart
 * max length after formateed: 80
 */
void suli_uart_printf(void *uart_device, int16 uart_num, const char *fmt, ...)
{
    char buff[82];
    va_list args;
    int n;

    va_start(args, fmt);
    n = vsnprintf(buff, 80, fmt, args);
    va_end(args);

    uart_tx_data(buff, n);
}
Exemplo n.º 3
0
uint8_t imu_set_active_mode(void){
	uint8_t tx_buffer[4];
	uint8_t rx_buffer[4];
	
	tx_buffer[0] = 0xD4;
	tx_buffer[1] = 0xA3;
	tx_buffer[2] = 0x47;
	tx_buffer[3] = 0x01;
	
	while (1)
	{
		uart_tx_data(&imu_port,tx_buffer, 4);
		uart_rx_data(&imu_port,rx_buffer,4);
		_delay_ms(5);
	}
}
Exemplo n.º 4
0
uint8_t sms_send_message_number(char *szPhoneNumber, char* pData) {
	char szCmd[64];
	uint16_t msgNumber = 0; // Validation number from the network returned by the CMGS command
	int res = UART_ERROR;
	int verbose = g_iLCDVerbose;
	int phonecode = 129;
	char *token;
	SIM_CARD_CONFIG *sim = config_getSIM();

	state_SMS_lastMessageACK(sim, -1);

	if (szPhoneNumber == NULL || strlen(szPhoneNumber) == 0)
		return UART_SUCCESS;

	if (pData == NULL || strlen(pData) == 0)
		return UART_SUCCESS;

	if (g_iLCDVerbose == VERBOSE_BOOTING) {
		lcd_clear();
		lcd_printf(LINE1, "SYNC SMS %d", g_pDevCfg->cfgSIM_slot + 1);
		lcd_printl(LINE2, szPhoneNumber);
		lcd_disable_verbose();
	}

	strcat(pData, ctrlZ);

	// 129 - number in national format
	// 145 - number in international format (contains the "+")

	if (szPhoneNumber[0] == '+')
		phonecode = 145;

	http_deactivate();
	sprintf(szCmd, "AT+CMGS=\"%s\",%d\r\n", szPhoneNumber, phonecode);

	uart_setSMSPromptMode();
	if (uart_tx_waitForPrompt(szCmd, TIMEOUT_CMGS_PROMPT)) {
		uart_tx_data(pData, TIMEOUT_CMGS, 1);

		token = strstr(uart_getRXHead(), "ERROR");
		if (token == NULL) {
			token = strstr(uart_getRXHead(), "+CMGS:");
			if (token != NULL) {
				msgNumber = atoi(token + 6);
				state_SMS_lastMessageACK(sim, msgNumber);
			}
			if (msgNumber != 0)
				res = UART_SUCCESS;
			else
				res = UART_ERROR;
		} else {
			res = UART_ERROR;
		}
	}

	if (verbose == VERBOSE_BOOTING)
		lcd_enable_verbose();

	if (res == UART_SUCCESS) {
		lcd_clear();
		lcd_printl(LINE1, "SMS Confirm");
		lcd_printf(LINE2, "MSG %d", msgNumber);
		delay(HUMAN_DISPLAY_INFO_DELAY);
		_NOP();
	} else {
		lcd_print("TIMEOUT");
		delay(HUMAN_DISPLAY_ERROR_DELAY);
	}

	_NOP();
	return res;
}
Exemplo n.º 5
0
void uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len) {
    uart_tx_data(uart_obj, (uint8_t*)str, len);
}
Exemplo n.º 6
0
STATIC void uart_tx_char(pyb_uart_obj_t *uart_obj, int c) {
    uint8_t ch = c;
    uart_tx_data(uart_obj, &ch, 1);
}
Exemplo n.º 7
0
void uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len) {
    int errcode;
    uart_tx_data(uart_obj, str, len, &errcode);
}
Exemplo n.º 8
0
/*
 * write a float
 * num - number to write
 * decimal - x decimal point
 */
void suli_uart_write_float(void *uart_device, int16 uart_num, float data, uint8 prec)
{
    char buff[32];
    modp_dtoa2((double)data, buff, prec);
    uart_tx_data(buff, strlen(buff));
}
Exemplo n.º 9
0
/*
 * seed a byte to uart
 */
void suli_uart_send_byte(void *uart_device, int16 uart_num, uint8 data)
{
    uart_tx_data(&data, 1);
}
Exemplo n.º 10
0
/*
 * Send a Buff to uart
 * - uart_device: uart device pointer
 * - uart_num: uart number
 * - *data: buff to sent
 * - len: data length
 */
void suli_uart_send(void * uart_device, int16 uart_num, uint8 *data, uint16 len)
{
    uart_tx_data(data, len);
}
Exemplo n.º 11
0
STATIC void uart_tx_char(pyb_uart_obj_t *uart_obj, int c) {
    uint16_t ch = c;
    int errcode;
    uart_tx_data(uart_obj, &ch, 1, &errcode);
}