Skip to content

Commit

Permalink
Merge pull request #9 from nasa-itc/nos3#381-rw-checkout-application
Browse files Browse the repository at this point in the history
[nasa/nos3#381] generic_reaction_wheel checkout
  • Loading branch information
jlucas9 authored Jan 6, 2025
2 parents 1e89c31 + c24ed5f commit 5d8d604
Show file tree
Hide file tree
Showing 12 changed files with 612 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fsw/standalone/build/*
4 changes: 3 additions & 1 deletion fsw/cfs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ include(../../../ComponentSettings.cmake)

include_directories(mission_inc)
include_directories(platform_inc)
include_directories(../shared)

aux_source_directory(src APP_SRC_FILES)
include_directories(${hwlib_MISSION_DIR}/fsw/public_inc)

# Create the app module
add_cfe_app(generic_rw ${APP_SRC_FILES})
add_cfe_app(generic_rw ${APP_SRC_FILES}
../shared/generic_reaction_wheel_device.c)

62 changes: 62 additions & 0 deletions fsw/cfs/platform_inc/generic_reaction_wheel_platform_cfg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/************************************************************************
** File:
** $Id: generic_reaction_wheel_platform_cfg.h $
**
** Purpose:
** Define generic_reaction_wheel Platform Configuration Parameters
**
** Notes:
**
*************************************************************************/
#ifndef _GENERIC_REACTION_WHEEL_PLATFORM_CFG_H_
#define _GENERIC_REACTION_WHEEL_PLATFORM_CFG_H_

/*
** Default GENERIC_REACTION_WHEEL_1 Configuration
*/
#ifndef GENERIC_REACTION_WHEEL_1_CFG
/* Notes:
** NOS3 uart requires matching handle and bus number
*/
#define GENERIC_REACTION_WHEEL_1_CFG_STRING "/dev/tty2"
#define GENERIC_REACTION_WHEEL_1_CFG_HANDLE 2
#define GENERIC_REACTION_WHEEL_1_CFG_IS_OPEN PORT_CLOSED
#define GENERIC_REACTION_WHEEL_1_CFG_BAUDRATE_HZ 115200
#define GENERIC_REACTION_WHEEL_1_CFG_MS_TIMEOUT 50 /* Max 255 */
/* Note: Debug flag disabled (commented out) by default */
//#define GENERIC_REACTION_WHEEL_1_CFG_DEBUG
#endif

/*
** Default GENERIC_REACTION_WHEEL_2 Configuration
*/
#ifndef GENERIC_REACTION_WHEEL_2_CFG
/* Notes:
** NOS3 uart requires matching handle and bus number
*/
#define GENERIC_REACTION_WHEEL_2_CFG_STRING "/dev/tty3"
#define GENERIC_REACTION_WHEEL_2_CFG_HANDLE 3
#define GENERIC_REACTION_WHEEL_2_CFG_IS_OPEN PORT_CLOSED
#define GENERIC_REACTION_WHEEL_2_CFG_BAUDRATE_HZ 115200
#define GENERIC_REACTION_WHEEL_2_CFG_MS_TIMEOUT 50 /* Max 255 */
/* Note: Debug flag disabled (commented out) by default */
//#define GENERIC_REACTION_WHEEL_2_CFG_DEBUG
#endif

/*
** Default GENERIC_REACTION_WHEEL_3 Configuration
*/
#ifndef GENERIC_REACTION_WHEEL_3_CFG
/* Notes:
** NOS3 uart requires matching handle and bus number
*/
#define GENERIC_REACTION_WHEEL_3_CFG_STRING "/dev/tty4"
#define GENERIC_REACTION_WHEEL_3_CFG_HANDLE 4
#define GENERIC_REACTION_WHEEL_3_CFG_IS_OPEN PORT_CLOSED
#define GENERIC_REACTION_WHEEL_3_CFG_BAUDRATE_HZ 115200
#define GENERIC_REACTION_WHEEL_3_CFG_MS_TIMEOUT 50 /* Max 255 */
/* Note: Debug flag disabled (commented out) by default */
//#define GENERIC_REACTION_WHEEL_3_CFG_DEBUG
#endif

#endif /* _GENERIC_REACTION_WHEEL_PLATFORM_CFG_H_ */
75 changes: 13 additions & 62 deletions fsw/cfs/src/generic_reaction_wheel_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ static uart_info_t RW_UART[3] = {
{.deviceString = &deviceName2[0], .handle = 4, .isOpen = PORT_CLOSED, .baud = 115200},
};

/* Forward declarations */
static int32_t GetCurrentMomentum(int wheel_number, double *momentum);

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* GENERIC_RW_AppMain() -- Application entry point and main process loop */
/* */
Expand Down Expand Up @@ -213,10 +210,10 @@ int32 GENERIC_RW_AppInit( void )
} /* End of GENERIC_RW_AppInit() */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* Name: GENERIC_RW_ProcessCommandPacket */
/* Name: GENERIC_RW_ProcessCommandPacket */
/* */
/* Purpose: */
/* This routine will process any packet that is received on the GENERIC_RW */
/* This routine will process any packet that is received on the GENERIC_RW*/
/* command pipe. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand Down Expand Up @@ -388,12 +385,12 @@ 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;
} else {
CFE_EVS_SendEvent(GENERIC_RW_CMD_REQ_DATA_EID, CFE_EVS_EventType_ERROR,"Request Generic Reaction Wheel Data - Error reading momentum");
CFE_EVS_SendEvent(GENERIC_RW_CMD_REQ_DATA_EID, CFE_EVS_EventType_ERROR,"Request Generic Reaction Wheel Data - Error reading momentum. Status: %d", status);
}
}

Expand All @@ -403,52 +400,16 @@ int32 GENERIC_RW_Current_Momentum( const GENERIC_RW_Noop_t *Msg )
return CFE_SUCCESS;
} /* End of GENERIC_RW_Current_Momentum */

/************************************************************************
** Get current momentum data from the UART
*************************************************************************/
static int32_t GetCurrentMomentum(int wheel_number, double *momentum)
{
uint8_t DataBuffer[1024];
int32 DataLen;
char *reply;

char *request = "CURRENT_MOMENTUM";
int32_t status = uart_write_port(&RW_UART[wheel_number], (uint8_t*)request, strlen(request));
if (status < 0) {
CFE_EVS_SendEvent(GENERIC_RW_CMD_REQ_DATA_EID, CFE_EVS_EventType_ERROR, "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]);
if (DataLen > 0)
{
/* grab the bytes */
status = uart_read_port(&RW_UART[wheel_number], DataBuffer, DataLen);
if (status < 0) {
CFE_EVS_SendEvent(GENERIC_RW_CMD_REQ_DATA_EID, CFE_EVS_EventType_ERROR, "GetCurrentMomentum: Error reading from UART=%d\n", status);
} else {
DataBuffer[DataLen] = 0; // Ensure null termination
reply = (char *)DataBuffer;
if (strncmp(reply, "CURRENT_MOMENTUM=", 17) == 0) {
*momentum = atof(&reply[17]);
} else {
status = 0;
}
}
}

return status;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* GENERIC_RW_Noop -- GENERIC_RW Set Torque command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
int32 GENERIC_RW_Set_Torque( const GENERIC_RW_Cmd_t *Msg )
int32_t GENERIC_RW_Set_Torque( const GENERIC_RW_Cmd_t *Msg )
{
int32_t status;
double torque;
char request[22];
uint8_t wheel_num;

GENERIC_RW_AppData.HkTlm.Payload.CommandCounter++;
GENERIC_RW_Cmd_t *cmd;
Expand All @@ -458,26 +419,16 @@ int32 GENERIC_RW_Set_Torque( const GENERIC_RW_Cmd_t *Msg )
torque = cmd->data;
torque /= 10000.0; // units are 10^-4 Newton-meters (so we don't have to send floats in the command)

sprintf(request, "SET_TORQUE=%10.4f", torque);
status = uart_write_port(&RW_UART[cmd->wheel_number], (uint8_t*)request, strlen(request));
//OS_printf("Generic Reaction Wheel: Sending command:%s\n", request);
if (status < 0) {
wheel_num = cmd->wheel_number;

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

if (status < 0)
{
CFE_EVS_SendEvent(GENERIC_RW_CMD_SET_TORQUE_EID, CFE_EVS_EventType_ERROR, "Generic Reaction Wheel: Error writing to UART=%d\n", status);
} else {
/* Read the reply */
uint8_t DataBuffer[1024];
int32 DataLen;
/* check how many bytes are waiting on the uart */
DataLen = uart_bytes_available(&RW_UART[cmd->wheel_number]);
if (DataLen > 0)
{
uart_read_port(&RW_UART[cmd->wheel_number], DataBuffer, DataLen);
DataBuffer[DataLen] = 0; // Ensure null termination
//OS_printf("Generic Reaction Wheel: Response on UART=%s\n", (char *)DataBuffer);
}
}

return CFE_SUCCESS;
return status;
} /* End of GENERIC_RW_Set_Torque */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
Expand Down
1 change: 1 addition & 0 deletions fsw/cfs/src/generic_reaction_wheel_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "generic_reaction_wheel_perfids.h"
#include "generic_reaction_wheel_msgids.h"
#include "generic_reaction_wheel_msg.h"
#include "generic_reaction_wheel_device.h"

/***********************************************************************/
#define GENERIC_RW_PIPE_DEPTH 32 /* Depth of the Command Pipe for Application */
Expand Down
80 changes: 80 additions & 0 deletions fsw/shared/generic_reaction_wheel_device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*******************************************************************************
** File: generic_reaction_wheel_device.c
**
** Purpose:
** This file contains the source code for the GENERIC_REACTION_WHEEL device.
**
*******************************************************************************/

/*
** Include Files
*/
#include "generic_reaction_wheel_device.h"

/************************************************************************
** Get current momentum data from the UART
*************************************************************************/
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(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(wheel);
if (DataLen > 0)
{
/* grab the bytes */
status = uart_read_port(wheel, DataBuffer, DataLen);
if (status < 0) {
OS_printf("GetCurrentMomentum: Error reading from UART=%d\n", status);
} else {
DataBuffer[DataLen] = 0; // Ensure null termination
reply = (char *)DataBuffer;
if (strncmp(reply, "CURRENT_MOMENTUM=", 17) == 0) {
*momentum = atof(&reply[17]);
} else {
status = 0;
}
}
}

return status;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* SetRWTorque(); */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
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(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);
} else {
/* Read the reply */
uint8_t DataBuffer[1024];
int32_t DataLen;
/* check how many bytes are waiting on the uart */
DataLen = uart_bytes_available(wheel);
if (DataLen > 0)
{
uart_read_port(wheel, DataBuffer, DataLen);
DataBuffer[DataLen] = 0; // Ensure null termination
//OS_printf("Generic Reaction Wheel: Response on UART=%s\n", (char *)DataBuffer);
}
}

return status;
} /* End of SetRWTorque */
22 changes: 22 additions & 0 deletions fsw/shared/generic_reaction_wheel_device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
** File: generic_reaction_wheel_device.h
**
** Purpose:
** This is the header file for the GENERIC_REACTION_WHEEL device.
**
*******************************************************************************/
#ifndef _GENERIC_REACTION_WHEEL_DEVICE_H_
#define _GENERIC_REACTION_WHEEL_DEVICE_H_

/*
** Required header files.
*/
#include "device_cfg.h"
#include "hwlib.h"
#include "generic_reaction_wheel_platform_cfg.h"

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

#endif /* _SAMPLE_DEVICE_H_ */
65 changes: 65 additions & 0 deletions fsw/standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
cmake_minimum_required(VERSION 2.6.4)

project (generic_reaction_wheel_checkout)

if (NOT DEFINED TGTNAME)
message(FATAL_ERROR "TGTNAME must be defined on the cmake command line (e.g. \"-DTGTNAME=cpu1\")")
endif()

include(../../../ComponentSettings.cmake)

if(${TGTNAME} STREQUAL cpu1)
find_path(_ITC_CMAKE_MODULES_
NAMES FindITC_Common.cmake
PATHS ${ITC_CMAKE_MODULES}
${ITC_DEV_ROOT}/cmake/modules
$ENV{ITC_DEV_ROOT}/cmake/modules
/usr/local/cmake/modules
/usr/cmake/modules)
if(NOT _ITC_CMAKE_MODULES_)
message(WARNING "Unable to find ITC CMake Modules")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${_ITC_CMAKE_MODULES_})

find_package(NOSENGINE REQUIRED QUIET COMPONENTS common transport client uart can i2c spi)
endif()

include_directories("./")
include_directories("../cfs/platform_inc")
include_directories("../cfs/src")
include_directories("../shared")
include_directories("../../../../fsw/apps/hwlib/fsw/public_inc")

set(generic_reaction_wheel_checkout_src
generic_reaction_wheel_checkout.c
../shared/generic_reaction_wheel_device.c
)

if(${TGTNAME} STREQUAL cpu1)
include_directories("../../../../fsw/apps/hwlib/sim/inc")
set(generic_reaction_wheel_checkout_src
${generic_reaction_wheel_checkout_src}
../../../../fsw/apps/hwlib/sim/src/libuart.c
../../../../fsw/apps/hwlib/sim/src/libcan.c
../../../../fsw/apps/hwlib/sim/src/libi2c.c
../../../../fsw/apps/hwlib/sim/src/libspi.c
../../../../fsw/apps/hwlib/sim/src/nos_link.c
)
set(generic_reaction_wheel_checkout_libs
${ITC_Common_LIBRARIES}
${NOSENGINE_LIBRARIES}
)
endif()
if(${TGTNAME} STREQUAL cpu2)
set(generic_reaction_wheel_checkout_src
${generic_reaction_wheel_checkout_src}
../../../../fsw/apps/hwlib/fsw/linux/libuart.c
)
endif()

add_executable(generic_reaction_wheel_checkout ${generic_reaction_wheel_checkout_src})
target_link_libraries(generic_reaction_wheel_checkout ${generic_reaction_wheel_checkout_libs})

if(${TGTNAME} STREQUAL cpu1)
set_target_properties(generic_reaction_wheel_checkout PROPERTIES COMPILE_FLAGS "-g" LINK_FLAGS "-g")
endif()
Loading

0 comments on commit 5d8d604

Please sign in to comment.