Обновление

This commit is contained in:
cfif 2026-04-21 12:02:40 +03:00
parent 3a633c1a1d
commit 1882d6d995
2 changed files with 88 additions and 88 deletions

View File

@ -91,7 +91,7 @@ typedef struct {
tSerialPortFrameIO *ioCanFrame; tSerialPortFrameIO *ioCanFrame;
tLoggerInterface *logger; tLoggerInterface *logger;
char hexString[LEN_DEBUG_TP_BUFF]; char hexString[LEN_DEBUG_TP_BUFF];
volatile bool isFlowControl; bool isFlowControl;
uint32_t timeoutFF; uint32_t timeoutFF;

View File

@ -152,85 +152,6 @@ uint16_t sendConsecutiveFrame(tCanSerialPortFrameTp *env, uint8_t *data, uint16_
} }
bool waitFlowControl(tCanSerialPortFrameTp *env) {
env->isFlowControl = true;
uint32_t timeEnd = SystemGetMs() + WAIT_FC_FRAME_TIMEOUT;
while (timeEnd > SystemGetMs()) {
if (!env->isFlowControl) {
break;
}
}
if (env->isFlowControl) {
LoggerStrInfoStatic(LOGGER, LOG_SIGN, "Flow control frame timeout");
return false;
}
return true;
}
bool sendFirstFrame(tCanSerialPortFrameTp *env, uint8_t *data, uint16_t size, uint32_t id, uint32_t timeout) {
uint8_t dataTpFrame[8];
uint16_t pDataLen = 0;
memset(dataTpFrame, TP_FRAME_PADDING, sizeof(dataTpFrame));
eTpFrameFF *frame = (eTpFrameFF *) dataTpFrame;
frame->typeFrame = TP_TYPE_FRAME_FF;
frame->dlL = size;
frame->dlM = (size >> 8);
memcpy(&frame->data[0], &data[pDataLen], 6);
pDataLen += 6;
uint16_t sent = env->ioCanFrame->transmit(env->ioCanFrame->env, (uint8_t *) frame, 8, id,
PROTOCOL_CAN_TYPE_UDS, timeout);
bool result = waitFlowControl(env);
if (!result)
return false;
uint16_t countPacketFull = (size - 6) / 7;
uint16_t sizePacketTail = (size - 6) % 7;
uint8_t sn = 1;
for (uint16_t i = 0; i < countPacketFull; ++i) {
sendConsecutiveFrame(env, &data[pDataLen], 7, id, sn, timeout);
pDataLen += 7;
++sn;
if (sn > 15) {
sn = 0;
}
}
if (sizePacketTail) {
sendConsecutiveFrame(env, &data[pDataLen], sizePacketTail, id, sn, timeout);
pDataLen += sizePacketTail;
}
return true;
}
bool
CanSerialPortFrameTpTransmit(tCanSerialPortFrameTp *env, uint8_t *data, uint16_t size, uint32_t id, uint32_t timeout) {
bool result;
// Single Frame SF
if (size <= 7) {
result = sendSingleFrame(env, data, size, id, timeout);
} else {
result = sendFirstFrame(env, data, size, id, timeout);
}
return result;
}
eTpResult vCanSerialPortFrameTpReceive(tCanSerialPortFrameTp *env, uint32_t timeout) { eTpResult vCanSerialPortFrameTpReceive(tCanSerialPortFrameTp *env, uint32_t timeout) {
can_rx_message_type canFrame; can_rx_message_type canFrame;
@ -399,9 +320,11 @@ eTpResult vCanSerialPortFrameTpReceive(tCanSerialPortFrameTp *env, uint32_t time
} }
_Noreturn void CanTpProcessing_ListenerTask(tCanSerialPortFrameTp *env) { bool waitFlowControl(tCanSerialPortFrameTp *env) {
while (1) {
eTpResult result = vCanSerialPortFrameTpReceive(env, 1000); env->isFlowControl = true;
eTpResult result = vCanSerialPortFrameTpReceive(env, WAIT_FC_FRAME_TIMEOUT);
if (result == TP_RECEIVED_FC_DATA) { if (result == TP_RECEIVED_FC_DATA) {
if (env->isFlowControl) { if (env->isFlowControl) {
@ -412,6 +335,83 @@ _Noreturn void CanTpProcessing_ListenerTask(tCanSerialPortFrameTp *env) {
} }
} }
if (env->isFlowControl) {
LoggerStrInfoStatic(LOGGER, LOG_SIGN, "Flow control frame timeout");
return false;
}
return true;
}
bool sendFirstFrame(tCanSerialPortFrameTp *env, uint8_t *data, uint16_t size, uint32_t id, uint32_t timeout) {
uint8_t dataTpFrame[8];
uint16_t pDataLen = 0;
memset(dataTpFrame, TP_FRAME_PADDING, sizeof(dataTpFrame));
eTpFrameFF *frame = (eTpFrameFF *) dataTpFrame;
frame->typeFrame = TP_TYPE_FRAME_FF;
frame->dlL = size;
frame->dlM = (size >> 8);
memcpy(&frame->data[0], &data[pDataLen], 6);
pDataLen += 6;
uint16_t sent = env->ioCanFrame->transmit(env->ioCanFrame->env, (uint8_t *) frame, 8, id,
PROTOCOL_CAN_TYPE_UDS, timeout);
bool result = waitFlowControl(env);
if (!result)
return false;
uint16_t countPacketFull = (size - 6) / 7;
uint16_t sizePacketTail = (size - 6) % 7;
uint8_t sn = 1;
for (uint16_t i = 0; i < countPacketFull; ++i) {
sendConsecutiveFrame(env, &data[pDataLen], 7, id, sn, timeout);
pDataLen += 7;
++sn;
if (sn > 15) {
sn = 0;
}
}
if (sizePacketTail) {
sendConsecutiveFrame(env, &data[pDataLen], sizePacketTail, id, sn, timeout);
pDataLen += sizePacketTail;
}
return true;
}
bool
CanSerialPortFrameTpTransmit(tCanSerialPortFrameTp *env, uint8_t *data, uint16_t size, uint32_t id, uint32_t timeout) {
bool result;
// Single Frame SF
if (size <= 7) {
result = sendSingleFrame(env, data, size, id, timeout);
} else {
result = sendFirstFrame(env, data, size, id, timeout);
}
return result;
}
_Noreturn void CanTpProcessing_ListenerTask(tCanSerialPortFrameTp *env) {
while (1) {
eTpResult result = vCanSerialPortFrameTpReceive(env, 1000);
if (result == TP_RECEIVED_FC_DATA) {
LoggerErrorStatic(LOGGER, LOG_SIGN, "Error: An unexpected Flow Control Frame was received (listener)");
}
if (result == TP_RECEIVED_DATA) { if (result == TP_RECEIVED_DATA) {
#if (LOG_UDS_TP == 1) #if (LOG_UDS_TP == 1)