uint8_t FileBuf[1024];
uint16_t FileLen = 0;
//回调函数,t可以为文件名也可以是文件数据 pbuf是数据,当pbuf为NULL时结束 len是数据的长度
void YModemCallback(uint8_t t, uint8_t *pbuf, uint16_t len)
{
if(pbuf != NULL && (t == YMODEM_FILEDATA))
{
memcpy(&FileBuf[FileLen], pbuf, len);
FileLen += len;
}
}
//YModem发送接口
void YmodemSend(uint8_t cmd)
{
bHalUartSend(HAL_LOG_UART, &cmd, 1);
}
//串口接收空闲
int UartIdleCallback(uint8_t *pbuf, uint16_t len)
{
bYmodemParse(pbuf, len);
return 0;
}
//串口接收实例
bUTIL_UART_INSTANCE(YmodemRec, 1128, 50, UartIdleCallback);
int main()
{
...
bInit();
bYmodemInit(YModemCallback, YmodemSend);
//启动传输
bYmodemStart();
...
}
void USART1_IRQHandler()
{
uint8_t uart_dat = 0;
if (USART_GetITStatus(USART1, USART_IT_RXNE) == SET)
{
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
uart_dat = USART_ReceiveData(USART1);
bUtilUartRxHandler(&YmodemRec, uart_dat);
}
}