/**
 * @Author: 李建
 * @Date: 2024/9/7 10:46
 * Description: modbus rtu实现写文件功能码0x15
 * Copyright: Copyright (©) 2024 永续绿建. All rights reserved.
 */
#include "mb.h"
#include "mbframe.h"
// 定义ymodem协议包的起始始偏移地址
#define MB_PDU_YMODEM_PACK_OFFSET       ( 0 )
// 定义帧头的偏移地址
#define MB_PDU_YMODEL_PACK_HEADER_OFFSET ( MB_PDU_YMODEM_PACK_OFFSET + 1 )

/* ----------------------- Static functions ---------------------------------*/
eMBException prveMBError2Exception(eMBErrorCode eErrorCode);

#if MB_FUNC_WRITE_FILE_ENABLE

eMBException eMBFuncWriteFile(eMBRTUSlaveObj *obj,UCHAR *pucFrame, USHORT *usLen) {
    eMBErrorCode    eRegStatus;
    eMBException    eStatus = MB_EX_NONE;
    eRegStatus = obj->callback->eMbWriteFileCb( &pucFrame[MB_PDU_YMODEL_PACK_HEADER_OFFSET],
                                 &pucFrame[MB_PDU_YMODEL_PACK_HEADER_OFFSET], usLen );

    /* If an error occured convert it into a Modbus exception. */
    if( eRegStatus != MB_ENOERR )
    {
        eStatus = prveMBError2Exception( eRegStatus );
    }
}

#endif