Skip to content

Commit

Permalink
examples/subobc: apply driver -> component driver migration
Browse files Browse the repository at this point in the history
  • Loading branch information
sksat committed Oct 13, 2023
1 parent 4a5789f commit 429b6de
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 66 deletions.
2 changes: 1 addition & 1 deletion examples/subobc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ add_definitions("-DGIT_REVISION_C2A_USER_SHORT=0x${GIT_REVISION_C2A_USER_SHORT}"
add_subdirectory(${C2A_CORE_DIR})

add_subdirectory(${C2A_USER_DIR}/applications)
add_subdirectory(${C2A_USER_DIR}/driver)
add_subdirectory(${C2A_USER_DIR}/component_driver)
add_subdirectory(${C2A_USER_DIR}/hal)
add_subdirectory(${C2A_USER_DIR}/library)
add_subdirectory(${C2A_USER_DIR}/Settings)
Expand Down
2 changes: 1 addition & 1 deletion examples/subobc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ C2A 間通信の開発のために, [`examples/mobc`](/examples/mobc) とセ
- あくまで C2A 間通信開発のためなので,最小限の Tlm, Cmd などしか登録されてないなど,大幅に省略している.
- したがって,C2A の User のサンプルとしては, [`examples/mobc`](/examples/mobc) を参照するほうが望ましい.
- 一方で, MOBC との通信部分や, sub OBC としての振る舞いについてはこちらを参照すること.
- C2A 間通信については, [`docs/Driver/Communication with Components`](/docs/driver/communication_with_components.md) も参照すること.
- C2A 間通信については, [`docs/Driver/Communication with Components`](/docs/component_driver/communication_with_components.md) も参照すること.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#include "./driver_super_params.h"

#define DS_STREAM_REC_BUFFER_SIZE_DEFAULT (DS_IF_RX_BUFFER_SIZE * 2) /*!< DS_StreamRecBuffer のバッファサイズのデフォルト値
UART などの非同期通信はメモリに余力があれば DS_IF_RX_BUFFER_SIZE * 2 を推奨
#define CDS_STREAM_REC_BUFFER_SIZE_DEFAULT (CDS_IF_RX_BUFFER_SIZE * 2) /*!< CDS_StreamRecBuffer のバッファサイズのデフォルト値
UART などの非同期通信はメモリに余力があれば CDS_IF_RX_BUFFER_SIZE * 2 を推奨
詳細は dirver_super.c @note を参照 */

#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file
* @brief DriverSuperパラメタのオーバーライド用ヘッダー
* @brief ComponentDriverSuperパラメタのオーバーライド用ヘッダー
*/
#ifndef DRIVER_SUPER_PARAMS_H_
#define DRIVER_SUPER_PARAMS_H_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <src_core/tlm_cmd/packet_handler.h>
#include <src_core/library/print.h>
#include "../../Settings/port_config.h"
#include "../../Settings/DriverSuper/driver_buffer_define.h"
#include "../../Settings/component_driver_super/driver_buffer_define.h"
#include <src_core/library/result.h>

static RESULT DI_MOBC_init_(void);
Expand All @@ -20,8 +20,8 @@ static MOBC_Driver mobc_driver_;
const MOBC_Driver* const mobc_driver = &mobc_driver_;

// バッファ
static DS_StreamRecBuffer DI_MOBC_rx_buffer_;
static uint8_t DI_MOBC_rx_buffer_allocation_[DS_STREAM_REC_BUFFER_SIZE_DEFAULT];
static CDS_StreamRecBuffer DI_MOBC_rx_buffer_;
static uint8_t DI_MOBC_rx_buffer_allocation_[CDS_STREAM_REC_BUFFER_SIZE_DEFAULT];

static const uint8_t DI_MOBC_kRtTlmPhMaxNumOfProc_ = 4; //!< 一度に送出する最大テレメ数

Expand All @@ -33,21 +33,21 @@ AppInfo DI_MOBC_update(void)

static RESULT DI_MOBC_init_(void)
{
DS_ERR_CODE ret1;
DS_INIT_ERR_CODE ret2;
CDS_ERR_CODE ret1;
CDS_INIT_ERR_CODE ret2;
RESULT err = RESULT_OK;

ret1 = DS_init_stream_rec_buffer(&DI_MOBC_rx_buffer_,
ret1 = CDS_init_stream_rec_buffer(&DI_MOBC_rx_buffer_,
DI_MOBC_rx_buffer_allocation_,
sizeof(DI_MOBC_rx_buffer_allocation_));
if (ret1 != DS_ERR_CODE_OK)
if (ret1 != CDS_ERR_CODE_OK)
{
Printf("MOBC buffer init Failed ! %d \n", ret1);
err = RESULT_ERR;
}

ret2 = MOBC_init(&mobc_driver_, PORT_CH_UART_MOBC, &DI_MOBC_rx_buffer_);
if (ret2 != DS_INIT_OK)
if (ret2 != CDS_INIT_OK)
{
Printf("MOBC init Failed ! %d \n", ret2);
err = RESULT_ERR;
Expand All @@ -58,7 +58,7 @@ static RESULT DI_MOBC_init_(void)

static RESULT DI_MOBC_update_(void)
{
DS_REC_ERR_CODE ret;
CDS_REC_ERR_CODE ret;
ret = MOBC_rec(&mobc_driver_);

// TODO: 必要があればここに処理を
Expand Down Expand Up @@ -86,11 +86,11 @@ static RESULT DI_MOBC_rt_tlm_packet_handler_(void)
CommonTlmPacket packet; // FIXME: これは static にする?
// static のほうがコンパイル時にアドレスが確定して安全. Out of stack space を回避できる
// 一方でメモリ使用量は増える.
mobc_driver_.info.c2a.send_tlm_err_code = DS_CMD_OK;
mobc_driver_.info.c2a.send_tlm_err_code = CDS_CMD_OK;

for (i = 0; i < DI_MOBC_kRtTlmPhMaxNumOfProc_; i++)
{
DS_CMD_ERR_CODE ret;
CDS_CMD_ERR_CODE ret;

// TODO: ここは一部 MW に入れるべきなのかなぁ...?
// 最近 C2A の MW の扱いが難しい.いっそなくすか?
Expand Down Expand Up @@ -119,14 +119,14 @@ static RESULT DI_MOBC_rt_tlm_packet_handler_(void)
// AOBC のアノマリ基準は?

// 最後に起きたエラーを保存する
mobc_driver_.info.c2a.send_tlm_err_code = DS_CMD_ILLEGAL_PARAMETER;
mobc_driver_.info.c2a.send_tlm_err_code = CDS_CMD_ILLEGAL_PARAMETER;
continue;
}

// TODO: TPC のヘッダを別途設定する必要はないか,ちゃんと確認する.多分ないと思うけど

ret = MOBC_send(&mobc_driver_, &packet);
if (ret != DS_CMD_OK)
if (ret != CDS_CMD_OK)
{
// 最後に起きたエラーを保存する
mobc_driver_.info.c2a.send_tlm_err_code = ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef DI_MOBC_H_
#define DI_MOBC_H_

#include "../../driver/etc/mobc.h"
#include "../../component_driver/etc/mobc.h"
#include <src_core/system/application_manager/app_info.h>
#include <src_core/tlm_cmd/common_cmd_packet.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include "./mobc.h"
#include <src_core/tlm_cmd/common_tlm_cmd_packet.h>
#include <src_core/driver/eb90_frame_for_driver_super.h>
#include <src_core/driver/common_tlm_cmd_packet_for_driver_super.h>
#include <src_core/component_driver/eb90_frame_for_driver_super.h>
#include <src_core/component_driver/common_tlm_cmd_packet_for_driver_super.h>
#include <string.h>

#define MOBC_STREAM_TLM_CMD (0) //!< テレコマで使うストリーム
Expand All @@ -18,14 +18,14 @@ static uint8_t MOBC_tx_frame_[EB90_FRAME_HEADER_SIZE +
CTCP_MAX_LEN +
EB90_FRAME_FOOTER_SIZE];

static DS_ERR_CODE MOBC_load_driver_super_init_settings_(DriverSuper* p_super);
static DS_ERR_CODE MOBC_analyze_rec_data_(DS_StreamConfig* p_stream_config,
static CDS_ERR_CODE MOBC_load_driver_super_init_settings_(ComponentDriverSuper* p_super);
static CDS_ERR_CODE MOBC_analyze_rec_data_(CDS_StreamConfig* p_stream_config,
void* p_driver);


DS_INIT_ERR_CODE MOBC_init(MOBC_Driver* mobc_driver, uint8_t ch, DS_StreamRecBuffer* rx_buffer)
CDS_INIT_ERR_CODE MOBC_init(MOBC_Driver* mobc_driver, uint8_t ch, CDS_StreamRecBuffer* rx_buffer)
{
DS_ERR_CODE ret;
CDS_ERR_CODE ret;

memset(mobc_driver, 0x00, sizeof(MOBC_Driver));

Expand All @@ -35,18 +35,18 @@ DS_INIT_ERR_CODE MOBC_init(MOBC_Driver* mobc_driver, uint8_t ch, DS_StreamRecBuf
mobc_driver->driver.uart_config.data_length = UART_DATA_LENGTH_8BIT;
mobc_driver->driver.uart_config.stop_bit = UART_STOP_BIT_1BIT;

ret = DS_init(&(mobc_driver->driver.super),
ret = CDS_init(&(mobc_driver->driver.super),
&(mobc_driver->driver.uart_config),
rx_buffer,
MOBC_load_driver_super_init_settings_);
if (ret != DS_ERR_CODE_OK) return DS_INIT_DS_INIT_ERR;
return DS_INIT_OK;
if (ret != CDS_ERR_CODE_OK) return CDS_INIT_CDS_INIT_ERR;
return CDS_INIT_OK;
}


static DS_ERR_CODE MOBC_load_driver_super_init_settings_(DriverSuper* p_super)
static CDS_ERR_CODE MOBC_load_driver_super_init_settings_(ComponentDriverSuper* p_super)
{
DS_StreamConfig* p_stream_config;
CDS_StreamConfig* p_stream_config;

p_super->interface = UART;

Expand All @@ -57,40 +57,40 @@ static DS_ERR_CODE MOBC_load_driver_super_init_settings_(DriverSuper* p_super)

// 定期 TLM の監視機能の有効化しない → ので設定上書きなし

DSSC_enable(p_stream_config);
CDSSC_enable(p_stream_config);

return DS_ERR_CODE_OK;
return CDS_ERR_CODE_OK;
}


DS_REC_ERR_CODE MOBC_rec(MOBC_Driver* mobc_driver)
CDS_REC_ERR_CODE MOBC_rec(MOBC_Driver* mobc_driver)
{
DS_ERR_CODE ret;
DS_StreamConfig* p_stream_config;
CDS_ERR_CODE ret;
CDS_StreamConfig* p_stream_config;

ret = DS_receive(&(mobc_driver->driver.super));
ret = CDS_receive(&(mobc_driver->driver.super));

if (ret != DS_ERR_CODE_OK) return DS_REC_DS_RECEIVE_ERR;
if (ret != CDS_ERR_CODE_OK) return CDS_REC_CDS_RECEIVE_ERR;

p_stream_config = &(mobc_driver->driver.super.stream_config[MOBC_STREAM_TLM_CMD]);
if (DSSC_get_rec_status(p_stream_config)->status_code != DS_STREAM_REC_STATUS_FIXED_FRAME) return DS_REC_OK; // 受信せず(TODO: 詳細なエラー処理は一旦しない)
if (CDSSC_get_rec_status(p_stream_config)->status_code != CDS_STREAM_REC_STATUS_FIXED_FRAME) return CDS_REC_OK; // 受信せず(TODO: 詳細なエラー処理は一旦しない)

ret = DS_analyze_rec_data(&(mobc_driver->driver.super), MOBC_STREAM_TLM_CMD, mobc_driver);
ret = CDS_analyze_rec_data(&(mobc_driver->driver.super), MOBC_STREAM_TLM_CMD, mobc_driver);

if (ret != DS_ERR_CODE_OK) return DS_REC_ANALYZE_ERR;
if (ret != CDS_ERR_CODE_OK) return CDS_REC_ANALYZE_ERR;

return DS_REC_OK;
return CDS_REC_OK;
}


static DS_ERR_CODE MOBC_analyze_rec_data_(DS_StreamConfig* p_stream_config, void* p_driver)
static CDS_ERR_CODE MOBC_analyze_rec_data_(CDS_StreamConfig* p_stream_config, void* p_driver)
{
MOBC_Driver* mobc_driver = (MOBC_Driver*)p_driver;
CommonCmdPacket packet; // FIXME: これは static にする?
// static のほうがコンパイル時にアドレスが確定して安全. Out of stack space を回避できる
// 一方でメモリ使用量は増える.
DS_ERR_CODE ret = CCP_get_ccp_from_dssc(p_stream_config, &packet);
if (ret != DS_ERR_CODE_OK)
CDS_ERR_CODE ret = CCP_get_ccp_from_dssc(p_stream_config, &packet);
if (ret != CDS_ERR_CODE_OK)
{
mobc_driver->info.comm.rx_err_code = MOBC_RX_ERR_CODE_INVALID_PACKET;
return ret;
Expand All @@ -101,7 +101,7 @@ static DS_ERR_CODE MOBC_analyze_rec_data_(DS_StreamConfig* p_stream_config, void
if (!EB90_FRAME_is_valid_crc_of_dssc(p_stream_config))
{
mobc_driver->info.comm.rx_err_code = MOBC_RX_ERR_CODE_CRC_ERR;
return DS_ERR_CODE_ERR;
return CDS_ERR_CODE_ERR;
}

// MOBC からのコマンドは以下のパターン
Expand All @@ -120,30 +120,30 @@ static DS_ERR_CODE MOBC_analyze_rec_data_(DS_StreamConfig* p_stream_config, void
// FIXME: CTCP 大工事が終わったら,返り値をちゃんと見るようにする
mobc_driver->info.c2a.ph_ack = PH_analyze_cmd_packet(&packet);

return DS_ERR_CODE_OK;
return CDS_ERR_CODE_OK;
}


DS_CMD_ERR_CODE MOBC_send(MOBC_Driver* mobc_driver, const CommonTlmPacket* packet)
CDS_CMD_ERR_CODE MOBC_send(MOBC_Driver* mobc_driver, const CommonTlmPacket* packet)
{
DS_ERR_CODE ret;
DS_StreamConfig* p_stream_config;
CDS_ERR_CODE ret;
CDS_StreamConfig* p_stream_config;

p_stream_config = &(mobc_driver->driver.super.stream_config[MOBC_STREAM_TLM_CMD]);

// tx_frameの設定
CTP_set_tx_frame_to_dssc(p_stream_config, packet);

ret = DS_send_general_cmd(&(mobc_driver->driver.super), MOBC_STREAM_TLM_CMD);
ret = CDS_send_general_cmd(&(mobc_driver->driver.super), MOBC_STREAM_TLM_CMD);

if (ret == DS_ERR_CODE_OK)
if (ret == CDS_ERR_CODE_OK)
{
return DS_CMD_OK;
return CDS_CMD_OK;
}
else
{
// TODO: エラー処理?
return DS_CMD_DRIVER_SUPER_ERR;
return CDS_CMD_DRIVER_SUPER_ERR;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define MOBC_H_

#include <src_core/hal/uart.h>
#include <src_core/driver/driver_super.h>
#include <src_core/component_driver/driver_super.h>
#include <src_core/system/time_manager/obc_time.h>
#include <src_core/tlm_cmd/common_tlm_packet.h>
#include <src_core/tlm_cmd/packet_handler.h>
Expand Down Expand Up @@ -46,14 +46,14 @@ typedef struct
// C2A 情報
struct
{
DS_CMD_ERR_CODE send_tlm_err_code; //!< テレメトリ送信時のエラーコード
CDS_CMD_ERR_CODE send_tlm_err_code; //!< テレメトリ送信時のエラーコード
PH_ACK ph_ack; //!< 受信したコマンドを PH に渡したときの返り値
} c2a; //!< C2A 情報
// 通信情報
struct
{
MOBC_TX_ERR_CODE tx_err_code; //!< DriverSuper ではなく Driver が持つべき通信エラー情報
MOBC_RX_ERR_CODE rx_err_code; //!< DriverSuper ではなく Driver が持つべき通信エラー情報
MOBC_TX_ERR_CODE tx_err_code; //!< ComponentDriverSuper ではなく Driver が持つべき通信エラー情報
MOBC_RX_ERR_CODE rx_err_code; //!< ComponentDriverSuper ではなく Driver が持つべき通信エラー情報
} comm; //!< 通信情報
} MOBC_Info;

Expand All @@ -66,7 +66,7 @@ typedef struct
{
struct
{
DriverSuper super; //!< DriverSuper class
ComponentDriverSuper super; //!< ComponentDriverSuper class
UART_Config uart_config; //!< UART class
} driver;
MOBC_Info info;
Expand All @@ -80,25 +80,25 @@ typedef struct
* @param mobc_driver: 初期化する MOBC_Driver 構造体へのポインタ
* @param ch: MOBC が接続されている UART ポート番号
* @param rx_buffer: 受信バッファ
* @return DS_INIT_ERR_CODE
* @return CDS_INIT_ERR_CODE
*/
DS_INIT_ERR_CODE MOBC_init(MOBC_Driver* mobc_driver, uint8_t ch, DS_StreamRecBuffer* rx_buffer);
CDS_INIT_ERR_CODE MOBC_init(MOBC_Driver* mobc_driver, uint8_t ch, CDS_StreamRecBuffer* rx_buffer);


/**
* @brief MOBC からのデータ( MOBC → AOBC のコマンド)受信
* @param mobc_driver: MOBC_Driver 構造体へのポインタ
* @return DS_REC_ERR_CODE
* @return CDS_REC_ERR_CODE
*/
DS_REC_ERR_CODE MOBC_rec(MOBC_Driver* mobc_driver);
CDS_REC_ERR_CODE MOBC_rec(MOBC_Driver* mobc_driver);


/**
* @brief MOBC へのデータ(MOBC → AOBCのテレメ)送信
* @param mobc_driver: MOBC_Driver 構造体へのポインタ
* @param packet: 送信する CTP packet
* @return DS_CMD_ERR_CODE
* @return CDS_CMD_ERR_CODE
*/
DS_CMD_ERR_CODE MOBC_send(MOBC_Driver* mobc_driver, const CommonTlmPacket* packet);
CDS_CMD_ERR_CODE MOBC_send(MOBC_Driver* mobc_driver, const CommonTlmPacket* packet);

#endif
2 changes: 1 addition & 1 deletion examples/subobc/src/src_user/tlm_cmd/user_packet_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ PH_ACK PH_user_analyze_cmd(const CommonCmdPacket* packet);
* ここから Driver を叩いて送信まで行うことになる(実行時間は CA_execute_cmd と同じだけ許容されているので OK)
* @param packet: CCP
* @retval CCP_CmdRet{CCP_EXEC_SUCCESS, *} など: 無事に転送された.転送先の結果を返す
* @retval CCP_CmdRet{CCP_EXEC_ROUTING_FAILED, *}: 転送失敗(詳細エラーは DriverSuper を参照)
* @retval CCP_CmdRet{CCP_EXEC_ROUTING_FAILED, *}: 転送失敗(詳細エラーは ComponentDriverSuper を参照)
*/
CCP_CmdRet PH_user_cmd_router(const CommonCmdPacket* packet);

Expand Down
2 changes: 1 addition & 1 deletion examples/subobc/sync_with_mobc_example.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ call :sync_file ".\src\src_user\hal\sils_mockup\README.md" "..\mobc\src\src_user
call :sync_file ".\src\src_user\hal\sils_mockup\uart_sils.c" "..\mobc\src\src_user\hal\sils_mockup\uart_sils.c"
call :sync_file ".\src\src_user\hal\sils_mockup\wdt_sils.c" "..\mobc\src\src_user\hal\sils_mockup\wdt_sils.c"
call :sync_file ".\src\src_user\Settings\git_revision_config.h" "..\mobc\src\src_user\Settings\git_revision_config.h"
call :sync_file ".\src\src_user\Settings\DriverSuper\driver_buffer_define.h" "..\mobc\src\src_user\Settings\DriverSuper\driver_buffer_define.h"
call :sync_file ".\src\src_user\Settings\ComponentDriverSuper\driver_buffer_define.h" "..\mobc\src\src_user\Settings\ComponentDriverSuper\driver_buffer_define.h"
call :sync_file ".\src\src_user\Settings\tlm_cmd\common_cmd_packet_define.c" "..\mobc\src\src_user\Settings\tlm_cmd\common_cmd_packet_define.c"
call :sync_file ".\src\src_user\Settings\tlm_cmd\common_tlm_cmd_packet_define.h" "..\mobc\src\src_user\Settings\tlm_cmd\common_tlm_cmd_packet_define.h"
call :sync_file ".\src\src_user\tlm_cmd\block_command_user_settings.c" "..\mobc\src\src_user\tlm_cmd\block_command_user_settings.c"
Expand Down

0 comments on commit 429b6de

Please sign in to comment.