142 lines
5.3 KiB
C
142 lines
5.3 KiB
C
#ifndef _RS_FUNCTIONS_H
|
|
#define _RS_FUNCTIONS_H
|
|
|
|
|
|
#define MAX_RECEIVE_LENGTH 254
|
|
#define MAX_SEND_LENGTH 400 //266 //254
|
|
|
|
#define CMD_RS232_MODBUS_1 1
|
|
#define CMD_RS232_MODBUS_3 3
|
|
#define CMD_RS232_MODBUS_4 4
|
|
#define CMD_RS232_MODBUS_5 5
|
|
#define CMD_RS232_MODBUS_6 6
|
|
#define CMD_RS232_MODBUS_15 15
|
|
#define CMD_RS232_MODBUS_16 16
|
|
|
|
#define RS_TIME_OUT 6000
|
|
#define RS_TIME_OUT_MPU 6000//6000 // îæèäàíèå îòâåòà îò ÌÏÓ
|
|
#define RS_TIME_OUT_HMI 1000
|
|
#define RS_TIME_OUT_MAX 10000
|
|
#define RS_TIME_OUT_LOST 1000
|
|
|
|
|
|
|
|
typedef unsigned char CHAR;
|
|
|
|
// Message RS declaration
|
|
typedef struct {
|
|
unsigned int commnumber; // Íîìåð ïîðòà
|
|
unsigned long RS_Length; // Äëèíà ïàêåòà
|
|
|
|
unsigned int *pRS_RecvPtr; // Áóôåð ïðèåìà
|
|
unsigned int *pRS_SendPtr; // Áóôåð ïîñûëêè
|
|
unsigned int *pRS_SendPtr_stage1; // Áóôåð ïîñûëêè
|
|
unsigned int *pRS_SendPtr_stage2; // Áóôåð ïîñûëêè
|
|
unsigned int *pRecvPtr;
|
|
|
|
unsigned int RS_PrevCmd; // Ïðåäûäóùàß êîììàíäà
|
|
unsigned int RS_Cmd; // Òåêóùàß êîììàíäà
|
|
unsigned int RS_Header[MAX_RECEIVE_LENGTH]; // Çàãîëîâîê
|
|
|
|
unsigned int flag_TIMEOUT_to_Send; // Ôëàã îæèäàíèß òàéìàóòà íà îòñûëêó
|
|
unsigned int flag_TIMEOUT_to_Receive; // Ôëàã îæèäàíèß òàéìàóòà íà ïðèåì
|
|
unsigned int RS_DataReady; // Ôëàã ãîòîâíîñòè RS äàííûõ
|
|
unsigned int buffer[MAX_SEND_LENGTH]; // Áóôåð äëß îòñûëêè ïî RS
|
|
unsigned int buffer_stage1[8]; // Áóôåð äëß îòñûëêè ïî RS
|
|
// unsigned int buffer_stage2[8]; // Áóôåð äëß îòñûëêè ïî RS
|
|
|
|
unsigned int addr_answer; // àäðåñ êóäà îòâå÷àòü â ðåæèìå âåäóùåãî
|
|
unsigned int addr_recive;// àäðåñ ïî êîòîðîìó íàñ çàïðîñèëè
|
|
unsigned int flag_LEADING; // Ôëàã ðåæèìà êîíòðîëëåðà (ïî óìîë÷àíèþ âåäîìûé)
|
|
unsigned long RS_RecvLen;
|
|
unsigned long RS_SLength; // Äëèíà ïàêåòà äëß ïîñûëêè
|
|
unsigned long RS_SendLen; // Êîëè÷åñòâî áàéò óæå ïåðåäàëè
|
|
|
|
unsigned long RS_SLength_stage1; // Äëèíà ïàêåòà äëß ïîñûëêè
|
|
unsigned long RS_SLength_stage2; // Äëèíà ïàêåòà äëß ïîñûëêè
|
|
|
|
unsigned int time_wait_rs_out;
|
|
unsigned int time_wait_rs_out_mpu;
|
|
unsigned int time_wait_rs_lost; // ñëèøêîì áîëüøàÿ ïàóçà ìåæäó áàéòàìè - åñòü ïîòåðÿ!!!
|
|
|
|
|
|
char RS_SendBlockMode; /* Ðåæèì ïåðåäà÷è */
|
|
char RS_SendBlockMode_stage1; /* Ðåæèì ïåðåäà÷è */
|
|
char RS_SendBlockMode_stage2; /* Ðåæèì ïåðåäà÷è */
|
|
char RS_Flag9bit; /* äëß RS485???????? */
|
|
|
|
int BS_LoadOK;/** Ôëàã óñïåøíîñòè ïðèåìà áëîêà */
|
|
int RS_FlagBegin;
|
|
int RS_HeaderCnt;
|
|
int RS_FlagSkiping;
|
|
|
|
int RS_DataReadyAnswer; // ôëàã, ÷òî ìû ïîëó÷èëè îòâåò íà ñâîé çàïðîñ, åñëè ìû ìàñòåð
|
|
int RS_DataReadyAnswerAnalyze; // ôëàã, ÷òî ìû ïîëó÷èëè îòâåò íà ñâîé çàïðîñ, åñëè ìû ìàñòåð è îáðàáîòàëè åãî
|
|
|
|
int RS_DataSended; // ôëàã, ÷òî ìû îòïðàâèëè ñâîé çàïðîñ, æäåì îòâåò è ìû ìàñòåð
|
|
int RS_DataWillSend; // ôëàã, ÷òî ìû ïîäãîòîâèëè ñâîé çàïðîñ è ñåé÷àñ íà÷íåì åãî ïåðåäàâàòü è ìû ìàñòåð
|
|
|
|
int RS_DataReadyRequest; // ôëàã, ÷òî ìû ïîëó÷èëè çàïðîñ, åñëè ìû ñëåéâ
|
|
int RS_DataReadyFullUpdate; // ôëàã, ÷òî ìû ïîëó÷èëè îòâåòû è ìàññèâ ïîëíîñòüþ îáíîâèëñÿ
|
|
|
|
int RS_OnTransmitedData ; // ôëàã ÷òî ìû åùå ïåðåäàåì çàïðîøåííûå äàííûå
|
|
int current_tx_stage;
|
|
int cmd_tx_stage;
|
|
|
|
unsigned int count_recive_ok; // ïðèíÿòî ïîñûëîê ñ âàëèäíûì crc,
|
|
unsigned int count_recive_error_crc; // îøèáîê crc
|
|
unsigned int count_recive_dirty; // ïðèíÿòî ïîñûëîê äî ðàñ÷åòà crc, ñîâïàëà òîëüêî äëèíà è êîä êîìàíäû
|
|
unsigned int count_recive_bad; // ïðèíÿòî ïîñûëîê c íåïðàâèëüíûì ôîðìàòîì
|
|
unsigned int count_recive_bytes_all; // ïðèíÿòî âñåãî áàéò
|
|
unsigned int count_recive_bytes_skipped; // ïðîïóùåíî âñåãî áàéò
|
|
unsigned int count_recive_cmd_skipped; // ïðîïóùåíî âñåãî ïîñûëîê
|
|
unsigned int count_recive_rxerror; // îøèáêè ïî ïðåðûâàíèþ
|
|
|
|
unsigned int do_resetup_rs; // âûïîëíèòü ïåðåñáðîñ ïîðòà ïðè îøèáêàõ.
|
|
|
|
|
|
|
|
|
|
|
|
} RS_DATA_STRUCT;
|
|
|
|
#define RS_DATA_STRUCT_DEFAULT {0,0,0,0,0,0,0,0,0,{0}, 0,0,0,{0},{0}, 0,0,0,0,0,0, 0,0, 0,0, 0,0,0,0, 0,0, 0,0,0, 0, 0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0}
|
|
//////////////////////////////////////////////////////////
|
|
|
|
#define TMS_TO_TERMINAL_TEST_ALL_STRUCT_DEFAULT {{0}, {0}, {0}, 0, 0, 0}
|
|
|
|
enum {
|
|
CMD_RS232_LOAD = 51, CMD_RS232_UPLOAD, CMD_RS232_RUN, CMD_RS232_XFLASH, CMD_RS232_TFLASH,
|
|
CMD_RS232_PEEK, CMD_RS232_POKE, CMD_RS232_INITLOAD, CMD_RS232_INIT,CMD_RS232_EXTEND,
|
|
CMD_RS232_VECTOR = 61, CMD_RS232_IMPULSE, CMD_RS232_STD = 65, CMD_RS232_TEST_ALL, CMD_RS232_STD_ANS,
|
|
CMD_RS232_LAST
|
|
};
|
|
|
|
//enum {
|
|
// false = 0, true
|
|
// };
|
|
|
|
#define RS_LEN_CMD CMD_RS232_LAST
|
|
|
|
//extern RS_DATA_STRUCT RS232_A, RS232_B;
|
|
extern RS_DATA_STRUCT rs_a,rs_b;
|
|
|
|
int RS_Send(RS_DATA_STRUCT *rs_arr,unsigned int *pBuf,unsigned long len);
|
|
void RS232_WorkingWith(unsigned int enable_rs_a, unsigned int enable_rs_b, unsigned int enable_int_timeout);
|
|
void RS232_TuneUp(unsigned long speed_baud_a, unsigned long speed_baud_b);
|
|
void inc_RS_timeout_cicle(void);
|
|
void resetup_rs_on_timeout_lost(int rsp);
|
|
|
|
void resetup_rs(RS_DATA_STRUCT *rs_arr);
|
|
void resetup_mpu_rs(RS_DATA_STRUCT *rs_arr);
|
|
int test_rs_live(RS_DATA_STRUCT *rs_arr);
|
|
void RS_SetControllerLeading(RS_DATA_STRUCT *RS232_Arr,int boool);
|
|
void RS_SetAdrAnswerController(RS_DATA_STRUCT *RS232_Arr,int set_addr_answer);
|
|
void SetCntrlAddr (int cntrl_addr,int cntrl_addr_for_all);
|
|
|
|
extern float KmodTerm, freqTerm;
|
|
extern unsigned int RS_Len[RS_LEN_CMD];
|
|
extern int flag_special_mode_rs;
|
|
|
|
#endif
|