Skip to content

Commit

Permalink
add CmdSpacePacket
Browse files Browse the repository at this point in the history
  • Loading branch information
meltingrabbit committed Jan 27, 2022
1 parent b00ce73 commit 7b19192
Show file tree
Hide file tree
Showing 6 changed files with 747 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @file
* @brief CmdSpacePacket のユーザー設定
*/
#ifndef CMD_SPACE_PACKET_PARAMS_H_
#define CMD_SPACE_PACKET_PARAMS_H_

#undef CSP_MAX_LEN
#undef CSP_2ND_HDR_VER_TO_USE

#define CSP_MAX_LEN (128)
#define CSP_2ND_HDR_VER_TO_USE (CSP_2ND_HDR_VER_1)

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,29 @@
#ifndef COMMON_CMD_PACKET_DEFINE_H_
#define COMMON_CMD_PACKET_DEFINE_H_

#include <src_core/TlmCmd/Ccsds/TCPacket.h>
#include <src_core/TlmCmd/Ccsds/cmd_space_packet.h>

// CommonCmdPacket として TCP をつかう
// FIXME: CmdSpacePacket に差し替える
typedef TCP CommonCmdPacket;
// CommonCmdPacket として CmdSpacePacket をつかう
typedef CmdSpacePacket CommonCmdPacket;

// 2021-01-22 追加
// DEST_TYPE を定義
typedef TCP_CMD_DEST_TYPE CCP_DEST_TYPE;
// 自分宛て CMD を示す AIPD を定義
// FIXME: Space Packet が整備されたら直す
#define CCP_APID_TO_ME (APID_MOBC_CMD)

/**
* @enum CCP_DEST_TYPE
* @brief コマンドの解釈の宛先を規定
* @note TO_ME: 自分自身 → 自分自身の TLC や BC として解釈.コマンド実行時に必要に応じて別 OBC へ配送 (この定義は C2A Core で使うため,どんな C2A でも必須)
* @note TO_*: 転送先の TL や BC として解釈 (直接指定 OBC へ配送. GS から来たコマンドを自身のキューにいれない)
* @note 4bit を想定
*/
typedef enum
{
CCP_DEST_TYPE_TO_ME = 0,
CCP_DEST_TYPE_TO_MOBC = 1,
CCP_DEST_TYPE_TO_AOBC = 2,
CCP_DEST_TYPE_TO_TOBC = 3,
CCP_DEST_TYPE_TO_UNKOWN = 4
} CCP_DEST_TYPE;

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @note CCP: CommonCmdPacket
*/
#include <src_core/TlmCmd/common_cmd_packet.h>
#include <string.h>


int CCP_is_valid_packet(const CommonCmdPacket* packet)
Expand All @@ -17,102 +18,82 @@ int CCP_is_valid_packet(const CommonCmdPacket* packet)

cycle_t CCP_get_ti(const CommonCmdPacket* packet)
{
return (cycle_t)TCP_CMD_get_ti(packet);
return (cycle_t)CSP_get_ti(packet);
}

void CCP_set_ti(CommonCmdPacket* packet, cycle_t ti)
{
TCP_CMD_set_ti(packet, (uint32_t)ti);
CSP_set_ti(packet, (uint32_t)ti);
}

APID CCP_get_apid(const CommonCmdPacket* packet)
{
return TCP_get_apid(packet);
return CSP_get_apid(packet);
}

void CCP_set_apid(CommonCmdPacket* packet, APID apid)
{
TCP_set_apid(packet, apid);
CSP_set_apid(packet, apid);
}

CCP_EXEC_TYPE CCP_get_exec_type(const CommonCmdPacket* packet)
{
// TCP_CMD_EXEC_TYPEとCCP_EXEC_TYPEの定義は合わせている.(正確には、前者は後者に含まれている.)
TCP_CMD_EXEC_TYPE exec_type = TCP_CMD_get_exec_type(packet);
if (exec_type == TCP_CMD_EXEC_TYPE_UNKNOWN)
{
return CCP_EXEC_TYPE_UNKNOWN;
}
else
{
return (CCP_EXEC_TYPE)exec_type;
}
return CSP_get_exec_type(packet);
}

void CCP_set_exec_type(CommonCmdPacket* packet, CCP_EXEC_TYPE type)
{
// CCP_EXEC_TYPEのほうがとりうる数値の幅が広いので,アサーション
if ((int)type >= (int)TCP_CMD_EXEC_TYPE_UNKNOWN)
{
TCP_CMD_set_exec_type(packet, TCP_CMD_EXEC_TYPE_UNKNOWN);
}
else
{
TCP_CMD_set_exec_type(packet, (TCP_CMD_EXEC_TYPE)type);
}
CSP_set_exec_type(packet, type);
}

// 2021-01-22 追加
CCP_DEST_TYPE CCP_get_dest_type(const CommonCmdPacket* packet)
{
return (CCP_DEST_TYPE)TCP_CMD_get_dest_type(packet);
return CSP_get_dest_type(packet);
}

// 2021-01-22 追加
void CCP_set_dest_type(CommonCmdPacket* packet, CCP_DEST_TYPE type)
{
TCP_CMD_set_dest_type(packet, (TCP_CMD_DEST_TYPE)type);
CSP_set_dest_type(packet, type);
}

CMD_CODE CCP_get_id(const CommonCmdPacket* packet)
{
return (CMD_CODE)TCP_CMD_get_channel_id(packet);
return CSP_get_cmd_id(packet);
}

void CCP_set_id(CommonCmdPacket* packet, CMD_CODE id)
{
TCP_CMD_set_channel_id(packet, (uint16_t)id);
CSP_set_cmd_id(packet, id);
}

uint16_t CCP_get_packet_len(const CommonCmdPacket* packet)
{
return (uint16_t)(TCP_get_packet_len(packet) + TCP_PRM_HDR_LEN);
return CSP_get_packet_len(packet);
}

uint16_t CCP_get_param_len(const CommonCmdPacket* packet)
{
// ユーザーデータ長からヘッダ長を除いたものがパラメータ長
return (uint16_t)(TCP_get_packet_len(packet) - TCP_CMD_2ND_HDR_LEN - TCP_CMD_USER_HDR_LEN);
return CSP_get_param_len(packet);
}

uint16_t CCP_get_max_param_len(void)
{
return (uint16_t)(TCP_MAX_LEN - TCP_PRM_HDR_LEN - TCP_CMD_2ND_HDR_LEN - TCP_CMD_USER_HDR_LEN);
return (uint16_t)(CSP_MAX_LEN - SP_PRM_HDR_LEN - CSP_SND_HDR_LEN);
}

const uint8_t* CCP_get_param_head(const CommonCmdPacket* packet)
{
return TCP_CMD_get_param_head(packet);
return CSP_get_param_head(packet);
}

void CCP_set_param(CommonCmdPacket* packet, const uint8_t* param, uint16_t len)
{
TCP_CMD_set_param(packet, param, len);
CSP_set_param(packet, param, len);
}

void CCP_set_common_hdr(CommonCmdPacket* packet)
{
TCP_CMD_set_common_hdr(packet);
CSP_set_common_hdr(packet);
}

#pragma section
Loading

0 comments on commit 7b19192

Please sign in to comment.