/********** * Polprog 2018 * 3 clause BSD licence * http://polprog.net */ #include #include #include #include #include "util.h" #define BUFSIZE 128 #define LINESIZE 26 #define SLEEP_MS 1000 void xxd(char* d){ while(*d != 0){ printf("%02X ", *d); d++; } } int main(int argc, char** argv){ if (argc < 2) { printf("Usage: %s \n", argv[0]); exit(1); } struct termios options; //serial port options printf("Initializing serial port: 9600 8n1\n"); //initialize serial port int portfd = open_port(argv[1]); tcgetattr(portfd, &options); cfsetispeed(&options, B9600); cfsetospeed(&options, B9600); options.c_cflag &= ~CRTSCTS; //no hw flow control options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; /* Mask the character size bits */ options.c_cflag |= CS8; /* Select 8 data bits */ options.c_cflag |= (CLOCAL | CREAD); options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //raw input fcntl(portfd, F_SETFL, FNDELAY); //enable blocking tcsetattr(portfd, TCSANOW, &options); printf("Port attributes set\n"); char * line = malloc(LINESIZE); if ( line == NULL ) exit(1); int i = 0; time_t timet; struct tm timestruct; printf("Running.....\n"); do{ timet = time(NULL); timestruct = *localtime(&timet); strftime(line, LINESIZE, "%d %b %y %T \n", ×truct); //printf("%s\r", line); write_chars(portfd, line); usleep(SLEEP_MS*1000); }while(1); return 0; }