1 | #include <sys/types.h>
|
2 | #include <sys/stat.h>
|
3 | #include <fcntl.h>
|
4 | #include <termios.h>
|
5 | #include <stdio.h>
|
6 | #include <string.h>
|
7 | #include <unistd.h>
|
8 | #include "crc.h"
|
9 |
|
10 | #define BAUDRATE B4800
|
11 | #define MODEMDEVICE "/dev/ttyS0"
|
12 | #define _POSIX_SOURCE 1 /* POSIX compliant source */
|
13 | #define FALSE 0
|
14 | #define TRUE 1
|
15 | volatile int STOP=FALSE;
|
16 |
|
17 |
|
18 | int main(void)
|
19 | {
|
20 | int fd;
|
21 | int res;
|
22 | struct termios oldtio;
|
23 | struct termios newtio;
|
24 | char buf[255];
|
25 | char dest[2];
|
26 | char quelle[2];
|
27 | char temp[10];
|
28 |
|
29 | char *status;
|
30 | char *zentr_nr;
|
31 | char *linien_nr;
|
32 | char *melder_nr;
|
33 |
|
34 | status = (char *)malloc(20);
|
35 | zentr_nr = (char *)malloc(20);
|
36 | linien_nr = (char *)malloc(20);
|
37 | melder_nr = (char *)malloc(20);
|
38 |
|
39 | dest[0] = 0x30;
|
40 | dest[1] = 0x31;
|
41 | quelle[0] = 0x39;
|
42 | quelle[1] = 0x36;
|
43 |
|
44 | /* UART initialisieren und starten /dev/ttyS0 */
|
45 |
|
46 | fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY | O_SYNC );
|
47 | tcgetattr(fd,&oldtio); /* save current serial port settings */
|
48 | bzero(&newtio, sizeof(newtio)); /* clear struct for new port settings */
|
49 | newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
|
50 | newtio.c_iflag = IGNPAR | ICRNL;
|
51 | newtio.c_oflag = 0;
|
52 | newtio.c_lflag = ICANON;
|
53 | newtio.c_cc[VINTR] = 0; /* Ctrl-c */
|
54 | newtio.c_cc[VQUIT] = 0; /* Ctrl-\ */
|
55 | newtio.c_cc[VERASE] = 0; /* del */
|
56 | newtio.c_cc[VKILL] = 0; /* @ */
|
57 | newtio.c_cc[VEOF] = 4; /* Ctrl-d */
|
58 | newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
|
59 | newtio.c_cc[VMIN] = 1; /* blocking read until 1 character arrives */
|
60 | newtio.c_cc[VSWTC] = 0; /* '\0' */
|
61 | newtio.c_cc[VSTART] = 0; /* Ctrl-q */
|
62 | newtio.c_cc[VSTOP] = 0; /* Ctrl-s */
|
63 | newtio.c_cc[VSUSP] = 0; /* Ctrl-z */
|
64 | newtio.c_cc[VEOL] = 0; /* '\0' */
|
65 | newtio.c_cc[VREPRINT] = 0; /* Ctrl-r */
|
66 | newtio.c_cc[VDISCARD] = 0; /* Ctrl-u */
|
67 | newtio.c_cc[VWERASE] = 0; /* Ctrl-w */
|
68 | newtio.c_cc[VLNEXT] = 0; /* Ctrl-v */
|
69 | newtio.c_cc[VEOL2] = 0; /* '\0' */
|
70 | tcflush(fd, TCIFLUSH);
|
71 | tcsetattr(fd,TCSANOW,&newtio);
|
72 |
|
73 |
|
74 | /* Endlosschleife zum Empfangen und Senden von Nachrichten */
|
75 | while (1) {
|
76 | res = read(fd,buf,255);
|
77 | buf[res]=0;
|
78 |
|
79 | printf("Empf: %s\n", buf);
|
80 |
|
81 | switch(buf[9]){
|
82 | case '1': printf("Mimimax case %d\n", buf[9]);
|
83 | minimax_quittierung(quelle, dest, fd);
|
84 | break;
|
85 | case '2': printf("Mimimax case %d\n", buf[9]);
|
86 | minimax_quittierung(quelle, dest, fd);
|
87 | break;
|
88 | case '3': printf("Mimimax case %d\n", buf[9]);
|
89 | minimax_quittierung(quelle, dest, fd);
|
90 | break;
|
91 | case '4': printf("Mimimax case %d\n", buf[9]);
|
92 | minimax_quittierung(quelle, dest, fd);
|
93 | break;
|
94 | case '5': printf("Mimimax case %d\n", buf[9]);
|
95 | minimax_quittierung(quelle, dest, fd);
|
96 | break;
|
97 | case '6': printf("Mimimax case %d\n", buf[9]);
|
98 | printf("Starte kopieren...\n");
|
99 |
|
100 | temp[0] = (char)buf[10];
|
101 | temp[1] = (char)buf[11];
|
102 | temp[2] = '\0';
|
103 | status = temp;
|
104 |
|
105 | temp[0] = (char)buf[16];
|
106 | temp[1] = (char)buf[17],
|
107 | temp[2] = '\0';
|
108 | zentr_nr = temp;
|
109 |
|
110 | temp[0] = (char)buf[20];
|
111 | temp[1] = (char)buf[21];
|
112 | temp[2] = (char)buf[22];
|
113 | temp[3] = (char)buf[23];
|
114 | temp[4] = '\0';
|
115 | linien_nr = temp;
|
116 |
|
117 | temp[0] = (char)buf[24];
|
118 | temp[1] = (char)buf[25];
|
119 | temp[2] = '\0';
|
120 | melder_nr = temp;
|
121 |
|
122 | printf("Status: %s\n", status);
|
123 | printf("Zentrale: %s\n", zentr_nr);
|
124 | printf("Linie: %s\n", linien_nr);
|
125 | printf("Melder: %s\n", melder_nr);
|
126 | minimax_quittierung(quelle, dest, fd);
|
127 | break;
|
128 | case '7': printf("Mimimax case %d\n", buf[9]);
|
129 | minimax_quittierung(quelle, dest, fd);
|
130 | break;
|
131 | case 'L': printf("Mimimax case %d\n", buf[9]);
|
132 | minimax_quittierung(quelle, dest, fd);
|
133 | break;
|
134 | case 'b': printf("Mimimax case %d\n", buf[9]);
|
135 | minimax_quittierung(quelle, dest, fd);
|
136 | break;
|
137 | case 'x': printf("Mimimax case %d\n", buf[9]);
|
138 | minimax_quittierung(quelle, dest, fd);
|
139 | break;
|
140 | case 'Q': printf("Mimimax case %d\n", buf[9]);
|
141 | minimax_quittierung(quelle, dest, fd);
|
142 | break;
|
143 | case 'N': printf("Mimimax case %d\n", buf[9]);
|
144 | minimax_quittierung(quelle, dest, fd);
|
145 | break;
|
146 | case 'l': printf("Mimimax case %d\n", buf[9]);
|
147 | minimax_quittierung(quelle, dest, fd);
|
148 | break;
|
149 | case 'I': printf("Mimimax case %d\n", buf[9]);
|
150 | minimax_quittierung(quelle, dest, fd);
|
151 | break;
|
152 | default : printf("Mimimax case default\n");
|
153 | minimax_negativ(quelle, dest, fd);
|
154 | break;
|
155 | }
|
156 | status = 0;
|
157 | zentr_nr = 0;
|
158 | linien_nr = 0;
|
159 | melder_nr = 0;
|
160 | printf("***********************************************************************************\n");
|
161 | }
|
162 |
|
163 | tcsetattr(fd,TCSANOW,&oldtio);
|
164 | }
|