void checkGPSUart(void) { mychar = uart1Getch(); if (mychar != -1) parseGPS((unsigned char)mychar); }
boolean getCANFrame( uint32_t *pid, uint8_t *psize, uint8_t *pData ) { int i; int c; char * pEnd; static char canmsg[ 50 ]; static int cnt; static boolean bMsg = false; // Must be valid pointers if ( NULL == pid ) return false; if ( NULL == psize ) return false; if ( NULL == pData ) return false; // If no character in the queue => No message while ( -1 != ( c = uart1Getch() ) ) { if ( bMsg ) { if ( 0x0d == c ) { // A full frame received // Format iiiiiiiidxxxxxxxxxxxxxxxx // iiiiiiii - id // d - Number of databytes // xxx....databytes // Get datacount first *psize = ( canmsg[ 8 ] - 0x30 ); canmsg[ 8 ] = 0; *pid = strtoul( canmsg, &pEnd, 16 ); strcpy( canmsg, canmsg + 9 ); for ( i=*psize-1; i>=0; i-- ) { pData[ i ] = (unsigned char)strtoul( canmsg + 2 * i, &pEnd, 16 ); canmsg[ 2 * i ] = 0; } SendCANFrame( *pid, *psize, pData ); cnt = 0; bMsg = false; return true; } else { canmsg[ cnt ] = (char)c; cnt++; canmsg[ cnt ] = 0; if ( cnt > sizeof( canmsg ) ) { // Something is wrong - start again (no frame is this long) cnt = 0; bMsg = false; } } } else { if ( 'T' == c ) { bMsg = true; // We have a message cnt = 0; } } } return false; }
int main(void) { int ch; int8_t res; systemInit(); gpioInit(); uart1Init(UART_BAUD(BAUD), UART_8N1, UART_FIFO_8); // setup the UART uart1Puts("\r\nMMC/SD Card Filesystem Test (P:LPC2138 L:EFSL)\r\n"); uart1Puts("efsl LPC2000-port and this Demo-Application\r\n"); uart1Puts("done by Martin Thomas, Kaiserslautern, Germany\r\n"); /* init efsl debug-output */ lpc2000_debug_devopen(uart1Putch); ledToggle(); rprintf("CARD init..."); if ( ( res = efs_init( &efs, 0 ) ) != 0 ) { rprintf("failed with %i\n",res); } else { rprintf("ok\n"); rprintf("Directory of 'root':\n"); ls_openDir( &list, &(efs.myFs) , "/"); while ( ls_getNext( &list ) == 0 ) { list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0'; rprintf( "%s ( %li bytes )\n" , list.currentEntry.FileName, list.currentEntry.FileSize ) ; } if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) { rprintf("File %s open. Content:\n", LogFileName); while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) { buf[e]='\0'; uart1Puts((char*)buf); } rprintf("\n"); file_fclose( &filer ); } if ( file_fopen( &filew, &efs.myFs , LogFileName , 'a' ) == 0 ) { rprintf("File %s open for append. Appending...", LogFileName); strcpy((char*)buf, "Martin hat's angehaengt\r\n"); if ( file_write( &filew, strlen((char*)buf), buf ) == strlen((char*)buf) ) { rprintf("ok\n"); } else { rprintf("fail\n"); } file_fclose( &filew ); } if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) { rprintf("File %s open. Content:\n", LogFileName); while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) { buf[e]='\0'; uart1Puts((char*)buf); } rprintf("\n"); file_fclose( &filer ); } fs_umount( &efs.myFs ) ; } while(1) { if ((ch = uart1Getch()) >= 0) { uart1Puts("You pressed : "); uart1Putch(ch); uart1Puts("\r\n"); if ( ch == 'M' ) { rprintf("Creating FS\n"); mkfs_makevfat(&efs.myPart); } ledToggle(); } } return 0; /* never reached */ }