1 contributor
/**
* @file readnmea.c
* @author Yanik Cawidrone
* @date 1st July 2017
* @version 0.1
* @brief A Linux user space program that communicates with the fakenmea LKM.
* @see http://derekmolloy.ie/writing-a-linux-kernel-module-part-2-a-character-device/
* @see https://github.com/derekmolloy/exploringBB.git
*/
#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<fcntl.h>
#include<string.h>
#include<unistd.h>
#include <time.h>
#define BUFFER_LENGTH 256
static char receive[BUFFER_LENGTH];
int main(){
int ret, fd;
char stringToSend[BUFFER_LENGTH];
fd = open("/dev/nmea", O_RDONLY); // Open the device with read/write access
if (fd < 0){
perror("Failed to open the device...");
return errno;
}
ret = read(fd, receive, BUFFER_LENGTH); // Read the response from the LKM
if (ret < 0){
perror("Failed to read the message from the device.");
return errno;
}
printf("%s", receive);
close(fd);
return 0;
}