Commit 3ed74037 authored by Mathis Schmieder's avatar Mathis Schmieder
Browse files

Implemented transmission of alpha-numeric messages via UART

parent fa4fae9a
......@@ -96,10 +96,6 @@ int main(void)
HAL_UART_Receive_IT(&huart2, (uint8_t*) &UART2_Data, 1);
/*__HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);
HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART2_IRQn);*/
/* USER CODE END 2 */
/* Infinite loop */
......@@ -109,18 +105,75 @@ int main(void)
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
/* //CreatePocsag(10791,3,"STM32 Pocsag Pager Test!", 0, 1);
CreatePocsag(0x9c8, 1, "094016 130212", 0, 1);
rfm69_send((uint8_t *)GetPocsagMsgPointer(), GetPocsagSize());
rfm69_sleep(); */
}
/* USER CODE END 3 */
}
}
int parse_uart(uint8_t *msg)
{
/*
* We expect a message in the form of
* P:destination address:function bits:message
*
* example:
* P:10791:3:NOOT NOOT!
*/
if (msg[0] != 'P')
{
// Wrong message format
char *answer = "EEE\r\n";
HAL_UART_Transmit(&huart2, (uint8_t*)answer, strlen(answer), 1000);
return -1;
}
// Create POCSAG message
int8_t err = 0;
uint32_t address;
uint8_t function;
char message[40];
char *p;
p = strtok(msg, ":");
if (!p)
err = -1;
p = strtok(NULL, ":");
if (p)
address = atoi(p);
else
err = -1;
p = strtok(NULL, ":");
if (p)
function = atoi(p);
else
err = -1;
// get the message part
p = strtok(NULL, "");
if (p)
sprintf(message, "%s", p);
else
err = -1;
if (err < 0)
{
char *answer = "EEE\r\n";
HAL_UART_Transmit(&huart2, (uint8_t*)answer, strlen(answer), 1000);
return err;
}
CreatePocsag(address,function,&message, 0, 1);
rfm69_send((uint8_t *)GetPocsagMsgPointer(), GetPocsagSize());
rfm69_sleep();
return err;
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
char n = 0;
char UART_Aux[32];
char UART_Aux[255];
if (huart->Instance == USART2)
{
......@@ -131,8 +184,8 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
}
else
{
n = sprintf(UART_Aux, "%s", UART_Buffer);
HAL_UART_Transmit(&huart2, (uint8_t *)&UART_Aux, n, 1000);
sprintf(UART_Aux, "%s", UART_Buffer);
parse_uart((uint8_t *)&UART_Aux);
memset(&UART_Buffer[0], 0, sizeof(UART_Buffer));
UART_i = 0;
}
......
......@@ -78,8 +78,7 @@ void USART2_IRQHandler(void)
/* USER CODE END USART2_IRQn 0 */
HAL_UART_IRQHandler(&huart2);
/* USER CODE BEGIN USART2_IRQn 1 */
/* uint8_t ich = USART2->DR;
HAL_UART_Transmit(&huart2, &ich,sizeof(ich), HAL_MAX_DELAY); */
/* USER CODE END USART2_IRQn 1 */
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment