
#ifndef __ONE_START_H__
#define __ONE_START_H__

#include "dy_utils/dy_common.h"
#include <pthread.h>
#include <time.h>

/***************************************************************************
调用入参格式:
{
    "opt": "start",
    "par": {
        "setpower": 100.5
    }
}
opt可选:
    start:开始
    stop:停止
    get:获取诊断状态
    set:设置参数
par:可选
    只有设置参数的时候有用

返回格式:
{
    "opt": "start",
    "code": 0,
    "status": 0,
    "it": [
        {
            "name": "name1",
            "status": 0,
            "message": "message1"
        },
        {
            "name": "name2",
            "status": 0,
            "message": "message2"
        }
    ]
}
opt:返回的opt,和入参的opt一致
code:0成功,其他失败
status:是一个枚举，代表整体的状态
    0：未开始
    1：处理中
    2：已完成
it:启动流程的项目列表
    name:项目名称
    status:是一个枚举，代表项目的状态
        0：未开始
        1：处理中
        2：已完成
    message:项目提示信息,屏控可以不关心
****************************************************************************/

typedef enum one_start_status
{
    one_start_no_start = 0,
    one_start_processing = 1,
    one_start_completed = 2,
    one_start_stoped = 3
} one_start_status;

typedef enum one_start_it_status
{
    one_start_it_no_start = 0,
    one_start_it_processing = 1,
    one_start_it_pass = 2
} one_start_it_status;

typedef struct one_start_it one_start_it;
typedef struct one_start one_start;
struct one_start_it
{
    const char *name;                            // 诊断项目的名称，需要保证唯一
    one_start_it_status status;                  // 诊断状态
    char message[256];                           // 提示信息
    int (*fun)(one_start_it *this_p, void *par); // 诊断方法
};

#define POINT_NAME_LEN 64
#define SLAVE_NAME_LEN 32

typedef struct one_start_cmd
{
    const char *cmd;
    int (*fun)(one_start *this_p, void *par);
} one_start_cmd;

typedef struct one_start
{
    char no[SLAVE_NAME_LEN]; // 诊断从机名
    one_start_status status;
    int it_size;          // 诊断项目总数
    one_start_it *cur_it; // 当前正在诊断项
    one_start_it *it;     // 所有诊断项
    //
    one_start_cmd *cmd;
    int cmd_size;
} one_start;

char *one_start_loop(const char *opt);
#endif
