FIX 1.修改频率和相位;

main
wangbo 1 week ago
parent d46c2ad720
commit b2ed0728d8

@ -163,7 +163,6 @@ typedef struct
uint32_t times;
uint32_t inums;
uint32_t noise_sum;
uint32_t cycle;
} channel_t;
/* . */

@ -191,7 +191,7 @@ extern int32_t pd_main(void);
extern int32_t pd_main_after(void);
extern int32_t pd_port_cmd_config_register(int32_t pri, pd_port_cmd_save_config_f *func);
extern void pd_show(void);
extern uint32_t _pd_get_frequency();
extern uint32_t _pd_get_frequency(int test);
#endif
#endif
/************************ (C) COPYRIGHT LandPower ***** END OF FILE ****/

@ -405,7 +405,7 @@ int32_t _csg_trend_send(pd_trend_port_t *ptrend)
{
char *pkt = NULL;
uint8_t port_idx;
uint32_t nums;
uint32_t nums = 0;
uint32_t len;
int32_t rv = 0;
char *data_point = NULL;
@ -428,9 +428,12 @@ int32_t _csg_trend_send(pd_trend_port_t *ptrend)
return E_NONE;
}
ch->times++;
if(data->data_vaild == FALSE)
{
nums = 0;
return E_NONE;
}
else
{
@ -440,13 +443,7 @@ int32_t _csg_trend_send(pd_trend_port_t *ptrend)
{
nums = CSG_SEND_SELF_WAVE_NUM;
}
ch->times++;
ch->eigen.vport = pd_config.config_port[0][port_idx].vport;;
ch->eigen.channel_type = pd_config.config_port[0][port_idx].type;
ch->eigen.unit = 2;
ch->eigen.power_frequency = _pd_get_frequency();
ch->eigen.discharge_nums += data->total_pulse_nums;
for (int i = 0; i < nums; i++)
@ -470,31 +467,43 @@ int32_t _csg_trend_send(pd_trend_port_t *ptrend)
{
ch->eigen.pulse_peak = header->max;
}
if (ch->times == 1)
//printf("port = %d times=%d nums = %d\n", ch->port, ch->times, nums);
if (ch->eigen.first_sec == 0 && ch->eigen.first_ns == 0)
{
ch->eigen.first_sec = header->epoch_sec;
ch->eigen.first_ns = header->nano_sec;
ch->eigen.power_frequency = _pd_get_frequency(1);
}
else if (ch->times == 500)
else if (ch->times >= 500)
{
ch->eigen.last_sec = header->epoch_sec;
ch->eigen.last_ns = header->nano_sec;
}
ch->wave[ch->inums+i].amplitude = header->max;
ch->wave[ch->inums+i].period = ch->cycle++;
if (ch->cycle > 50)
ch->cycle = 1;
ch->wave[ch->inums+i].phase = header->phase;
ch->wave[ch->inums+i].period = header->pt_frame_num;
ch->wave[ch->inums+i].phase = header->phase / 100;
}
ch->inums += nums;
struct timespec ts;
// 获取当前时间
if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
{
perror("clock_gettime");
}
//DBG(DBG_M_PD_CSG_EIGEN, "vport=%d times = %d time:%ld.%ld\r\n", ch->port, ch->times, ts.tv_sec, ts.tv_nsec);
if (ch->times < 500)
{
return E_NONE;
}
ch->eigen.vport = pd_config.config_port[0][port_idx].vport;;
ch->eigen.channel_type = pd_config.config_port[0][port_idx].type;
ch->eigen.unit = 2;
ch->eigen.frame_num = ch->inums;
ch->eigen.noise = ch->noise_sum / ch->inums;
@ -507,11 +516,8 @@ int32_t _csg_trend_send(pd_trend_port_t *ptrend)
sum += 1;
}
ch->eigen.pkt_sum = sum;
DBG(DBG_M_PD_CSG_EIGEN,"vport=%d pkt_sum=%d noise_sum=%d noise=%d pulse_peak=%d frame_num=%d\r\n",
ch->eigen.vport, ch->eigen.pkt_sum, ch->noise_sum, ch->eigen.noise, ch->eigen.pulse_peak, ch->eigen.frame_num);
ch->times = 0;
ch->inums = 0;
ch->noise_sum = 0;
DBG(DBG_M_PD_CSG_EIGEN,"vport=%d pkt_sum=%d noise_sum=%d noise=%d pulse_peak=%d frame_num=%d power_frequency=%d \r\n",
ch->eigen.vport, ch->eigen.pkt_sum, ch->noise_sum, ch->eigen.noise, ch->eigen.pulse_peak, ch->eigen.frame_num, ch->eigen.power_frequency);
memcpy(pkt + sizeof(csg_pkt_head_t), (char *)&ch->eigen, sizeof(csg_eigen_value_t));
@ -534,6 +540,9 @@ int32_t _csg_trend_send(pd_trend_port_t *ptrend)
usleep(100);
}
memset(&ch->eigen, 0, sizeof(csg_eigen_value_t));
ch->times = 0;
ch->inums = 0;
ch->noise_sum = 0;
return E_NONE;
}
@ -584,7 +593,7 @@ int32_t _csg_trend_send(pd_trend_port_t *ptrend)
image_head->century_second = 0;
image_head->nanosecond = 0;
image_head->frequency = _pd_get_frequency();
image_head->frequency = _pd_get_frequency(1);
image_head->sampling_time = 2;
nums = data->frame_numbers;
@ -611,9 +620,9 @@ int32_t _csg_trend_send(pd_trend_port_t *ptrend)
return E_ERROR;
}
image_head->phase = header->phase;
image_head->phase = header->phase / 100;
image_head->pulse_peak = header->max;
image_head->cycle_count = (header->pt_frame_num % 50) + 1;
image_head->cycle_count = header->pt_frame_num;
image_head->noise = header->noise;
image_head->century_second = header->epoch_sec;
image_head->nanosecond = header->nano_sec;
@ -1608,7 +1617,6 @@ void *_csg_heartbeat_handle(void *arg)
DBG(DBG_M_PD_CSG_ERR, "csg %dport send data malloc failed!\r\n",pch->port);
return NULL;
}
pch->cycle = 1;
/* 等待初始化完成 */
while(!is_system_init)

@ -734,6 +734,7 @@ void _dau_data_original(void)
//static struct timespec trend_ts = {0};
//static pd_trend_t trend[PD_DAU_PORT_SUM] = {0};
//pd_trend_t *ptrend = NULL;
struct timespec ts;
wave_additional_data_t *header = NULL;
pd_trend_port_t *ptrend = NULL;
static uint16_t count[PD_DAU_PORT_SUM][360] = {0};
@ -781,10 +782,11 @@ void _dau_data_original(void)
}
//_dau_write_channel_to_file(pd_original_port, port);
// time_get(&time_s, &time_us);
// pd_original_port->century_second = time_s;
// pd_original_port->nano_second = time_us * 1000;
if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
{
perror("clock_gettime");
}
if(pd_original_port->data_vaild)
{
@ -810,18 +812,6 @@ void _dau_data_original(void)
// perror("sync CPU failed \n");
// }
#if 0
struct timespec ts;
// 获取当前时间
if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
{
perror("clock_gettime");
}
//image_head->century_second = ts.tv_sec;
//image_head->nanosecond = ts.tv_nsec;
#endif
#if 1
if (pd_data.trend_port[port] == NULL)
{
@ -841,9 +831,10 @@ void _dau_data_original(void)
char *data_point = NULL;
data_point = (char*)(pd_original_port->original_pointer) + (i * pd_original_port->single_frame_length * sizeof(int16_t));
header = _dau_get_wave_addtion_data(data_point, pd_original_port->single_frame_length);
int Phase = header->phase / 100;
DBG(DBG_M_PD_DAU_SEND, "port[%d]frame_numbers=%d total_pulse_nums=%d phase=%d,noise=%d,max=%d,pt_frame_num=%d,time=%ld %ld.%ld\r\n", port, pd_original_port->frame_numbers,
pd_original_port->total_pulse_nums, header->phase, header->noise, header->max, header->pt_frame_num, pd_original_port->century_second, header->epoch_sec, header->nano_sec);
DBG(DBG_M_PD_DAU_SEND, "port[%d]frame_numbers=%d total_pulse_nums=%d phase=%d,noise=%d,max=%d,pt_frame_num=%d,time##=%d %d.%d\r\n", port, pd_original_port->frame_numbers,
pd_original_port->total_pulse_nums, Phase, header->noise, header->max, header->pt_frame_num, pd_original_port->century_second, header->epoch_sec, header->nano_sec);
if (header->max > ptrend->pulse_max)
ptrend->pulse_max = header->max;
ptrend->pulse_avg += header->max;
@ -852,14 +843,14 @@ void _dau_data_original(void)
{
ptrend->century_second = pd_original_port->century_second;
}
if (header->phase >= 360)
if (Phase >= 360)
{
DBG(DBG_M_PD_DAU_ERR,"phase error: %d\r\n", header->phase);
DBG(DBG_M_PD_DAU_ERR,"phase error: %d\r\n", Phase);
}
else
{
count[port][header->phase]++;
count[port][Phase]++;
}
}
@ -893,7 +884,10 @@ void _dau_data_original(void)
memset(count[port], 0, sizeof(count[port]));
}
#endif
}
}
//DBG(DBG_M_PD_DAU_SEND, "data_vaild = %d time=%ld.%ld \r\n", pd_original_port->data_vaild, ts.tv_sec, ts.tv_nsec);
if (_dau_msg_send_csg(PD_SEND_TYPE_ORIGINAL_DATA, (void *)pd_original_port, port) != E_NONE)
{
@ -1115,17 +1109,9 @@ void dau_mode_set(uint8_t unit)
dau[unit]->reg->reg_global.irigB_polarity = pd_config.config.irigB_polarity;
dau[unit]->reg->reg_global.ch_type = DEFAULT_CH_TYPE;
dau[unit]->reg->reg_global.unit = DEFAULT_CH_UNIT;
//dau_t * dau_node = dau[0];
//if (dau_node->is_connect == TRUE)
{
if (IS_BITMAP_SET(pd_config.config.pt_B_sync_mode, PD_BIT_BCODE))
{
dau[unit]->reg->reg_global.ps_epoch_sec = time(NULL);
printf("####Z# time:%ld\r\n", time(NULL));
}
}
_dau_set_time(time(NULL));
reg_value = dau[unit]->reg->reg_global.port_enable;
for(idx=0; idx<PD_DAU_PORT_SUM; idx++)
{

@ -46,6 +46,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <math.h>
#include "pd_dau.h"
#include "pd_csg.h"
@ -288,10 +289,8 @@ CMD(pd_pt_B_sync_mode,
if(dau_node->is_connect == TRUE)
{
dau_node->reg->reg_global.pt_B_sync_mode = pd_config.config.pt_B_sync_mode;
if (IS_BITMAP_SET(pd_config.config.pt_B_sync_mode, PD_BIT_BCODE))
{
dau_node->reg->reg_global.ps_epoch_sec = time(NULL);
}
_dau_set_time(time(NULL));
}
return CMD_SUCCESS;
}
@ -375,22 +374,33 @@ CMD(show_running_port,
return CMD_SUCCESS;
}
uint32_t _pd_get_frequency()
uint32_t _pd_get_frequency(int test)
{
uint32_t frequency;
float frequency;
dau_t * dau_node = dau[0];
float period;
if (IS_BITMAP_SET(pd_config.config.pt_B_sync_mode, PD_BIT_PT))
{
frequency = (uint32_t)(1000000000UL / pd_config.config.pt_internal_period);
period = pd_config.config.pt_internal_period;
frequency = (1000000000UL / period);
}
else
{
dau_t * dau_node = dau[0];
if (dau_node->is_connect != TRUE)
return E_ERROR;
frequency = (uint32_t)(1000000000UL / dau_node->reg->reg_global.pt_cycle);;
period = dau_node->reg->reg_global.pt_cycle;
frequency = (1000000000UL / period);
}
return frequency;
if (test )
{
if ((uint32_t)roundf(frequency) != 50)
{
printf("frequency=%f period=%f\n", frequency, period);
}
}
return (uint32_t)roundf(frequency);
}
int _pd_read_register_century_second()

Loading…
Cancel
Save