motorcontroldemo_028/Vsrc/DRV_INTERFACE.c
2019-07-29 08:18:57 +03:00

109 lines
3.7 KiB
C

/*!
Copyright 2017 ÀÎ "ÍÈÈÝÒ" è ÎÎÎ "ÍÏÔ ÂÅÊÒÎÐ"
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
\file DRV_INTERFACE.c
\brief ×åðåç äàííûå ìîäóëü îáåñïå÷èâàåòñß ðàáîòà ñ áàíêîì àâàðèé (÷òåíèå, î÷èñòêà).
//Ïðåäïîëàãàåòñß, ÷òî ìîäóëü ìîæåò ðàñøèðßòü ôóíêöèîíàëüíîñòü (ñêà÷èâàòü êàèå-òî äðóãèå äàííûå)...
//ÏÐÈÌÅ×ÀÍÈÅ äëÿ ïðîãðàììèñòà:
1.äëÿ êîìàíä ðàáîòàþùèõ ïî ñåòè ñ àâòîìàòèçèðîâàííûìè ñèñòåìàìè (Þíèêîí,, ïóëüòû è ò.ä.) ïîñëå âûïîëíåíèÿ êîìàíäû ïîëå ans_data äîëæíî áûòü óñòàíîâëåíî çíà÷åíèåì çàïðîñà:
p->ans_data = temp;
÷òî ñîîáùèò âíåøíåé ñèñòåìå, ÷òî çàïðîñ îáðàáîòàí.  ýòîì ñëó÷àå ïîëå p->ans_data îáíóëÿåòñÿ âíåøíåé àâòîìàòèçèðîâàííîé ñèñòåìîé ïîñëå ñáîðà èíôîðìàöèè ñ ïîëåé
p->data_Low
p->data_High
2.äëÿ âíóòðåííèõ âûçîâîâ ïîëå p->ans_data òðîãàòü íå íóæíî
\author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru
\version v 2.1 2017_07_24
*/
#include "main.h"
void DRV_INTERFACE_Calc(TDrvInterface *p) {
TEvent event;
long temp = (p->req_data); //ïðèíßòèå çàïðîñà
p->INTERFACE_delta_time_sec = global_time.relative_time1.second_counter - p->INTERFACE_time_sec;
// ïðîâåðêà "óõîäà" îòâåòà
if ((p->ans_data != 0) && (p->INTERFACE_delta_time_sec < DRV_INTERFACE_RESET_TIME))
return;
//ðàç ñþäà ïîïàëè çíà÷èò ëèáî òàéìàóò äëß àíñà èñòåê, ëèáî îí íóëåâîé
//â ëþáîì ñëó÷àå åãî îáíóëßåì
p->ans_data = 0;
//çàïðîñ îáíóëßåì òîëüêî ïîñëå âûïîëíåíèß, ÷òîáû âíåøíèå óñòðîéñòâà ìîãëè êîíòðîëèòü âûïîëíåíèå çàïðîñà
switch ((temp) >> 16)
{
case DATA_REQUEST_READ_FAULT: //çàïðîñ íà ÷òåíèå îøèáêè
{
FaultLog.read(&FaultLog, (temp & 0x0FFFF), &event);
//ôîðìèðóåì îòâåò
p->data_Low = (((Uint32) (event.ev_num)) << 16) + event.ev_code;
p->data_High = event.ev_time;
p->ans_data = temp; //ãîâîðèì Þíèêîíó, ÷òî êîìàíäà îáðàáîòàíà
//ôèêñèðóåì âðåìß îòâåòà
p->INTERFACE_time_sec = global_time.relative_time1.second_counter;
break;
}
case DATA_REQUEST_WRITE_FAULT: //çàïðîñ íà çàïèñü îøèáêè
{
//!!!
//ïîêà ÷åðåç èíòåðôåéñ ïèñàòü îøèáêó íåëüçß
break;
}
case DATA_REQUEST_WRITE_WORK_TIME: //çàïðîñ íà çàïèñü work_time
{
global_time.relative_time1.relative_date.hour = 0;
global_time.relative_time1.relative_date.minute = 0;
global_time.WtiteSPI_flag = 1;
break;
}
case DATA_REQUEST_READ_WORK_TIME: //çàïðîñ íà ÷òåíèå work_time
{
//Ma][: Áó!
break;
}
case DATA_REQUEST_WRITE_OPER_TIME: { //çàïðîñ íà çàïèñü oper_time
global_time.relative_time2.relative_date.hour = 0;
global_time.relative_time2.relative_date.minute = 0;
global_time.WtiteSPI_flag = 1;
break;
}
case DATA_REQUEST_READ_OPER_TIME: //çàïðîñ íà ÷òåíèå îøèáêè
{
//Ma][: Áó!
break;
}
case DATA_REQUEST_CLEAR_ALL: //çàïðîñ íà î÷èñòêó áàíêà àâàðèé
{
FaultLog.clear(&FaultLog);
//ôîðìèðóåì îòâåò
p->data_High = 0;
p->data_Low = 0;
p->ans_data = temp; //ãîâîðèì Þíèêîíó, ÷òî êîìàíäà îáðàáîòàíà
//ôèêñèðóåì âðåìß îòâåòà
p->INTERFACE_time_sec = global_time.relative_time1.second_counter;
break;
}
}
p->req_data = 0;//îáíóëßåì ïîëå çàïðîñà, ÷òîáû íå âûïîëíèòü åãî ïîâòîðíî
}