Rev 112 | Rev 117 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 112 | Rev 116 | ||
---|---|---|---|
Line 54... | Line 54... | ||
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
57 | #include <stdio.h> |
57 | #include <stdio.h> |
58 | #include <stdarg.h> |
58 | #include <stdarg.h> |
- | 59 | #include <string.h> |
|
59 | #include "91x_lib.h" |
60 | #include "91x_lib.h" |
60 | #include "main.h" |
61 | #include "main.h" |
61 | #include "uart0.h" |
62 | #include "uart0.h" |
62 | #include "uart1.h" |
63 | #include "uart1.h" |
63 | #include "timer.h" |
64 | #include "timer.h" |
64 | #include "ubx.h" |
65 | #include "ubx.h" |
65 | #include "mkprotocol.h" |
66 | #include "mkprotocol.h" |
Line 66... | Line -... | ||
66 | - | ||
67 | u8 UART0_Request_VersionInfo = FALSE; |
- | |
68 | u8 UART0_Request_NaviData = FALSE; |
- | |
69 | u32 UART0_NaviData_Timer; |
- | |
- | 67 | ||
70 | u32 UART0_NaviData_Interval = 0; // in ms |
68 | |
71 | //------------------------------------------------------------------------------------ |
69 | //------------------------------------------------------------------------------------ |
Line -... | Line 70... | ||
- | 70 | // global variables |
|
- | 71 | ||
72 | // global variables |
72 | MKOSD_VersionInfo_t MKOSD_VersionInfo; |
73 | 73 | ||
74 | #define UART0_BAUD_RATE 57600 //Baud Rate for the serial interfaces |
74 | #define UART0_BAUD_RATE 57600 //Baud Rate for the serial interfaces |
75 | // UART0 MUXER |
75 | // UART0 MUXER |
76 | UART0_MuxerState_t UART0_Muxer = UART0_UNDEF; |
76 | UART0_MuxerState_t UART0_Muxer = UART0_UNDEF; |
Line 85... | Line 85... | ||
85 | // the rx buffer |
85 | // the rx buffer |
86 | #define UART0_RX_BUFFER_LEN 150 |
86 | #define UART0_RX_BUFFER_LEN 150 |
87 | u8 UART0_rbuffer[UART0_RX_BUFFER_LEN]; |
87 | u8 UART0_rbuffer[UART0_RX_BUFFER_LEN]; |
88 | Buffer_t UART0_rx_buffer; |
88 | Buffer_t UART0_rx_buffer; |
Line -... | Line 89... | ||
- | 89 | ||
- | 90 | u8 UART0_Request_VersionInfo = FALSE; |
|
- | 91 | u8 UART0_Request_NaviData = FALSE; |
|
- | 92 | u32 UART0_NaviData_Timer; |
|
Line 89... | Line 93... | ||
89 | 93 | u32 UART0_NaviData_Interval = 0; // in ms |
|
90 | 94 | ||
Line 91... | Line 95... | ||
91 | //------------------------------------------------------------------------------------ |
95 | //------------------------------------------------------------------------------------ |
Line 301... | Line 305... | ||
301 | 305 | ||
Line 302... | Line 306... | ||
302 | MKProtocol_DecodeSerialFrame(&UART0_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
306 | MKProtocol_DecodeSerialFrame(&UART0_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
303 | 307 | ||
- | 308 | switch(SerialMsg.Address) // check for Slave Address |
|
- | 309 | { |
|
- | 310 | case MKOSD_ADDRESS: // answers from the MKOSD |
|
- | 311 | switch(SerialMsg.CmdID) |
|
- | 312 | { |
|
- | 313 | case 'V': |
|
- | 314 | memcpy(&MKOSD_VersionInfo, SerialMsg.pData, sizeof(MKOSD_VersionInfo)); // copy echo pattern |
|
- | 315 | break; |
|
- | 316 | default: |
|
- | 317 | break; |
|
- | 318 | } // case MKOSD_ADDRESS |
|
304 | switch(SerialMsg.Address) // check for Slave Address |
319 | break; |
305 | { |
320 | |
306 | case NC_ADDRESS: // own Slave Address |
321 | case NC_ADDRESS: // own Slave Address |
307 | switch(SerialMsg.CmdID) |
322 | switch(SerialMsg.CmdID) |
308 | { |
323 | { |
309 | default: |
324 | default: |
310 | break; |
325 | break; |
Line 311... | Line 326... | ||
311 | } // case NC_ADDRESS |
326 | } // case NC_ADDRESS |
312 | // "break;" is missing here to fall thru to the common commands |
- | |
313 | 327 | // "break;" is missing here to fall thru to the common commands |
|
314 | default: // and any other Slave Address |
328 | |
315 | 329 | default: // and any other Slave Address |
|
316 | switch(SerialMsg.CmdID) // check CmdID |
330 | switch(SerialMsg.CmdID) // check CmdID |
317 | { |
331 | { |
318 | case 'o': // request for navigation information |
332 | case 'o': // request for navigation information |
319 | UART0_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
333 | UART0_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
320 | if(UART0_NaviData_Interval > 0) UART0_Request_NaviData = TRUE; |
334 | if(UART0_NaviData_Interval > 0) UART0_Request_NaviData = TRUE; |
321 | break; |
335 | break; |
322 | 336 | ||
323 | case 'v': // request for version info |
337 | case 'v': // request for version info |
324 | UART0_Request_VersionInfo = TRUE; |
338 | UART0_Request_VersionInfo = TRUE; |
325 | break; |
339 | break; |
326 | default: |
340 | default: |
327 | // unsupported command recieved |
341 | // unsupported command recieved |
328 | break; |
342 | break; |
329 | } |
343 | } |
330 | break; // default: |
344 | break; // default: |
Line 331... | Line 345... | ||
331 | } |
345 | } |
Line 360... | Line 374... | ||
360 | { |
374 | { |
361 | if(DebugUART == UART0) return; |
375 | if(DebugUART == UART0) return; |
362 | UART0_Transmit(); // output pending bytes in tx buffer |
376 | UART0_Transmit(); // output pending bytes in tx buffer |
363 | if(UART0_tx_buffer.Locked == TRUE) return; |
377 | if(UART0_tx_buffer.Locked == TRUE) return; |
Line -... | Line 378... | ||
- | 378 | ||
- | 379 | ||
- | 380 | if(UART0_Request_VersionInfo && (UART0_tx_buffer.Locked == FALSE)) |
|
- | 381 | { |
|
- | 382 | MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
|
- | 383 | UART0_Request_VersionInfo = FALSE; |
|
364 | 384 | } |
|
365 | if(( (UART0_NaviData_Interval && CheckDelay(UART0_NaviData_Timer) ) || UART0_Request_NaviData) && (UART0_tx_buffer.Locked == FALSE)) |
385 | if(( (UART0_NaviData_Interval && CheckDelay(UART0_NaviData_Timer) ) || UART0_Request_NaviData) && (UART0_tx_buffer.Locked == FALSE)) |
366 | { |
386 | { |
367 | NaviData.Errorcode = ErrorCode; |
387 | NaviData.Errorcode = ErrorCode; |
368 | MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
388 | MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
369 | UART0_NaviData_Timer = SetDelay(UART0_NaviData_Interval); |
389 | UART0_NaviData_Timer = SetDelay(UART0_NaviData_Interval); |
370 | UART0_Request_NaviData = FALSE; |
390 | UART0_Request_NaviData = FALSE; |
371 | } |
391 | } |
372 | UART0_Transmit(); // output pending bytes in tx buffer |
392 | UART0_Transmit(); // output pending bytes in tx buffer |
- | 393 | } |
|
- | 394 | ||
- | 395 | ||
- | 396 | /**************************************************************/ |
|
- | 397 | /* Get the version of the MKOSD */ |
|
- | 398 | /**************************************************************/ |
|
- | 399 | void UART0_GetMKOSDVersion(void) |
|
- | 400 | { |
|
- | 401 | u32 timeout; |
|
- | 402 | u8 msg[64]; |
|
- | 403 | ||
- | 404 | MKOSD_VersionInfo.SWMajor = 0xFF; |
|
- | 405 | MKOSD_VersionInfo.SWMinor = 0xFF; |
|
- | 406 | MKOSD_VersionInfo.SWPatch = 0xFF; |
|
- | 407 | ||
- | 408 | if(UART0_Muxer != UART0_MKGPS) UART0_Connect_to_MKGPS(); |
|
- | 409 | while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer; |
|
- | 410 | ||
- | 411 | MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'v', MKOSD_ADDRESS, 0); // request for version info |
|
- | 412 | while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer; |
|
- | 413 | ||
- | 414 | timeout = SetDelay(500); |
|
- | 415 | do |
|
- | 416 | { |
|
- | 417 | UART0_ProcessRxData(); |
|
- | 418 | if(MKOSD_VersionInfo.SWMajor != 0xFF) break; |
|
- | 419 | }while(!CheckDelay(timeout)); |
|
- | 420 | ||
- | 421 | if(MKOSD_VersionInfo.SWMajor != 0xFF) |
|
- | 422 | { |
|
- | 423 | sprintf(msg, "\n\r MK-OSD V%d.%d%c", MKOSD_VersionInfo.SWMajor, MKOSD_VersionInfo.SWMinor, 'a'+MKOSD_VersionInfo.SWPatch); |
|
- | 424 | UART1_PutString(msg); |
|
- | 425 | } |
|
- | 426 | //else UART1_PutString("\n\r No version information from MK-OSD."); |