Hi.
I’ve been trying to hookup a LS20031 GPS to the Sparkfun GPIO Block for Edison. So far the GPS is blinking so i guess its doing ok when it comes to power and getting a lock. But I’m getting stuck on the Edison side, my c code so far is looking like this:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <string.h>
#include <errno.h>
#include <mraa.h>
void* handling_uart(void *arg) {
unsigned char rbuffer[256];
int *uart0 = (int *)arg;
errno = 0;
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
while(1) {
pthread_testcancel();
printf("going to try and read\n");
read((*uart0), rbuffer, 256);
memset(rbuffer, 0, 256);
printf("\n read() %s\n", rbuffer);
printf("read done. \r\n");
}
}
int main(void) {
mraa_uart_context uart_i;
uart_i = mraa_uart_init(0);
// not sure what mraa_uart_init is doing
if(uart_i == NULL) {
printf("failed to find uart\n");
}
int uart0 = -1;
pthread_t thread;
int ret, status;
char serial_port[] = "/dev/ttyMFD1";
uart0 = open(serial_port, O_RDWR, O_NONBLOCK);
if(uart0 == -1) {
printf("\n open() failed with error [%s]\n", strerror(errno));
return -1;
}
struct termios options;
tcgetattr(uart0, &options);
cfsetispeed(&options, B57600);
cfsetospeed(&options, B57600);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_cc[VTIME] = 0;
options.c_cc[VMIN] = 0;
options.c_lflag |= ICANON;
tcflush(uart0, TCIFLUSH);
tcsetattr(uart0, TCSANOW, &options);
ret = pthread_create(&thread, NULL, handling_uart, &uart0);
if(ret) {
printf("\n pthread create failed with error [%s]\n", strerror(errno));
return -1;
}
char c = getchar();
status = pthread_cancel(thread);
if(status) {
printf("\n pthread cancel failed with error [%s]\n", strerror(errno));
return -1;
}
close(uart0);
return 0;
}
$ gcc -pthread -o uart uart.c -lmraa
I’m not sure if the serial is /dev/ttyMFD1, I have tried all the rest listed under ls /dev/tty*.
currently at a loss what i could be doing wrong.
it could all be wrong of course.