forked from SZV10X_Software/SZV103_FM33A0xxEV_SiZhu

wujiazhi
2024-06-13 72def895431ad7a08e635b11f3da738e2b2c4618
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#include "cyclic_storage_data_created_api.h"
#include "cyclic_storage_cfg_api.h"
#include "low_pwr_test.h"
#include "string.h"
#include "sundry.h"
 
TYPE_CHECK_SIZE(SYS_SEND_FLOW_DATA_SYSLOG_FORMAT_T,110);//ºË²é½á¹¹Ìå´óС    
TYPE_CHECK_SIZE(SYS_FLOW_DATA_SYSLOG_FORMAT_T,62);//ºË²é½á¹¹Ìå´óС    
 
TYPE_CHECK_SIZE(RESTORE_DEFAULT_SYSLOG_FORMAT_T,11);//ºË²é½á¹¹Ìå´óС    
 
TYPE_CHECK_SIZE(ALARM_SYSLOG_FORMAT_T,108);
TYPE_CHILDTYPE_MEMBER_CHECK_SIZE(ALARM_SYSLOG_FORMAT_T,alarm_syslog_union,measure_alarm_data_s,48);//ºË²é½á¹¹Ìå´óС    
TYPE_CHILDTYPE_MEMBER_CHECK_SIZE(ALARM_SYSLOG_FORMAT_T,alarm_syslog_union,other_alarm_data_s,32);//ºË²é½á¹¹Ìå´óС
 
TYPE_CHECK_SIZE(PAY_SYSLOG_FORMAT_T,30);//ºË²é½á¹¹Ìå´óС    
PAY_SYSLOG_FORMAT_T pay_para_g = {0}; // ³äÖµ´ÎÊýÐèÒªÖØÆôʱ´Ó´¢´æÖлñÈ¡
 
TYPE_CHECK_SIZE(VALVE_SYSLOG_FORMAT_T,19);//ºË²é½á¹¹Ìå´óС    
VALVE_SYSLOG_FORMAT_T valve_log_g = {0}; // ¿ª¹Ø·§´ÎÊýÐèÒªÖØÆôʱ´Ó´¢´æÖлñÈ¡
 
TYPE_CHECK_SIZE(PARA_AMEND_SYSLOG_FORMAT_T,233);//ºË²é½á¹¹Ìå´óС    
TYPE_CHILDTYPE_MEMBER_CHECK_SIZE(PARA_AMEND_SYSLOG_FORMAT_T,para_amend_union,gas_cumulate_amend_s,36);
TYPE_CHILDTYPE_MEMBER_CHECK_SIZE(PARA_AMEND_SYSLOG_FORMAT_T,para_amend_union,balance_amend_s,20);
TYPE_CHILDTYPE_MEMBER_CHECK_SIZE(PARA_AMEND_SYSLOG_FORMAT_T,para_amend_union,billing_price_amend_s,222);
TYPE_CHILDTYPE_MEMBER_CHECK_SIZE(PARA_AMEND_SYSLOG_FORMAT_T,para_amend_union,press_cfg_amend_s,88);
TYPE_CHILDTYPE_MEMBER_CHECK_SIZE(PARA_AMEND_SYSLOG_FORMAT_T,para_amend_union,temp_cfg_amend_s,76);
TYPE_CHILDTYPE_MEMBER_CHECK_SIZE(PARA_AMEND_SYSLOG_FORMAT_T,para_amend_union,flow_cfg_amend_s,56);
TYPE_CHILDTYPE_MEMBER_CHECK_SIZE(PARA_AMEND_SYSLOG_FORMAT_T,para_amend_union,cal_pulse_amend_s,16);
TYPE_CHILDTYPE_MEMBER_CHECK_SIZE(PARA_AMEND_SYSLOG_FORMAT_T,para_amend_union,sys_func_cfg_amend_s,16);
TYPE_CHILDTYPE_MEMBER_CHECK_SIZE(PARA_AMEND_SYSLOG_FORMAT_T,para_amend_union,sys_alarm_ctl_bytes_amend_s,56);
TYPE_CHILDTYPE_MEMBER_CHECK_SIZE(PARA_AMEND_SYSLOG_FORMAT_T,para_amend_union,sys_valve_ctl_bytes_amend_s,44);
TYPE_CHILDTYPE_MEMBER_CHECK_SIZE(PARA_AMEND_SYSLOG_FORMAT_T,para_amend_union,billing_alarm_cfg_amend_s,78);
TYPE_CHILDTYPE_MEMBER_CHECK_SIZE(PARA_AMEND_SYSLOG_FORMAT_T,para_amend_union,sec_corr_para_amend_s,160);
PARA_AMEND_SYSLOG_FORMAT_T para_amend_log_g = {0};
 
TYPE_CHECK_SIZE(TIMING_SYSLOG_FORMAT_T,23);//ºË²é½á¹¹Ìå´óС    
TIMING_SYSLOG_FORMAT_T timing_log_g = {0};
 
 
 
/*Ô¶´«·¢Ë͵ÄÁ÷Á¿Êý¾Ý¼Ç¼¹¹Ôì*/
void SendFlowData_LogRecordCreated(SYS_SEND_FLOW_DATA_SYSLOG_FORMAT_T *pOutput, SYS_REAL_TIME_DATA_T *realtime_data_p,
                                                                                BILLING_REAL_PARA_T *billing_realtime_p, __IO RTC_TimeDateTypeDef *calendar_p)
{
    /*¹¹ÔìÊý¾Ý*/
  pOutput->record_time[0] = calendar_p->Year; // Ê±¼ä¼Ç¼¹¹Ôì
  pOutput->record_time[1] = calendar_p->Month;
  pOutput->record_time[2] = calendar_p->Date;
  pOutput->record_time[3] = calendar_p->Hour;
  pOutput->record_time[4] = calendar_p->Minute;
  pOutput->record_time[5] = calendar_p->Second;
 
  pOutput->forward_cumulate_sc = realtime_data_p->measure_para_s.forward_cumulate_sc; // Á÷Á¿¼Ç¼¹¹Ôì
  pOutput->forward_cumulate_wc = realtime_data_p->measure_para_s.forward_cumulate_wc;
  pOutput->instant_sc = realtime_data_p->measure_para_s.instant_sc;
  pOutput->instant_wc = realtime_data_p->measure_para_s.instant_wc;
  pOutput->temperature = realtime_data_p->measure_para_s.temperature;
  pOutput->pressure = realtime_data_p->measure_para_s.pressure;
 
  pOutput->price_now = billing_realtime_p->price_now; // ¼Æ·Ñ¼Ç¼¹¹Ôì
  pOutput->balance_now = billing_realtime_p->balance_now;
 
  pOutput->cpu_temp = realtime_data_p->state_para_s.cpu_temperature; // ×´Ì¬Êý¾Ý¹¹Ôì
  pOutput->lith_vcc = realtime_data_p->state_para_s.lith_vcc;
  pOutput->alka_vcc = realtime_data_p->state_para_s.alka_vcc;
  pOutput->snr_up = realtime_data_p->state_para_s.snr_up;
  pOutput->snr_down = realtime_data_p->state_para_s.snr_down;
  pOutput->signal_gain_up = realtime_data_p->state_para_s.signal_gain_up;
  pOutput->signal_gain_down = realtime_data_p->state_para_s.signal_gain_down;
  pOutput->signal_intensity_up = realtime_data_p->state_para_s.signal_intensity_up;
  pOutput->signal_intensity_down = realtime_data_p->state_para_s.signal_intensity_down;
  pOutput->tof_up = realtime_data_p->state_para_s.tof_up;
  pOutput->tof_down = realtime_data_p->state_para_s.tof_down;
  pOutput->sound_vel = realtime_data_p->state_para_s.sound_vel;
  pOutput->flow_vel = realtime_data_p->state_para_s.flow_vel;
  memcpy(pOutput->sys_state_bytes, (void *)&sys_admin_g.sys_admin.state_bytes, SYS_STATUS_BYTES_TYPE_LENGTH);
}
/*ʱ/ÈÕ/ÔÂÕý³£µÄÁ÷Á¿Êý¾Ý¼Ç¼¹¹Ôì*/
void FlowData_LogRecordCreated(SYS_FLOW_DATA_SYSLOG_FORMAT_T *pOutput, SYS_REAL_TIME_DATA_T *realtime_data_p,
                               BILLING_REAL_PARA_T *billing_realtime_p, __IO RTC_TimeDateTypeDef *calendar_p)
{
  pOutput->record_time[0] = calendar_p->Year; // Ê±¼ä¼Ç¼¹¹Ôì
  pOutput->record_time[1] = calendar_p->Month;
  pOutput->record_time[2] = calendar_p->Date;
  pOutput->record_time[3] = calendar_p->Hour;
  pOutput->record_time[4] = calendar_p->Minute;
  pOutput->record_time[5] = calendar_p->Second;
 
  pOutput->forward_cumulate_sc = realtime_data_p->measure_para_s.forward_cumulate_sc; // Á÷Á¿¼Ç¼¹¹Ôì
  pOutput->forward_cumulate_wc = realtime_data_p->measure_para_s.forward_cumulate_wc;
  pOutput->instant_sc = realtime_data_p->measure_para_s.instant_sc;
  pOutput->instant_wc = realtime_data_p->measure_para_s.instant_wc;
  pOutput->temperature = realtime_data_p->measure_para_s.temperature;
  pOutput->pressure = realtime_data_p->measure_para_s.pressure;
 
  pOutput->price_now = billing_realtime_p->price_now; // ¼Æ·Ñ¼Ç¼¹¹Ôì
  pOutput->balance_now = billing_realtime_p->balance_now;
}
 
 
void System_ValveLog_CyclicStorageHandler(VALVE_WORK_TYPE *pSucc_flag, SYS_ALARM_VALVE_T cause_id,
                                          VALVE_SYSLOG_FORMAT_T *valve_log_buffer_p, __IO RTC_TimeDateTypeDef *calendar_p)
{
  if (*pSucc_flag != VWT_NONE)
  {
        E2p_GPIO_Clk_Init();
    const SYSLOG_CYCLIC_TABLE_T *log_data_p = &sys_log_cyclic_table[CYCL_VALVE];
 
    valve_log_buffer_p->record_num = log_data_p->table_id->log_index + log_data_p->data_num * log_data_p->table_id->log_cyclic_full_cnt;
 
    valve_log_buffer_p->record_time[0] = calendar_p->Year; // Ê±¼ä¼Ç¼¹¹Ôì
    valve_log_buffer_p->record_time[1] = calendar_p->Month;
    valve_log_buffer_p->record_time[2] = calendar_p->Date;
    valve_log_buffer_p->record_time[3] = calendar_p->Hour;
    valve_log_buffer_p->record_time[4] = calendar_p->Minute;
    valve_log_buffer_p->record_time[5] = calendar_p->Second;
 
    valve_log_buffer_p->work_type = *pSucc_flag;
    valve_log_buffer_p->switch_cause = cause_id;
    if (*pSucc_flag == VWT_NORMAL_CLOSE || *pSucc_flag == VWT_FORCED_CLOSE)
      valve_log_buffer_p->close_cnt++;
    else if (*pSucc_flag == VWT_OPEN)
      valve_log_buffer_p->open_cnt++;
    Sys_Log_E2pCyclicMultipleWrite(log_data_p, (uint8_t *)valve_log_buffer_p,1);
    *pSucc_flag = VWT_NONE;
  }
}
 
void AlarmLog_CyclicStorageHandler(SYS_ALARM_VALVE_T * pAlarm_id, SYS_REAL_TIME_DATA_T *realtime_data_p,
                                  BILLING_REAL_PARA_T *billing_realtime_p, __IO RTC_TimeDateTypeDef *calendar_p)
{
    if(*pAlarm_id != AV_NORMAL)
    {
#ifdef RS232_PRINTF                
        printf("ÆÕͨ±¨¾¯ÈÕÖ¾¼Ç¼ = %X\r\n", sys_alarm_id_g);
#endif
        E2p_GPIO_Clk_Init();
        ALARM_SYSLOG_FORMAT_T buffer = {0};
        buffer.record_time[0] = calendar_p->Year; // Ê±¼ä¼Ç¼¹¹Ôì
        buffer.record_time[1] = calendar_p->Month;
        buffer.record_time[2] = calendar_p->Date;
        buffer.record_time[3] = calendar_p->Hour;
        buffer.record_time[4] = calendar_p->Minute;
        buffer.record_time[5] = calendar_p->Second;
 
        buffer.alarm_id = *pAlarm_id;
 
        buffer.forward_cumulate_sc = realtime_data_p->measure_para_s.forward_cumulate_sc;
        buffer.forward_cumulate_wc = realtime_data_p->measure_para_s.forward_cumulate_wc;
        buffer.instant_sc = realtime_data_p->measure_para_s.instant_sc;
        buffer.instant_wc = realtime_data_p->measure_para_s.instant_wc;
        buffer.temperature = realtime_data_p->measure_para_s.temperature;
        buffer.pressure = realtime_data_p->measure_para_s.pressure;
        buffer.cpu_temperature = realtime_data_p->state_para_s.cpu_temperature;
        buffer.lith_vcc = realtime_data_p->state_para_s.lith_vcc;
        buffer.alka_vcc = realtime_data_p->state_para_s.alka_vcc;
        memcpy(buffer.status_bytes, (void *)&sys_admin_g.sys_admin.state_bytes, SYS_STATUS_BYTES_TYPE_LENGTH);
        // ¼ÆÁ¿±¨¾¯
        if ((*pAlarm_id >= AV_UT_LOSE && *pAlarm_id <= AV_MEASURE_ERR))
        {
            const SYSLOG_CYCLIC_TABLE_T *log_data_p = &sys_log_cyclic_table[CYCL_MEASURE_ALARM];
            memcpy(&buffer.alarm_syslog_union.measure_alarm_data_s, &sys_realtime_data_g.state_para_s.tof_up, 20);
            buffer.alarm_syslog_union.measure_alarm_data_s.sound_vel = sys_realtime_data_g.state_para_s.sound_vel;
            buffer.alarm_syslog_union.measure_alarm_data_s.flow_vel = sys_realtime_data_g.state_para_s.flow_vel;
            buffer.record_num = log_data_p->table_id->log_index + log_data_p->data_num * log_data_p->table_id->log_cyclic_full_cnt;
            Sys_Log_E2pCyclicMultipleWrite(log_data_p, (uint8_t *)&buffer,1);
        }
        else
        {
            const SYSLOG_CYCLIC_TABLE_T *log_data_p = &sys_log_cyclic_table[CYCL_OTHER_ALARM];
            buffer.alarm_syslog_union.other_alarm_data_s.price_now = billing_realtime_p->price_now;
            buffer.alarm_syslog_union.other_alarm_data_s.balance_now = billing_realtime_p->balance_now;
 
            buffer.record_num = log_data_p->table_id->log_index + log_data_p->data_num * log_data_p->table_id->log_cyclic_full_cnt;
            Sys_Log_E2pCyclicMultipleWrite(log_data_p, (uint8_t *)&buffer,1);
        }
        *pAlarm_id = AV_NORMAL;
    }
}
 
 
void PayLog_CyclicStorageHandler(uint8_t * pPay_flag,PAY_SYSLOG_FORMAT_T * pay_log_buffer_p,__IO RTC_TimeDateTypeDef *calendar_p)
{
    if (*pPay_flag)
  {
    *pPay_flag = 0;
        E2p_GPIO_Clk_Init();
    const SYSLOG_CYCLIC_TABLE_T *log_data_p = &sys_log_cyclic_table[CYCL_PAY];
    pay_log_buffer_p->record_num = log_data_p->table_id->log_index + log_data_p->data_num * log_data_p->table_id->log_cyclic_full_cnt;
 
    pay_log_buffer_p->plant_number = 1;
        pay_log_buffer_p->pay_cnt++;
 
    pay_log_buffer_p->record_time[0] = calendar_p->Year; // Ê±¼ä¼Ç¼¹¹Ôì
    pay_log_buffer_p->record_time[1] = calendar_p->Month;
    pay_log_buffer_p->record_time[2] = calendar_p->Date;
    pay_log_buffer_p->record_time[3] = calendar_p->Hour;
    pay_log_buffer_p->record_time[4] = calendar_p->Minute;
    pay_log_buffer_p->record_time[5] = calendar_p->Second;
    Sys_Log_E2pCyclicMultipleWrite(log_data_p, (uint8_t *)pay_log_buffer_p,1);
  }
}
 
void TimingLog_CyclicStorageHandler(TIMING_SYSLOG_FORMAT_T * timing_log_buffer_p,__IO RTC_TimeDateTypeDef *calendar_p)
{
    if(timing_log_buffer_p->timing_cause)
    {
        E2p_GPIO_Clk_Init();
        const SYSLOG_CYCLIC_TABLE_T *log_data_p = &sys_log_cyclic_table[CYCL_TIMING];
        timing_log_buffer_p->record_num = log_data_p->table_id->log_index + log_data_p->data_num * log_data_p->table_id->log_cyclic_full_cnt;;
        timing_log_buffer_p->plant_number = 1;
        
        timing_log_buffer_p->record_time_now[0] = calendar_p->Year; // Ê±¼ä¼Ç¼¹¹Ôì
    timing_log_buffer_p->record_time_now[1] = calendar_p->Month;
    timing_log_buffer_p->record_time_now[2] = calendar_p->Date;
    timing_log_buffer_p->record_time_now[3] = calendar_p->Hour;
    timing_log_buffer_p->record_time_now[4] = calendar_p->Minute;
    timing_log_buffer_p->record_time_now[5] = calendar_p->Second;
 
        Sys_Log_E2pCyclicMultipleWrite(log_data_p, (uint8_t *)timing_log_buffer_p,1);
        timing_log_buffer_p->timing_cause = TC_NULL;
    }
}
 
void ParaAmendLog_CyclicStorageHandler(PARA_AMEND_T * pAmend_flag,PARA_AMEND_SYSLOG_FORMAT_T * amend_log_buffer_p,__IO RTC_TimeDateTypeDef *calendar_p)
{
    if (*pAmend_flag != PARA_AMEND_NONE)
  {
        E2p_GPIO_Clk_Init();
    amend_log_buffer_p->plant_number = 1;
    amend_log_buffer_p->record_time[0] = calendar_g.Year; // Ê±¼ä¼Ç¼¹¹Ôì
    amend_log_buffer_p->record_time[1] = calendar_g.Month;
    amend_log_buffer_p->record_time[2] = calendar_g.Date;
    amend_log_buffer_p->record_time[3] = calendar_g.Hour;
    amend_log_buffer_p->record_time[4] = calendar_g.Minute;
    amend_log_buffer_p->record_time[5] = calendar_g.Second;
    for (uint8_t i = 0; i < PARA_AMEND_TABLE_NUM; i++)
    {
      if (*pAmend_flag == para_amend_table[i].amend_id && para_amend_table[i].data_address != NULL)
      {
        amend_log_buffer_p->record_num = para_amend_table[i].data_address->table_id->log_index +
                                      para_amend_table[i].data_address->data_num * para_amend_table[i].data_address->table_id->log_cyclic_full_cnt;
        Sys_Log_E2pCyclicMultipleWrite(para_amend_table[i].data_address, (uint8_t *)amend_log_buffer_p,1);
        break;
      }
    }
        *pAmend_flag = PARA_AMEND_NONE;
//    memset(amend_log_buffer_p, 0, AMEND_LOG_FORMAT_HEAD);
  }
}