From aeb0e4c206cbe02191c13adb409500cea3be50cd Mon Sep 17 00:00:00 2001 From: andy Date: Sun, 10 Dec 2023 11:13:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=BB=E5=8A=A1=E6=8F=92?= =?UTF-8?q?=E6=A7=BD,=E6=9C=AA=E5=86=99=E5=AE=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 19 ++-- checher_slave.uvoptx | 2 +- checher_slave.uvprojx | 21 ++-- source/ReadMe.txt | 3 + source/elec_det/elec_det.c | 10 ++ source/elec_det/elec_judge.c | 2 +- source/elec_det/elec_task_slot.c | 130 +++++++++++++++++++++++++ source/elec_det/elec_task_slot.h | 30 ++++++ source/elec_det/interface/CheckerExt.c | 51 ++++++++++ source/main/compiler_info.h | 2 +- 10 files changed, 249 insertions(+), 21 deletions(-) create mode 100644 source/elec_det/elec_task_slot.c create mode 100644 source/elec_det/elec_task_slot.h diff --git a/.vscode/settings.json b/.vscode/settings.json index 579b074..9a682d3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,13 +1,14 @@ { "files.associations": { - "stm32f4xx.h": "c", - "signal.h": "c", - "dev_flash.h": "c", - "opt.h": "c", - "if_can.h": "c", - "board.h": "c", - "prot_uc.h": "c", - "tran_for_slave.h": "c", - "ewupdata.h": "c" + "stm32f4xx.h": "c", + "signal.h": "c", + "dev_flash.h": "c", + "opt.h": "c", + "if_can.h": "c", + "board.h": "c", + "prot_uc.h": "c", + "tran_for_slave.h": "c", + "ewupdata.h": "c", + "elec_task_slot.h": "c" } } \ No newline at end of file diff --git a/checher_slave.uvoptx b/checher_slave.uvoptx index e1d76ae..365583f 100644 --- a/checher_slave.uvoptx +++ b/checher_slave.uvoptx @@ -798,7 +798,7 @@ stm32lib - 1 + 0 0 0 0 diff --git a/checher_slave.uvprojx b/checher_slave.uvprojx index 6aa634b..84cdee3 100644 --- a/checher_slave.uvprojx +++ b/checher_slave.uvprojx @@ -185,6 +185,7 @@ 0 0 0 + 0 0 0 8 @@ -351,7 +352,7 @@ 0 0 0 - 0 + 4 @@ -803,7 +804,7 @@ 2 2 2 - 2 + 0 @@ -1907,7 +1908,7 @@ 2 2 2 - 2 + 0 @@ -2403,7 +2404,7 @@ 2 2 2 - 2 + 0 @@ -2502,7 +2503,7 @@ 2 2 2 - 2 + 0 @@ -2581,7 +2582,7 @@ 2 2 2 - 2 + 0 @@ -2655,7 +2656,7 @@ app 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060960::V5.06 update 7 (build 960)::.\ARMCC 0 @@ -2830,6 +2831,7 @@ 0 0 0 + 0 0 0 8 @@ -2996,7 +2998,7 @@ 0 0 0 - 0 + 4 @@ -4345,6 +4347,7 @@ 0 0 0 + 0 0 0 8 @@ -4511,7 +4514,7 @@ 0 0 0 - 0 + 4 diff --git a/source/ReadMe.txt b/source/ReadMe.txt index ddcd9e0..275700f 100644 --- a/source/ReadMe.txt +++ b/source/ReadMe.txt @@ -282,3 +282,6 @@ 使用定时器来精确控制数据发送的时间间隙,保证和其他小板不冲突 2023.12.7 广播命令根据数据量自动计算发送数据的窗口时间 +2023.12.10 + 添加任务插槽,未写完 + diff --git a/source/elec_det/elec_det.c b/source/elec_det/elec_det.c index 40750ce..b53aaa5 100644 --- a/source/elec_det/elec_det.c +++ b/source/elec_det/elec_det.c @@ -27,6 +27,16 @@ #include "interface/CheckerExt.h" + +/* + +此文件定义了电子模块与外界软件程序交互的接口 + +*/ + + + + #define PLAN_MAX_TASK 64 #define TASK_PAR_BACK_LEN 10 diff --git a/source/elec_det/elec_judge.c b/source/elec_det/elec_judge.c index 0404488..0938286 100644 --- a/source/elec_det/elec_judge.c +++ b/source/elec_det/elec_judge.c @@ -377,8 +377,8 @@ void elec_judge(elec_judge_def *e,int task_num,uint8_t *exe_ack, for(int i=0;ischeme->task[i]; if(BIT_CHECK(exe_flag,i)){ - task=&e->scheme->task[i]; if(task->taskidjudge_fun_num){ e->judge_fun_table[task->taskid](e,i,data); }else if((task->taskid>=CHECKER_MAXID_COUNT)&& diff --git a/source/elec_det/elec_task_slot.c b/source/elec_det/elec_task_slot.c new file mode 100644 index 0000000..7fef8eb --- /dev/null +++ b/source/elec_det/elec_task_slot.c @@ -0,0 +1,130 @@ + +#include "elec_task_slot.h" +#include "board.h" +#include "stdlib.h" +#include "string.h" + + + +/* + +此文件定义动态任务插入的机制 + +*/ + + +#define ERR_TABLE_SIZE 10 + +typedef struct _task_node{ + task_def task; + struct _task_node *next; +}task_node; + + + + +typedef struct{ + int node_num; + task_node *head; + task_node *current; + int err_num; + uint8_t err_table[ERR_TABLE_SIZE] +}task_slot_def; + + + +void task_slot_delete(void) +{ + task_slot_def *t=app_variable("task_slot",0,0); + if(t){ + task_node *n=t->head; + task_node *old=0; + while(n){ + old=n; + n=n->next; + free(old); + } + free(t); + } +} + + +// 初始化 +void *task_slot_init(void) +{ + task_slot_def *t=app_variable("task_slot",0,0); + if(t==0){ + t=calloc(1,sizeof(task_slot_def)); + app_variable("task_slot",t,0); + } + return t; +} + + + +// 添加一个任务 +int task_slot_add_item(void *context,task_def *item) +{ + task_slot_def *t=context; + if(t==0){ + return -1; + } + task_node **n=&t->head; + task_node *tail; + tail=calloc(1,sizeof(task_node)); + memcpy(tail,item,sizeof(task_node)); + while(*n){ + n=&(*n)->next; + } + (*n)=tail; + return 0; +} + + + + +// 找到下一个slot +task_def *task_slot_next(void *context,uint8_t slot_index) +{ + task_slot_def *t=context; + if(t==0){ + return 0; + } + task_node *n; + while(t->current){ + n=t->current; + t->current=n->next; + if(n->task.slot_index==slot_index){ + return &n->task; + } + } + return 0; +} + + +int task_slot_add_err(void *context,uint8_t err) +{ + task_slot_def *t=context; + if(t==0){ + return -1; + } + int index=-1; + for(int i=0;ierr_table[i]==0){ + if(index<0) index=i; + } + if(t->err_table[i]==err){ + return; + } + } + if(index>=0){ + t->err_table[index]=err; + t->err_num++; + return 0; + } + return -2; +} + + + + diff --git a/source/elec_det/elec_task_slot.h b/source/elec_det/elec_task_slot.h new file mode 100644 index 0000000..7836c0b --- /dev/null +++ b/source/elec_det/elec_task_slot.h @@ -0,0 +1,30 @@ + +#ifndef elec_task_slot_h__ +#define elec_task_slot_h__ + +#include "board.h" + +#pragma pack (1) +typedef struct{ + uint8_t slot_index; + uint8_t task_id; + uint8_t par_count;// 参数个数 + uint8_t ret_count;// 返回值个数 + uint8_t errcode; + uint8_t params[20]; + uint8_t rets[20]; +}task_def; +#pragma pack () + +void *task_slot_init(void); + +int task_slot_add_item(void *context,task_def *item); + +task_def *task_slot_next(void *context,uint8_t slot_index); + +int task_slot_add_err(void *context,uint8_t err); + + +#endif + + diff --git a/source/elec_det/interface/CheckerExt.c b/source/elec_det/interface/CheckerExt.c index 9d6965d..9b920b1 100644 --- a/source/elec_det/interface/CheckerExt.c +++ b/source/elec_det/interface/CheckerExt.c @@ -5,6 +5,7 @@ #include "CheckerExt.h" #include "basechecker.h" #include "elec_det.h" +#include "elec_task_slot.h" @@ -117,7 +118,57 @@ static int calc_skip_num(int index) } + + + +/*rc{ +执行动态插入的任务, +找到此插槽的所有动态任务并依次执行,如未找到则直接返回 +par0:要执行的任务插槽 +return:无 +exe:动态插入的任务执行失败则此任务失败 +}*/ +void CheckerExt_Slot(void) +{ + int index; + uint16_t ret=0; + int self_index=checker_runcfg.task_info.runindex; + if(checker_runcfg.param_count<1){ + ret=1; + goto end; + } + index=checker_runcfg.params[0]; + task_def *t=0; + void *task_slot=task_slot_init(); + if(task_slot==0){ + goto end; + } + if(elec_task_env_back()){ + ret=2; + goto end; + } + while(t=task_slot_next(task_slot,(uint8_t)index),t){ + // t-> + } + if(elec_task_env_restore()){ + ret=5; + goto end; + } + end: + Checker_MaskResult(ret,self_index); +} + + + + + + + + + + CheckerTask exttaskArray[CHECKER_EXTID_COUNT]={ CheckerExt_CalcErr, + CheckerExt_Repeat, }; diff --git a/source/main/compiler_info.h b/source/main/compiler_info.h index e588e71..fe3da01 100644 --- a/source/main/compiler_info.h +++ b/source/main/compiler_info.h @@ -6,7 +6,7 @@ -#define BUILD_DATE "2023-12-08 08:46:40" +#define BUILD_DATE "2023-12-09 12:34:57" #define SOFT_VERSION "2.07"