Exemplo n.º 1
0
boolean file_ext_write(void* user_data)
{
  file_info_struct* data_file = (file_info_struct*)user_data;
  
  VMUINT writelen = 0;
  VMINT ret = 0;
  ret = vm_fs_write(data_file->handle, (void*)data_file->data, strlen(data_file->data), &writelen);
    if(ret < 0)
    {
        vm_log_info("Failed to write file");
        return true;
    }
  return true;
}
Exemplo n.º 2
0
extern int _write(int file, char* ptr, int len)
{
    if(file < 3) {
        int i;

        for(i = 0; i < len; i++) {
            retarget_putc(*ptr);
            ptr++;
        }
        return len;
    } else {
        VMUINT written_bytes;

        vm_fs_write(file, ptr, len, &written_bytes);
        LOG("_write(%d, %s, %d, %d)\n", file, ptr, len, written_bytes);
        return written_bytes;
    }
}
/* The callback to be invoked by the system engine. */
void handle_sysevt(VMINT message, VMINT param) {
    switch (message) {
    case VM_EVENT_CREATE:
        break;
    case VM_EVENT_PAINT: {
        VMWCHAR path[100];
        VMINT fs = 0;
        VMCHAR flag = 0;
        VMCHAR write = 'a';
        VMINT write_size = 0;
        VMINT ret = 0;
        /* This file is a flag to not update the firmware after the firmware was updated and the board reboots.
           It's to prevent calling the update API in an endless loop. */
        vm_chset_ascii_to_ucs2(path, 100, "c:\\firmware.txt");
        fs = vm_fs_open(path,VM_FS_MODE_READ,FALSE);
        if(fs<0) {
            fs = vm_fs_open(path,VM_FS_MODE_CREATE_ALWAYS_WRITE,FALSE);
        }
        if(fs>=0) {
            vm_fs_read(fs,(void *)&flag,sizeof(VMCHAR),&write_size);
            if(flag==0) {
                vm_fs_seek(fs,0,VM_FS_BASE_BEGINNING);
                vm_fs_write(fs,(void *)&write,sizeof(VMCHAR),&write_size);
            }
            vm_fs_close(fs);
            if(flag=='a') {
                vm_log_info("firmware:have firmware update");
                ret = firmware_read_update_status();
                vm_log_info("firmware:update result = %d ",ret);
                vm_fs_delete(path);
            }
            if(flag==0) {
                vm_log_info("firmware update begin");
                vm_firmware_trigger_update();
                vm_log_info("firmware update end");
                vm_pwr_reboot();
            }
        }
    }
    break;
    default:
        break;
    }
}