/* Get a frame from the camera. Serial protocol char: I */ void get_frame () { unsigned char ch; move_image((unsigned char *)DMA_BUF1, (unsigned char *)DMA_BUF2, (unsigned char *)FRAME_BUF, imgWidth, imgHeight); if (overlay_flag) { frame[9] = (framecount % 10) + 0x30; frame[8] = ((framecount/10)% 10) + 0x30; frame[7] = ((framecount/100)% 10) + 0x30; set_caption(frame, imgWidth); } output_start = (unsigned char *)JPEG_BUF; output_end = encode_image((unsigned char *)FRAME_BUF, output_start, quality, FOUR_TWO_TWO, imgWidth, imgHeight); image_size = (unsigned int)(output_end - output_start); led1_on(); framecount++; uart0SendString(imgHead); uart0SendChar((unsigned char)(image_size & 0x000000FF)); uart0SendChar((unsigned char)((image_size & 0x0000FF00) >> 8)); uart0SendChar((unsigned char)((image_size & 0x00FF0000) >> 16)); uart0SendChar(0x00); cp = (unsigned char *)JPEG_BUF; for (i=0; i<image_size; i++) { while (*pPORTHIO & 0x0001) { continue; } uart0SendChar(*cp++); } while (uart0GetChar(&ch)) { // flush input continue; } }
/***************************************************************************** * * Description: * Routine for printing integer numbers in various formats. The number is * printed in the specified 'base' using exactly 'noDigits', using +/- if * signed flag 'sign' is TRUE, and using the character specified in 'pad' * to pad extra characters. * * Params: * [in] base - Base to print number in (2-16) * [in] noDigits - Number of digits to print (max 32) * [in] sign - Flag if sign is to be used (TRUE), or not (FALSE) * [in] pad - Character to pad any unused positions * [in] number - Signed number to print * ****************************************************************************/ void printNumber(unsigned char base, unsigned char noDigits, unsigned char sign, unsigned char pad, int number) { static unsigned char hexChars[16] = "0123456789ABCDEF"; unsigned char *pBuf; unsigned char buf[32]; unsigned int numberAbs; unsigned int count; // prepare negative number if(sign && (number < 0)) numberAbs = -number; else numberAbs = number; // setup little string buffer count = (noDigits - 1) - (sign ? 1 : 0); pBuf = buf + sizeof(buf); *--pBuf = '\0'; // force calculation of first digit // (to prevent zero from not printing at all!!!) *--pBuf = hexChars[(numberAbs % base)]; numberAbs /= base; // calculate remaining digits while(count--) { if(numberAbs != 0) { //calculate next digit *--pBuf = hexChars[(numberAbs % base)]; numberAbs /= base; } else // no more digits left, pad out to desired length *--pBuf = pad; } // apply signed notation if requested if(sign) { if(number < 0) *--pBuf = '-'; else if(number > 0) *--pBuf = '+'; else *--pBuf = ' '; } // print the string right-justified uart0SendString(pBuf); }
/* Dump flash buffer to serial Serial protocol char: z-d */ void serial_out_flashbuffer () { uart0SendString((unsigned char *)"##zdump: \n"); cp = (unsigned char *)FLASH_BUFFER; for (i=0; i < FLASH_BUFFER_EXTENT ; i++) { while (*pPORTHIO & 0x0001) continue; if (*cp == 0) return; uart0SendChar(*cp++); } }
void sntx_err(int error) { char *p, *temp; int linecount = 1; int i; static char *e[]= { "syntax error", "unbalanced parentheses", "no expression present", "equals sign expected", "not a variable", "parameter error", "semicolon expected", "unbalanced braces", "function undefined", "type specifier expected", "too many nested function calls", "return without call", "parentheses expected", "while expected", "closing quote expected", "not a string", "too many local variables", }; uart0SendString(e[error]); p = p_buf; while(p != prog) { p++; if(*p == '\n') linecount++; } uart0SendString(" in line "); printNumber(10, 8, FALSE, ' ', linecount); uart0SendChar('\n'); temp = p; for(i=0; i<20 && p>p_buf && *p!='\n'; i++, p--); for(i=0; i<30 && p<=temp; i++, p++) uart0SendChar(*p); }
void print() { int i; start_check(); get_token(); while(*token !=')') { if(token_type==STRING) { uart0SendString(token); } else { putback(); eval_exp(&i); printNumber(10, 10, FALSE, ' ', i); } get_token(); } uart0SendChar('\n'); get_token(); if(*token!=';') sntx_err(SEMI_EXPECTED); putback(); }
/* Get current time Serial protocol char: t */ void serial_out_time () { uart0SendString((unsigned char *)"time[ms]: "); printNumber(10, 10, 0, ' ', readRTC()); uart0SendChar('\n'); }
/* Get frame count. Serial protocol char: f */ void serial_out_framecount () { uart0SendString((unsigned char *)"framecount: "); printNumber(10, 8, 0, ' ', framecount); uart0SendChar('\n'); }
/* SRV-1 Firmware Version Request Serial protocol char: V */ void serial_out_version () { uart0SendString((unsigned char *)"Version - "); uart0SendString((unsigned char *)version_string); uart0SendChar('\n'); }
/* Turn image overlay off. Serial protocol char: O */ void overlay_off () { overlay_flag = 0; QUIET(uart0SendString("#O")); }
/* Turn image overlay on. Serial protocol char: o */ void overlay_on () { overlay_flag = 1; QUIET(uart0SendString("#o")); }
/* Turn lasers off Serial protocol char: L */ void lasers_off () { *pPORTHIO &= 0xFC7F; QUIET(uart0SendString("#L")); }
/* Turn lasers on Serial protocol char: l */ void lasers_on () { *pPORTHIO |= 0x0380; QUIET(uart0SendString("#l")); }