Skip to content

Commit

Permalink
Single characters reception fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasz Juranek committed Jun 14, 2017
1 parent bf37f1a commit 8305fed
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ int main(void)
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) {
slcanFlushUSBBuffer();
// slcanFlushUSBBuffer();
slCanCheckCommand();
if (canRxFlags.flags.byte != 0) {
slcanReciveCanFrame(hcan.pRxMsg);
Expand Down
55 changes: 26 additions & 29 deletions Src/slcan/slcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,28 @@ void slcanClose()
state = STATE_CONFIG;
}

int slcanFlushUSBBuffer()
{
if (dataToSend != 0)
{
if (CDC_Transmit_FS(frameBuffer, dataToSend) == USBD_OK)
{
dataToSend = 0;
return 0;
}
}
return -1;
}

static int addToUSBBuffer(uint8_t * pointer, uint8_t len)
{
if ((dataToSend + len) >= FRAME_BUFFER_SIZE)
return -1; // buffer overflow

memcpy(&frameBuffer[dataToSend], pointer, len);
dataToSend += len;
return 0;
}
//int slcanFlushUSBBuffer()
//{
// if (dataToSend != 0)
// {
// if (CDC_Transmit_FS(frameBuffer, dataToSend) == USBD_OK)
// {
// dataToSend = 0;
// return 0;
// }
// }
// return -1;
//}
//
//static int addToUSBBuffer(uint8_t * pointer, uint8_t len)
//{
// if ((dataToSend + len) >= FRAME_BUFFER_SIZE)
// return -1; // buffer overflow
//
// memcpy(&frameBuffer[dataToSend], pointer, len);
// dataToSend += len;
// return 0;
//}



Expand All @@ -125,13 +125,10 @@ static void slcanOutputFlush(void)
if (hUsbDeviceFS.dev_state != USBD_STATE_CONFIGURED) // use auxiliary uart only if usb not connected
HAL_UART_Transmit(&huart2,sl_frame,sl_frame_len,100); //ll todo figure out time
else {
addToUSBBuffer(sl_frame, sl_frame_len);
// while (CDC_Transmit_FS(sl_frame, sl_frame_len) != USBD_OK);
// while (((USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData)->TxState)
// {
// volatile i;
// i++;
// }
// addToUSBBuffer(sl_frame, sl_frame_len);
while (((USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData)->TxState){;} //should change by hardware
while (CDC_Transmit_FS(sl_frame, sl_frame_len) != USBD_OK);

}
sl_frame_len = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions Src/slcan/slcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


#define VERSION_FIRMWARE_MAJOR 2
#define VERSION_FIRMWARE_MINOR 2
#define VERSION_FIRMWARE_MINOR 3

#define VERSION_HARDWARE_MAJOR 1
#define VERSION_HARDWARE_MINOR 1
Expand All @@ -33,7 +33,7 @@
//ex TZ12020506

void slcanClose();
int slcanFlushUSBBuffer();
//int slcanFlushUSBBuffer();
uint8_t slcanReciveCanFrame(CanRxMsgTypeDef *pRxMsg);
int slCanProccesInput(uint8_t ch);
void slCanCheckCommand();
Expand Down
13 changes: 5 additions & 8 deletions Src/usbd_cdc_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
/* USER CODE BEGIN PRIVATE_DEFINES */
/* Define size for the receive and transmit buffer over CDC */
/* It's up to user to redefine and/or remove those define */
#define APP_RX_DATA_SIZE 32
#define APP_TX_DATA_SIZE 32
#define APP_RX_DATA_SIZE 128
#define APP_TX_DATA_SIZE 128
/* USER CODE END PRIVATE_DEFINES */
/**
* @}
Expand Down Expand Up @@ -230,7 +230,7 @@ static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length)
break;

case CDC_SET_CONTROL_LINE_STATE:
slcanClose();//ll
slcanClose();
break;

case CDC_SEND_BREAK:
Expand Down Expand Up @@ -266,14 +266,11 @@ static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
uint32_t i;
for (i =0; i != *Len; i++)
{
if (slCanProccesInput(Buf[i]) != 1)
{
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
}
slCanProccesInput(Buf[i]);
}

USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
// USBD_CDC_ReceivePacket(&hUsbDeviceFS);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);

return (USBD_OK);
/* USER CODE END 6 */
Expand Down

0 comments on commit 8305fed

Please sign in to comment.