void VideoResizeHandler::send( Connector *conn, AVDescriptor* descriptor ) { char buf[AV_DESCRIPTOR_BUF_SIZE]; char *ptr = (char *)MSG_PAYLOAD(buf); int offset = 0; float value = descriptor->getX(); memcpy(ptr+offset, &value, FLOAT_SIZE ); offset+=FLOAT_SIZE; value = descriptor->getY(); memcpy(ptr+offset, &value, FLOAT_SIZE ); offset+=FLOAT_SIZE; value = descriptor->getWidth(); memcpy(ptr+offset, &value, FLOAT_SIZE ); offset+=FLOAT_SIZE; value =descriptor->getHeight(); memcpy(ptr+offset, &value, FLOAT_SIZE ); offset += FLOAT_SIZE; MAKE_MSG(buf,messages::videoResize,offset+MESSAGE_HEADER); util::Buffer msg( buf, offset+MESSAGE_HEADER, false ); conn->send( &msg ); }
void KeyEventHandler::process( util::Buffer *msg ) { if (!_onKeyEvent.empty()) { util::BYTE *payload = MSG_PAYLOAD(msg->buffer()); util::DWORD value = GET_BE_DWORD( payload ); util::BYTE isUp = GET_BYTE(payload+4); _onKeyEvent( static_cast<util::key::type>( value ), (isUp == 1) ); } }
// Verifies that update-start command is valid. // Will enter RECEIVING_FIRMWARE state if everything checks out. static void startFirmwareUpdate() { uint8_t i, checksum = 0;//, reset_vector[3]; // Calculate checksum for (i = 0; i < UPDATE_START_LENGTH; i++) { checksum += MSG_PAYLOAD(i); } // Checksum fail if (checksum != 0) { send_buf[1] = ERROR_CHECKSUM_FAIL; send(CMD_NACK,2); return; } // Get firmware size, NOT including reset vector bytes_total = MSG_ST_BYTES; // Check that firmware is within legal size range. if (bytes_total > FLASH_FW_MAX_SIZE) { // Send error report to host. send_buf[1] = ERROR_ILLEGAL_SIZE; send(CMD_NACK,2); return; } // Get firmware's reset vector. temp_data[0] = MSG_ST_RESET_OPCODE; temp_data[1] = MSG_ST_RESET_ADDR_H; temp_data[2] = MSG_ST_RESET_ADDR_L; // Write reset vector to non-volatile flash flash_erase_page(FW_NV_DATA_PAGE); flash_write_bytes(FW_RESET_VECTOR, temp_data, 3); // Get firmware serial number. Will be written to NV when update complete. firmware_number = MSG_ST_NUMBER; bytes_received = 0; /* // Read out old reset vector. movx_access_code(); flash_read_bytes(0x0000, reset_vector, 3); movx_access_data(); // Erase first page, containing reset vector. flash_erase_page(0); // Write back the old reset vector. movx_access_code(); flash_write_bytes(0x0000, reset_vector, 3); movx_access_data(); // Erase the reset of pages available to firmware. */ for (i = BOOTLOADER_PAGES; i < BOOTLOADER_PAGES+FLASH_PAGES(bytes_total); ++i) { flash_erase_page(i); } send(CMD_ACK,1); if (send_success) state = RECEIVING_FIRMWARE; else state = PINGING; return; }
// Writes hex-record's data field to flash memory. // Will update bytes_received and send reply to host. void writeHexRecord(state_t *state, uint16_t *bytes_received) { uint8_t i, checksum = 0, bytes = MSG_WR_BYTE_COUNT; uint16_t addr = MSG_WR_ADDR; // Disable RF receiving while writing. CE_LOW(); // Calculate checksum for message. for (i = 0; i < bytes+HEX_BYTES; i++) { checksum += MSG_PAYLOAD(i); } if (checksum != 0) { // Checksum fail send_buf[1] = ERROR_CHECKSUM_FAIL; send(CMD_NACK); return; } // Copy data portion of payload to idata temp memory. for (i = 0; i < bytes; i++) { temp_data[i] = MSG_WR_DATA(i); } // This will prevent the reset vector from being overwritten. if (addr == 0x0000) { PCON |= PMW; // Offset write with the 3 bytes of the reset vector hal_flash_bytes_write((addr+3), (temp_data+3), (bytes-3)); PCON &= ~PMW; // Make sure that bytes to be written is within legal pages. } else if (addr+bytes < FLASH_FW_MAX_SIZE) { // Write line to flash. PCON |= PMW; hal_flash_bytes_write(addr, temp_data, bytes); PCON &= ~PMW; // Address is outside pages available to new firmware. } else { // Invalid address send_buf[1] = ERROR_ILLEGAL_ADDRESS; send(CMD_NACK); return; } // Add bytes to total received. *bytes_received += bytes; // Acknowledge message send(CMD_ACK); if (!send_success) { *state = ERROR; } return; }
// Writes hex-record's data field to flash memory. // Will update bytes_received and send reply to host. static void writeHexRecord() { uint8_t i, checksum = 0, bytes = MSG_WR_BYTE_COUNT; uint16_t addr = MSG_WR_ADDR; // Calculate checksum for message. for (i = 0; i < bytes+HEX_BYTES; i++) { checksum += MSG_PAYLOAD(i); } if (checksum != 0) { // Checksum fail send_buf[1] = ERROR_CHECKSUM_FAIL; send(CMD_NACK,2); return; } // Copy data portion of payload to idata temp memory. for (i = 0; i < bytes; i++) { temp_data[i] = MSG_WR_DATA(i); } /* // This will prevent the reset vector from being overwritten. if (addr == 0x0000) { movx_access_code();; // Offset write with the 3 bytes of the reset vector flash_write_bytes((addr+3), (temp_data+3), (bytes-3)); movx_access_data(); // Make sure that bytes to be written is within legal pages. } else */ if (addr+bytes < FLASH_FW_END && addr >= FLASH_FW_BEGIN) { // Write line to flash. movx_access_code(); flash_write_bytes(addr, temp_data, bytes); movx_access_data(); // Address is outside pages available to new firmware. } else { send_buf[1] = ERROR_ILLEGAL_ADDRESS; send(CMD_NACK,2); return; } // Add bytes to total received. bytes_received += bytes; // Acknowledge message send(CMD_ACK,1); if (!send_success) { state = ERROR; } return; }
void VideoResizeHandler::process( util::Buffer *msg ) { if (!_onVideoResizeEvent.empty()) { AVDescriptor msgData; util::BYTE *payload = MSG_PAYLOAD(msg->buffer()); float value = 0; memcpy( &value, payload, FLOAT_SIZE ); msgData.setX(value); payload += FLOAT_SIZE; memcpy( &value, payload, FLOAT_SIZE ); msgData.setY(value); payload += FLOAT_SIZE; memcpy( &value, payload, FLOAT_SIZE ); msgData.setWidth(value); payload += FLOAT_SIZE; memcpy( &value, payload, FLOAT_SIZE ); msgData.setHeight(value); _onVideoResizeEvent( &msgData ); } }
// Verifies that update-start command is valid. // Will enter RECEIVING_FIRMWARE state if everything checks out. void startFirmwareUpdate(state_t *state, uint16_t *bytes_total, uint16_t *bytes_received, uint8_t *firmware_number) { uint8_t i, checksum = 0, reset_vector[3]; uint16_t bytes = 0; // Calculate checksum for (i = 0; i < UPDATE_START_LENGTH; i++) { checksum += MSG_PAYLOAD(i); } // Checksum fail if (checksum != 0) { send_buf[1] = ERROR_CHECKSUM_FAIL; send(CMD_NACK); return; } // Get firmware size bytes = MSG_ST_BYTES; // Check that firmware is within legal size range. if (bytes > FLASH_FW_MAX_SIZE) { // Send error report to host. send_buf[1] = ERROR_ILLEGAL_SIZE; send(CMD_NACK); return; } *bytes_total = bytes; // Get firmware's reset vector. temp_data[0] = MSG_ST_RESET_OPCODE; temp_data[1] = MSG_ST_RESET_ADDR_H; temp_data[2] = MSG_ST_RESET_ADDR_L; // Write reset vector to non-volatile flash hal_flash_page_erase(FW_NV_DATA_PAGE); hal_flash_bytes_write(FW_RESET_VECTOR, temp_data, 3); // Get firmware serial number. Will be written to NV when update complete. *firmware_number = MSG_ST_NUMBER; *bytes_received = 0; // Read out old reset vector. PCON |= PMW; hal_flash_bytes_read(0x0000, reset_vector, 3); PCON &= ~PMW; // Erase first page, containing reset vector. hal_flash_page_erase(0); // Write back the old reset vector. PCON |= PMW; hal_flash_bytes_write(0x0000, reset_vector, 3); PCON &= ~PMW; // Erase the reset of pages available to firmware. for (i = 1; i < FLASH_FW_PAGES; i++) { hal_flash_page_erase(i); } send(CMD_ACK); if (send_success) { *state = RECEIVING_FIRMWARE; } else { *state = LISTENING; } return; }