From 036c2fd1b8eb6dfacd4fc54ddfd1103da1491c66 Mon Sep 17 00:00:00 2001 From: yunyaobaihong <896458252@qq.com> Date: Wed, 31 May 2023 15:10:10 +0800 Subject: [PATCH 1/3] fix:demo repair logic random in repeat and can not load protocol file in windows --- libsigrok4DSL/hardware/demo/demo.c | 82 ++++++++++++++++++++++++------ libsigrok4DSL/hardware/demo/demo.h | 4 +- 2 files changed, 68 insertions(+), 18 deletions(-) diff --git a/libsigrok4DSL/hardware/demo/demo.c b/libsigrok4DSL/hardware/demo/demo.c index 5a17b738..6032a22f 100644 --- a/libsigrok4DSL/hardware/demo/demo.c +++ b/libsigrok4DSL/hardware/demo/demo.c @@ -159,16 +159,64 @@ static int vdev_init(struct sr_dev_inst *sdi) static void dso_status_update(struct session_vdev *vdev) { - struct sr_status *status = (struct sr_status*)&vdev->mstatus; - - // status->ch0_cyc_tlen = 340; - // status->ch1_cyc_tlen = 340; - // status->ch0_cyc_cnt = 100; - // status->ch1_cyc_cnt = 85; - // status->ch0_max = 158; - // status->ch1_max = 158; - // status->ch0_min = 78; - // status->ch1_min = 78; +// struct sr_status *status = (struct sr_status*)&vdev->mstatus; +// struct session_packet_buffer *pack_buffer = vdev->packet_buffer; + +// uint8_t ch_max = DSO_MID_VAL; +// uint8_t ch_min = DSO_MID_VAL; +// uint16_t max_count = 0; +// int interval1 = 0; +// int interval2 = 0; +// for(int i = 0 ; i<20000 ; i+=2) +// { +// uint8_t val = *(uint8_t*)(pack_buffer->post_buf +i); +// if (val > ch_max) +// ch_max = val; +// if (val < ch_min) +// ch_min = val; + +// if(vdev->timebase == SR_US(200)) +// { +// if(val == 177 && !interval1) +// { +// interval1 = i; +// continue; +// } +// if(val == 177 && !interval2) +// { +// interval2 = i; +// continue; +// } +// } +// else +// { +// if(val == 178 && !interval1) +// { +// interval1 = i; +// } +// if(val == 78 && !interval2) +// { +// interval2 = i; +// } +// } +// } + +// if(vdev->sample_generator != PATTERN_RANDOM) +// { +// status->ch0_cyc_tlen = (uint32_t)abs(interval1-interval2); +// status->ch1_cyc_tlen = (uint32_t)abs(interval1-interval2); +// if(vdev->timebase == SR_US(200)) +// { +// status->ch0_cyc_tlen = status->ch0_cyc_tlen/2; +// status->ch1_cyc_tlen = status->ch1_cyc_tlen/2; +// } +// status->ch0_cyc_cnt = 1; +// status->ch1_cyc_cnt = 1; +// } + +// //187,68 +// status->ch0_max = status->ch1_max = ch_max; +// status->ch0_min = status->ch1_min = ch_min; // status->ch0_cyc_plen = 170; // status->ch1_cyc_plen = 170; // status->ch0_cyc_llen = 0; @@ -244,7 +292,7 @@ static void logic_adjust_samplerate(struct session_vdev * vdev) } -static void init_analog_random_data(struct session_vdev * vdev) +static int init_analog_random_data(struct session_vdev * vdev) { if(vdev->analog_buf != NULL) { @@ -266,6 +314,7 @@ static void init_analog_random_data(struct session_vdev * vdev) *(uint8_t*)(vdev->analog_buf + i) = *(uint8_t*)(vdev->analog_buf + i -1); } vdev->analog_buf_len = DSO_BUF_LEN; + return SR_OK; } static int delay_time(struct session_vdev *vdev) @@ -380,7 +429,7 @@ static int get_pattern_mode_from_file(uint8_t device_mode) int str_len; strcpy(dir_str,DS_RES_PATH); - strcat(dir_str,"../"); + memset(dir_str+strlen(dir_str)-strlen("res/"),0,strlen("res/")); strcat(dir_str,"demo/"); if(device_mode == LOGIC) @@ -567,7 +616,7 @@ static void adjust_samplerate(struct sr_dev_inst *sdi) } -static void init_random_data(struct session_vdev * vdev,struct sr_dev_inst *sdi) +static int init_random_data(struct session_vdev * vdev,struct sr_dev_inst *sdi) { int cur_probe = 0; int probe_count[LOGIC_MAX_PROBE_NUM] = {0}; @@ -576,9 +625,10 @@ static void init_random_data(struct session_vdev * vdev,struct sr_dev_inst *sdi) memset(probe_status,LOGIC_HIGH_LEVEL,16); memset(vdev->logic_buf,0,LOGIC_BUF_LEN); + srand((unsigned)time(NULL)); for(int i = 0 ;i < vdev->enabled_probes;i++) { - probe_count[i] = rand()%SR_KB(5); + probe_count[i] = rand()%SR_KB(1); } for(int i = 0 ; i < vdev->logic_buf_len ;i++) @@ -600,12 +650,12 @@ static void init_random_data(struct session_vdev * vdev,struct sr_dev_inst *sdi) probe_status[cur_probe] = LOGIC_LOW_LEVEL; else probe_status[cur_probe] = LOGIC_HIGH_LEVEL; - probe_count[cur_probe] = rand()%SR_KB(5); + probe_count[cur_probe] = rand()%SR_KB(1); memset(vdev->logic_buf+i,probe_status[cur_probe],1); probe_count[cur_probe] -= 1; } } - return 0; + return SR_OK; } diff --git a/libsigrok4DSL/hardware/demo/demo.h b/libsigrok4DSL/hardware/demo/demo.h index c40d79a3..02f3d67f 100644 --- a/libsigrok4DSL/hardware/demo/demo.h +++ b/libsigrok4DSL/hardware/demo/demo.h @@ -459,7 +459,7 @@ static int logic_adjust_probe(struct sr_dev_inst *sdi, int num_probes); static void logic_adjust_samplerate(struct session_vdev * vdev); -static void init_analog_random_data(struct session_vdev * vdev); +static int init_analog_random_data(struct session_vdev * vdev); static int delay_time(struct session_vdev *vdev); @@ -479,7 +479,7 @@ static int reset_dsl_path(struct sr_dev_inst *sdi,uint8_t device_mode ,uint8_t p static void adjust_samplerate(struct sr_dev_inst *sdi); -static void init_random_data(struct session_vdev * vdev,struct sr_dev_inst *sdi); +static int init_random_data(struct session_vdev * vdev,struct sr_dev_inst *sdi); static int hw_init(struct sr_context *sr_ctx); From f15946f577e9ed4ae0269407781d13a7abbf1d11 Mon Sep 17 00:00:00 2001 From: yunyaobaihong <896458252@qq.com> Date: Wed, 31 May 2023 15:15:38 +0800 Subject: [PATCH 2/3] fix:demo logic can not load protocol file in windows --- libsigrok4DSL/hardware/demo/demo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsigrok4DSL/hardware/demo/demo.c b/libsigrok4DSL/hardware/demo/demo.c index 6032a22f..e2a87382 100644 --- a/libsigrok4DSL/hardware/demo/demo.c +++ b/libsigrok4DSL/hardware/demo/demo.c @@ -522,7 +522,7 @@ static int reset_dsl_path(struct sr_dev_inst *sdi,uint8_t device_mode ,uint8_t p char *str = g_try_malloc0(500); strcpy(str,DS_RES_PATH); - strcat(str,"../"); + memset(dir_str+strlen(dir_str)-strlen("res/"),0,strlen("res/")); strcat(str,"demo/"); if (pattern_mode != PATTERN_RANDOM) From e832b190a897303bf1f37c3bb99a761f6ea4656d Mon Sep 17 00:00:00 2001 From: yunyaobaihong <896458252@qq.com> Date: Wed, 31 May 2023 15:21:42 +0800 Subject: [PATCH 3/3] fix:demo logic can not load protocol file in windows --- libsigrok4DSL/hardware/demo/demo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsigrok4DSL/hardware/demo/demo.c b/libsigrok4DSL/hardware/demo/demo.c index e2a87382..8fb7ee17 100644 --- a/libsigrok4DSL/hardware/demo/demo.c +++ b/libsigrok4DSL/hardware/demo/demo.c @@ -522,7 +522,7 @@ static int reset_dsl_path(struct sr_dev_inst *sdi,uint8_t device_mode ,uint8_t p char *str = g_try_malloc0(500); strcpy(str,DS_RES_PATH); - memset(dir_str+strlen(dir_str)-strlen("res/"),0,strlen("res/")); + memset(str+strlen(str)-strlen("res/"),0,strlen("res/")); strcat(str,"demo/"); if (pattern_mode != PATTERN_RANDOM)