Compare commits
2 Commits
b024569ca4
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a373695c4b | ||
|
|
43ac7e90fc |
@@ -2,7 +2,7 @@
|
||||
#define CANCONFIG_H
|
||||
|
||||
#define CAN_ONLY_EMULATING
|
||||
//#define CAN_ERROR_WITH_CORRECT_CRC
|
||||
#define CAN_ERROR_WITH_CORRECT_CRC
|
||||
|
||||
|
||||
// Настройки GPIO и таймера
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
CANEmu_HandleTypeDef hcanemu;
|
||||
uint32_t mbox;
|
||||
|
||||
CANEmu_HandleTypeDef hcanemu;
|
||||
int disable_poll_timeout = 1000;
|
||||
int flag_manual = 0;
|
||||
int transmit_prev = 0;
|
||||
|
||||
@@ -41,9 +41,14 @@ void CAN_SendFrame(CANEmu_HandleTypeDef *canemu)
|
||||
|
||||
void CANEmu_Working(CANEmu_HandleTypeDef *canemu)
|
||||
{
|
||||
uint32_t tick_now = HAL_GetTick();
|
||||
|
||||
if(flag_manual == 0)
|
||||
{
|
||||
if(tick_now - hmodbus1.lastRxTick > disable_poll_timeout)
|
||||
MB_DATA.Coils.START_POLLING = 0;
|
||||
canemu->start_poll = MB_DATA.Coils.START_POLLING;
|
||||
|
||||
canemu->transmit = MB_DATA.Coils.START_SINGLE_FRAME;
|
||||
canemu->period_ms = MB_DATA.HoldRegs.CAN_PERIOD;
|
||||
if(canemu->period_ms < CAN_MIN_PERIOD)
|
||||
@@ -92,4 +97,4 @@ void CANEmu_Working(CANEmu_HandleTypeDef *canemu)
|
||||
CAN_SendFrame(canemu);
|
||||
}
|
||||
transmit_prev = canemu->transmit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ uint16_t compute_crc15(const uint8_t *bits, uint32_t len) {
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
int stuff_to_skip = 1;
|
||||
void apply_bit_stuffing_with_error(const uint8_t *src, uint32_t src_len, uint8_t *dst, uint32_t *dst_len, uint8_t skip_stuff) {
|
||||
*dst_len = 0;
|
||||
uint8_t last_bit = src[0];
|
||||
@@ -49,10 +50,12 @@ void apply_bit_stuffing_with_error(const uint8_t *src, uint32_t src_len, uint8_t
|
||||
if (bit == last_bit) {
|
||||
count++;
|
||||
if (count == 5) {
|
||||
if (!skip_stuff) {
|
||||
if(skip_stuff != stuff_to_skip)
|
||||
append_bit(dst, dst_len, !bit); // вставляем противоположный бит
|
||||
}
|
||||
count = 0;
|
||||
if (skip_stuff) {
|
||||
skip_stuff++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
count = 1;
|
||||
|
||||
@@ -59,8 +59,8 @@
|
||||
#define RS_Reset_RX_Flags(_hRS_) RS_Reset_RX_Active_Flags(_hRS_); _hRS_->f.RX_Busy = 0; _hRS_->f.RX_Done = 0; _hRS_->f.RX_Half = 0
|
||||
#define RS_Reset_TX_Flags(_hRS_) _hRS_->f.TX_Busy = 0; _hRS_->f.TX_Done = 0
|
||||
|
||||
#define RS_Set_RX_End_Flag(_hRS_) _hRS_->f.RX_Done = 1;
|
||||
#define RS_Set_TX_End_Flag(_hRS_) _hRS_->f.TX_Done = 1
|
||||
#define RS_Set_RX_End_Flag(_hRS_) _hRS_->f.RX_Done = 1; _hRS_->lastRxTick = uwTick;
|
||||
#define RS_Set_TX_End_Flag(_hRS_) _hRS_->f.TX_Done = 1; _hRS_->lastTxTick = uwTick;
|
||||
|
||||
#define RS_Set_RX_End(_hRS_) RS_Reset_RX_Flags(_hRS_); RS_Set_RX_End_Flag(_hRS_)
|
||||
#define RS_Set_TX_End(_hRS_) RS_Reset_TX_Flags(_hRS_); RS_Set_TX_End_Flag(_hRS_)
|
||||
@@ -186,6 +186,8 @@ typedef struct // RS_HandleTypeDef
|
||||
|
||||
/* RS STATUS */
|
||||
RS_StatusTypeDef RS_STATUS; ///< RS status
|
||||
uint32_t lastRxTick;
|
||||
uint32_t lastTxTick;
|
||||
}RS_HandleTypeDef;
|
||||
extern RS_HandleTypeDef hmodbus1;
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -180,7 +180,24 @@
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>raw_bits</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>6</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>can_bits</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>7</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>stuff_to_skip</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<WatchWindow2>
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
<WinNumber>2</WinNumber>
|
||||
<ItemText>stuff_to_skip</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow2>
|
||||
<Tracepoint>
|
||||
<THDelay>0</THDelay>
|
||||
</Tracepoint>
|
||||
|
||||
Reference in New Issue
Block a user