Browse Source

485测试通过

bfysop-v2
mr.zhangsan 1 year ago
parent
commit
1140221ef0
  1. 173
      source/app/app_config.c
  2. 80
      source/app/app_config.h
  3. 4
      source/app/main.c
  4. 4
      source/app/main.h
  5. 14
      source/app/task_adc.c
  6. 70
      source/app/task_rs485.c
  7. 11
      source/tpc/debug.h

173
source/app/app_config.c

@ -5,103 +5,106 @@
GlobalParam G;
GlobalRegister R;
int i;
void L3_param_init(void)
{
#if 0
int i;
for(i=0;i<D_ch_max_num;i++)
{
G.weight[i] = 0;
}
G.allweight = 0;
G._total_weight = 0;
G._total_zweight = 0;
//L3_eeprom_read_param();
#endif
}
// void L3_param_init(void)
// {
// #if 0
// G.xx = 0;
// //L3_eeprom_read_param();
// #endif
// }
//读取reg内容,写入iap
void L3_reg_2_iap(void)
{
#if 0
iapData.slaver_id = R.p.slaver_id;
iapData.adc_ch_status = R.p.adc_ch_status;
iapData.weight_max = R.p.weight_max;
iapData.lmd = R.p.lmd;
iapData.adc_blur_mid = R.p.adc_blur_mid;
iapData.adc_blur_avg = R.p.adc_blur_avg;
iapData.adc_blur_shift[0] = R.p.adc_blur_shift[0];
iapData.adc_blur_shift[1] = R.p.adc_blur_shift[1];
iapData.adc_blur_shift[2] = R.p.adc_blur_shift[2];
iapData.adc_blur_threshold[0] = R.p.adc_blur_threshold[0];
iapData.adc_blur_threshold[1] = R.p.adc_blur_threshold[1];
//写入eeprom
if(L1_eep_write_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, (U8*)&iapData,sizeof(IapData),TRUE) == 0)
{
L0_uart0_sendstr("e2p write success");
}
#endif
if(L1_eep_write_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, D_EEP_SECTOR_BLOCK_SIZE, (U8*)&R.p,sizeof(R.p),TRUE) == 0)
{
L0_uart0_sendstr("e2p write success");
return;
}
L0_uart0_sendstr("e2p write failed");
}
// void L3_reg_2_iap(void)
// {
// #if 0
// iapData.slaver_id = R.p.slaver_id;
// iapData.adc_ch_status = R.p.adc_ch_status;
// iapData.weight_max = R.p.weight_max;
// iapData.lmd = R.p.lmd;
// iapData.adc_blur_mid = R.p.adc_blur_mid;
// iapData.adc_blur_avg = R.p.adc_blur_avg;
// iapData.adc_blur_shift[0] = R.p.adc_blur_shift[0];
// iapData.adc_blur_shift[1] = R.p.adc_blur_shift[1];
// iapData.adc_blur_shift[2] = R.p.adc_blur_shift[2];
// iapData.adc_blur_threshold[0] = R.p.adc_blur_threshold[0];
// iapData.adc_blur_threshold[1] = R.p.adc_blur_threshold[1];
// //写入eeprom
// if(L1_eep_write_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, (U8*)&iapData,sizeof(IapData),TRUE) == 0)
// {
// L0_uart0_sendstr("e2p write success");
// }
// #endif
// if(L1_eep_write_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, D_EEP_SECTOR_BLOCK_SIZE, (U8*)&R.p,sizeof(R.p),TRUE) == 0)
// {
// L0_uart0_sendstr("e2p write success");
// return;
// }
// L0_uart0_sendstr("e2p write failed");
// }
//读取iap内容,写入reg
void L3_iap_2_reg(void)
{
#if 0
if(L1_eep_read_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, (U8*)&iapData, NULL) == 1)
{
L0_uart0_sendstr("e2p read failed");
}
L0_uart0_sendstr("e2p read success");
R.p.slaver_id = iapData.slaver_id;
R.p.adc_ch_status = iapData.adc_ch_status;
R.p.weight_max = iapData.weight_max ;
R.p.lmd = iapData.lmd;
R.p.adc_blur_mid = iapData.adc_blur_mid;
R.p.adc_blur_avg = iapData.adc_blur_avg;
R.p.adc_blur_shift[0] = iapData.adc_blur_shift[0];
R.p.adc_blur_shift[1] = iapData.adc_blur_shift[1];
R.p.adc_blur_shift[2] = iapData.adc_blur_shift[2];
R.p.adc_blur_threshold[0] = iapData.adc_blur_threshold[0];
R.p.adc_blur_threshold[1] = iapData.adc_blur_threshold[1];
#endif
if(L1_eep_read_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, D_EEP_SECTOR_BLOCK_SIZE, (U8*)&R.p, NULL) == 0)
{
L0_uart0_sendstr("e2p read success");
return;
}
L0_uart0_sendstr("e2p read failed");
}
// //读取iap内容,写入reg
// void L3_iap_2_reg(void)
// {
// #if 0
// if(L1_eep_read_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, (U8*)&iapData, NULL) == 1)
// {
// L0_uart0_sendstr("e2p read failed");
// }
// L0_uart0_sendstr("e2p read success");
// R.p.slaver_id = iapData.slaver_id;
// R.p.adc_ch_status = iapData.adc_ch_status;
// R.p.weight_max = iapData.weight_max ;
// R.p.lmd = iapData.lmd;
// R.p.adc_blur_mid = iapData.adc_blur_mid;
// R.p.adc_blur_avg = iapData.adc_blur_avg;
// R.p.adc_blur_shift[0] = iapData.adc_blur_shift[0];
// R.p.adc_blur_shift[1] = iapData.adc_blur_shift[1];
// R.p.adc_blur_shift[2] = iapData.adc_blur_shift[2];
// R.p.adc_blur_threshold[0] = iapData.adc_blur_threshold[0];
// R.p.adc_blur_threshold[1] = iapData.adc_blur_threshold[1];
// #endif
// if(L1_eep_read_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, D_EEP_SECTOR_BLOCK_SIZE, (U8*)&R.p, NULL) == 0)
// {
// L0_uart0_sendstr("e2p read success");
// return;
// }
// L0_uart0_sendstr("e2p read failed");
// }
void L3_reg_reset(void)
{
R.p.adc_ch_status = ADC_status_ch2_Ready | ADC_status_ch3_Ready | ADC_status_ch4_Ready; //修改采集通道
R.p.slaver_id = D_UART4_485_SLAVER_ID;
R.p.weight_max = 500; //500kg
R.p.lmd = 2; //2mv/v
R.p.adc_blur_mid = 1;
R.p.adc_blur_avg = 6;
R.p.adc_blur_shift[0] = 0;
R.p.adc_blur_shift[1] = 2;
R.p.adc_blur_shift[2] = 4;
R.p.adc_blur_threshold[0] = 1600; //g
R.p.adc_blur_threshold[1] = 700; //g
R.slave_id = 0x01;
R.low_power_mode = 0;
R.func_btn = 0;
R.nfc.nfc_no[0] = 0;
R.nfc.nfc_no[1] = 0;
for(i=0;i<4;i++){
R.rfids[i].rfid_no[0] = 0;
R.rfids[i].rfid_no[1] = 0;
R.rfids[i].rssi = 0;
R.rfids[i].ant = 0;
};
//for test
// R.slave_id = 0x01;
// R.low_power_mode = 0;
// R.func_btn = 1;
// R.nfc.nfc_no[0] = 0x01;
// R.nfc.nfc_no[1] = 0x23;
// for(i=0;i<4;i++){
// R.rfids[i].rfid_no[0] = 0xA0;
// R.rfids[i].rfid_no[1] = 0xB0;
// R.rfids[i].rssi = 0x61;
// R.rfids[i].ant = i;
// };
}
void L3_reg_init(void)
{
//R.reserved1 = R.reserved2 = R.reserved3 = 0x55;
//R.zero = 0;
//R.status_eep_save = 0;
L3_reg_reset();
L3_iap_2_reg();
//L3_iap_2_reg();
}

80
source/app/app_config.h

@ -6,52 +6,50 @@
#define APP_VERSION 0x10
#define D_COUNT_WEIGHT(adc) (U32)((adc) / D_ADS1213_GAIN_VAL / R.p.lmd * R.p.weight_max * 1000 / (2 * 0x7FFFFF / 1000 ))
#define D_COUNT_ADC(wInG) (U32)((wInG) * D_ADS1213_GAIN_VAL * R.p.lmd * (2 * 0x7FFFFF / 1000) / R.p.weight_max / 1000)
//STEP 1 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Register CONFIG
//寄存器编号从1开始
//#define D_COUNT_WEIGHT(adc) (U32)(1000.0 * R.p.weight_max * (adc) / (2 * 0x7FFFFF / 1000 * D_ADS1213_GAIN_VAL * R.p.lmd))
//#define D_blur_threshold_2_1(threshold) (U32) ( 1.0 * threshold *(2 * 0x7FFFFF / 1000 * D_ADS1213_GAIN_VAL * R.p.lmd) / (1000.0 * R.p.weight_max ))
#define D_COUNT_WEIGHT(adc) (U32)((adc) / D_ADS1213_GAIN_VAL / R.p.lmd * R.p.weight_max * 1000 / (2 * 0x7FFFFF / 1000 ))
#define D_COUNT_ADC(wInG) (U32)((wInG) * D_ADS1213_GAIN_VAL * R.p.lmd * (2 * 0x7FFFFF / 1000) / R.p.weight_max / 1000)
#define ADC_status_chx_Ready_BASE 0x01
#define ADC_status_ch1_Ready 0x01
#define ADC_status_ch2_Ready 0x02
#define ADC_status_ch3_Ready 0x04
#define ADC_status_ch4_Ready 0x08
#define D_ADC_CHANNEL_NUM 4
// #define D_COUNT_WEIGHT(adc) (U32)((adc) / D_ADS1213_GAIN_VAL / R.p.lmd * R.p.weight_max * 1000 / (2 * 0x7FFFFF / 1000 ))
// #define D_COUNT_ADC(wInG) (U32)((wInG) * D_ADS1213_GAIN_VAL * R.p.lmd * (2 * 0x7FFFFF / 1000) / R.p.weight_max / 1000)
// //STEP 1 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Register CONFIG
// //寄存器编号从1开始
// //#define D_COUNT_WEIGHT(adc) (U32)(1000.0 * R.p.weight_max * (adc) / (2 * 0x7FFFFF / 1000 * D_ADS1213_GAIN_VAL * R.p.lmd))
// //#define D_blur_threshold_2_1(threshold) (U32) ( 1.0 * threshold *(2 * 0x7FFFFF / 1000 * D_ADS1213_GAIN_VAL * R.p.lmd) / (1000.0 * R.p.weight_max ))
// #define D_COUNT_WEIGHT(adc) (U32)((adc) / D_ADS1213_GAIN_VAL / R.p.lmd * R.p.weight_max * 1000 / (2 * 0x7FFFFF / 1000 ))
// #define D_COUNT_ADC(wInG) (U32)((wInG) * D_ADS1213_GAIN_VAL * R.p.lmd * (2 * 0x7FFFFF / 1000) / R.p.weight_max / 1000)
// #define ADC_status_chx_Ready_BASE 0x01
// #define ADC_status_ch1_Ready 0x01
// #define ADC_status_ch2_Ready 0x02
// #define ADC_status_ch3_Ready 0x04
// #define ADC_status_ch4_Ready 0x08
// #define D_ADC_CHANNEL_NUM 4
typedef struct global_register
{
//本机ID
U8 slave_id;
//低功耗模式
U8 low_power_mode;
//RO Register
U16 reserved1;
U32 total_weight; //净重(显示重量)*100
U32 total_zweight; //皮重*100
//RW Register
U16 reserved2;
U16 zero; //清0标志,写入任何值清0(去皮)
U16 status_eep_save; //eep写入寄存器,1则写入eep并清0
//U16 reset; //reset标志,写入任何值,所有参数恢复初始值
struct
{ //需要持久化的参数,不能超过72字节,否则会导致eeprom溢出
U16 slaver_id;
U16 adc_ch_status;
U16 weight_max; //量程
U16 lmd; //2mv/v
U16 adc_blur_mid; //中值滤波
U16 adc_blur_avg; //均值滤波
U16 adc_blur_shift[3]; //移位滤波点数
U16 adc_blur_threshold[2]; //移位滤波阀值
}p;
U16 reserved3;
U32 adval[D_ADC_CHANNEL_NUM]; //4路重量
U32 ch_weight[D_ADC_CHANNEL_NUM]; //4路重量
U32 rough_weight; // 毛重
//功能按键
U8 func_btn;
//NFC缓冲区
struct {
//nfc卡号,只取后2个字节
U8 nfc_no[2];
}nfc;
//RFID缓冲区
struct {
//rfid卡号,只取后2个字节
U8 rfid_no[2];
//rfid信号强度
U8 rssi;
//rfid天线编号
U8 ant;
}rfids[4];
}GlobalRegister;
extern GlobalRegister R;

4
source/app/main.c

@ -101,9 +101,9 @@ void L0_main_init(void)
L1_tick_init();
L0_timer0_Init();
// L3_reg_init();
//全局寄存器初始化
L3_reg_init();
// L3_param_init();
// L2_485_init();
// L0_ADS1213_INIT();
//任务初始化

4
source/app/main.h

@ -53,11 +53,7 @@
#include "../msp/eeprom.h"
#include "../app/app_config.h"
#include "../app/task_modbus.h"
#include "../app/task_adc.h"
#include "../app/task_debug.h"
#include "../app/task_register.h"
#include "../app/task_encrypt.h"
#include "../app/task_nfc.h"
#include "../app/task_rfid.h"
#include "../app/task_rs485.h"

14
source/app/task_adc.c

@ -51,13 +51,13 @@ U32 Abs(S32 a)
void L3_task_adc_init(U8 ch)
{
//通道采集任务初始化
L1_task_init(&ts_adc_channel_samples[ch].task);
L3_task_s_go(ts_adc_channel_samples[ch],D_task_init);
ts_adc_channel_samples[ch].status = (R.p.adc_ch_status >> ch) & 0x1;
ts_adc_channel_samples[ch].pool = 0;
ts_adc_channel_samples[ch].adcval = 0;
ts_adc_channel_samples[ch].n = 0;
ts_adc_channel_samples[ch].ch = D_ADCCH_1 + ch;
// L1_task_init(&ts_adc_channel_samples[ch].task);
// L3_task_s_go(ts_adc_channel_samples[ch],D_task_init);
// ts_adc_channel_samples[ch].status = (R.p.adc_ch_status >> ch) & 0x1;
// ts_adc_channel_samples[ch].pool = 0;
// ts_adc_channel_samples[ch].adcval = 0;
// ts_adc_channel_samples[ch].n = 0;
// ts_adc_channel_samples[ch].ch = D_ADCCH_1 + ch;
#if 0
//通道中值滤波任务初始化

70
source/app/task_rs485.c

@ -18,6 +18,11 @@
S_TASK_RS485 _s_task_rs485;
TPC_RS485 tpc_rs485;
TPC_RS485_ACK tpc_rs485_ack;
static U8 acklen = 0;
static U8 i = 0;
U8 constructor_rs485_ack();
//=============================================
void L3_task_rs485_init(void)
@ -28,7 +33,8 @@ void L3_task_rs485_init(void)
#define D_task_RS485_READ 0x50
#define D_task_RS485_PRINT 0x51
#define D_task_RS485_MODE 0x52
#define D_task_RS485_ACK 0x52
#define D_task_RS485_MODE 0x53
void L3_task_rs485_handler(S_TASK_RS485 *s)
{
@ -41,8 +47,29 @@ void L3_task_rs485_handler(S_TASK_RS485 *s)
ts_uart4_recv_buf.ok = 0;
Lc_buf_copy_uc((U8*)&tpc_rs485, ts_uart4_recv_buf.buf, ts_uart4_recv_buf.num);
tpc_rs485.ocr = tpc_rs485.buf[tpc_rs485.num[0] << 8 | tpc_rs485.num[1]];
L2_task_go_Tdelay(D_task_RS485_PRINT,0);
// L2_task_go_Tdelay(D_task_RS485_PRINT,0);
L2_task_go_Tdelay(D_task_RS485_ACK,0);
}
TTSS_Task_step(D_task_RS485_ACK)
if(tpc_rs485.slaveId == R.slave_id)
{
//读取
if(tpc_rs485.cmd == 0x10)
{
//buf[0] 低功耗模式
R.low_power_mode = tpc_rs485.buf[0];
//buf[1-2], rfid映射
//TODO
//构造响应包,并且返回
acklen = constructor_rs485_ack();
//写出
L0_uart4_sendArray((U8*)&tpc_rs485_ack, acklen);
}
}
L2_task_go_Tdelay(D_task_RS485_READ,0);
TTSS_Task_step(D_task_RS485_PRINT)
L0_uart0_sendstr("\r\n--------- Recv RS485 --------\r\n");
@ -67,6 +94,45 @@ void L3_task_rs485_handler(S_TASK_RS485 *s)
TTSS_Task_end();
}
U8 constructor_rs485_ack()
{
U8 num = (1 + sizeof(R.nfc) + sizeof(R.rfids));
tpc_rs485_ack.head[0] = 0xAA;
tpc_rs485_ack.head[1] = 0x55;
tpc_rs485_ack.slaveId = R.slave_id;
tpc_rs485_ack.cmd = 0x10;
tpc_rs485_ack.num[0] = (num >> 8) & 0xFF;
tpc_rs485_ack.num[1] = num & 0xFF;
tpc_rs485_ack.buf[0] = R.func_btn;
Lc_buf_copy_uc((U8*)&tpc_rs485_ack.buf[1], (U8*)&R.nfc, sizeof(R.nfc));
Lc_buf_copy_uc((U8*)&tpc_rs485_ack.buf[1+sizeof(R.nfc)], (U8*)R.rfids, sizeof(R.rfids));
tpc_rs485_ack.ocr = 0;
tpc_rs485_ack.ocr += tpc_rs485_ack.slaveId;
tpc_rs485_ack.ocr += tpc_rs485_ack.cmd;
tpc_rs485_ack.ocr += tpc_rs485_ack.num[0];
tpc_rs485_ack.ocr += tpc_rs485_ack.num[1];
for(i=0;i<num;i++)
{
tpc_rs485_ack.ocr += tpc_rs485_ack.buf[i];
}
tpc_rs485_ack.buf[num] = tpc_rs485_ack.ocr;
//清0资源
R.func_btn = 0;
R.nfc.nfc_no[0] = 0x00;
R.nfc.nfc_no[1] = 0x00;
R.rfids[0].rfid_no[0] = 0x00;
R.rfids[0].rfid_no[1] = 0x00;
R.rfids[1].rfid_no[0] = 0x00;
R.rfids[1].rfid_no[1] = 0x00;
R.rfids[2].rfid_no[0] = 0x00;
R.rfids[2].rfid_no[1] = 0x00;
R.rfids[3].rfid_no[0] = 0x00;
R.rfids[3].rfid_no[1] = 0x00;
return 6 + num + 1;
}

11
source/tpc/debug.h

@ -72,6 +72,17 @@ typedef struct _tpc_rs485_
U8 ocr;
}TPC_RS485;
#define TPC_RS485_ACK_DAT_MAX 32
typedef struct _tpc_rs485_ack_
{
U8 head[2];
U8 slaveId;
U8 cmd;
U8 num[2];
U8 buf[TPC_RS485_ACK_DAT_MAX];
U8 ocr;
}TPC_RS485_ACK;
#define D_HETU_FX_buf_max 5 //定长协议 长度为5
#define D_HETU_FX_fi 0x60

Loading…
Cancel
Save