Exemple #1
0
void set_pattern()
{
	int i;
	char c;
	
	print("Enter new pattern: ");
	i = 0;
	while(1) {
		c = uart_rcv();
		switch(c) {
			case '0':
			case '1':
				if(i < (PATTERN_LEN-1)) {
					pattern[i++] = c;
					uart_tx(c);
				}
				break;
			case '\r':
			case '\n':
				pattern[i] = 0;
				uart_tx('\n');
				return;
		}
	}
}
Exemple #2
0
void output(uint8 len1, uint8* data1, uint16 len2, uint8* data2)
{
    if (uart_tx(len1, data1) || uart_tx(len2, data2)) {
        printf("ERROR: Writing to serial port failed\n");
        exit(1);
    }
}
Exemple #3
0
void
putstr (char *str)
{
  while (*str)
    {
      if (*str == '\n')
	uart_tx ('\r');
      uart_tx (*(str++));
    }
}
static void ICACHE_FLASH_ATTR ack_last_message(void) {
	const uint8_t seq = 0 | (uart_con_last_sequence_number_seen << 4);
	uint8_t checksum = 0;

	PEARSON(checksum, UART_CON_HEADER_SIZE);
	uart_tx(UART_CONNECTION, UART_CON_HEADER_SIZE);
	PEARSON(checksum, seq);
	uart_tx(UART_CONNECTION, seq);
	uart_tx(UART_CONNECTION, checksum);
}
Exemple #5
0
int8_t sms_process_messages() {
	char *token;
	char SM_ME[5]; // Internal memory or sim card used
	uint32_t iIdx;
	SIM_CARD_CONFIG *sim = config_getSIM();
	uint8_t usedr = 0; // Reading memory
	uint8_t totalr = 0;

	config_setLastCommand(COMMAND_SMS_PROCESS);

	memset(SM_ME, 0, sizeof(SM_ME));

	lcd_printf(LINEC, "Fetching SMSs");
	lcd_printf(LINE2, "SIM %d", config_getSelectedSIM() + 1);

	//check if messages are available
	uart_tx("+CPMS?");

	// Failed to get parameters
	int8_t uart_state = uart_getTransactionState();
	if (uart_state != UART_SUCCESS)
		return uart_state;

	PARSE_FINDSTR_RET(token, COMMAND_RESULT_CPMS, UART_FAILED);
	PARSE_FIRSTSTRING(token, SM_ME, sizeof(SM_ME) - 1, ", \n", UART_FAILED);
	PARSE_NEXTVALUE(token, &usedr, ", \n", UART_FAILED);
	PARSE_NEXTVALUE(token, &totalr, ", \n", UART_FAILED);

	if (check_address_empty(sim->iMaxMessages) || sim->iMaxMessages != totalr) {
		sim->iMaxMessages = totalr;
	}

	if (usedr == 0) {
		lcd_printf(LINEC, "No new messages", usedr);
		return UART_SUCCESS;
	}

	lcd_printf(LINEC, "%d SMS Fetch", usedr);
	lcd_printl(LINE2, "Msg Processing..");

	uart_tx("+CSDH=0"); // Disable extended output

	for (iIdx = 1; iIdx <= totalr; iIdx++) {
		if (sms_process_memory_message(iIdx) == UART_SUCCESS) {
			usedr--;
			delmsg(iIdx);
		} else
			_NOP();
	}

	delallmsg();
	uart_tx("+CSDH=1"); // Restore extended output

	return UART_SUCCESS;
}
Exemple #6
0
/**
 * Send BGAPI packet using UART interface
 *
 * @param len1 Length of fixed portion of packet (always at least 4)
 * @param data1 Fixed-length portion of BGAPI packet (should always be <len1> bytes long)
 * @param len2 Length of variable portion of packet data payload (trailing uint8array or uint16array)
 * @param data2 Variable-length portion of data payload (should always be <len2> bytes long)
 */
void send_api_packet(uint8 len1, uint8 *data1, uint16 len2, uint8 *data2)
{
#ifdef DEBUG
  // display outgoing BGAPI packet
//  print_raw_packet((struct ble_header *)data1, data2);
#endif
  if (uart_tx(len1, data1) || uart_tx(len2, data2)) {
    // uart_tx returns non-zero on failure
    fprintf(stderr, "ERROR: Writing to serial port failed\n");
    exit(1);
  }
}
Exemple #7
0
bool initUartOutput(flowOutputState state, char* port, unsigned int baud, size_t bufferSize) {
	// Initialize UART communication
	int uartErrno = uart_open(port, baud);
	if (uartErrno) {
		caerLog(CAER_LOG_ALERT, SUBSYSTEM_UART,
				"Failed to identify serial communication, errno=%i.",uartErrno);
		return (false);
	}
	// Test message
	char* testMessage = "DVS128UART";
	if (uart_tx((int) strlen(testMessage), (unsigned char*) testMessage)) {
		caerLog(CAER_LOG_ALERT, SUBSYSTEM_UART,
				"Test transmission unsuccessful - connection closed.");
		uart_close();
		return(false);
	}

	// Start output handler thread
	state->thread = 0;
	if (thrd_create(&state->thread, &outputHandlerThread, state) != thrd_success) {
		caerLog(CAER_LOG_ALERT, SUBSYSTEM_UART,"Failed to start output handler thread");
		return (false);
	}
	state->buffer = ringBufferInit(bufferSize);
	if (state->buffer == NULL) {
		caerLog(CAER_LOG_ERROR, SUBSYSTEM_UART, "Failed to allocate transfer ring-buffer.");
		return (false);
	}
	atomic_store(&state->running, true);
	caerLog(CAER_LOG_NOTICE, SUBSYSTEM_UART, "Streaming flow events to port %s.",port);
	return (true);
}
Exemple #8
0
static void print(const char *str)
{
	while(*str) {
		uart_tx(*str);
		str++;
	}
}
Exemple #9
0
/**
 * Poll the specified string out the log port.
 *
 * @param s The specified string
 */
void log_s(const char *s) {
#ifdef LOG_AVAILABLE
#ifdef UART_AVAILABLE
    uart_tx(s);
#endif /* UART_AVAILABLE */
#endif /* LOG_AVAILBLE */
}
Exemple #10
0
/*f test_entry_point
 */
extern int test_entry_point()
{
    int i;
    static const char text[] = "A test message from the UART\n";

    for (i=0; text[i]; i++)
    {
        uart_tx( text[i] );
    }
    uart_tx( 0 );
    uart_tx( 0 );

    for (i=0; i<1000; i++);

    return 0;
}
Exemple #11
0
void uart_tx_str(const char* str) {
    char c;
    while((c=*str)) {
        uart_tx(c);
        str++;
    }
}
main()
{
unsigned char temp;
unsigned char a[10];
	unsigned char i=0;

	uart_init();
lcd_init();

	do
	{		
		temp=uart_rx();
		uart_tx(temp);
		a[i++]=temp;
		lcd_cmd(0x01);
		lcd_data(temp);
		lcd_cmd(0x85);
		lcd_int(temp);
		lcd_cmd(0x89);
		lcd_string("0x");
		lcd_hex(temp);
		delay_ms(1000);
	}while(temp!=13);
	a[--i]='\0';
	lcd_cmd(0xc0);
	lcd_string(a);
	delay_ms(5000);
}
void main_task(void *pvParameters) {
    DBG("main task...");

    gpio_init();

#ifndef TEST_DATA
    //unsigned char mac[] = {0x00, 0xF4, 0xB9, 0x6A, 0x32, 0xED};
    //wifi_promiscuous_set_mac(mac);
    wifi_promiscuous_enable(1);

#ifdef FIXED_CHANNEL
    wifi_set_channel(FIXED_CHANNEL);
#endif

#endif

#ifdef TEST_DATA
    unsigned char mac[6];
    int i;

    for (i; i < 6; i++) {
        mac[i] = (unsigned char) i;
    }

    while (1) {
        uart_tx(0xff, 0xee, -14, (char *) mac, 10, 0x10203040);
        vTaskDelay(1000 / portTICK_RATE_MS);
    }
#endif

    vTaskSuspend(NULL);
}
Exemple #14
0
void mark_handler(void) {
    tooth_counter = 0;
    permit_tooth_counter = true;
    if (uart_tx_done(&uart0)) {
        sprintf(data, "Mark\n");
        uart_tx(&uart0, data, strlen(data));
    }
}
Exemple #15
0
/**
 * Received a rfm12 packet
 *
 * @param value The packet data
 */
void rfm12_receive(uint8_t *value) {

#ifdef UART_AVAILABLE
    uart_tx_uint16_t((((uint16_t)value[1] << 8) | value[2]));
    uart_tx_uint16_t((((uint16_t)value[3] << 8) | value[4]));
    uart_tx("\n");
#endif /* UART_AVAILABLE */
}
Exemple #16
0
char key_get_key(void)
{
	uart_tx('C');		//tell the keyboard to send the last key
	
	while(!uart_available()) {}
	
	return uart_read_buff();
}
Exemple #17
0
void action_main_init(void) {
    coil_act_sorting_insert(&root, &coil14on);
    coil_act_sorting_insert(&root, &coil14off);
    coil_act_sorting_insert(&root, &coil23on);
    coil_act_sorting_insert(&root, &coil23off);
    while (!(uart_tx_done(&uart0)));
    sprintf(data, "Action inited\n");
    uart_tx(&uart0, data, strlen(data));
}
Exemple #18
0
void port_main_init(void) {
    pin_out(&b4);
    pin_out(&b5);
    pin_out(&b6);
    pin_out(&b7);
    pin_in_pu(&l1);
    while (!(uart_tx_done(&uart0)));
    sprintf(data, "Port inited\n");
    uart_tx(&uart0, data, strlen(data));
}
Exemple #19
0
void uart_main_init(uart_t* uart) {
    uart_init(uart);
    uart_baud_rate(uart, UART_UBRR_VALUE);
    uart_character_size(uart, 8);
    uart_parity_mode(uart, UPM_DIS);
    uart_stop_bit(uart, 1);
    while (!(uart_tx_done(uart)));
    sprintf(data, "Uart inited\n");
    uart_tx(uart, data, strlen(data));
}
Exemple #20
0
/*******************************************************************************
* PUBLIC FUNCTION: uart_putstr
*
* PARAMETERS:
* ~ csz_string	- The null terminated string to transmit.
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Transmit a string using the UART.
*
*******************************************************************************/
void uart_putstr(const char* csz_string)
{
	// Loop until the end of string.
	while (*csz_string != '\0') {
		uart_tx(*csz_string);
			
		// Point to next character.
		csz_string++;
	}
}
Exemple #21
0
/**
 * Function called when a message needs to be written to the serial port.
 * @param msg_len Length of the message.
 * @param msg_data Message data, including the header.
 * @param data_len Optional variable data length.
 * @param data Optional variable data.
 */
static void on_message_send(uint16 msg_len, uint8* msg_data){
    /** Variable for storing function return values. */
    int ret;

    ret = uart_tx(msg_len, msg_data);
    if (ret < 0) {
        printf("on_message_send() - failed to write to serial port %s, ret: %d, errno: %d\n", uart_port, ret, errno);
        exit(EXIT_FAILURE);
    }
}
Exemple #22
0
/* Функция вызывается из прерывания и не может быть прервана. */
void uart_tx_done()
{
    if (out_offset < SIZE(out_combuf)) {
        uint8_t data;
        data = ITEM(out_combuf, out_offset);
        data ^= out_xor_char;
        if ((BEGIN_MARKER == data) || (ESC_MARKER == data)) {
            out_xor_char = XOR_MARKER;
            uart_tx(ESC_MARKER);
            return;
        }
        out_xor_char = 0;
        ++out_offset;
        uart_tx(data);
    } else {
        out_offset = -1;
        if( ISZIGLOAD ) __post_task( &task_combuf_send );
    }
}
Exemple #23
0
void stop_handler(void) {
    tooth_counter = 0;
    permit_tooth_counter = false;
    test_off();
    coil14_off();
    coil23_off();
    if (uart_tx_done(&uart0)) {
        sprintf(data, "Stop\n");
        uart_tx(&uart0, data, strlen(data));
    }
}
Exemple #24
0
Fichier : uart.c Projet : rargo/app
int uart_printf(int ch, const char *fmt, ...)
{
	va_list varg;

	va_start(varg, fmt);
	vsprintf((char *)uart_printf_buffer, fmt, varg);
	va_end(varg);

	return uart_tx(ch, uart_printf_buffer, \
			strlen((char *)uart_printf_buffer));
}
Exemple #25
0
/**
 * Function called when a message needs to be written to the serial port.
 * @param msg_len Length of the message.
 * @param msg_data Message data, including the header.
 * @param data_len Optional variable data length.
 * @param data Optional variable data.
 */
static void on_message_send(uint16_t msg_len, uint8_t* msg_data)
{
    /** Variable for storing function return values. */
    int ret;

    ret = uart_tx(msg_len, msg_data);
    if (ret < 0)
    {
        printf("on_message_send() - failed to write to serial port");
        exit(EXIT_FAILURE);
    }
}
Exemple #26
0
void main()
{
	char commands[] = {128, 131 };
	char commands2[] = { 145, 0, 10, 0, 105};
	//char commands2[] = {152, 13, 137, 1, 44, 128, 0, 156, 1, 144, 137, 0, 0, 0, 0};
	int num_of_commands=2;
	int num_of_commands2=5;	

	int fd;
	fd=uart_init(57600,"/dev/ttyUSB0");
	for(int i=0;i<num_of_commands;i++)
	{
		uart_tx(fd,commands[i]);
	}
	sleep(1);
	for(int i=0;i<num_of_commands2;i++)
	{
		uart_tx(fd,commands2[i]);
	}
        sleep(1);
	printf("stopping\n");
//stop
	char commands3 [] = {128, 131}; 
	char commands4 [] ={145, 0, 0, 0, 0};
	//unsigned char commands[] = {128,132,139,2,0,0};
	int num_of_commands3=2;
	int num_of_commands4=5;	

	for(int i=0;i<num_of_commands3;i++)
	{
		uart_tx(fd,commands3[i]);
	}
	sleep(1);
	for(int i=0;i<num_of_commands4;i++)
	{
		uart_tx(fd,commands4[i]);
	}
	uart_deinit(fd);
}
Exemple #27
0
/*f command_read_location
 */
static int command_read_location( int argc, unsigned int *args )
{
    unsigned int *ptr;
    unsigned int v;
    int i, j, max;
    if (argc<1)
        return 1;
    max = 8;
    if (argc>1)
    {
        max = args[1];
    }
    max = (max>256)?256:max;

    ptr = (unsigned int *)args[0];

    for (i=j=0; (i<max); i++)
    {
        if (j==0)
        {
            if (i>0)
            {
                uart_tx_nl();
            }
            uart_tx_hex8( (unsigned int)(ptr+i*sizeof(int)) );
            uart_tx(':');
        }
        else
        {
            uart_tx(' ');
        }
        v = ptr[i];
        uart_tx_hex8(v);
        j++;
        if (j==8) j=0;
    }
    return 0;
}
/*
 * Poll for data. If RXNE, receive the packet. If TXE, see if there's another
 * packet to transmit.
 */
void uart_platform_poll(void)
{
	u8 *dr;

	if (GP_USART->SR & USART_SR_RXNE) {
		uart_recv(GP_USART->DR & 0xff);
	}
	if (GP_USART->SR & USART_SR_TXE) {
		dr = uart_tx();
		if (dr != NULL) {
			GP_USART->DR = *dr & 0xff;
		}
	}
}
Exemple #29
0
/**
 * The main function.
 */
int main(void) {

    /* Initialization */
    init_qfly();
    log_s("receiver initialization ... ok\n");

    /* Our loop */
    while (1) {

        /* Wait 100ms */
        _delay_ms(100);

#ifdef UART_AVAILABLE
        if (uart_rx_ready()) {
            uart_tx("Echo: ");
            uart_tx(uart_rx());
            uart_tx("\n");
        }
#endif /* UART_AVAILABLE */
    }

    /* Finally. (Never ever) */
    return 0;
}
Exemple #30
0
Fichier : main.c Projet : 8l/potato
int main(void)
{
	const char * hello_string = "Hello world\n\r";

	uart_initialize(&uart0, (volatile void *) PLATFORM_UART0_BASE);
	uart_set_divisor(&uart0, uart_baud2divisor(115200, PLATFORM_SYSCLK_FREQ));

	for(int i = 0; hello_string[i] != 0; ++i)
	{
		while(uart_tx_fifo_full(&uart0));
		uart_tx(&uart0, hello_string[i]);
	}

	return 0;
}