428 Star 2.3K Fork 513

OpenHarmony / docs

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
Clone or download
utils-library.md 7.79 KB
Copy Edit Web IDE Raw Blame History

Utils Library

Overview

The Utils library stores basic components of OpenHarmony. These basic components are used by OpenHarmony service subsystems and upper-layer applications.

The Utils library provides the following capabilities on different platforms:

  • LiteOS Cortex-M (Hi3861 platform): KV stores, file operations, timers, and IoT peripheral control
  • LiteOS Cortex-A (Hi3516 and Hi3518 platforms): KV stores, timers, and ACE JavaScript APIs

Directory Structure

utils/native/lite/                 # Root directory of the Utils library
├── file                        # Implementation of the file interface
├── hals                        # HAL directory
│   └── file                   # Header files of the hardware abstraction layer for file operations
├── include                     # Files of external interfaces provided by the Utils library
├── js                          # ACE JavaScript API directory                 
│   └── builtin					
│       ├── common
│       ├── deviceinfokit       # Device information kit
│       ├── filekit             # File kit
│       └── kvstorekit          # KV store kit
├── kal                          # KAL directory
│   └── timer                   # KAL implementation of the timer
├── kv_store	                    # KV store implementation
│   ├── innerkits               # Internal KV store interfaces
│   └── src	                    # KV store source file
└── timer_task                   # Timer implementation

base/iot_hardware                   # IoT peripheral control
├── frameworks          
│   └── wifiiot_lite            # Implementation of the IoT peripheral control module
├── hals
│   └── wifiiot_lite            # HAL interfaces
└── interfaces
    └── kits                     # Interfaces of the IoT peripheral control module

vendor/hisi/hi3861/hi3861_adapter/hals/iot_hardware  # HAL for IoT peripheral control
└── wifiiot_lite                 # Implementation of the interfaces at the HAL

Constraints

The Utils library is developed using the C language.

Table 1 Capabilities and constraints of the Utils library

Component

Platform

Description

Constraint

KV store

LiteOS Cortex-M and LiteOS Cortex-A

Provides KV storage for applications.

N/A

File operation

LiteOS Cortex-M

Provides unified file operation interfaces that can be used on different underlying chip components.

N/A

Timer

LiteOS Cortex-M and LiteOS Cortex-A

Provides unified timer operation interfaces that can be used on different underlying chip components.

N/A

IoT peripheral control

LiteOS Cortex-M

Provides the capability of performing operations for peripherals.

  

Usage

  • KV store

    Obtaining an interface
    char key1[] = "rw.sys.version";
    char value1[32] = {0};
    int ret = UtilsGetValue(key1, value1, 32);
    
    Setting the interface
    char key14[] = "key_14";
    ret = UtilsSetValue(key14, defValue);
  • File operation

    // open && write
    char fileName[] = "testfile";
    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);
    
    // stat
    int fileLen = 0;
    ret = UtilsFileStat(fileName, &fileLen);
    printf("file size = %d\n", fileLen);
    
    // seek
    int fd1 = UtilsFileOpen(fileName, O_RDWR_FS, 0);
    ret = UtilsFileSeek(fd1, 5, SEEK_SET_FS);
    printf("lseek ret = %d\n", ret);
    char buf[32] = {0};
    int readLen = UtilsFileRead(fd1, buf, 32);
    ret = UtilsFileClose(fd1);
    printf("read len = %d : buf = %s\n", readLen, buf);
    
    // delete
    ret = UtilsFileDelete(fileName);
    printf("delete ret = %d\n", ret);

Repositories Involved

iothardware_frameworks_wifiiot_lite

iothardware_hals_wifiiot_lite

iothardware_interfaces_kits_wifiiot_lite

utils_native_lite

1
https://gitee.com/openharmony/docs.git
git@gitee.com:openharmony/docs.git
openharmony
docs
docs
master

Search