Skip to content

Commit

Permalink
[nasa/nos3#381] Fixed Reaction Wheel Checkout app and main app/device…
Browse files Browse the repository at this point in the history
… to work with device as intended
  • Loading branch information
kevincbruce committed Dec 19, 2024
1 parent 86e0534 commit d2c65b5
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 52 deletions.
13 changes: 11 additions & 2 deletions fsw/cfs/src/generic_reaction_wheel_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
*/
GENERIC_RW_AppData_t GENERIC_RW_AppData;

static char deviceName0[] = "/dev/tty2";
static char deviceName1[] = "/dev/tty3";
static char deviceName2[] = "/dev/tty4";
static uart_info_t RW_UART[3] = {
{.deviceString = &deviceName0[0], .handle = 2, .isOpen = PORT_CLOSED, .baud = 115200},
{.deviceString = &deviceName1[0], .handle = 3, .isOpen = PORT_CLOSED, .baud = 115200},
{.deviceString = &deviceName2[0], .handle = 4, .isOpen = PORT_CLOSED, .baud = 115200},
};

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* GENERIC_RW_AppMain() -- Application entry point and main process loop */
/* */
Expand Down Expand Up @@ -376,7 +385,7 @@ int32 GENERIC_RW_Current_Momentum( const GENERIC_RW_Noop_t *Msg )

/* Read data from the UARTs for all 3 wheels */
for (int i = 0; i < 3; i++) {
status = GetCurrentMomentum(i, &momentum);
status = GetCurrentMomentum(&RW_UART[i], &momentum);
//OS_printf("GENERIC_RW: GetCurrentMomentum: status=%d, momentum=%f\n", status, momentum);
if (status > 0) {
GENERIC_RW_AppData.HkTlm.Payload.data.momentum[i] = momentum;
Expand Down Expand Up @@ -412,7 +421,7 @@ int32_t GENERIC_RW_Set_Torque( const GENERIC_RW_Cmd_t *Msg )

wheel_num = cmd->wheel_number;

status = SetRWTorque(wheel_num, torque);
status = SetRWTorque(&RW_UART[wheel_num], torque);

if (status < 0)
{
Expand Down
16 changes: 8 additions & 8 deletions fsw/shared/generic_reaction_wheel_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
/************************************************************************
** Get current momentum data from the UART
*************************************************************************/
int32_t GetCurrentMomentum(int wheel_number, double *momentum)
int32_t GetCurrentMomentum(uart_info_t *wheel, double *momentum)
{
uint8_t DataBuffer[1024];
int32_t DataLen;
char *reply;

char *request = "CURRENT_MOMENTUM";
int32_t status = uart_write_port(&RW_UART[wheel_number], (uint8_t*)request, strlen(request));
int32_t status = uart_write_port(wheel, (uint8_t*)request, strlen(request));
if (status < 0) {
OS_printf("GetCurrentMomentum: Error writing to UART=%d\n", status);
}
/* check how many bytes are waiting on the uart */
DataLen = uart_bytes_available(&RW_UART[wheel_number]);
DataLen = uart_bytes_available(wheel);
if (DataLen > 0)
{
/* grab the bytes */
status = uart_read_port(&RW_UART[wheel_number], DataBuffer, DataLen);
status = uart_read_port(wheel, DataBuffer, DataLen);
if (status < 0) {
OS_printf("GetCurrentMomentum: Error reading from UART=%d\n", status);
} else {
Expand All @@ -52,13 +52,13 @@ int32_t GetCurrentMomentum(int wheel_number, double *momentum)
/* SetRWTorque(); */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
int32_t SetRWTorque( uint8_t wheel_num, double torque )
int32_t SetRWTorque( uart_info_t *wheel, double torque )
{
int32_t status;
char request[22];

sprintf(request, "SET_TORQUE=%10.4f", torque);
status = uart_write_port(&RW_UART[wheel_num], (uint8_t*)request, strlen(request));
status = uart_write_port(wheel, (uint8_t*)request, strlen(request));
//OS_printf("Generic Reaction Wheel: Sending command:%s\n", request);
if (status < 0) {
OS_printf("Generic Reaction Wheel: Error writing to UART=%d\n", status);
Expand All @@ -67,10 +67,10 @@ int32_t SetRWTorque( uint8_t wheel_num, double torque )
uint8_t DataBuffer[1024];
int32_t DataLen;
/* check how many bytes are waiting on the uart */
DataLen = uart_bytes_available(&RW_UART[wheel_num]);
DataLen = uart_bytes_available(wheel);
if (DataLen > 0)
{
uart_read_port(&RW_UART[wheel_num], DataBuffer, DataLen);
uart_read_port(wheel, DataBuffer, DataLen);
DataBuffer[DataLen] = 0; // Ensure null termination
//OS_printf("Generic Reaction Wheel: Response on UART=%s\n", (char *)DataBuffer);
}
Expand Down
10 changes: 2 additions & 8 deletions fsw/shared/generic_reaction_wheel_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@
#include "hwlib.h"
#include "generic_reaction_wheel_platform_cfg.h"

static uart_info_t RW_UART[3] = {
{.deviceString = &GENERIC_REACTION_WHEEL_1_CFG_STRING[0], .handle = GENERIC_REACTION_WHEEL_1_CFG_HANDLE, .isOpen = GENERIC_REACTION_WHEEL_1_CFG_IS_OPEN, .baud = GENERIC_REACTION_WHEEL_1_CFG_BAUDRATE_HZ},
{.deviceString = &GENERIC_REACTION_WHEEL_2_CFG_STRING[0], .handle = GENERIC_REACTION_WHEEL_2_CFG_HANDLE, .isOpen = GENERIC_REACTION_WHEEL_2_CFG_IS_OPEN, .baud = GENERIC_REACTION_WHEEL_2_CFG_BAUDRATE_HZ},
{.deviceString = &GENERIC_REACTION_WHEEL_3_CFG_STRING[0], .handle = GENERIC_REACTION_WHEEL_3_CFG_HANDLE, .isOpen = GENERIC_REACTION_WHEEL_3_CFG_IS_OPEN, .baud = GENERIC_REACTION_WHEEL_3_CFG_BAUDRATE_HZ},
};

/* Forward declarations */
int32_t GetCurrentMomentum(int wheel_number, double *momentum);
int32_t SetRWTorque(uint8_t wheel_num, double torque);
int32_t GetCurrentMomentum(uart_info_t *wheel, double *momentum);
int32_t SetRWTorque(uart_info_t *wheel, double torque);

#endif /* _SAMPLE_DEVICE_H_ */
Binary file not shown.
Binary file not shown.
Binary file modified fsw/standalone/build/generic_reaction_wheel_checkout
Binary file not shown.
73 changes: 39 additions & 34 deletions fsw/standalone/generic_reaction_wheel_checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
/*
** Global Variables
*/

double RwData;
static uart_info_t RW_UART[3] = {
{.deviceString = &GENERIC_REACTION_WHEEL_1_CFG_STRING[0], .handle = GENERIC_REACTION_WHEEL_1_CFG_HANDLE, .isOpen = GENERIC_REACTION_WHEEL_1_CFG_IS_OPEN, .baud = GENERIC_REACTION_WHEEL_1_CFG_BAUDRATE_HZ},
{.deviceString = &GENERIC_REACTION_WHEEL_2_CFG_STRING[0], .handle = GENERIC_REACTION_WHEEL_2_CFG_HANDLE, .isOpen = GENERIC_REACTION_WHEEL_2_CFG_IS_OPEN, .baud = GENERIC_REACTION_WHEEL_2_CFG_BAUDRATE_HZ},
{.deviceString = &GENERIC_REACTION_WHEEL_3_CFG_STRING[0], .handle = GENERIC_REACTION_WHEEL_3_CFG_HANDLE, .isOpen = GENERIC_REACTION_WHEEL_3_CFG_IS_OPEN, .baud = GENERIC_REACTION_WHEEL_3_CFG_BAUDRATE_HZ},
};
int32_t RwData;

/*
** Component Functions
Expand Down Expand Up @@ -77,7 +81,7 @@ int process_command(int cc, int num_tokens, char tokens[MAX_INPUT_TOKENS][MAX_IN
{
int32_t status = OS_SUCCESS;
int32_t exit_status = OS_SUCCESS;
int32_t torque;
uint32_t torque;

/* Process command */
switch(cc)
Expand All @@ -93,16 +97,16 @@ int process_command(int cc, int num_tokens, char tokens[MAX_INPUT_TOKENS][MAX_IN
case CMD_GET_MOMENTUM:
if (check_number_arguments(num_tokens, 0) == OS_SUCCESS)
{
for ( int i = 0; i < sizeof(RW_UART); i++)
for ( int i = 0; i < 3; i++)
{
status = GetCurrentMomentum(i, &RwData);
if (status == OS_SUCCESS)
status = GetCurrentMomentum(&RW_UART[i], &RwData);
if (status < 0)
{
OS_printf("RW_GetCurrentMomentum: Success! Momentum: %d\n", &RwData);
OS_printf("GENERIC_REACTION_WHEEL_RequestData command failed for RW %d!\n", i);
}
else
{
OS_printf("GENERIC_REACTION_WHEEL_RequestData command failed!\n");
OS_printf("RW_GetCurrentMomentum: Success for RW %d! Momentum: %ld\n", i, RwData);
}
}
}
Expand All @@ -111,18 +115,18 @@ int process_command(int cc, int num_tokens, char tokens[MAX_INPUT_TOKENS][MAX_IN
case CMD_SET_TORQUE:
if (check_number_arguments(num_tokens, 3) == OS_SUCCESS)
{
for (uint8_t i = 0; i < sizeof(RW_UART); i++)
{
torque = atoi(tokens[i]);
status = SetRWTorque(i, torque);
if (status == OS_SUCCESS)
for (int i = 0; i < 3; i++)
{
OS_printf("RW %d torque successfully set to %d\n", i, torque);
}
else
{
OS_printf("Configuration command failed!\n");
}
torque = atoi(tokens[i]);
status = SetRWTorque(&RW_UART[i], torque);
if (status < 0)
{
OS_printf("GENERIC_REACTION_WHEEL_SetTorque command failed for RW %d!\n", i);
}
else
{
OS_printf("RW %d torque successfully set to %ld\n", i, torque);
}
}
}
break;
Expand Down Expand Up @@ -150,21 +154,22 @@ int main(int argc, char *argv[])
nos_init_link();
#endif

/* Open device specific protocols */
for (int i = 0; i < sizeof(RW_UART); i++)
/* Connect to the UART */
status = uart_init_port(&RW_UART[0]);
if(status != OS_SUCCESS)
{
status = uart_init_port(&RW_UART[i]);

if (status == OS_SUCCESS)
{
printf("UART device %s configured with baudrate %d \n", RW_UART[i].deviceString, RW_UART[i].baud);
}
else
{
printf("UART device %s failed to initialize! \n", RW_UART[i].deviceString);
run_status = OS_ERROR;
}
}
OS_printf("GENERIC_RW Checkout: UART 0 port initialization error!\n");
}
status = uart_init_port(&RW_UART[1]);
if(status != OS_SUCCESS)
{
OS_printf("GENERIC_RW Checkout: UART 1 port initialization error!\n");
}
status = uart_init_port(&RW_UART[2]);
if(status != OS_SUCCESS)
{
OS_printf("GENERIC_RW Checkout: UART 2 port initialization error!\n");
}

/* Main loop */
print_help();
Expand Down Expand Up @@ -203,7 +208,7 @@ int main(int argc, char *argv[])
}

// Close the devices
for ( int i = 0; i < sizeof(RW_UART); i++ )
for ( int i = 0; i < 3; i++ )
{
uart_close_port(&RW_UART[i]);
}
Expand Down

0 comments on commit d2c65b5

Please sign in to comment.