127 lines
4.6 KiB
C
127 lines
4.6 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 V_ModBus.h
|
|
\brief Äðàéâåð ModBus (ñì. TModBus)
|
|
\author Alecksey Anuchin
|
|
\version v 1.1 24/03/2017
|
|
\defgroup V_ModBus Äðàéâåð ModBus (ñì. TModBus)
|
|
@{
|
|
*/
|
|
|
|
#ifndef V_MODBUS_H
|
|
#define V_MODBUS_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "mbod.h"
|
|
|
|
|
|
#define MODBUS_MAX_RX_COUNT 10
|
|
|
|
/*! \class TModBus
|
|
\brief Äðàéâåð ModBus
|
|
|
|
Êëàññ \a TModBus, îñíîâàííûé íà ñòðóêòóðå SModBus, îáðàáàòûâàåò
|
|
âõîäÿùèå ïîñûëêè ïî RS-485 êàê ïîñûëêè ModBus (RTU). */
|
|
|
|
//! ñì. TModBus
|
|
|
|
|
|
//! Ñòðóêòóðà modbus äëÿ õðàíåíèÿ âíóòðåííèõ äàííûõ
|
|
typedef struct {volatile Uint16 In[MODBUS_MAX_RX_COUNT];//!<Ìàññèâ äëÿ ïðèíÿòèÿ äàííûõ
|
|
volatile Uint16 InCount;//!<Ñ÷åò÷èê äëÿ ìàññèâà ïðèíÿòûõ äàííûõ
|
|
volatile MB_Record /*const*/ *Addr;//!<Óêàçàòåëü íà ñëîâàðü
|
|
volatile Uint16 TimeOut;//!<Òåêóùèé òàéìàóò, êîòîðûé íàäî âûäåðæèâàòü
|
|
volatile Uint16 TimeOut1_5;//!<Ðàññ÷èòàííûé òàéìàóò 1,5 äëèíû ïåðåäàííîãî áàéòà
|
|
volatile Uint16 TimeOut2_5;//!<Ðàññ÷èòàííûé òàéìàóò 2,5 äëèíû ïåðåäàííîãî áàéòà
|
|
volatile Uint16 ToSend;//!<Äàííûå äëÿ îòïðàâêè
|
|
volatile Uint16 NumOfHRs;//!<Êîëè÷åñòâî Holding Registers
|
|
volatile Uint16 MiddleOfHRs;//!<Ñåðåäèíà Holding Registers
|
|
volatile Uint16 InitialStepOfHRs;//!<Øàã Holding Registers
|
|
volatile Uint16 NumOfIRs;//!<Êîëè÷åñòâî Input Registers
|
|
volatile Uint16 MiddleOfIRs;//!<Ñåðåäèíà Input Registers
|
|
volatile Uint16 InitialStepOfIRs;//!<Øàã Input Registers
|
|
volatile Uint16 NumOfCs;//!<Êîëè÷åñòâî Coils
|
|
volatile Uint16 MiddleOfCs;//!<Ñåðåäèíà Coils
|
|
volatile Uint16 InitialStepOfCs;//!<Øàã Coils
|
|
volatile Uint16 NumOfDIs;//!<Êîëè÷åñòâî Discrete Inputs
|
|
volatile Uint16 MiddleOfDIs;//!<Ñåðåäèíà Discrete Inputs
|
|
volatile Uint16 InitialStepOfDIs;//!<Øàã Discrete Inputs
|
|
volatile Uint16 RxCRC;//!<Ïðèíèìàåìàÿ êîíòðîëüíàÿ ñóììà
|
|
volatile Uint16 TxCRC;//!<Ïåðåäàâàåìàÿ êîíòðîëüíàÿ ñóììà
|
|
volatile Uint16 MagicNumber;//!<Ýì...
|
|
volatile int16 TxState;//!<Ñîñòîÿíèå ïåðåäà÷è
|
|
volatile Uint16 temp;//!<
|
|
volatile int16 RecievedCounter;//!<Ñ÷åò÷èê äëÿ îòñ÷èûâàíèÿ òàéìàóòà ïî ïðèåìó
|
|
UART_TypeDef *NT_UART;//!Óêàçàòåëü íà èñïîëüçóåìûé ìîäóëü UART
|
|
} MODBUS_INT;
|
|
|
|
#define MODBUS_INT_DEFAULTS {{0},0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
|
|
0xFFFF,0xFFFF, 0xA001,-1, 0,0, \
|
|
}
|
|
|
|
struct SModBus{Uint32 BaudRate;//!<Ñêîðîñòü ðàáîòû ïî RS
|
|
Uint16 ExecutionFreq;//!< ×àñòîòà òàêòèðîâàíèÿ ìîäóëÿ
|
|
Uint16 RSNodeID; //!< Íîìåð óçëà â ñåòè
|
|
Uint16 Enabled; //!< Ðàçðåøåíèå èçìåíåíèÿ ïàðàìåòðîâ ïðèâîäà ÷åðåç ModBus
|
|
Uint16 Refresh; //!< Ôëàã èçìåíåíèÿ ïàðàìåòðîâ ïî Modbus
|
|
int16 error;
|
|
int16 errorCode;
|
|
int16 AutoRestart;
|
|
int16 clear_error;
|
|
Uint16 received_data;
|
|
Uint16 GPIOsValue;
|
|
Uint16 isOnline;//!< Â ñåòè ìû èëè íåò (èäóò ëè ïàêåòû)
|
|
Uint32 OfflineCounter;//!< Ñ÷åò÷èê èíêðåìåíòèðóåòñÿ ñ ÷àñòîòîé âûçîâà ïðîöåäóðû ModBus_Execute è îáíóëÿåòñÿ, åñëè â ñåòè åñòü ïàêåòû
|
|
Uint32 OfflineCounterMax;//!< Òàéìàóò îòñóòñòâèÿ ïàêåòîâ â ñåòè (â åäèíèöàõ ñ÷¸òà OfflineCounter)
|
|
Uint16 ReceiveByteCounter;//!< Ñ÷åò÷èê ïðèíÿòûõ áàéò
|
|
Uint16 ReceivePacketCounter;//!< Ñ÷åò÷èê ïðèíÿòûõ ïîñûëîê
|
|
MODBUS_INT MBInternals;//!< Ñëóæåáíûå ïåðåìåííûå äëÿ ðàáîòû äðàéâåðà (íå äëÿ ïîëüçîâàòåëÿ)
|
|
void (*Init)(volatile struct SModBus*);
|
|
void (*Execute)(volatile struct SModBus*);
|
|
};
|
|
|
|
|
|
typedef volatile struct SModBus TModBus;
|
|
|
|
|
|
#define MODBUS_DEFAULTS {9600,10000, 0x01, 1, 0,\
|
|
0,0,0,0,0,0,0,0,0,0,0,\
|
|
MODBUS_INT_DEFAULTS,\
|
|
ModBus_Init, \
|
|
ModBus_Execute,\
|
|
}
|
|
|
|
|
|
//! \memberof TModBus
|
|
void ModBus_Init(TModBus *p);
|
|
//! \memberof TModBus
|
|
void ModBus_Execute(TModBus *p);
|
|
//! \memberof TModBus
|
|
int16 ModBus_FindVocAddr(TModBus *p,volatile MB_Record Table[], Uint16 TableSize, int16 Type, Uint16 Index, int16 NumOfIndexs, int16 Mid, int16 Step);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
|
|
/*@}*/
|