169570cc8Sopenharmony_ci/*
269570cc8Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
369570cc8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
469570cc8Sopenharmony_ci * you may not use this file except in compliance with the License.
569570cc8Sopenharmony_ci * You may obtain a copy of the License at
669570cc8Sopenharmony_ci *
769570cc8Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
869570cc8Sopenharmony_ci *
969570cc8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1069570cc8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1169570cc8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1269570cc8Sopenharmony_ci * See the License for the specific language governing permissions and
1369570cc8Sopenharmony_ci * limitations under the License.
1469570cc8Sopenharmony_ci */
1569570cc8Sopenharmony_ci
1669570cc8Sopenharmony_ci#include <stdio.h>
1769570cc8Sopenharmony_ci#include <stdlib.h>
1869570cc8Sopenharmony_ci
1969570cc8Sopenharmony_ci#include "hnpsamplelib.h"
2069570cc8Sopenharmony_ci
2169570cc8Sopenharmony_ci#ifdef __cplusplus
2269570cc8Sopenharmony_ciextern "C" {
2369570cc8Sopenharmony_ci#endif
2469570cc8Sopenharmony_ci
2569570cc8Sopenharmony_ci#define HNPSAMPLE_INDEX_2 2
2669570cc8Sopenharmony_ci#define MAX_DELAY_TIME 60
2769570cc8Sopenharmony_ci
2869570cc8Sopenharmony_ci// hnpsample软件功能包括:读取cfg文件并打印内容,执行依赖的so函数。通过argv[1]参数控制运行的时间,单位s
2969570cc8Sopenharmony_ciint main(int argc, char *argv[])
3069570cc8Sopenharmony_ci{
3169570cc8Sopenharmony_ci    int sectime = 0;
3269570cc8Sopenharmony_ci
3369570cc8Sopenharmony_ci    printf("\nstart hnp sample");
3469570cc8Sopenharmony_ci
3569570cc8Sopenharmony_ci    if (argc == HNPSAMPLE_INDEX_2) {
3669570cc8Sopenharmony_ci        sectime = atoi(argv[1]);
3769570cc8Sopenharmony_ci        if (sectime > MAX_DELAY_TIME) {
3869570cc8Sopenharmony_ci            sectime = 0;
3969570cc8Sopenharmony_ci        }
4069570cc8Sopenharmony_ci    }
4169570cc8Sopenharmony_ci
4269570cc8Sopenharmony_ci    // 读取配置文件内容并打印
4369570cc8Sopenharmony_ci    FILE *file = fopen("../cfg/hnpsample.cfg", "r");
4469570cc8Sopenharmony_ci    if (file != NULL) {
4569570cc8Sopenharmony_ci        printf("\ncfg file content:\n");
4669570cc8Sopenharmony_ci        int ch;
4769570cc8Sopenharmony_ci        while ((ch = fgetc(file)) != EOF) {
4869570cc8Sopenharmony_ci            putchar(ch);
4969570cc8Sopenharmony_ci        }
5069570cc8Sopenharmony_ci        printf("\ncfg file end.");
5169570cc8Sopenharmony_ci        fclose(file);
5269570cc8Sopenharmony_ci    } else {
5369570cc8Sopenharmony_ci        printf("\n open cfg=../cfg/hnpsample.cfg failed.");
5469570cc8Sopenharmony_ci    }
5569570cc8Sopenharmony_ci
5669570cc8Sopenharmony_ci    // 调用依赖so的函数并进行相应延时处理
5769570cc8Sopenharmony_ci    HnpSampleLibDelay(sectime);
5869570cc8Sopenharmony_ci
5969570cc8Sopenharmony_ci    printf("\nhnp sample end");
6069570cc8Sopenharmony_ci    return 0;
6169570cc8Sopenharmony_ci}
6269570cc8Sopenharmony_ci
6369570cc8Sopenharmony_ci
6469570cc8Sopenharmony_ci#ifdef __cplusplus
6569570cc8Sopenharmony_ci}
6669570cc8Sopenharmony_ci#endif