Rev 483 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 483 | Rev 522 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | 4 | ||
5 | char names[MAX_BT_DEVICES][248]; |
5 | char names[MAX_BT_DEVICES][248]; |
Line 6... | Line 6... | ||
6 | char addrs[MAX_BT_DEVICES][19]; |
6 | char addrs[MAX_BT_DEVICES][19]; |
- | 7 | ||
Line 7... | Line 8... | ||
7 | 8 | char BtHostRxBuffer[150]; |
|
8 | char BtHostRxBuffer[150]; |
9 | char BtHostRxBufferDecoded[150]; |
9 | 10 | ||
10 | 11 | int BtRxCount; |
|
Line 11... | Line 12... | ||
11 | int scan_bt() |
12 | int scan_bt() |
Line 61... | Line 62... | ||
61 | unsigned int opt = sizeof(rem_addr); |
62 | unsigned int opt = sizeof(rem_addr); |
Line 62... | Line 63... | ||
62 | 63 | ||
Line -... | Line 64... | ||
- | 64 | int maxfd, sock_flags; |
|
- | 65 | ||
- | 66 | ||
- | 67 | unsigned char BT_TxBuffer[MAX_BUFF_LEN]; |
|
Line 63... | Line 68... | ||
63 | int maxfd, sock_flags; |
68 | |
64 | 69 | extern struct str_DebugOut DebugOut; |
|
Line 65... | Line 70... | ||
65 | 70 | struct str_VersionInfo VersionInfo; |
|
Line 98... | Line 103... | ||
98 | send(client,"\r",1,0); |
103 | send(client,"\r",1,0); |
99 | } |
104 | } |
100 | return 1; |
105 | return 1; |
101 | } |
106 | } |
Line -... | Line 107... | ||
- | 107 | ||
- | 108 | ||
- | 109 | struct { |
|
- | 110 | unsigned char MenuePunkt; |
|
- | 111 | unsigned char MaxMenue; |
|
- | 112 | char DisplayBuff[80]; |
|
- | 113 | } menu; |
|
- | 114 | ||
- | 115 | ||
- | 116 | void copy_lcd_str(int x,int y,char str[]) |
|
- | 117 | { |
|
- | 118 | int pos=0; |
|
- | 119 | while (str[pos]!=0) |
|
- | 120 | { |
|
- | 121 | ||
- | 122 | menu.DisplayBuff[y*20+x+pos]=str[pos]; |
|
- | 123 | pos++; |
|
- | 124 | } |
|
- | 125 | ||
- | 126 | } |
|
- | 127 | ||
- | 128 | ||
- | 129 | ||
- | 130 | void Menu(void) |
|
- | 131 | { |
|
- | 132 | ||
- | 133 | // menu.MenuePunkt=0; |
|
- | 134 | menu.MaxMenue=3; |
|
- | 135 | int x; |
|
- | 136 | int y; |
|
- | 137 | ||
- | 138 | char tmp_str[20]; |
|
- | 139 | ||
- | 140 | for (x=0;x<20;x++) |
|
- | 141 | for (y=0;y<4;y++) |
|
- | 142 | menu.DisplayBuff[y*20+x]=' '; |
|
- | 143 | ||
- | 144 | switch(menu.MenuePunkt) |
|
- | 145 | { |
|
- | 146 | case 0: |
|
- | 147 | // LCD_printfxy(0,0,"+ Riddim +"); |
|
- | 148 | /* LCD_printfxy(0,1,"Version: %d %d",0,8); |
|
- | 149 | LCD_printfxy(0,2,""); |
|
- | 150 | LCD_printfxy(0,3,"(cc) 2009 ligi"); |
|
- | 151 | */ |
|
- | 152 | // clear_lcd |
|
- | 153 | ||
- | 154 | ||
- | 155 | ||
- | 156 | sprintf(tmp_str,"+ Riddim +"); |
|
- | 157 | copy_lcd_str(0,0,tmp_str); |
|
- | 158 | ||
- | 159 | sprintf(tmp_str,"Version: V%d.%d/%d",RIDDIM_VERSION_MAJOR,RIDDIM_VERSION_MINOR,RIDDIM_VERSION_PATCH); |
|
- | 160 | copy_lcd_str(0,1,tmp_str); |
|
- | 161 | ||
- | 162 | ||
- | 163 | sprintf(tmp_str,"(cc) 2009 LiGi"); |
|
- | 164 | copy_lcd_str(0,3,tmp_str); |
|
- | 165 | ||
- | 166 | // sprintf(&menu.DisplayBuff,"+ Riddim ++"); |
|
- | 167 | ||
- | 168 | // sprintf(&menu.DisplayBuff+20,"Version: %d %d",0,8); |
|
- | 169 | ||
- | 170 | break; |
|
- | 171 | ||
- | 172 | case 1: |
|
- | 173 | sprintf(tmp_str,"Loop:"); |
|
- | 174 | copy_lcd_str(0,0,tmp_str); |
|
- | 175 | sprintf(tmp_str," Count %ld",trip_count); |
|
- | 176 | copy_lcd_str(0,1,tmp_str); |
|
- | 177 | sprintf(tmp_str," Time %ld",last_trip_time); |
|
- | 178 | copy_lcd_str(0,2,tmp_str); |
|
- | 179 | break; |
|
- | 180 | ||
- | 181 | ||
- | 182 | case 2: |
|
- | 183 | sprintf(tmp_str,"Inputs:"); |
|
- | 184 | copy_lcd_str(0,0,tmp_str); |
|
- | 185 | sprintf(tmp_str," Complete %d",evdevs_count); |
|
- | 186 | copy_lcd_str(0,1,tmp_str); |
|
- | 187 | sprintf(tmp_str," Connected %d",input_count); |
|
- | 188 | copy_lcd_str(0,2,tmp_str); |
|
- | 189 | sprintf(tmp_str," Configured %d",configured_input_count); |
|
- | 190 | copy_lcd_str(0,3,tmp_str); |
|
- | 191 | break; |
|
- | 192 | ||
- | 193 | case 3: |
|
- | 194 | sprintf(tmp_str,"Nick: %d",act_nick); |
|
- | 195 | copy_lcd_str(0,0,tmp_str); |
|
- | 196 | sprintf(tmp_str,"Roll %d",act_roll); |
|
- | 197 | copy_lcd_str(0,1,tmp_str); |
|
- | 198 | sprintf(tmp_str,"Gier %d",act_gier); |
|
- | 199 | copy_lcd_str(0,2,tmp_str); |
|
- | 200 | sprintf(tmp_str,"Gas %d",act_gas); |
|
- | 201 | copy_lcd_str(0,3,tmp_str); |
|
- | 202 | break; |
|
- | 203 | ||
- | 204 | default: |
|
- | 205 | sprintf(tmp_str,"illegal page %d",menu.MenuePunkt); |
|
- | 206 | copy_lcd_str(0,0,tmp_str); |
|
- | 207 | break; |
|
- | 208 | } |
|
- | 209 | } |
|
- | 210 | ||
- | 211 | ||
- | 212 | ||
- | 213 | void BT_Decode64(void) // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden. |
|
- | 214 | { |
|
- | 215 | unsigned char a,b,c,d; |
|
- | 216 | unsigned char x,y,z; |
|
- | 217 | unsigned char ptrIn = 3; // start at begin of data block |
|
- | 218 | unsigned char ptrOut = 0; |
|
- | 219 | unsigned char len = BtRxCount - 5; // von der Gesamtbytezahl eines Frames gehen 3 Bytes des Headers ('#',Addr, Cmd) und 3 Bytes des Footers (CRC1, CRC2, '\r') ab. |
|
- | 220 | ||
- | 221 | while(len) |
|
- | 222 | { |
|
- | 223 | a = BtHostRxBuffer[ptrIn++] - '='; |
|
- | 224 | b = BtHostRxBuffer[ptrIn++] - '='; |
|
- | 225 | c = BtHostRxBuffer[ptrIn++] - '='; |
|
- | 226 | d = BtHostRxBuffer[ptrIn++] - '='; |
|
- | 227 | ||
- | 228 | x = (a << 2) | (b >> 4); |
|
- | 229 | y = ((b & 0x0f) << 4) | (c >> 2); |
|
- | 230 | z = ((c & 0x03) << 6) | d; |
|
- | 231 | printf("\naaaaa %d / %d\naaaaa s %s => x %d ; y %d ; z %d \n",ptrOut, BtRxCount ,BtHostRxBuffer,x,y,z); |
|
- | 232 | ||
- | 233 | ||
- | 234 | if(len--) BtHostRxBufferDecoded[ptrOut++] = x; else break; |
|
- | 235 | if(len--) BtHostRxBufferDecoded[ptrOut++] = y; else break; |
|
- | 236 | if(len--) BtHostRxBufferDecoded[ptrOut++] = z; else break; |
|
- | 237 | } |
|
- | 238 | //RxDataLen = ptrOut ; // wie viele Bytes wurden dekodiert? |
|
- | 239 | ||
- | 240 | } |
|
- | 241 | ||
- | 242 | void BT_AddCRC(unsigned int wieviele) |
|
- | 243 | { |
|
- | 244 | unsigned int tmpCRC = 0,i; |
|
- | 245 | for(i = 0; i < wieviele;i++) |
|
- | 246 | { |
|
- | 247 | tmpCRC += BT_TxBuffer[i]; |
|
- | 248 | } |
|
- | 249 | tmpCRC %= 4096; |
|
- | 250 | BT_TxBuffer[i++] = '=' + tmpCRC / 64; |
|
- | 251 | BT_TxBuffer[i++] = '=' + tmpCRC % 64; |
|
- | 252 | BT_TxBuffer[i++] = '\r'; |
|
- | 253 | } |
|
- | 254 | ||
- | 255 | void BT_SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
|
- | 256 | { |
|
- | 257 | // return; |
|
- | 258 | int status =0; |
|
- | 259 | unsigned int pt = 0; |
|
- | 260 | unsigned char a,b,c; |
|
- | 261 | unsigned char ptr = 0; |
|
- | 262 | ||
- | 263 | printf("packing base len %d -cmd %c\n",len,cmd); |
|
- | 264 | ||
- | 265 | BT_TxBuffer[pt++] = '#'; // Startzeichen |
|
- | 266 | BT_TxBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
|
- | 267 | BT_TxBuffer[pt++] = cmd; // Commando |
|
- | 268 | ||
- | 269 | while(len) |
|
- | 270 | { |
|
- | 271 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
|
- | 272 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
|
- | 273 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
|
- | 274 | BT_TxBuffer[pt++] = '=' + (a >> 2); |
|
- | 275 | BT_TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
|
- | 276 | BT_TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
|
- | 277 | BT_TxBuffer[pt++] = '=' + ( c & 0x3f); |
|
- | 278 | } |
|
- | 279 | ||
- | 280 | ||
- | 281 | ||
- | 282 | BT_AddCRC(pt); |
|
- | 283 | printf("Sending to BT_Client %d \n" , pt); |
|
- | 284 | ||
- | 285 | status = send(client,"\r" , 1, 0); |
|
- | 286 | ||
- | 287 | ||
- | 288 | // for (c=0;c<pt+2;c++) |
|
- | 289 | // { |
|
- | 290 | status = write(client,&BT_TxBuffer , pt+3); |
|
- | 291 | ||
- | 292 | ||
- | 293 | status = send(client,"\r" , 1, 0); |
|
- | 294 | printf("\n"); |
|
- | 295 | } |
|
- | 296 | ||
- | 297 | ||
- | 298 | void bt_process_buffer() |
|
- | 299 | { |
|
- | 300 | printf("processing buffer\n"); |
|
- | 301 | switch(BtHostRxBuffer[2]) |
|
- | 302 | { |
|
- | 303 | ||
- | 304 | case 'v': |
|
- | 305 | printf("got version request\n"); |
|
- | 306 | VersionInfo.SWMinor=RIDDIM_VERSION_MINOR; |
|
- | 307 | VersionInfo.SWMajor=RIDDIM_VERSION_MAJOR; |
|
- | 308 | VersionInfo.SWPatch=RIDDIM_VERSION_PATCH; |
|
- | 309 | ||
- | 310 | BT_SendOutData('V', RIDDIM_ADDRESS, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
|
- | 311 | ||
- | 312 | break; |
|
- | 313 | ||
- | 314 | case 'l': |
|
- | 315 | printf("got display request\n"); |
|
- | 316 | Menu(); |
|
- | 317 | menu.MenuePunkt=BtHostRxBufferDecoded[0]; |
|
- | 318 | printf("sending %s \n",menu.DisplayBuff); |
|
- | 319 | BT_SendOutData('L', RIDDIM_ADDRESS, (unsigned char *) &menu, sizeof(menu)); |
|
- | 320 | break; |
|
- | 321 | ||
- | 322 | } |
|
- | 323 | ||
- | 324 | } |
|
- | 325 | ||
- | 326 | ||
- | 327 | ||
- | 328 | ||
- | 329 | ||
- | 330 | ||
- | 331 | ||
- | 332 | ||
- | 333 | int r=0; |
|
- | 334 | ||
- | 335 | struct timeval last_debug_time; |
|
- | 336 | struct timeval act_time; |
|
102 | 337 | ||
103 | int bt_host_tick(int mk_fd) |
338 | int bt_host_tick(int mk_fd) |
Line 104... | Line 339... | ||
104 | { |
339 | { |
105 | 340 | ||
Line 110... | Line 345... | ||
110 | // timeout.tv_usec = 100; |
345 | // timeout.tv_usec = 100; |
111 | FD_ZERO(&readfds); |
346 | FD_ZERO(&readfds); |
112 | FD_ZERO(&writefds); |
347 | FD_ZERO(&writefds); |
113 | FD_SET(s, &readfds); |
348 | FD_SET(s, &readfds); |
114 | maxfd = s; |
349 | maxfd = s; |
115 | 350 | ||
116 | printf("waiting for connection\n"); |
351 | printf("waiting for bt connection\n"); |
117 | // status = select(maxfd + 1, &readfds, &writefds, 0, &timeout); |
352 | // status = select(maxfd + 1, &readfds, &writefds, 0, &timeout); |
118 | status = select(maxfd + 1, &readfds, &writefds, 0,& (struct timeval) { 0, 100 }); |
353 | status = select(maxfd + 1, &readfds, &writefds, 0,& (struct timeval) { 0, 100 }); |
119 | if( status > 0 && FD_ISSET( s, &readfds ) ) { |
354 | if( status > 0 && FD_ISSET( s, &readfds ) ) { |
120 | // incoming connection |
355 | // incoming connection |
121 | client = accept( s, (struct sockaddr*)&rem_addr, &opt ); |
356 | client = accept( s, (struct sockaddr*)&rem_addr, &opt ); |
Line 139... | Line 374... | ||
139 | } |
374 | } |
Line 140... | Line 375... | ||
140 | 375 | ||
141 | } |
376 | } |
142 | else |
377 | else |
- | 378 | { |
|
- | 379 | gettimeofday(&act_time,NULL); |
|
- | 380 | if (act_time.tv_sec>last_debug_time.tv_sec) |
|
- | 381 | { |
|
- | 382 | ||
- | 383 | DebugOut.Analog[9]=23; // voltage |
|
- | 384 | DebugOut.Analog[5]=23; // alt |
|
- | 385 | ||
- | 386 | BT_SendOutData('D', RIDDIM_ADDRESS, (unsigned char *) &DebugOut, sizeof(DebugOut)); |
|
- | 387 | ||
- | 388 | ||
- | 389 | gettimeofday(&last_debug_time,NULL); |
|
143 | { |
390 | } |
144 | printf("reading from bt_host"); |
391 | printf("reading from bt_host"); |
145 | char in_char='#'; |
392 | char in_char='#'; |
146 | int count=0; |
- | |
Line -... | Line 393... | ||
- | 393 | int count=0; |
|
147 | int r=0; |
394 | |
148 | 395 | struct timeval timeout; |
|
- | 396 | timeout.tv_sec = 0; |
|
149 | // timeout.tv_sec = 0; |
397 | timeout.tv_usec = 100; |
150 | //timeout.tv_usec = 100; |
398 | |
151 | FD_ZERO(&readfds); |
399 | FD_ZERO(&readfds); |
152 | FD_ZERO(&writefds); |
400 | FD_ZERO(&writefds); |
Line 153... | Line 401... | ||
153 | FD_SET(client, &readfds); |
401 | FD_SET(client, &readfds); |
154 | maxfd = client; |
402 | maxfd = client; |
155 | 403 | ||
156 | printf("waiting for connection\n"); |
404 | printf("waiting for connection\n"); |
- | 405 | status = select(maxfd + 1, &readfds, 0, 0, &timeout); |
|
157 | //status = select(maxfd + 1, &readfds, 0, 0, &timeout); |
406 | if( status >0 ) |
158 | if( status >0 ) |
407 | { |
159 | { |
408 | count=read(client,&in_char,1); |
160 | send(mk_fd,"\r",1,0); |
- | |
161 | while(in_char!='\r') |
409 | //send(mk_fd,"\r",1,0); |
162 | { |
410 | if (count==-1) |
163 | 411 | { |
|
- | 412 | bt_host_connected=0; |
|
164 | count=read(client,&in_char,1); |
413 | //return 0; |
165 | if (count==-1) |
414 | } |
166 | { |
415 | else |
167 | bt_host_connected=0; |
416 | if(in_char!='\r') |
168 | return 0; |
417 | { |
169 | } |
418 | |
- | 419 | printf("count: %d in %d chr %c r:%d\n",count,in_char,in_char,r); |
|
- | 420 | //send(mk_fd,&in_char,1,0); |
|
- | 421 | BtHostRxBuffer[r++]=in_char; |
|
- | 422 | ||
- | 423 | } |
|
- | 424 | else |
|
- | 425 | { |
|
- | 426 | BtRxCount=r; |
|
- | 427 | r=0; |
|
170 | printf("count: %d in %d chr %c\n",count,in_char,in_char); |
428 | |
171 | send(mk_fd,&in_char,1,0); |
429 | BT_Decode64(); |
172 | BtHostRxBuffer[r]=in_char; |
430 | bt_process_buffer(); |
173 | } |
431 | } |
174 | send(mk_fd,"\r",1,0); |
432 | // send(mk_fd,"\r",1,0); |
175 | } |
433 | } |