diff --git a/fsw/cfs/src/generic_reaction_wheel_app.c b/fsw/cfs/src/generic_reaction_wheel_app.c index 81fc748..f2a5e75 100755 --- a/fsw/cfs/src/generic_reaction_wheel_app.c +++ b/fsw/cfs/src/generic_reaction_wheel_app.c @@ -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 */ /* */ @@ -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; @@ -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) { diff --git a/fsw/shared/generic_reaction_wheel_device.c b/fsw/shared/generic_reaction_wheel_device.c index 5595192..3d2cb6f 100644 --- a/fsw/shared/generic_reaction_wheel_device.c +++ b/fsw/shared/generic_reaction_wheel_device.c @@ -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 { @@ -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); @@ -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); } diff --git a/fsw/shared/generic_reaction_wheel_device.h b/fsw/shared/generic_reaction_wheel_device.h index 351b09b..4bc8718 100644 --- a/fsw/shared/generic_reaction_wheel_device.h +++ b/fsw/shared/generic_reaction_wheel_device.h @@ -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_ */ \ No newline at end of file diff --git a/fsw/standalone/build/CMakeFiles/generic_reaction_wheel_checkout.dir/generic_reaction_wheel_checkout.c.o b/fsw/standalone/build/CMakeFiles/generic_reaction_wheel_checkout.dir/generic_reaction_wheel_checkout.c.o index cd87664..3f995df 100644 Binary files a/fsw/standalone/build/CMakeFiles/generic_reaction_wheel_checkout.dir/generic_reaction_wheel_checkout.c.o and b/fsw/standalone/build/CMakeFiles/generic_reaction_wheel_checkout.dir/generic_reaction_wheel_checkout.c.o differ diff --git a/fsw/standalone/build/CMakeFiles/generic_reaction_wheel_checkout.dir/home/jstar/Desktop/github-nos3/components/generic_reaction_wheel/fsw/shared/generic_reaction_wheel_device.c.o b/fsw/standalone/build/CMakeFiles/generic_reaction_wheel_checkout.dir/home/jstar/Desktop/github-nos3/components/generic_reaction_wheel/fsw/shared/generic_reaction_wheel_device.c.o index c6f7a03..05809d7 100644 Binary files a/fsw/standalone/build/CMakeFiles/generic_reaction_wheel_checkout.dir/home/jstar/Desktop/github-nos3/components/generic_reaction_wheel/fsw/shared/generic_reaction_wheel_device.c.o and b/fsw/standalone/build/CMakeFiles/generic_reaction_wheel_checkout.dir/home/jstar/Desktop/github-nos3/components/generic_reaction_wheel/fsw/shared/generic_reaction_wheel_device.c.o differ diff --git a/fsw/standalone/build/generic_reaction_wheel_checkout b/fsw/standalone/build/generic_reaction_wheel_checkout index cb63367..1e182d8 100644 Binary files a/fsw/standalone/build/generic_reaction_wheel_checkout and b/fsw/standalone/build/generic_reaction_wheel_checkout differ diff --git a/fsw/standalone/generic_reaction_wheel_checkout.c b/fsw/standalone/generic_reaction_wheel_checkout.c index fb8db4c..73f1cf8 100644 --- a/fsw/standalone/generic_reaction_wheel_checkout.c +++ b/fsw/standalone/generic_reaction_wheel_checkout.c @@ -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 @@ -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) @@ -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); } } } @@ -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; @@ -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(); @@ -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]); }