diff --git a/source/codec/codec.c b/source/codec/codec.c index 9c19df0..c58f740 100644 --- a/source/codec/codec.c +++ b/source/codec/codec.c @@ -322,6 +322,6 @@ array_def *protew_decode(protu_def *p,array_def *data) array_def *protew_encode(protu_def *p,array_def *data) { } -protuc_codec_export(ew_slave,protm_decode,protm_encode); +// protuc_codec_export(ew_slave,protm_decode,protm_encode); diff --git a/source/elec_det/driver/EWDriver.c b/source/elec_det/driver/EWDriver.c index 4a42428..decef01 100644 --- a/source/elec_det/driver/EWDriver.c +++ b/source/elec_det/driver/EWDriver.c @@ -6,6 +6,7 @@ #include "hardware/power.h" #include "ewdriver.h" #include "hardware/timer_cfg.h" +#include "debug.h" static volatile EWBus_Mod_en bus_mod = OFF_MOD; static volatile CurrentSample_Range_eu buscurrent_range = Current_Max; @@ -683,6 +684,186 @@ uint8_t DMod_FireBusReadDatasV2(uint8_t* buf, uint8_t len, uint32_t time_out) } + +static uint16_t us_plus_H,us_plus_H2;//高电平采用次数 +static uint16_t us_plus_T,us_plus_T2;//采样周期 +typedef struct{ + uint16_t cur_idle; + uint16_t cur_idle_ad; + uint16_t cur_high_value; + uint16_t cur_idle_line; + uint16_t cur_max; +}firebus_def; +uint8_t DMod_FireBusReadDatasV2_RC(uint8_t* buf, uint8_t len, uint32_t time_out) +{ + uint32_t ul_ad_sample; + uint32_t ul_check_falg; //奇校验 + uint32_t us_time_out = time_out; + uint32_t ul_data = 0; + uint32_t us_dataT_Or;//数据周期 + uint32_t us_temp1,us_temp2; + uint16_t ad_max = 0,ad_min_temp=0,ad_max_temp = 0; + firebus_def fire_dat={0}; + uint8_t ret=0; + CurrentSample_Range_eu range = buscurrent_range;//档位保存 + Power_SetSampleCurrentRange(R10_2mA_30mA_MC); + ADC_CurChnnelSet(AN_MAL_CH,ADC_SPEED_HFAST); + delay_us(2000); + //总线跳转到中电平 + EW_DIFF_MOD_M; + //延时等待电流稳定 + delay_us(800); + //COM_PH2_Out = 0; + PBout(I2IC_SCL_Pin_Nu) = 0; + delay_us(200); + //获取中电平电流 + PBout(I2IC_SCL_Pin_Nu) = 1 ; + DMod_GetIdle2V(); + fire_dat.cur_idle=SMod_Read_Idle_C; + fire_dat.cur_idle_ad=ADC_GetCurADCFast(); + PBout(I2IC_SCL_Pin_Nu) = 0 ; + //读取指定长度数据 + //读取单字节数据 + ul_data = 0; + //等待起始信号唤醒信号 + us_plus_H = 0; + us_plus_T = 0; + us_time_out = 2000 + time_out; + do{ + + ul_ad_sample = ADC_GetCurADCFast(); + if(ad_max < ul_ad_sample) + ad_max = ul_ad_sample; + if(ul_ad_sample > SMod_Read_Idle_C) + { + if(ul_ad_sample-SMod_Read_Idle_C>50){ + us_plus_H++; + fire_dat.cur_high_value=fire_dat.cur_high_value/2+ul_ad_sample/2; + }else{ + SMod_Read_Idle_C=ul_ad_sample; + } + }else{ + us_plus_H = 0; + fire_dat.cur_high_value=0; + } + delay_us(2); + us_time_out--; + } + while((us_plus_H < 4) && (us_time_out > 0)); + fire_dat.cur_max=ad_max; + if(us_time_out < 1)//等待起始信号超时 + { + ret=1; + goto end; + } + + // 空闲判线以最高电平为基准 + SMod_Read_Idle_C=(SMod_Read_Idle_C+fire_dat.cur_high_value)/2; + fire_dat.cur_idle_line=SMod_Read_Idle_C; + + while(len > 0) + { + //等待数据帧起始信号 + us_time_out = 10; + us_plus_T2 = 0xFFFF; + us_plus_H2 = 0; + while(us_time_out > 0) + { + us_plus_H = 0; + us_plus_T = 0; + idle_line = SMod_Read_Idle_C; +// idle_line = ad_max - SMod_Read_Idle_C; +// idle_line = (idle_line>>1)+ (idle_line>>4)+ SMod_Read_Idle_C; + if(SMod_FireBusReadPlus(&us_plus_H,&us_plus_T,time_out,idle_line,&ad_max_temp,&ad_min_temp ) > 0) + { + ret=2; + goto end; + } + if(us_plus_H2 > (us_plus_T2- us_plus_H2)) + { + us_temp1 = us_plus_T << 1; //2倍 + us_temp2 = us_plus_T + (us_plus_T >> 1);//1.5倍 + if((us_plus_T2 > us_temp2) && (us_plus_T2 < us_temp1)) + { + break; + } + } + us_plus_T2 = us_plus_T; + us_plus_H2 = us_plus_H; + us_time_out--; + } + //采集8bit数据+1位校验 + ul_data = 0; + ul_check_falg = 0; + us_time_out = 0; + us_plus_T2 = 0; + us_dataT_Or = us_plus_T;//保存数据周期 + do{ + ul_data <<= 1; + if(us_plus_H > (us_plus_T- us_plus_H)) //高电平时间大于低电平 1 + { + ul_data |= 0x01; + ul_check_falg ^= 0x01; + }else{//检测是否是结束信号 0 + us_temp1 = us_plus_T2 << 1; //2倍 + us_temp2 = us_plus_T2 + (us_plus_T2 >> 1);//1.5倍 + if((us_plus_T > us_temp2) && (us_plus_T < us_temp1)) + { + break; + } + } + //约束数据周期范围 +// if(((us_dataT_Or+4) < us_plus_T) +// || ((us_dataT_Or - 4) > us_plus_T)) +// { +// SetSampleCurrentRange(range); +// EW_SINGLE_MOD_H; +// return 3; +// } + us_plus_T2 = us_plus_T; + us_plus_H2 = us_plus_H; + us_plus_H = 0; + us_plus_T = 0; + //idle_line = ad_max - SMod_Read_Idle_C; + //idle_line = (idle_line>>1)+ (idle_line>>4)+ SMod_Read_Idle_C; + idle_line = SMod_Read_Idle_C; + if(SMod_FireBusReadPlus(&us_plus_H,&us_plus_T,time_out,idle_line,&ad_max_temp,&ad_min_temp ) > 0) + { + ret=4; + goto end; + } + ad_max = (uint16_t)(ad_max * 0.7f + ad_max_temp*0.3f); + us_time_out++; + }while(us_time_out < 13); + if(ul_check_falg == 0) + { + ret=5; + goto end; + } + if(us_time_out != 9) + { + ret=6; + goto end; + } + ul_data >>= 2; + *buf = (uint8_t)ul_data; + buf++; + len--; + } + //delay_us(time_out >> 1); + + end: + EW_DIFF_MOD_H; + Power_SetSampleCurrentRange(range); + if(ret){ +// DBG_LOG("cur_idle=%d,high_value=%d,idle_line=%d.",fire_dat.cur_idle, fire_dat.cur_high_value,fire_dat.cur_idle_line); +// DBG_LOG("cur_max=%d,cur_idle_ad=%d",fire_dat.cur_max,fire_dat.cur_idle_ad); + } + return ret; +} + + + /* @brief 差分模式数据发送 @param buf 发送数据缓存 @@ -803,7 +984,7 @@ uint8_t DMod_ReadBytesXor(uint8_t* buf, uint8_t len,uint16_t retry_times) { uint8_t ret; // for(int i=0;i