Subversion Repositories canSerial

Rev

Rev 3 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 4
Line 105... Line 105...
105
uint32_t TxMailbox;
105
uint32_t TxMailbox;
106
 
106
 
107
char const version[] = "$PDGY,Mike_James_Converter_#00001_Mode:15\r\n";
107
char const version[] = "$PDGY,Mike_James_Converter_#00001_Mode:15\r\n";
108
char const keepawake[] = "$PDGY,000000,1,,4,%ld.%03ld,,,\r\n";
108
char const keepawake[] = "$PDGY,000000,1,,4,%ld.%03ld,,,\r\n";
109
 
109
 
-
 
110
// Allocation of serial buffer sizes and storage
-
 
111
#define TX_BUFFER_SIZE 512
-
 
112
#define RX_BUFFER_SIZE 16
-
 
113
uint8_t tx_buffer[TX_BUFFER_SIZE];
-
 
114
uint8_t rx_buffer[RX_BUFFER_SIZE];
-
 
115
 
110
// reset a search context
116
// reset a search context
111
void resetContext(contextType *c)
117
void resetContext(contextType *c)
112
{
118
{
113
  c->payloadRemaining = 0; // number of bytes remaining
119
  c->payloadRemaining = 0; // number of bytes remaining
114
  c->payloadTotal = 0;     // number total number of bytes
120
  c->payloadTotal = 0;     // number total number of bytes
Line 265... Line 271...
265
 
271
 
266
void processCmd(char *buff, int len)
272
void processCmd(char *buff, int len)
267
{
273
{
268
  buff[len] = 0; // terminate in case of error
274
  buff[len] = 0; // terminate in case of error
269
  char lineBuff[100];
275
  char lineBuff[100];
270
  int pos = small_sprintf(lineBuff, "$PDGY,ACK,%s\r\n", buff + 6);
276
  int pos = small_sprintf(lineBuff, "$PDGY,ACK,%s\r\n", buff);
271
  if (pos < SerialTransmitSpace(&uc1))
277
  if (pos < SerialTransmitSpace(&uc1))
272
  {
278
  {
273
    __disable_irq();
279
    __disable_irq();
274
    sendString(&uc1, (char *)lineBuff, pos);
280
    sendString(&uc1, (char *)lineBuff, pos);
275
    __enable_irq();
281
    __enable_irq();
Line 312... Line 318...
312
  MX_SPI1_Init();
318
  MX_SPI1_Init();
313
  /* USER CODE BEGIN 2 */
319
  /* USER CODE BEGIN 2 */
314
 
320
 
315
  HAL_CAN_Start(&hcan);
321
  HAL_CAN_Start(&hcan);
316
 
322
 
317
  init_usart_ctl(&uc1, &huart1);
323
  init_usart_ctl(&uc1, &huart1,
-
 
324
                 tx_buffer,
-
 
325
                 rx_buffer,
-
 
326
                 TX_BUFFER_SIZE,
-
 
327
                 RX_BUFFER_SIZE);
318
 
328
 
319
  EnableSerialRxInterrupt(&uc1);
329
  EnableSerialRxInterrupt(&uc1);
320
 
330
 
321
  // Activate the notification
331
  // Activate the notification
322
  HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING);
332
  HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING);
Line 325... Line 335...
325
  sendString(&uc1, (char *)version, sizeof(version));
335
  sendString(&uc1, (char *)version, sizeof(version));
326
 
336
 
327
  uint32_t sendTime = HAL_GetTick() + 1000;
337
  uint32_t sendTime = HAL_GetTick() + 1000;
328
  char cmdBuff[100];
338
  char cmdBuff[100];
329
 
339
 
330
  // serial utils library command editor 
340
  // serial utils library command editor
331
  editBuffer cmdEdit;
341
  editBuffer cmdEdit;
332
 
342
 
333
  initReadLine( &cmdEdit, cmdBuff, 100, READLINES_CR);
343
  initReadLine(&cmdEdit, cmdBuff, 100, READLINES_CR);
334
 
344
 
335
  for (int i = 0; i < CONTEXTS; ++i)
345
  for (int i = 0; i < CONTEXTS; ++i)
336
    resetContext(&contexts[i]);
346
    resetContext(&contexts[i]);
337
 
347
 
338
  /* USER CODE END 2 */
348
  /* USER CODE END 2 */
Line 343... Line 353...
343
  {
353
  {
344
    /* USER CODE END WHILE */
354
    /* USER CODE END WHILE */
345
 
355
 
346
    /* USER CODE BEGIN 3 */
356
    /* USER CODE BEGIN 3 */
347
 
357
 
348
 editBufferReturn ret = readLine(&uc1, &cmdEdit);
358
    editBufferReturn ret = readLine(&uc1, &cmdEdit);
349
 
359
 
350
  if (ret == EDIT_CR)
360
    if (ret == EDIT_CR)
351
  {
361
    {
352
      processCmd (cmdBuff,charCount(&cmdEdit));
362
      processCmd(cmdBuff, charCount(&cmdEdit));
-
 
363
      resetInput(&cmdEdit);
353
  }
364
    }
354
 
365
 
355
    if (HAL_GetTick() > sendTime)
366
    if (HAL_GetTick() > sendTime)
356
    {
367
    {
357
      sendTime += 1000;
368
      sendTime += 1000;
358
      heartBeat();
369
      heartBeat();