代码拉取完成,页面将自动刷新
同步操作将从 OpenHarmony/docs 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
表1 文件操作接口说明
接口名 | 描述 |
---|---|
int UtilsFileOpen(const char* path, int oflag, int mode) | 打开或创建文件 |
int UtilsFileClose(int fd) | 关闭文件 |
int UtilsFileRead(int fd, char *buf, unsigned int len) | 读取特定长度的文件数据 |
int UtilsFileWrite(int fd, const char *buf, unsigned int len) | 向文件写入特定大小的数据 |
int UtilsFileDelete(const char *path) | 删除指定文件 |
int UtilsFileStat(const char *path, unsigned int *fileSize) | 获取文件大小 |
int UtilsFileSeek(int fd, int offset, unsigned int whence) | 重新定位文件读/写偏移量 |
int UtilsFileCopy(const char* src, const char* dest) | 将源文件复制一份并存储到目标文件 |
int UtilsFileMove(const char* src, const char* dest) | 将源文件移动到指定目标文件 |
文件操作使用示例:
// open && write
char fileName[] = "testfile";
static const char def[] = "utils_file_operation implement.";
int fd = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS | O_TRUNC_FS, 0);
printf("file handle = %d\n", fd);
int ret = UtilsFileWrite(fd, def, strlen(def));
printf("write ret = %d\n", ret);
// seek
ret = UtilsFileSeek(fd, 5, SEEK_SET_FS);
printf("lseek ret = %d\n", ret);
// read && close
char buf[64] = {0};
int readLen = UtilsFileRead(fd, buf, 64);
ret = UtilsFileClose(fd);
printf("read len = %d : buf = %s\n", readLen, buf);
// stat
int fileLen = 0;
ret = UtilsFileStat(fileName, &fileLen);
printf("file size = %d\n", fileLen);
// delete
ret = UtilsFileDelete(fileName);
printf("delete ret = %d\n", ret);
表2 KV存储接口说明
接口名 | 描述 |
---|---|
int UtilsGetValue(const char* key, char* value, unsigned int len) | 提供给上层应用根据key获取对应数据项 |
int UtilsSetValue(const char* key, const char* value) | 提供给上层应用用于存储/更新key对应数据项 |
int UtilsDeleteValue(const char* key) | 提供给上层应用删除key对应数据项 |
KV存储使用示例:
// set
char key[] = "rw.sys.version_100";
char value[] = "Hello kv operation implement!";
int ret = UtilsSetValue(key, value);
printf("UtilsSetValue set ret = %d\n", ret);
// get
char temp[128] = {0};
ret = UtilsGetValue(key, temp, 128);
printf("UtilsGetValue get ret = %d, temp = %s\n", ret, temp);
// delete
ret = UtilsDeleteValue(key);
printf("UtilsDeleteValue delete ret = %d\n", ret);
基于AbilityKit开发KV存储的native应用。
基于KV存储提供的接口编写用户程序,并编译出so(libLauncher.so)文件。
// set
char key[] = "rw.sys.version_100";
char value[] = "Hello kv operation implement!";
int ret = UtilsSetValue(key, value);
printf("UtilsSetValue set ret = %d\n", ret);
// get
char temp[128] = {0};
ret = UtilsGetValue(key, temp, 128);
printf("UtilsGetValue get ret = %d, temp = %s\n", ret, temp);
// delete
ret = UtilsDeleteValue(key);
printf("UtilsDeleteValue delete ret = %d\n", ret);
编写config.json文件,内容如下:
{
"app": {
"bundleName": "com.example.launcher",
"vendor": "example",
"version": {
"code": 1,
"name": "1.0"
}
},
"deviceConfig": {
"default": {
"reqSdk": {
"compatible": "zsdk 1.0.0",
"target": "zsdk 1.0.1"
},
"keepAlive": false
},
"smartCamera": {
"reqSdk": {
"compatible": "zsdk 1.0.0",
"target": "zsdk 1.0.1"
},
"keepAlive": false
}
},
"module": {
"package": "com.example.launcher",
"name": ".MyOpenHarmonyAbilityPackage",
"deviceType": [
"phone", "tv","tablet", "pc","car","smartWatch","sportsWatch","smartCamera"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "Launcher",
"moduleType": "entry"
},
"abilities": [{
"name": "MainAbility",
"icon": "res/drawable/phone.png",
"label": "test app 1",
"launchType": "standard",
"type": "page"
},
{
"name": "SecondAbility",
"icon": "res/drawable/phone.png",
"label": "test app 2",
"launchType": "standard",
"type": "page"
},
{
"name": "ServiceAbility",
"icon": "res/drawable/phone.png",
"label": "test app 2",
"launchType": "standard",
"type": "service"
}
]
}
}
生成hap包。
按照如下目录结构存放文件,res/drawable下面放置资源文件:
图1 资源文件路径图
将上述文件打包生成zip包,修改后缀为.hap,例如Launcher.hap
连接单板,通过串口向单板发送安装KV存储native应用的命令。
./nfs/dev_tools/bin/bm install -p /nfs/Launcher.hap
通过串口向单板发送运行KV存储native应用的命令。
./nfs/dev_tools/bin/aa start -p com.example.launcher -n ServiceAbility
连接单板,通过串口向单板发送AT+SYSPARA命令。
AT+SYSPARA
图2 LiteOS-M平台dump系统属性输出
连接单板,运行bin路径下的os_dump加参数--help,查看os_dump使用指导。
./bin/os_dump --help
os_dump加参数-l,查看当前系统有哪些模块支持获取属性。
./bin/os_dump -l
os_dump加参数syspara,查看当前系统属性。
./bin/os_dump syspara
图3 LiteOS-A平台dump系统属性输出
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。