int
au_do_update(int idx, long sz)
{
image_header_t *hdr;
char *addr;
long start, end;
int off, rc;
uint nbytes;
hdr = (image_header_t *)LOAD_ADDR;
#if defined(CONFIG_FIT)
if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
puts ("Non legacy image format not supported\n");
return -1;
}
#endif
/* disable the power switch */
*CPLD_VFD_BK |= POWER_OFF;
/* execute a script */
if (image_check_type (hdr, IH_TYPE_SCRIPT)) {
addr = (char *)((char *)hdr + image_get_header_size ());
/* stick a NULL at the end of the script, otherwise */
/* parse_string_outer() runs off the end. */
addr[image_get_data_size (hdr)] = 0;
addr += 8;
parse_string_outer(addr, FLAG_PARSE_SEMICOLON);
return 0;
}
start = aufl_layout[FIDX_TO_LIDX(idx)].start;
end = aufl_layout[FIDX_TO_LIDX(idx)].end;
/* unprotect the address range */
/* this assumes that ONLY the firmware is protected! */
if (idx == IDX_FIRMWARE) {
#undef AU_UPDATE_TEST
#ifdef AU_UPDATE_TEST
/* erase it where Linux goes */
start = aufl_layout[1].start;
end = aufl_layout[1].end;
#endif
flash_sect_protect(0, start, end);
}
/*
* erase the address range.
*/
debug ("flash_sect_erase(%lx, %lx);\n", start, end);
flash_sect_erase(start, end);
wait_ms(100);
/* strip the header - except for the kernel and ramdisk */
if (image_check_type (hdr, IH_TYPE_KERNEL) ||
image_check_type (hdr, IH_TYPE_RAMDISK)) {
addr = (char *)hdr;
off = image_get_header_size ();
nbytes = image_get_image_size (hdr);
} else {
addr = (char *)((char *)hdr + image_get_header_size ());
#ifdef AU_UPDATE_TEST
/* copy it to where Linux goes */
if (idx == IDX_FIRMWARE)
start = aufl_layout[1].start;
#endif
off = 0;
nbytes = image_get_data_size (hdr);
}
/* copy the data from RAM to FLASH */
debug ("flash_write(%p, %lx %x)\n", addr, start, nbytes);
rc = flash_write(addr, start, nbytes);
if (rc != 0) {
printf("Flashing failed due to error %d\n", rc);
return -1;
}
/* check the dcrc of the copy */
if (crc32 (0, (uchar *)(start + off), image_get_data_size (hdr)) !=
image_get_dcrc (hdr)) {
printf ("Image %s Bad Data Checksum After COPY\n", aufile[idx]);
return -1;
}
/* protect the address range */
/* this assumes that ONLY the firmware is protected! */
if (idx == IDX_FIRMWARE)
flash_sect_protect(1, start, end);
return 0;
}
int /* O - 1 on success, 0 on error */
translate_messages(cups_array_t *cat, /* I - Message catalog */
const char *lang) /* I - Output language... */
{
/*
* Google provides a simple translation/language tool for translating
* from one language to another. It is far from perfect, however it
* can be used to get a basic translation done or update an existing
* translation when no other resources are available.
*
* Translation requests are sent as HTTP POSTs to
* "http://translate.google.com/translate_t" with the following form
* variables:
*
* Name Description Value
* -------- ---------------------------------- ----------------
* hl Help language? "en"
* ie Input encoding "UTF8"
* langpair Language pair "en|" + language
* oe Output encoding "UTF8"
* text Text to translate translation string
*/
int ret; /* Return value */
_cups_message_t *m; /* Current message */
int tries; /* Number of tries... */
http_t *http; /* HTTP connection */
http_status_t status; /* Status of POST request */
char *idptr, /* Pointer into msgid */
buffer[65536], /* Input/output buffer */
*bufptr, /* Pointer into buffer */
*bufend, /* Pointer to end of buffer */
length[16]; /* Content length */
int bytes; /* Number of bytes read */
/*
* Connect to translate.google.com...
*/
puts("Connecting to translate.google.com...");
if ((http = httpConnect("translate.google.com", 80)) == NULL)
{
perror("Unable to connect to translate.google.com");
return (0);
}
/*
* Scan the current messages, requesting a translation of any untranslated
* messages...
*/
for (m = (_cups_message_t *)cupsArrayFirst(cat), ret = 1;
m;
m = (_cups_message_t *)cupsArrayNext(cat))
{
/*
* Skip messages that are already translated...
*/
if (m->str && m->str[0])
continue;
/*
* Encode the form data into the buffer...
*/
snprintf(buffer, sizeof(buffer),
"hl=en&ie=UTF8&langpair=en|%s&oe=UTF8&text=", lang);
bufptr = buffer + strlen(buffer);
bufend = buffer + sizeof(buffer) - 5;
for (idptr = m->id; *idptr && bufptr < bufend; idptr ++)
if (*idptr == ' ')
*bufptr++ = '+';
else if (*idptr < ' ' || *idptr == '%')
{
sprintf(bufptr, "%%%02X", *idptr & 255);
bufptr += 3;
}
else if (*idptr != '&')
*bufptr++ = *idptr;
*bufptr++ = '&';
*bufptr = '\0';
sprintf(length, "%d", (int)(bufptr - buffer));
/*
* Send the request...
*/
printf("\"%s\" = ", m->id);
fflush(stdout);
tries = 0;
do
{
//.........这里部分代码省略.........
int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
void *din, unsigned long flags)
{
volatile spi8xxx_t *spi = &((immap_t *) (CONFIG_SYS_IMMR))->spi;
unsigned int tmpdout, tmpdin, event;
int numBlks = bitlen / 32 + (bitlen % 32 ? 1 : 0);
int tm, isRead = 0;
unsigned char charSize = 32;
debug("spi_xfer: slave %u:%u dout %08X din %08X bitlen %u\n",
slave->bus, slave->cs, *(uint *) dout, *(uint *) din, bitlen);
if (flags & SPI_XFER_BEGIN)
spi_cs_activate(slave);
spi->event = 0xffffffff; /* Clear all SPI events */
/* handle data in 32-bit chunks */
while (numBlks--) {
tmpdout = 0;
charSize = (bitlen >= 32 ? 32 : bitlen);
/* Shift data so it's msb-justified */
tmpdout = *(u32 *) dout >> (32 - charSize);
/* The LEN field of the SPMODE register is set as follows:
*
* Bit length setting
* len <= 4 3
* 4 < len <= 16 len - 1
* len > 16 0
*/
spi->mode &= ~SPI_MODE_EN;
if (bitlen <= 16) {
if (bitlen <= 4)
spi->mode = (spi->mode & 0xff0fffff) |
(3 << 20);
else
spi->mode = (spi->mode & 0xff0fffff) |
((bitlen - 1) << 20);
} else {
spi->mode = (spi->mode & 0xff0fffff);
/* Set up the next iteration if sending > 32 bits */
bitlen -= 32;
dout += 4;
}
spi->mode |= SPI_MODE_EN;
spi->tx = tmpdout; /* Write the data out */
debug("*** spi_xfer: ... %08x written\n", tmpdout);
/*
* Wait for SPI transmit to get out
* or time out (1 second = 1000 ms)
* The NE event must be read and cleared first
*/
for (tm = 0, isRead = 0; tm < SPI_TIMEOUT; ++tm) {
event = spi->event;
if (event & SPI_EV_NE) {
tmpdin = spi->rx;
spi->event |= SPI_EV_NE;
isRead = 1;
*(u32 *) din = (tmpdin << (32 - charSize));
if (charSize == 32) {
/* Advance output buffer by 32 bits */
din += 4;
}
}
/*
* Only bail when we've had both NE and NF events.
* This will cause timeouts on RO devices, so maybe
* in the future put an arbitrary delay after writing
* the device. Arbitrary delays suck, though...
*/
if (isRead && (event & SPI_EV_NF))
break;
}
if (tm >= SPI_TIMEOUT)
puts("*** spi_xfer: Time out during SPI transfer");
debug("*** spi_xfer: transfer ended. Value=%08x\n", tmpdin);
}
if (flags & SPI_XFER_END)
spi_cs_deactivate(slave);
return 0;
}
MDA_TASK_RETURN_CODE MDA_TASK_BUOY:: run_single_buoy(int buoy_index, BUOY_COLOR color) {
puts("Press q to quit");
assert (buoy_index >= 0 && buoy_index <= 1);
MDA_VISION_MODULE_BUOY buoy_vision;
MDA_TASK_RETURN_CODE ret_code = TASK_MISSING;
/// Here we store the starting attitude vector, so we can return to this attitude later
int starting_yaw = attitude_input->yaw();
printf("Starting yaw: %d\n", starting_yaw);
//set (DEPTH, 400);
TASK_STATE state = STARTING;
bool done_buoy = false;
static TIMER timer;
static TIMER master_timer;
timer.restart();
master_timer.restart();
//###### hack code for competition
set (SPEED, 0);
int hack_depth, hack_time;
read_mv_setting ("hacks.csv", "BUOY_DEPTH", hack_depth);
read_mv_setting ("hacks.csv", "BUOY_TIME", hack_time);
printf ("Buoy: going to depth %d\n", hack_depth);
fflush(stdout);
if (hack_depth > 500)
set (DEPTH, 500);
if (hack_depth > 600)
set (DEPTH, 600);
set (DEPTH, hack_depth);
set (YAW, starting_yaw);
printf ("Buoy: moving forward for %d seconds\n", hack_time);
fflush(stdout);
timer.restart();
while (timer.get_time() < hack_time) {
set (SPEED, 8);
}
set(SPEED, 0);
if (hack_depth > 600)
set (DEPTH, 600);
if (hack_depth > 500)
set (DEPTH, 500);
set (YAW, starting_yaw);
return TASK_DONE;
//###### end hack code for competition
/**
* Basic Algorithm
* - Assume for now that we just want to hit the cylindrical buoys when they're red
* - We want to search for 1 or 2 buoys. If we find both:
* - Are both non-red and/or cycling? Go for the one indicated by buoy_index
* - Is one non-red and/or cycling? Go for that one
* - Do we only see one buoy? Go there if non-red and/or cycling
*
*/
while (1) {
IplImage* frame = image_input->get_image();
if (!frame) {
ret_code = TASK_ERROR;
break;
}
MDA_VISION_RETURN_CODE vision_code = buoy_vision.filter(frame);
(void) vision_code;
// clear dwn image - RZ: do we need this?
//int down_frame_ready = image_input->ready_image(DWN_IMG);
//(void) down_frame_ready;
bool valid[2] = {false, false};
int ang_x[2], ang_y[2];
int range[2];
int color[2];
static bool color_cycling[2] = {false, false};
static int curr_index = -1;
static int prev_time = -1;
static int prev_color = -1;
static int n_valid_color_find_frames = 0;
if (!done_buoy) {
// state machine
if (state == STARTING) {
// here we just move forward until we find something, and pan if we havent found anything for a while
printf ("Starting: Moving Foward for 1 meter\n");
move (FORWARD, 1);
if (timer.get_time() > 1) {
set (SPEED, 0);
timer.restart();
buoy_vision.clear_frames();
state = STOPPED;
}
}
else if (state == STOPPED) {
//.........这里部分代码省略.........
请发表评论