按下按键开始检测,批检仪测试脚本

This commit is contained in:
ranchuan
2023-06-26 18:07:08 +08:00
parent cfda1c461b
commit a1a9b53780
13 changed files with 963 additions and 178 deletions

View File

@@ -117,5 +117,8 @@
赋码失败返回时返回小板的错误码
2023.6.25
电机下压
2023.6.26
第一次出现下载程序到一半,参数错误重启的情况
2023.6.26
批检仪完成整个检测流程测试编写测试脚本把检测结果保存到csv文件

View File

@@ -0,0 +1,118 @@
#include "board.h"
#include "stm32f4xx.h"
// PB6,7,8,9
// 输入脚
#define GPIO_Initer() {.GPIO_Mode=GPIO_Mode_IN,\
.GPIO_Speed=GPIO_Speed_100MHz,\
.GPIO_OType=GPIO_OType_PP,\
.GPIO_PuPd=GPIO_PuPd_UP \
}
typedef struct{
const char *name;
void (*gpio_clock_fun)(uint32_t,FunctionalState);
uint32_t gpio_rcc;
GPIO_TypeDef *gpio_base;
uint16_t gpio_pin;
volatile uint32_t *bitmap_pin;
}gpioin_dtb;
static const gpioin_dtb g_dtb[]={
{
.name="gpioin1",
.gpio_clock_fun=RCC_AHB1PeriphClockCmd,
.gpio_rcc=RCC_AHB1Periph_GPIOB,
.gpio_base=GPIOB,
.gpio_pin=6,
.bitmap_pin=&PININ(B,6),
},
{
.name="gpioin2",
.gpio_clock_fun=RCC_AHB1PeriphClockCmd,
.gpio_rcc=RCC_AHB1Periph_GPIOB,
.gpio_base=GPIOB,
.gpio_pin=7,
.bitmap_pin=&PININ(B,7),
},
{
.name="gpioin3",
.gpio_clock_fun=RCC_AHB1PeriphClockCmd,
.gpio_rcc=RCC_AHB1Periph_GPIOB,
.gpio_base=GPIOB,
.gpio_pin=8,
.bitmap_pin=&PININ(B,8),
},
{
.name="gpioin4",
.gpio_clock_fun=RCC_AHB1PeriphClockCmd,
.gpio_rcc=RCC_AHB1Periph_GPIOB,
.gpio_base=GPIOB,
.gpio_pin=9,
.bitmap_pin=&PININ(B,9),
},
};
typedef struct{
const gpioin_dtb *dtb;
}self_data;
static self_data g_self[LENGTH(g_dtb)];
def_find_fun(gpioin_dtb,g_dtb)
static int init(gpioin_def *g)
{
param_check(g);
if(g->private_data) return 0;
GPIO_InitTypeDef init=GPIO_Initer();
int index;
const gpioin_dtb *dtb=find(g->name,&index);
self_data *self=&g_self[index];
self->dtb=dtb;
g->private_data=self;
dtb->gpio_clock_fun(dtb->gpio_rcc,ENABLE);
init.GPIO_Pin = 1<<dtb->gpio_pin;
GPIO_Init(dtb->gpio_base, &init);
return 0;
}
static int deinit(gpioin_def *g)
{
return 0;
}
static int state(gpioin_def *g)
{
param_check(g);
param_check(g->private_data);
self_data *self=g->private_data;
return *self->dtb->bitmap_pin;
}
gpioin_init_export(gpioin1,init,deinit,state,0)
gpioin_init_export(gpioin2,init,deinit,state,0)
gpioin_init_export(gpioin3,init,deinit,state,0)
gpioin_init_export(gpioin4,init,deinit,state,0)

View File

@@ -6,7 +6,7 @@
#define BUILD_DATE "2023-06-25 17:31:20"
#define BUILD_DATE "2023-06-26 10:46:21"
#define SOFT_VERSION "0.01"

View File

@@ -40,7 +40,13 @@ typedef struct __pwm_def{
}pwm_def;
typedef struct __gpioin_def{
const char *name;
int (*init)(struct __gpioin_def *u);
int (*deinit)(struct __gpioin_def *u);
int (*state)(struct __gpioin_def *u);
void *private_data;
}gpioin_def;
@@ -88,7 +94,22 @@ typedef struct __pwm_def{
RT_USED static const struct dev_struct __dev_##name_ SECTION("devstruct")= \
{ \
__dev_##name_##_name, \
&_pwm_##name_, \
&_pwm_##name_,\
};
#define gpioin_init_export(name_,init_,deinit_,state_,priv_) \
const static char __dev_##name_##_name[] SECTION(".rodata.devstr") = #name_; \
RT_USED static gpioin_def _gpioin_##name_={\
.name=__dev_##name_##_name,\
.init=init_,\
.deinit=deinit_,\
.state=state_,\
.private_data=priv_,\
};\
RT_USED static const struct dev_struct __dev_##name_ SECTION("devstruct")= \
{ \
__dev_##name_##_name, \
&_gpioin_##name_,\
};

104
source/task/key.c Normal file
View File

@@ -0,0 +1,104 @@
#include "board.h"
#include "rtthread.h"
#include "debug.h"
#include "string.h"
#include "dev_flash.h"
#include "prot_uc.h"
#include "key.h"
#include "mystdlib.h"
// 作为批检仪使用时读取按键
typedef struct{
int inited;
int run;
}self_def;
static self_def g_self;
static void request_check(void *p);
static void key_thread(void *arg)
{
self_def *s=arg;
gpioin_def *in1,*in2,*in3,*in4;
int input=0,input_lock=1;
in1=dev_get("gpioin1");
in2=dev_get("gpioin2");
in3=dev_get("gpioin3");
in4=dev_get("gpioin4");
in1->init(in1);
in2->init(in2);
in3->init(in3);
in4->init(in4);
while (s->run)
{
rt_thread_mdelay(20);
//input=(in1->state(in1))|(in2->state(in2)<<1)|(in3->state(in3)<<2)|(in4->state(in4)<<3);
input=(in1->state(in1));
if(input!=input_lock)
{
DBG_LOG("key=%08X",input);
input_lock=input;
if((input&1)==0)
{
request_check(s);
}
}
}
}
// cmd=0x37
static void request_check(void *p)
{
const sys_param_def *par=sys_param();
array_def *d=arr_creat();
emit key_send_signal(p,0x37,arr_temp(d));
//DBG_LOG("tcp liver:%s",str_temp(arr_string(d)));
}
static void init_later(void *t)
{
void *protu=app_variable("protu",0,0);
if(protu){
protu_codec_set(protu,protu_find_codec("ym_checker"));
connect(t,key_send_signal,0,protu,protu_send_call);
DBG_LOG("key thread created");
}else{
DBG_WARN("can not fond variable \"protu\"");
}
}
static int init_thread(void)
{
if(strcmp(sys_param()->device_type,"checker")==0)
{
self_def *s=&g_self;
s->inited=1;
s->run=1;
rt_thread_t rt_t=rt_thread_create("key_t",key_thread,s,1024,15,20);
rt_thread_startup(rt_t);
app_valid_call("protu",init_later,s);
}
return 0;
}
app_init_export(init_thread)

28
source/task/key.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef key_h__
#define key_h__
#include "rtthread.h"
#include "transmit.h"
#include "signal.h"
#include "bytearray.h"
signal key_send_signal(void *obj,uint8_t cmd,array_def *data);
#endif

View File

@@ -4,6 +4,7 @@
#include "handle.h"
#include "handle_for_checker.h"
#include "handle_for_coder.h"
#include "key.h"
#include "log.h"
#include "moter.h"
#include "prot_mcu.h"
@@ -59,6 +60,17 @@ signal_export(port_end_signal);
uint32_t param[4];
param[0]=(uint32_t)src;
param[1]=(uint32_t)data;
param[2]=(uint32_t)ack;
param[3]=(uint32_t)err_str;
_signal_emit(obj,port_end_signal,param,4);
}
signal_export(port_end_signal);
void key_send_signal(void *obj,uint8_t cmd,array_def *data)
{