Skip to content

base bms cli #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.metadata/
.vscode/settings.json
RemoteSystemsTempFiles/.project
.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* task_command_line.h
*
* Created on: Oct 25, 2022
* Author: lonam
*/

#ifndef PHANTOM_DRIVERS_RTOS_INCLUDE_TASK_COMMAND_LINE_H_
#define PHANTOM_DRIVERS_RTOS_INCLUDE_TASK_COMMAND_LINE_H_

void initializeCommandLine();



#endif /* PHANTOM_DRIVERS_RTOS_INCLUDE_TASK_COMMAND_LINE_H_ */
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* task_command_line.c
*
* Created on: Oct 25, 2022
* Author: lonam
*/
#include "task_command_line.h"

#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "os_task.h"

#include "Phantom_sci.h"
#include "hwConfig.h"

static uint8 previous;
static xTaskHandle commandLineTaskHandle;
static void CommandLineTask(void* params){
while(1){
uint8 msg;
sciReceive(PC_UART, 1, &msg);
if(msg==previous){
// do nothing
} else if(msg=='1'){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when creating actual commands let's use proper macros. This makes it easier to read and change and uses no program memory because the values are placed at compile time

#define DO_SMT_CMD '1'

if (msg == DO_SMT_CMD)
...

UARTprintf("Message 1 received\r\n");
} else if(msg=='2'){
UARTprintf("Message 2 received\r\n");
} else if(msg=='3'){
UARTprintf("Message 3 received\r\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the code is written it's easier to see that a switch statement fits more nicely with this logic.

switch(param)
{
    case param:
          
           // do the thing 
           break;
}


}
previous = msg;
vTaskDelay(1000);
}
}
Comment on lines +19 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's easy to see now that there are 3 logical parts:

  1. wait for a message
  2. dispatch/process message
  3. update variables
// wait for user input
uint8 msg;
sciReceive();

// process input
if ()
{
}

// update previous
previous = msg;

vTaskDelay(1000);

spacing (along with comments) can make this clearer


void initializeCommandLine()
{
UARTInit(PC_UART, 9600);

xTaskCreate(CommandLineTask, "CommandLineTask", configMINIMAL_STACK_SIZE, ( void * ) 1, tskIDLE_PRIORITY, &commandLineTaskHandle);
}


10 changes: 8 additions & 2 deletions BMS Workspace-git/bms-1227-fw/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

#include "sys_common.h"

#include "task_command_line.h"

/* USER CODE BEGIN (1) */
/* USER CODE END */

Expand Down Expand Up @@ -73,8 +75,11 @@ int main(void)
{
/* USER CODE BEGIN (3) */

initBMSData(); // Initializes BMS data structure and ensures pointers are set properly
phantomSystemInit();
// initBMSData(); // Initializes BMS data structure and ensures pointers are set properly
// phantomSystemInit();


initializeCommandLine();

// Register the BMS agent and actor tasks:
if(!initSlavePipeline())
Expand All @@ -84,6 +89,7 @@ int main(void)
UARTprintf("Unable to initialize slave pipeline!\r\n");
}
}

// BMS_init(); // Initialize BMS slaves. Initialization must be re-added after PL455 rewrite.

// TODO: Initialize modern temperature here. Replaces line: InitializeTemperature() and setupThermistor()
Expand Down