|
@@ -1,3 +1,11 @@
|
|
|
+
|
|
|
+ * Copyright (c) 2023 - 2024 Stefan Strobel <stefan.strobel@shimatta.net>
|
|
|
+ *
|
|
|
+ * This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
+ * file, You can obtain one at https:
|
|
|
+ */
|
|
|
+
|
|
|
|
|
|
* @file shellmatta_ymodem.c
|
|
|
* @brief ymodem functions of shellmatta
|
|
@@ -39,330 +47,68 @@ static void shellmatta_ymodem_control(shellmatta_handle_t handle, const uint8_t
|
|
|
}
|
|
|
|
|
|
|
|
|
- * @brief Initialise the ymodem prior to actually receiving data
|
|
|
- * @param[in, out] handle shellmatta instance handle
|
|
|
- * @param[in] recvBuffer pointer to the buffer to save the received payload in
|
|
|
- * @param[in] recvPacketCallback pointer to the file size variable
|
|
|
- * @param[in] recvPacketCallback pointer to the packet size variable
|
|
|
- * @param[in] transmissionCompleteCallback callback functions for the ymodem module
|
|
|
- * @return todo
|
|
|
- * @note Disables the tranport layer if inactive or sets it to mandatory if active
|
|
|
+ * @brief reset function for the ymodem module
|
|
|
+ * @param[in, out] handle shellmatta instance handle
|
|
|
+ * @param[in] doCancel flag to execute the cancel-callback
|
|
|
*/
|
|
|
-shellmatta_retCode_t shellmatta_ymodem_init(shellmatta_handle_t handle,
|
|
|
- uint8_t* recvBuffer,
|
|
|
- void (*cancelCallback)(void),
|
|
|
- void (*recvPacketCallback)(void),
|
|
|
- void (*transmissionCompleteCallback)(void))
|
|
|
+static void shellmatta_ymodem_reset(shellmatta_handle_t handle, bool doCancel)
|
|
|
{
|
|
|
- shellmatta_retCode_t ret = SHELLMATTA_OK;
|
|
|
shellmatta_instance_t *inst = (shellmatta_instance_t *)handle;
|
|
|
- (void)memset((void *)&inst->ymodem, 0, sizeof(shellmatta_ymodem_t));
|
|
|
|
|
|
-
|
|
|
- if( (NULL != inst)
|
|
|
- && (SHELLMATTA_MAGIC == inst->magic))
|
|
|
+
|
|
|
+ if (doCancel)
|
|
|
{
|
|
|
-
|
|
|
- if(NULL == recvBuffer)
|
|
|
+
|
|
|
+ shellmatta_ymodem_control(handle, YMODEM_CA);
|
|
|
+ if (NULL != inst->ymodem.cancelCallback)
|
|
|
{
|
|
|
- if(inst->bufferSize <= YMODEM_PACKET_SIZE_1K)
|
|
|
- {
|
|
|
-
|
|
|
- ret = SHELLMATTA_USE_FAULT;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- inst->ymodem.packet.packetData = (uint8_t*)inst->buffer;
|
|
|
- }
|
|
|
+ inst->ymodem.cancelCallback();
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ inst->ymodem.state = SHELLMATTA_YMODEM_INACTIVE;
|
|
|
+ inst->ymodem.byteCounter = 0u;
|
|
|
+ inst->ymodem.packetCounter = 0u;
|
|
|
+ inst->ymodem.totalBytesReceived = 0u;
|
|
|
+ inst->ymodem.fileName = NULL;
|
|
|
+ inst->ymodem.fileSize = 0u;
|
|
|
+ inst->ymodem.pauseRequested = false;
|
|
|
+ (void)memset((void *)&inst->ymodem.packet, 0, sizeof(shellmatta_ymodem_packet_t));
|
|
|
+}
|
|
|
|
|
|
-
|
|
|
- inst->ymodem.packet.packetData = recvBuffer;
|
|
|
+shellmatta_retCode_t processPacket(shellmatta_handle_t handle)
|
|
|
+{
|
|
|
+ shellmatta_retCode_t ret = SHELLMATTA_OK;
|
|
|
+ shellmatta_instance_t *inst = (shellmatta_instance_t *)handle;
|
|
|
+ char *fileName;
|
|
|
+ uint32_t packetSize;
|
|
|
|
|
|
-
|
|
|
- inst->ymodem.cancelCallback = cancelCallback;
|
|
|
- inst->ymodem.recvPacketCallback = recvPacketCallback;
|
|
|
- inst->ymodem.transmissionCompleteCallback = transmissionCompleteCallback;
|
|
|
+
|
|
|
+ if(0u == inst->ymodem.packetCounter)
|
|
|
+ {
|
|
|
+ fileName = (char*)inst->ymodem.packet.packetData;
|
|
|
|
|
|
- inst->ymodem.state = SHELLMATTA_YMODEM_WAIT_FOR_START;
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)&inst->ymodem.packet.packetData[strlen(fileName)],
|
|
|
+ &inst->ymodem.fileSize);
|
|
|
|
|
|
-
|
|
|
- shellmatta_ymodem_control(handle, YMODEM_CRC);
|
|
|
+
|
|
|
+ inst->ymodem.recvHeaderCallback(inst->ymodem.fileSize, fileName);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- ret = SHELLMATTA_USE_FAULT;
|
|
|
- }
|
|
|
-
|
|
|
- return ret;
|
|
|
-}
|
|
|
+
|
|
|
+ packetSize = SHELLMATTA_MAX((inst->ymodem.totalBytesReceived + inst->ymodem.packet.size),
|
|
|
+ inst->ymodem.fileSize);
|
|
|
+ packetSize = packetSize % inst->ymodem.packet.size;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-shellmatta_retCode_t processPacket(shellmatta_handle_t *handle)
|
|
|
-{
|
|
|
- shellmatta_retCode_t ret = SHELLMATTA_OK;
|
|
|
- shellmatta_instance_t *inst = (shellmatta_instance_t *)handle;
|
|
|
-
|
|
|
- (void)inst;
|
|
|
+
|
|
|
+ inst->ymodem.recvPacketCallback(inst->ymodem.packet.packetData, packetSize, inst->ymodem.packetCounter);
|
|
|
+ }
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static shellmatta_retCode_t ymodem_stateMachine(shellmatta_handle_t *handle, uint8_t byte)
|
|
|
+static shellmatta_retCode_t ymodem_stateMachine(shellmatta_handle_t handle, uint8_t byte)
|
|
|
{
|
|
|
shellmatta_retCode_t ret = SHELLMATTA_OK;
|
|
|
shellmatta_instance_t *inst = (shellmatta_instance_t *)handle;
|
|
@@ -386,11 +132,9 @@ static shellmatta_retCode_t ymodem_stateMachine(shellmatta_handle_t *handle, uin
|
|
|
inst->ymodem.packet.size = YMODEM_PACKET_SIZE_1K;
|
|
|
inst->ymodem.state = SHELLMATTA_YMODEM_RECEIVE_HEADER;
|
|
|
break;
|
|
|
- case YMODEM_EOT:
|
|
|
- if(NULL != inst->ymodem.transmissionCompleteCallback)
|
|
|
- {
|
|
|
- inst->ymodem.transmissionCompleteCallback();
|
|
|
- }
|
|
|
+
|
|
|
+ inst->ymodem.transmissionCompleteCallback();
|
|
|
+
|
|
|
|
|
|
shellmatta_ymodem_control(handle, YMODEM_ACK);
|
|
|
shellmatta_ymodem_control(handle, YMODEM_CRC);
|
|
@@ -414,6 +158,7 @@ static shellmatta_retCode_t ymodem_stateMachine(shellmatta_handle_t *handle, uin
|
|
|
{
|
|
|
|
|
|
inst->ymodem.state = SHELLMATTA_YMODEM_WAIT_FOR_START;
|
|
|
+ shellmatta_ymodem_control(handle, YMODEM_NAK);
|
|
|
ret = SHELLMATTA_ERROR;
|
|
|
}
|
|
|
else
|
|
@@ -443,11 +188,14 @@ static shellmatta_retCode_t ymodem_stateMachine(shellmatta_handle_t *handle, uin
|
|
|
|
|
|
if(inst->ymodem.byteCounter >= YMODEM_CRC_SIZE)
|
|
|
{
|
|
|
+ inst->ymodem.state = SHELLMATTA_YMODEM_WAIT_FOR_START;
|
|
|
+
|
|
|
|
|
|
computedCrc = crc16Calc((const char*)inst->ymodem.packet.packetData,
|
|
|
inst->ymodem.packet.size);
|
|
|
if(computedCrc != inst->ymodem.packet.crc)
|
|
|
{
|
|
|
+ shellmatta_ymodem_control(handle, YMODEM_NAK);
|
|
|
ret = SHELLMATTA_ERROR;
|
|
|
}
|
|
|
else
|
|
@@ -455,30 +203,25 @@ static shellmatta_retCode_t ymodem_stateMachine(shellmatta_handle_t *handle, uin
|
|
|
ret = processPacket(handle);
|
|
|
if(SHELLMATTA_OK == ret)
|
|
|
{
|
|
|
-
|
|
|
- if(NULL != inst->ymodem.recvPacketCallback)
|
|
|
- {
|
|
|
- inst->ymodem.recvPacketCallback();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ inst->ymodem.packetCounter ++;
|
|
|
|
|
|
-
|
|
|
- shellmatta_ymodem_control(handle, YMODEM_ACK);
|
|
|
- if(0u == inst->ymodem.packetCounter)
|
|
|
- {
|
|
|
-
|
|
|
- shellmatta_ymodem_control(handle, YMODEM_CRC);
|
|
|
- }
|
|
|
- else
|
|
|
+ if(0u != inst->ymodem.packetCounter)
|
|
|
{
|
|
|
|
|
|
inst->ymodem.totalBytesReceived += inst->ymodem.packet.size;
|
|
|
}
|
|
|
- inst->ymodem.packetCounter ++;
|
|
|
+ if(true != inst->ymodem.pauseRequested)
|
|
|
+ {
|
|
|
+
|
|
|
+ shellmatta_ymodem_control(handle, YMODEM_ACK);
|
|
|
+ if(0u == inst->ymodem.packetCounter)
|
|
|
+ {
|
|
|
+
|
|
|
+ shellmatta_ymodem_control(handle, YMODEM_CRC);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- inst->ymodem.state = SHELLMATTA_YMODEM_WAIT_FOR_START;
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
@@ -489,7 +232,6 @@ static shellmatta_retCode_t ymodem_stateMachine(shellmatta_handle_t *handle, uin
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
shellmatta_retCode_t shellmatta_ymodem_processByte(shellmatta_handle_t handle, char byte)
|
|
|
{
|
|
|
shellmatta_instance_t *inst = (shellmatta_instance_t*)handle;
|
|
@@ -513,7 +255,6 @@ shellmatta_retCode_t shellmatta_ymodem_processByte(shellmatta_handle_t handle, c
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
shellmatta_retCode_t shellmatta_ymodem_poll(shellmatta_handle_t handle)
|
|
|
{
|
|
|
shellmatta_retCode_t ret = SHELLMATTA_ERROR;
|
|
@@ -529,211 +270,156 @@ shellmatta_retCode_t shellmatta_ymodem_poll(shellmatta_handle_t handle)
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * @brief Initialise the ymodem prior to actually receiving data
|
|
|
+ * @param[in, out] handle shellmatta instance handle
|
|
|
+ * @param[in] recvBuffer pointer to the buffer to save the received payload in
|
|
|
+ * @param[in] recvPacketCallback pointer to the file size variable
|
|
|
+ * @param[in] recvPacketCallback pointer to the packet size variable
|
|
|
+ * @param[in] transmissionCompleteCallback callback functions for the ymodem module
|
|
|
+ * @return errorcode #SHELLMATTA_OK
|
|
|
+ * #SHELLMATTA_USE_FAULT (param err)
|
|
|
+ * @note Disables the tranport layer if inactive or sets it to mandatory if active
|
|
|
+*/
|
|
|
+shellmatta_retCode_t shellmatta_ymodem_init(shellmatta_handle_t handle,
|
|
|
+ uint8_t* recvBuffer,
|
|
|
+ shellmatta_ymodem_cancel_t cancelCallback,
|
|
|
+ shellmatta_ymodem_recvHeader_t recvHeaderCallback,
|
|
|
+ shellmatta_ymodem_recvPacket_t recvPacketCallback,
|
|
|
+ shellmatta_ymodem_complete_t transmissionCompleteCallback)
|
|
|
+{
|
|
|
+ shellmatta_retCode_t ret = SHELLMATTA_OK;
|
|
|
+ shellmatta_instance_t *inst = (shellmatta_instance_t *)handle;
|
|
|
+
|
|
|
+
|
|
|
+ if( (NULL != inst)
|
|
|
+ && (SHELLMATTA_MAGIC == inst->magic)
|
|
|
+ && (NULL != cancelCallback)
|
|
|
+ && (NULL != recvHeaderCallback)
|
|
|
+ && (NULL != recvPacketCallback)
|
|
|
+ && (NULL != transmissionCompleteCallback))
|
|
|
+ {
|
|
|
+
|
|
|
+ if(NULL == recvBuffer)
|
|
|
+ {
|
|
|
+ if(inst->bufferSize <= YMODEM_PACKET_SIZE_1K)
|
|
|
+ {
|
|
|
+
|
|
|
+ ret = SHELLMATTA_USE_FAULT;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ inst->ymodem.packet.packetData = (uint8_t*)inst->buffer;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ (void)memset((void *)&inst->ymodem, 0, sizeof(shellmatta_ymodem_t));
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ inst->ymodem.packet.packetData = recvBuffer;
|
|
|
|
|
|
-
|
|
|
- * @brief Acknowledge handling. Will send ACK and set ymodem state back to SHELLMATTA_YMODEM_WAIT_FOR_START
|
|
|
- * @param[in, out] handle shellmatta handle of the instance
|
|
|
-*/
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ inst->ymodem.cancelCallback = cancelCallback;
|
|
|
+ inst->ymodem.recvHeaderCallback = recvHeaderCallback;
|
|
|
+ inst->ymodem.recvPacketCallback = recvPacketCallback;
|
|
|
+ inst->ymodem.transmissionCompleteCallback = transmissionCompleteCallback;
|
|
|
+
|
|
|
+ inst->ymodem.state = SHELLMATTA_YMODEM_WAIT_FOR_START;
|
|
|
+
|
|
|
+
|
|
|
+ shellmatta_ymodem_control(handle, YMODEM_CRC);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ret = SHELLMATTA_USE_FAULT;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
|
|
|
|
|
|
- * @brief Not-Acknowledge handling. Will send NAK and set ymodem state back to SHELLMATTA_YMODEM_WAIT_FOR_START
|
|
|
- * @param[in, out] handle shellmatta handle of the instance
|
|
|
+ * @brief pauses the shellmatta reception until #shellmatta_ymodem_resume resume is called
|
|
|
+ * @param[in, out] handle shellmatta instance handle
|
|
|
+ * @return errorcode #SHELLMATTA_OK
|
|
|
+ * #SHELLMATTA_USE_FAULT (param err)
|
|
|
+ * @note This can be used when an application needs processing time before accepting the next packet
|
|
|
*/
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+shellmatta_retCode_t shellmatta_ymodem_pause(shellmatta_handle_t handle)
|
|
|
+{
|
|
|
+ shellmatta_retCode_t ret = SHELLMATTA_OK;
|
|
|
+ shellmatta_instance_t *inst = (shellmatta_instance_t *)handle;
|
|
|
|
|
|
+
|
|
|
+ if( (NULL != inst)
|
|
|
+ && (SHELLMATTA_MAGIC == inst->magic))
|
|
|
+ {
|
|
|
+ inst->ymodem.pauseRequested = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ret = SHELLMATTA_USE_FAULT;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
|
|
|
|
|
|
- * @brief reset function for the ymodem module
|
|
|
- * @param[in, out] ymodem shellmatta ymomdem instance
|
|
|
- * @param[in] doCancel flag to execute the cancel-callback
|
|
|
+ * @brief Resume the ymodem module
|
|
|
+ * @param[in, out] handle shellmatta instance handle
|
|
|
+ * @return errorcode #SHELLMATTA_OK
|
|
|
+ * #SHELLMATTA_USE_FAULT (param err)
|
|
|
+ * @note This can be used when an application needs processing time before accepting the next packet
|
|
|
*/
|
|
|
-void shellmatta_ymodem_reset(shellmatta_ymodem_t *ymodem, bool doCancel)
|
|
|
+shellmatta_retCode_t shellmatta_ymodem_resume(shellmatta_handle_t handle)
|
|
|
{
|
|
|
-
|
|
|
- if (doCancel)
|
|
|
+ shellmatta_retCode_t ret = SHELLMATTA_OK;
|
|
|
+ shellmatta_instance_t *inst = (shellmatta_instance_t *)handle;
|
|
|
+
|
|
|
+
|
|
|
+ if( (NULL != inst)
|
|
|
+ && (SHELLMATTA_MAGIC == inst->magic))
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
- if (NULL != ymodem->cancelCallback)
|
|
|
+
|
|
|
+ shellmatta_ymodem_control(handle, YMODEM_ACK);
|
|
|
+ if(0u == inst->ymodem.packetCounter)
|
|
|
{
|
|
|
- ymodem->cancelCallback();
|
|
|
+
|
|
|
+ shellmatta_ymodem_control(handle, YMODEM_CRC);
|
|
|
}
|
|
|
+ inst->ymodem.pauseRequested = false;
|
|
|
}
|
|
|
-
|
|
|
- ymodem->state = SHELLMATTA_YMODEM_INACTIVE;
|
|
|
- ymodem->byteCounter = 0u;
|
|
|
- ymodem->packetCounter = 0u;
|
|
|
- ymodem->totalBytesReceived = 0u;
|
|
|
- ymodem->fileName = NULL;
|
|
|
- ymodem->fileSize = 0u;
|
|
|
- (void)memset((void *)&ymodem->packet, 0, sizeof(shellmatta_ymodem_packet_t));
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ret = SHELLMATTA_USE_FAULT;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
|
|
|
- * @brief Resets the ymodem module
|
|
|
+ * @brief Resets the ymodem module
|
|
|
* @param[in] doCancel Set this flag to execute the cancel-callback function within the ymodem-reset function
|
|
|
- * @note call this function after file transmission is done or cancelled
|
|
|
+ * @return errorcode #SHELLMATTA_OK
|
|
|
+ * #SHELLMATTA_USE_FAULT (param err)
|
|
|
+ * @note call this function after file transmission is done or cancelled
|
|
|
*/
|
|
|
-void shellmatta_ymodem_end(shellmatta_handle_t handle, bool doCancel)
|
|
|
+shellmatta_retCode_t shellmatta_ymodem_cancel(shellmatta_handle_t handle, bool doCancel)
|
|
|
{
|
|
|
+ shellmatta_retCode_t ret = SHELLMATTA_OK;
|
|
|
shellmatta_instance_t *inst = (shellmatta_instance_t *)handle;
|
|
|
|
|
|
- shellmatta_ymodem_reset(&inst->ymodem, doCancel);
|
|
|
-
|
|
|
- utils_clearInput((shellmatta_instance_t*)handle);
|
|
|
+
|
|
|
+ if( (NULL != inst)
|
|
|
+ && (SHELLMATTA_MAGIC == inst->magic))
|
|
|
+ {
|
|
|
+ shellmatta_ymodem_reset(handle, doCancel);
|
|
|
+
|
|
|
+ utils_clearInput((shellmatta_instance_t*)handle);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ret = SHELLMATTA_USE_FAULT;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
}
|