Skip to content

Commit

Permalink
add 2nd obc code as AOBC
Browse files Browse the repository at this point in the history
これから,C2A間通信の大工事をやっていくが,その前に既存のC2Aの間通信のコードをcommitしておく
  • Loading branch information
meltingrabbit committed Jan 31, 2022
1 parent 338a316 commit e65bf44
Show file tree
Hide file tree
Showing 29 changed files with 4,614 additions and 7 deletions.
1 change: 1 addition & 0 deletions Drivers/Super/driver_super_issl_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@


// [TODO] 以下は本当はTCPの定義から持ってきたい.TCPの整理が終わったらそうする
// FIXME: Space Packet 大工事が終わったら整合を取る!
#define DS_C2AFMT_TCP_CMD_PRIMARY_HEADER_SIZE (6) //!< C2A間通信のTCPCMDののPrimary header size
#define DS_C2AFMT_TCP_CMD_SECONDARY_HEADER_SIZE (1) //!< C2A間通信のTCPCMDののSecondary header size
#define DS_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE (6) //!< C2A間通信のTCPのTLMのPrimary header size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ project(C2A_USER_APPS)

set(C2A_SRCS
app_registry.c
DriverInstances/di_aobc.c
DriverInstances/di_gs.c
DriverInstances/di_uart_test.c
UserDefined/debug_apps.c
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#pragma section REPRO
/**
* @file
* @brief AOBC の DI と AOBC の cmd dispatcher
* @note C2A 間通信のデモ用であり, AOBC も C2A 搭載を仮定する
*/

#include "di_aobc.h"
#include "../../Drivers/Aocs/aobc.h"
#include "../../TlmCmd/user_packet_handler.h"
#include <src_core/Library/print.h>
#include "../../Settings/port_config.h"


static AOBC_Driver aobc_driver_;
const AOBC_Driver* const aobc_driver = &aobc_driver_;

static CommandDispatcher DI_AOBC_cdis_;
const CommandDispatcher* const DI_AOBC_cdis = &DI_AOBC_cdis_;

static void DI_AOBC_init_(void);
static void DI_AOBC_update_(void);

static void DI_AOBC_cmd_dispatcher_init_(void);
static void DI_AOBC_cmd_dispatcher_(void);


AppInfo DI_AOBC_update(void)
{
return AI_create_app_info("update_AOBC", DI_AOBC_init_, DI_AOBC_update_);
}


static void DI_AOBC_init_(void)
{
int ret = AOBC_init(&aobc_driver_, PORT_CH_RS422_AOBC);

if (ret != 0)
{
Printf("AOBC init Failed ! %d \n", ret);
}
}


static void DI_AOBC_update_(void)
{
int ret;
ret = AOBC_rec(&aobc_driver_);

// [TODO]
// 必要があればここに処理を
}


AppInfo DI_AOBC_cmd_dispatcher(void)
{
return AI_create_app_info("aobc_cdis",
DI_AOBC_cmd_dispatcher_init_,
DI_AOBC_cmd_dispatcher_);
}


static void DI_AOBC_cmd_dispatcher_init_(void)
{
DI_AOBC_cdis_ = CDIS_init(&PH_aobc_cmd_list);
}


static void DI_AOBC_cmd_dispatcher_(void)
{
CDIS_dispatch_command(&DI_AOBC_cdis_);
}


CCP_EXEC_STS DI_AOBC_dispatch_command(const CommonCmdPacket* packet)
{
DS_CMD_ERR_CODE ret;
CommonCmdPacket* pckt = (CommonCmdPacket*)packet; // const_cast
// ここで TCP_CMD_DEST_TYPE を宛先で受理できるように変更(なので const cast が発生している...)

if (CCP_get_dest_type(pckt) != CCP_DEST_TYPE_TO_ME)
{
// MOBC のキューに入らず直接転送
// そのままの EXEC_TYPE で転送.なにもしない
}
else
{
// MOBC のキューに溜まった後に実行されたもの
// 配送先 OBC では MOBC 側の TL などの影響は受けないはずなので RTC へ変換
CCP_set_exec_type(pckt, CCP_EXEC_TYPE_RT);
}

// 配送先 OBC が最終到達地なので
CCP_set_dest_type(pckt, CCP_DEST_TYPE_TO_ME);

ret = AOBC_send_cmd(&aobc_driver_, pckt);
return DS_conv_cmd_err_to_ccp_exec_sts(ret);
}


CCP_EXEC_STS Cmd_DI_AOBC_CDIS_CLEAR_ALL_REALTIME(const CommonCmdPacket* packet)
{
(void)packet;

CDIS_clear_command_list(&DI_AOBC_cdis_);
return CCP_EXEC_SUCCESS;
}


CCP_EXEC_STS Cmd_DI_AOBC_CDIS_CLEAR_ERR_LOG(const CommonCmdPacket* packet)
{
(void)packet;

// 記録されたエラー情報を解除
CDIS_clear_error_status(&DI_AOBC_cdis_);
return CCP_EXEC_SUCCESS;
}

#pragma section
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @file
* @brief AOBC の DI と AOBC の cmd dispatcher
* @note C2A 間通信のデモ用であり, AOBC も C2A 搭載を仮定する
*/
#ifndef INCLUDED_DI_AOBC_H
#define INCLUDED_DI_AOBC_H

#include "../../Drivers/Aocs/aobc.h"
#include "../../Drivers/Aocs/aobc_command_definitions.h"
#include "../../Drivers/Aocs/aobc_telemetry_definitions.h"
#include <src_core/System/ApplicationManager/app_info.h>
#include <src_core/TlmCmd/command_dispatcher.h>
#include <src_core/TlmCmd/common_tlm_cmd_packet.h>

extern const AOBC_Driver* const aobc_driver; //!< AOBC driver
extern const CommandDispatcher* const DI_AOBC_cdis; //!< AOBC cmd dispatcher

/**
* @brief AOBC update アプリ生成関数
* @param void
* @return void
*/
AppInfo DI_AOBC_update(void);

/**
* @brief AOBC cmd dispatcher アプリ生成関数
* @param void
* @return void
*/
AppInfo DI_AOBC_cmd_dispatcher(void);

/**
* @brief CommonCmdPacket を AOBC に送信する
* @note AOBC が自身のコマンドと解釈できるよう,Execution Type を上書きするため, packet を const cast する.[TODO] const cast やめたい
* @note この関数を呼んでも良いのは,user_packet_handler のみ!
* @param packet: CommonCmdPacket packet
* @retval CCP_EXEC_SUCCESS: 無事に転送された
* @retval それ以外: 転送失敗(DS_CMD_ERR_CODE を CCP_EXEC_STS に変換して返す.詳細エラーは DriverSuper を参照)
*/
CCP_EXEC_STS DI_AOBC_dispatch_command(const CommonCmdPacket* packet);

CCP_EXEC_STS Cmd_DI_AOBC_CDIS_CLEAR_ALL_REALTIME(const CommonCmdPacket* packet);

CCP_EXEC_STS Cmd_DI_AOBC_CDIS_CLEAR_ERR_LOG(const CommonCmdPacket* packet);

#endif
200 changes: 200 additions & 0 deletions Examples/minimum_user_for_s2e/src/src_user/Drivers/Aocs/aobc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
#pragma section REPRO
/**
* @file
* @brief AOBC の Driver
*/
#include "./aobc.h"
#include "./aobc_command_definitions.h"
#include "./aobc_telemetry_definitions.h"
#include "./aobc_telemetry_buffer.h"
#include <src_core/TlmCmd/common_tlm_cmd_packet.h>
#include <src_core/Library/endian_memcpy.h>
#include <string.h>

// ヘッダーフッター
static const uint8_t AOBC_stx_[DS_ISSLFMT_STX_SIZE] = {DS_ISSLFMT_STX_1ST_BYTE,
DS_ISSLFMT_STX_2ND_BYTE};
static const uint8_t AOBC_etx_[DS_ISSLFMT_ETX_SIZE] = {DS_ISSLFMT_ETX_1ST_BYTE,
DS_ISSLFMT_ETX_2ND_BYTE};

#define AOBC_STREAM_TLM_CMD (0) //!< テレコマで使うストリーム

static DS_ERR_CODE AOBC_load_driver_super_init_settings_(DriverSuper* p_super);
static DS_ERR_CODE AOBC_analyze_rec_data_(DS_StreamConfig* p_stream_config,
void* p_driver);

static uint8_t AOBC_tx_frame_[DS_ISSLFMT_COMMON_HEADER_SIZE +
CTCP_MAX_LEN +
DS_ISSLFMT_COMMON_FOOTER_SIZE];


int AOBC_init(AOBC_Driver* aobc_driver, uint8_t ch)
{
DS_ERR_CODE ret;

memset(aobc_driver, 0x00, sizeof(*aobc_driver));
AOBC_buffer_init();

aobc_driver->driver.uart_config.ch = ch;
aobc_driver->driver.uart_config.baudrate = 115200;
aobc_driver->driver.uart_config.parity_settings = PARITY_SETTINGS_NONE;
aobc_driver->driver.uart_config.data_length = UART_DATA_LENGTH_8BIT;
aobc_driver->driver.uart_config.stop_bit = UART_STOP_BIT_1BIT;

ret = DS_init(&(aobc_driver->driver.super),
&(aobc_driver->driver.uart_config),
AOBC_load_driver_super_init_settings_);
if (ret != DS_ERR_CODE_OK) return 1;
return 0;
}


static DS_ERR_CODE AOBC_load_driver_super_init_settings_(DriverSuper* p_super)
{
DS_StreamConfig* p_stream_config;

p_super->interface = UART;

// streamは0のみ
p_stream_config = &(p_super->stream_config[AOBC_STREAM_TLM_CMD]);
DSSC_enable(p_stream_config);

// 送信はする
DSSC_set_tx_frame(p_stream_config, AOBC_tx_frame_); // 送る直前に中身を memcpy する
DSSC_set_tx_frame_size(p_stream_config, 0); // 送る直前に値をセットする

// 定期的な受信はする
DSSC_set_rx_header(p_stream_config, AOBC_stx_, DS_ISSLFMT_STX_SIZE);
DSSC_set_rx_footer(p_stream_config, AOBC_etx_, DS_ISSLFMT_ETX_SIZE);
DSSC_set_rx_frame_size(p_stream_config, -1); // 可変
DSSC_set_rx_framelength_pos(p_stream_config, DS_ISSLFMT_COMMON_HEADER_SIZE + 4);
DSSC_set_rx_framelength_type_size(p_stream_config, 2);
// [TODO] これはちょっと要確認. CCSDS は 1 起算?
DSSC_set_rx_framelength_offset(p_stream_config,
DS_ISSLFMT_COMMON_HEADER_SIZE + DS_ISSLFMT_COMMON_FOOTER_SIZE + DS_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + 1);
DSSC_set_data_analyzer(p_stream_config, AOBC_analyze_rec_data_);

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

return DS_ERR_CODE_OK;
}


int AOBC_rec(AOBC_Driver* aobc_driver)
{
DS_ERR_CODE ret;
DS_StreamConfig* p_stream_config;

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

if (ret != DS_ERR_CODE_OK) return 1;

p_stream_config = &(aobc_driver->driver.super.stream_config[AOBC_STREAM_TLM_CMD]);
if (DSSC_get_rec_status(p_stream_config)->status_code != DS_STREAM_REC_STATUS_FIXED_FRAME) return 0; // 受信せず([TODO] 詳細なエラー処理は一旦しない)

ret = DS_analyze_rec_data(&(aobc_driver->driver.super), AOBC_STREAM_TLM_CMD, aobc_driver);

if (ret != DS_ERR_CODE_OK) return 1;

return 0;
}


static DS_ERR_CODE AOBC_analyze_rec_data_(DS_StreamConfig* p_stream_config,
void* p_driver)
{
AOBC_Driver* aobc_driver = (AOBC_Driver*)p_driver;

aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_OK;

// [TODO] ここに CRC チェックをいれる
// AOBC_RX_ERR_CODE_CRC_ERR を入れる

return AOBC_buffer_tlm_contents(p_stream_config, aobc_driver);
}


#if 0
// 非C2A系列はこのように書く
static DS_ERR_CODE AOBC_analyze_rec_data_(DS_StreamConfig* p_stream_config, void* p_driver)
{
AOBC_Driver* aobc_driver = (AOBC_Driver*)p_driver;
uint32_t tlm_ver = DS_ISSLFMT_get_tlm_version(p_stream_config);
uint32_t tlm_id = DS_ISSLFMT_get_tlm_id(tlm_ver, p_stream_config);

aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_OK;

// [TODO] ここ自動生成したい...
switch (tlm_id)
{
case AOBC_Tlm_CODE_HK:
return AOBC_analyze_tlm_hk_(p_stream_config, aobc_driver);
default:
aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_TLM_NOT_FOUND;
return DS_ERR_CODE_OK;
}
}
#endif


DS_CMD_ERR_CODE AOBC_send_cmd(AOBC_Driver* aobc_driver, const CommonCmdPacket* packet)
{
DS_ERR_CODE ret;
DS_StreamConfig* p_stream_config;
AOBC_CMD_CODE cmd_code;
uint16_t ctcp_len;
uint16_t crc;
size_t pos;
size_t size;

p_stream_config = &(aobc_driver->driver.super.stream_config[AOBC_STREAM_TLM_CMD]);

// tx_frameの設定
ctcp_len = CCP_get_packet_len(packet);
DSSC_set_tx_frame_size(p_stream_config,
(uint16_t)(ctcp_len + DS_ISSLFMT_COMMON_HEADER_SIZE + DS_ISSLFMT_COMMON_FOOTER_SIZE));

pos = 0;
size = DS_ISSLFMT_STX_SIZE;
memcpy(&(AOBC_tx_frame_[pos]), AOBC_stx_, size);
pos += size;
size = DS_ISSLFMT_LEN_SIZE;
endian_memcpy(&(AOBC_tx_frame_[pos]), &ctcp_len, size); // ここはエンディアンを気にする!
pos += size;
size = (size_t)ctcp_len;
memcpy(&(AOBC_tx_frame_[pos]), packet->packet, size);
pos += size;

crc = DS_ISSLFMT_calc_crc(AOBC_tx_frame_, pos);

size = DS_ISSLFMT_CRC_SIZE;
endian_memcpy(&(AOBC_tx_frame_[pos]), &crc, size); // ここはエンディアンを気にする!
pos += size;
size = DS_ISSLFMT_ETX_SIZE;
memcpy(&(AOBC_tx_frame_[pos]), AOBC_etx_, size);

cmd_code = (AOBC_CMD_CODE)CCP_get_id(packet);

// [TODO] ここではコマンドが実際に存在するか,ということはフィルタしない!(でいいよね?)
// 必要があれば,AOBC 側で弾くべき.
if (cmd_code == AOBC_Cmd_CODE_GENERATE_TLM)
{
ret = DS_send_req_tlm_cmd(&(aobc_driver->driver.super), AOBC_STREAM_TLM_CMD);
}
else
{
ret = DS_send_general_cmd(&(aobc_driver->driver.super), AOBC_STREAM_TLM_CMD);
}

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

#pragma section
Loading

0 comments on commit e65bf44

Please sign in to comment.