示例#1
0
extern int _lseek(int file, int offset, int whence)
{
    int position;
    int result;

    vm_fs_seek(file, offset, whence + 1);
    result = vm_fs_get_position(file, &position);

    LOG("_lseek(%d, %d, %d) - %d\n", file, offset, whence, position);
    return position;
}
/* 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;
    }
}
示例#3
0
VMBOOL read_conf_string(VMSTR variable_name, VMSTR output_buffer, VMUINT output_buffer_size) {
	VMINT res;
	VMUINT conf_size;
	VMUINT bytes_read;
	VMSTR conf_data;
	VMSTR key;
	VMSTR value;
	VMBOOL result_string_valid = FALSE;

	if (conf_handle_valid)
	{
		res = vm_fs_get_size(conf_handle, &conf_size);
		if (VM_IS_SUCCEEDED(res))
		{
			conf_data = vm_calloc(conf_size + strlen(conf_defaults) + 1);
			if (conf_data != NULL)
			{
				vm_fs_seek(conf_handle, 0, VM_FS_BASE_BEGINNING);
				res = vm_fs_read(conf_handle, conf_data, conf_size, &bytes_read);
				if (VM_IS_SUCCEEDED(res))
				{
					strcat(conf_data, conf_defaults);
					key = strtok(conf_data, "=");
					while (key != NULL) 
					{
						value = strtok(NULL, "\n");
						if (value != NULL && strcmp(variable_name, key) == 0 && strlen(value) < output_buffer_size)
						{
							strcpy(output_buffer, value);
							result_string_valid = TRUE;
							break;
						}
						key = strtok(NULL, "=");
					} 
				}
				vm_free(conf_data);
			}
		}
	}
	return result_string_valid;
}