shortened single line ifs and whiles
This commit is contained in:
@@ -50,9 +50,8 @@ static void printf_sync(const char *fmt, ...){
|
|||||||
|
|
||||||
static void serial_command_handler(CommandTask *cmd_task){
|
static void serial_command_handler(CommandTask *cmd_task){
|
||||||
const char *cmd_str = (const char *)cmd_task->command;
|
const char *cmd_str = (const char *)cmd_task->command;
|
||||||
if(strstr(cmd_str, PING_COMMAND) == cmd_str){
|
if(strstr(cmd_str, PING_COMMAND) == cmd_str)
|
||||||
printf_sync("%d:%s\n", cmd_task->id, PING_RESPONSE);
|
printf_sync("%d:%s\n", cmd_task->id, PING_RESPONSE);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_serial_line_task(void *params){
|
static void read_serial_line_task(void *params){
|
||||||
@@ -69,9 +68,7 @@ static void read_serial_line_task(void *params){
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(c == '\r'){
|
if(c == '\r') continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(c == '\n'){
|
if(c == '\n'){
|
||||||
buf[it] = '\0';
|
buf[it] = '\0';
|
||||||
@@ -81,9 +78,7 @@ static void read_serial_line_task(void *params){
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(it < MAX_COMMAND_LENGTH - 1){
|
if(it < MAX_COMMAND_LENGTH - 1) buf[it++] = (char)c;
|
||||||
buf[it++] = (char)c;
|
|
||||||
}
|
|
||||||
else{
|
else{
|
||||||
printf_sync("Command too long, discarding\n");
|
printf_sync("Command too long, discarding\n");
|
||||||
it = 0;
|
it = 0;
|
||||||
@@ -153,7 +148,6 @@ static void serial_processing_task(void *params){
|
|||||||
if(cmd_task_p->id == -1
|
if(cmd_task_p->id == -1
|
||||||
|| cmd_task_p->command[0] == '\0'
|
|| cmd_task_p->command[0] == '\0'
|
||||||
|| !is_valid_command(cmd_task_p->command)){
|
|| !is_valid_command(cmd_task_p->command)){
|
||||||
|
|
||||||
printf_sync("Invalid command format: %s\n", buf);
|
printf_sync("Invalid command format: %s\n", buf);
|
||||||
clear_command_task(cmd_task_p);
|
clear_command_task(cmd_task_p);
|
||||||
xQueueSendToBack(command_handler_task_queue, &cmd_task_p, portMAX_DELAY);
|
xQueueSendToBack(command_handler_task_queue, &cmd_task_p, portMAX_DELAY);
|
||||||
@@ -187,18 +181,14 @@ extern "C" void vApplicationStackOverflowHook(TaskHandle_t task, char *task_name
|
|||||||
(void)task_name;
|
(void)task_name;
|
||||||
|
|
||||||
taskDISABLE_INTERRUPTS();
|
taskDISABLE_INTERRUPTS();
|
||||||
while(true){
|
while(true) tight_loop_contents();
|
||||||
tight_loop_contents();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_serial_queue(){
|
static void init_serial_queue(){
|
||||||
serial_queue = xQueueCreate(MAX_SERIAL_QUEUE_COUNT, sizeof(char[64]));
|
serial_queue = xQueueCreate(MAX_SERIAL_QUEUE_COUNT, sizeof(char[64]));
|
||||||
if (serial_queue == NULL) {
|
if (serial_queue == NULL) {
|
||||||
printf("Failed to create serial queue\n");
|
printf("Failed to create serial queue\n");
|
||||||
while(true){
|
while(true) tight_loop_contents();
|
||||||
tight_loop_contents();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,25 +196,19 @@ static void init_command_handler(){
|
|||||||
command_handler_task_queue = xQueueCreate(COMMAND_HANDLER_TASK_COUNT, sizeof(CommandTask*));
|
command_handler_task_queue = xQueueCreate(COMMAND_HANDLER_TASK_COUNT, sizeof(CommandTask*));
|
||||||
if (command_handler_task_queue == NULL) {
|
if (command_handler_task_queue == NULL) {
|
||||||
printf("Failed to create command handler task queue\n");
|
printf("Failed to create command handler task queue\n");
|
||||||
while(true){
|
while(true) tight_loop_contents();
|
||||||
tight_loop_contents();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < COMMAND_HANDLER_TASK_COUNT; i++){
|
for(int i = 0; i < COMMAND_HANDLER_TASK_COUNT; i++){
|
||||||
CommandTask *cmd_task = (CommandTask*)malloc(sizeof(CommandTask));
|
CommandTask *cmd_task = (CommandTask*)malloc(sizeof(CommandTask));
|
||||||
if(cmd_task == nullptr){
|
if(cmd_task == nullptr){
|
||||||
printf("Failed to allocate memory for command task\n");
|
printf("Failed to allocate memory for command task\n");
|
||||||
while(true){
|
while(true) tight_loop_contents();
|
||||||
tight_loop_contents();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(xTaskCreateAffinitySet(command_handler_task, "CmdHandler", DEFAULT_TASK_STACK_SIZE, cmd_task, COMMAND_HANDLER_TASK_PRIO, distilleCore(0), &cmd_task->task_handle) != pdPASS){
|
if(xTaskCreateAffinitySet(command_handler_task, "CmdHandler", DEFAULT_TASK_STACK_SIZE, cmd_task, COMMAND_HANDLER_TASK_PRIO, distilleCore(0), &cmd_task->task_handle) != pdPASS){
|
||||||
printf("Failed to create command handler task\n");
|
printf("Failed to create command handler task\n");
|
||||||
while(true){
|
while(true) tight_loop_contents();
|
||||||
tight_loop_contents();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_command_task(cmd_task);
|
clear_command_task(cmd_task);
|
||||||
@@ -236,9 +220,7 @@ static void init_serial_out_mutex(){
|
|||||||
serial_out_mutex = xSemaphoreCreateMutex();
|
serial_out_mutex = xSemaphoreCreateMutex();
|
||||||
if (serial_out_mutex == NULL) {
|
if (serial_out_mutex == NULL) {
|
||||||
printf("Failed to create serial output mutex\n");
|
printf("Failed to create serial output mutex\n");
|
||||||
while(true){
|
while(true) tight_loop_contents();
|
||||||
tight_loop_contents();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,9 +237,7 @@ int main(){
|
|||||||
|
|
||||||
vTaskStartScheduler();
|
vTaskStartScheduler();
|
||||||
|
|
||||||
while (true) {
|
while (true) tight_loop_contents();
|
||||||
tight_loop_contents();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user