Rev 140 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 140 | Rev 483 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include "fc.h" |
1 | #include "fc.h" |
Line 2... | Line -... | ||
2 | - | ||
3 | - | ||
Line -... | Line 2... | ||
- | 2 | ||
- | 3 | ||
- | 4 | ||
4 | unsigned char TxBuffer[150]; |
5 | unsigned char TxBuffer[MAX_BUFF_LEN]; |
5 | unsigned char _TxBuffer[150]; |
6 | unsigned char _TxBuffer[MAX_BUFF_LEN]; |
Line 6... | Line 7... | ||
6 | 7 | ||
Line 27... | Line 28... | ||
27 | } |
28 | } |
Line 28... | Line 29... | ||
28 | 29 | ||
29 | 30 | ||
- | 31 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
|
30 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
32 | { |
31 | { |
33 | // return; |
32 | int status =0; |
34 | int status =0; |
33 | unsigned int pt = 0; |
35 | unsigned int pt = 0; |
Line 113... | Line 115... | ||
113 | char in_char='#'; |
115 | char in_char='#'; |
114 | int count=0; |
116 | int count=0; |
115 | int r=0; |
117 | int r=0; |
116 | int i=0; |
118 | int i=0; |
Line -... | Line 119... | ||
- | 119 | ||
117 | 120 | int p=0; |
|
118 | printf("starting read\n"); |
121 | printf("starting read\n"); |
119 | while(in_char!='\n') |
122 | while(in_char!='\r') |
- | 123 | { |
|
120 | { |
124 | p++; |
121 | // printf("b read\n"); |
125 | // printf("b read\n"); |
- | 126 | count=read(mk_socket,&in_char,1); |
|
- | 127 | ||
122 | count=read(mk_socket,&in_char,1); |
128 | // if ( count ==-1) exit(0); |
123 | //printf("a read %d\n",count); |
129 | printf("a read %d %d %c \n",p,count,in_char); |
124 | if (count!=-1) |
130 | if (count!=-1) |
125 | { |
131 | { |
126 | // printf("%c\n",in_char); |
132 | // printf("%c\n",in_char); |
Line 147... | Line 153... | ||
147 | } |
153 | } |
Line 148... | Line 154... | ||
148 | 154 | ||
149 | 155 | ||
150 | int connect_mk_bluetooth(char dest[18]) |
- | |
151 | { |
156 | int connect_mk_bluetooth(char dest[18]) |
Line 152... | Line 157... | ||
152 | 157 | { |
|
153 | struct sockaddr_rc addr ; |
158 | struct sockaddr_rc addr ; |
Line 163... | Line 168... | ||
163 | // connect to server |
168 | // connect to server |
164 | status = connect(mk_socket, (struct sockaddr *)&addr, sizeof(addr)); |
169 | status = connect(mk_socket, (struct sockaddr *)&addr, sizeof(addr)); |
Line 165... | Line 170... | ||
165 | 170 | ||
166 | printf("connection status %d\n",status); |
171 | printf("connection status %d\n",status); |
167 | return status; |
- | |
168 | 172 | return status; |
|
Line -... | Line 173... | ||
- | 173 | } |
|
- | 174 | ||
- | 175 | ||
- | 176 | int connect_mk_tty(char* tty_filename) |
|
- | 177 | { |
|
- | 178 | ||
- | 179 | mk_socket = open(tty_filename,O_RDWR); |
|
- | 180 | ||
- | 181 | ||
- | 182 | ||
- | 183 | struct termios termattr; |
|
- | 184 | speed_t baudRate; |
|
- | 185 | ||
- | 186 | /* Make a copy of the termios structure. */ |
|
- | 187 | tcgetattr(mk_socket, &termattr); |
|
- | 188 | ||
- | 189 | termattr.c_iflag = IGNBRK | IGNPAR; |
|
- | 190 | termattr.c_cflag=CS8 | CREAD | CLOCAL; |
|
- | 191 | // termattr.speed_t=B57600; |
|
- | 192 | ||
- | 193 | ||
- | 194 | tcsetattr(mk_socket, TCSANOW, &termattr); |
|
- | 195 | ||
- | 196 | ||
- | 197 | /* |
|
- | 198 | usleep(1000000); |
|
- | 199 | char in_char='#'; |
|
- | 200 | int count=0; |
|
- | 201 | int r=0; |
|
- | 202 | int i=0; |
|
- | 203 | ||
- | 204 | int p=0; |
|
- | 205 | printf("starting read %d\n",mk_socket); |
|
- | 206 | while (1) |
|
- | 207 | { |
|
- | 208 | p=0; |
|
- | 209 | r=0; |
|
- | 210 | char in_char='#'; |
|
- | 211 | while((in_char!='\r'))//&&(r<MAX_BUFF_LEN)) |
|
- | 212 | { |
|
- | 213 | // p++; |
|
- | 214 | // printf("b read\n"); |
|
- | 215 | count=read(mk_socket,&in_char,1); |
|
- | 216 | // tcflush( mk_socket, TCOFLUSH ); |
|
- | 217 | |
|
- | 218 | // printf("\np !read %d %d %c \n",p,count,in_char); |
|
- | 219 | ||
- | 220 | //count=read(mk_socket,&in_char,1); |
|
- | 221 | // tcflush( mk_socket, TCOFLUSH ); |
|
- | 222 | |
|
- | 223 | // printf("\np !read %d %d %d %c \n",r,p,count,in_char); |
|
- | 224 | printf("%d %c \n",r, in_char); |
|
- | 225 | |
|
- | 226 | if (count==1) |
|
- | 227 | { |
|
- | 228 | // printf("%c\n",in_char); |
|
- | 229 | RxBuffer[r]=in_char; |
|
- | 230 | |
|
- | 231 | if (in_char!=0) |
|
- | 232 | PrintableRxBuffer[r]=in_char; |
|
- | 233 | else |
|
- | 234 | PrintableRxBuffer[r]='0'; |
|
- | 235 | r++; |
|
- | 236 | } |
|
- | 237 | //else |
|
- | 238 | //printf("%d/%d",errno,EBADF); |
|
- | 239 | |
|
- | 240 | } |
|
- | 241 | PrintableRxBuffer[r]=0; |
|
- | 242 | printf("buff> %d\n %s\n", r, PrintableRxBuffer); |
|
- | 243 | } |
|
- | 244 | */ |
|
- | 245 | if (mk_socket<0) |
|
- | 246 | return 0; |
|
- | 247 | else |
|
Line 169... | Line 248... | ||
169 | } |
248 | return 1; |
170 | 249 | ||
171 | - | ||
172 | - | ||
173 | 250 | } |
|
Line 174... | Line 251... | ||
174 | int connect_mk_localhost_socket(int port) |
251 | |
175 | { |
252 | |
176 | 253 | int connect_mk_localhost_socket(int port) |
|
Line 177... | Line -... | ||
177 | int status; |
- | |
178 | struct sockaddr_in sa; |
- | |
179 | 254 | { |
|
180 | sa.sin_family = AF_INET; |
- | |
181 | sa.sin_addr.s_addr = htonl(0x0); |
- | |
182 | sa.sin_port = htons(port); |
- | |
Line 183... | Line -... | ||
183 | - | ||
184 | // allocate a socket |
- | |
185 | // s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); |
255 | struct sockaddr_in sa; |
186 | mk_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); |
- | |
187 | //); |
- | |
188 | - | ||
Line 189... | Line 256... | ||
189 | // set the connection parameters (who to connect to) |
256 |