/** * Write a block of bytes from the currently active input to the flash. * The block will be written to offset 0 of this bank/chip. * The whole block must be located in one bank and in one flash chip. * * return 1 for success, 0 for failure */ uint8_t flashWriteBankFromFile(uint8_t nBank, uint8_t nChip, uint16_t nSize) { uint8_t bReplaceEAPI; uint8_t oldState; uint16_t nOffset; uint16_t nBytes; nOffset = 0; bReplaceEAPI = 0; while (nSize) { nBytes = (nSize > FLASH_WRITE_SIZE) ? FLASH_WRITE_SIZE : nSize; oldState = progressGetStateAt(nBank, nChip); progressSetBankState(nBank, nChip, PROGRESS_READING); if (utilRead(buffer, nBytes) != nBytes) { screenPrintSimpleDialog(apStrFileTooShort); progressSetBankState(nBank, nChip, PROGRESS_UNTOUCHED); return 0; } progressSetBankState(nBank, nChip, oldState); // Check if EAPI has to be replaced if (nBank == 0 && nChip == 1 && nOffset == 0x1800 && memcmp(buffer, pStrEAPISignature, 4) == 0) bReplaceEAPI = 1; if (bReplaceEAPI) { if (nOffset == 0x1800) memcpy(buffer, EAPI_LOAD_TO, 0x100); else if (nOffset == 0x1900) memcpy(buffer, EAPI_LOAD_TO + 0x100, 0x100); else if (nOffset == 0x1a00) memcpy(buffer, EAPI_LOAD_TO + 0x200, 0x100); } if (!flashWriteBlock(nBank, nChip, nOffset, buffer)) return 0; if (!flashVerifyBlock(nBank, nChip, nOffset, buffer)) return 0; nSize -= nBytes; nOffset += nBytes; refreshElapsedTime(); } return 1; }
/** * Test writing to and reading from the same socket. */ void testSocketReadWrite() { int status; void *handle; void *context; int ntowrite; int nwritten; char *buf = testString; char inbuf[100]; status = utilOpen(&handle, testaddr, PORT_ECHO); assertTrue("open failed", status); ntowrite = strlen(buf); do { status = utilWrite(handle, buf, ntowrite); assertTrue("write failed", status > 0); ntowrite -= status; buf += status; } while (ntowrite > 0); status = pcsl_socket_shutdown_output(handle); assertTrue("shutdown failed", status == PCSL_NET_SUCCESS); while (1) { status = utilRead(handle, inbuf, sizeof(inbuf)-1); assertTrue("read failed", status != -1); if (status == 0) { break; } inbuf[status] = '\0'; printf("read => '%s'\n", inbuf); } (void)utilClose(handle); }
/** * Test of reading from a socket. */ void testSocketRead() { int status; void *handle; void *context; char buf[100]; int nread; status = utilOpen(&handle, testaddr, PORT_DAYTIME); assertTrue("open failed", status); while (1) { status = utilRead(handle, buf, sizeof(buf)-1); assertTrue("read failed", status != -1); if (status == 0) { break; } buf[status] = '\0'; printf("read => '%s'\n", buf); } puts("read => EOF"); (void)utilClose(handle); }