X-Git-Url: http://gitweb.hachti.de/?a=blobdiff_plain;f=pc-tools%2Fsrc-filters%2Fload.c;fp=pc-tools%2Fsrc-filters%2Fload.c;h=c4516210b38b043b7ccf7d0fbf36c0c1a218d1e1;hb=437b3ba835f66625031f4711cd0a963be67ccf5a;hp=0000000000000000000000000000000000000000;hpb=008a15c07914ebf7f69e6243c4d2754c8f959a7f;p=h316.git diff --git a/pc-tools/src-filters/load.c b/pc-tools/src-filters/load.c new file mode 100644 index 0000000..c451621 --- /dev/null +++ b/pc-tools/src-filters/load.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include +#include + +struct termios orgstate; +struct termios workstate; + +#define PORT_FILE "/dev/ttyS0" +#define BUFFER_SIZE 1000000 + +char * buffer; +int sp, ep, count, portfd; + +void sighandler(int sig){ + sp=0; + ep=count-1; + close (portfd); +// fprintf(stderr,"%i %i\n", sp, ep); + if (count>0) { + while(buffer[sp]==0) sp++; + while(buffer[ep]==0) ep--; + } + + write(1,buffer+sp,ep-sp+1); + tcdrain(2); + fprintf(stderr,"Eingelesen: %i\n",ep-sp+1); + tcsetattr(portfd, TCSANOW, &orgstate); + close(portfd); + exit(0); +} + +int main (int argc, char ** argv){ + + portfd=open(PORT_FILE, O_RDWR); + tcgetattr(portfd, &orgstate); + tcgetattr(portfd, &workstate); + cfmakeraw(&workstate); +// workstate.c_oflag=0; + workstate.c_cflag|=CS8+CREAD+CLOCAL+CRTSCTS+CSTOPB ; +// workstate.c_lflag=0; + cfsetspeed(&workstate, B4800); + tcsetattr(portfd, TCSANOW, &workstate); + count=0; + + signal(SIGINT, sighandler); + buffer=(char *) malloc(BUFFER_SIZE); + fprintf(stderr, "Warte auf Daten. Einspielen und dann CTRL-C drücken.\n"); + + while(1) { + int erg=read(portfd, buffer+count, 1); + if (erg>0) count+=erg; + } + + +} //main(); +// Ende.