Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
meltingrabbit committed Jan 26, 2022
1 parent d965f25 commit 198b7bd
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @file
* @brief SpacePacket のユーザー設定
*/
#ifndef SPACE_PACKET_PARAMS_H_
#define SPACE_PACKET_PARAMS_H_

#undef SP_TLM_MAX_LEN
#undef SP_CMD_MAX_LEN

#define SP_TLM_MAX_LEN (432)
#define SP_CMD_MAX_LEN (128)

#endif
116 changes: 58 additions & 58 deletions TlmCmd/Ccsds/TCPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#include <src_user/Library/stdint.h>

#define TCP_MAX_LEN (432u)
#define TCP_PRM_HDR_LEN (6u)
// #define TCP_MAX_LEN (432u)
// #define TCP_PRM_HDR_LEN (6u)
#define TCP_TLM_2ND_HDR_LEN (7u)
#define TCP_CMD_2ND_HDR_LEN (1u)
#define TCP_CMD_USER_HDR_LEN (8u)
Expand All @@ -19,62 +19,62 @@
#include <src_user/Settings/TlmCmd/Ccsds/apid_define.h>


/**
* @struct TCP
* @brief TCPacket or Space Packet
*/
typedef struct
{
uint8_t packet[TCP_MAX_LEN];
} TCP;

/**
* @enum TCP_VER
* @brief TCP version
* @note 3bit
*/
typedef enum
{
TCP_VER_1 = 0, // 000b: Version-1
TCP_VER_UNKNOWN
} TCP_VER;

/**
* @enum TCP_TYPE
* @brief tlm or cmd を規定
* @note 0/1の1bit
*/
typedef enum
{
TCP_TYPE_TLM = 0, // 0b: TELEMETRY
TCP_TYPE_CMD = 1 // 1b: COMMAND
} TCP_TYPE;

/**
* @enum TCP_2ND_HDR_FLAG
* @brief TCP の Secondary Header Flag の有無
* @note 0/1の1bit
*/
typedef enum
{
TCP_2ND_HDR_ABSENT = 0, // 0b: Secondary Header Absent
TCP_2ND_HDR_PRESENT = 1 // 1b: Secondary Header Present
} TCP_2ND_HDR_FLAG;

/**
* @enum TCP_SEQ_FLAG
* @brief Sequence Flag
* @note 2bit
* @note Packet Sequence Flag for each ADU もこれを用いる.
* その場合, component を segment と読み替える.
*/
typedef enum
{
TCP_SEQ_CONT = 0, // 00b: Continuation component of higher data structure.
TCP_SEQ_FIRST = 1, // 01b: First component of higher data structure.
TCP_SEQ_LAST = 2, // 10b: Last component of higher data structure.
TCP_SEQ_SINGLE = 3 // 11b: Standalone packet.
} TCP_SEQ_FLAG;
// /**
// * @struct TCP
// * @brief TCPacket or Space Packet
// */
// typedef struct
// {
// uint8_t packet[TCP_MAX_LEN];
// } TCP;

// /**
// * @enum TCP_VER
// * @brief TCP version
// * @note 3bit
// */
// typedef enum
// {
// TCP_VER_1 = 0, // 000b: Version-1
// TCP_VER_UNKNOWN
// } TCP_VER;

// /**
// * @enum TCP_TYPE
// * @brief tlm or cmd を規定
// * @note 0/1の1bit
// */
// typedef enum
// {
// TCP_TYPE_TLM = 0, // 0b: TELEMETRY
// TCP_TYPE_CMD = 1 // 1b: COMMAND
// } TCP_TYPE;

// /**
// * @enum TCP_2ND_HDR_FLAG
// * @brief TCP の Secondary Header Flag の有無
// * @note 0/1の1bit
// */
// typedef enum
// {
// TCP_2ND_HDR_ABSENT = 0, // 0b: Secondary Header Absent
// TCP_2ND_HDR_PRESENT = 1 // 1b: Secondary Header Present
// } TCP_2ND_HDR_FLAG;

// /**
// * @enum TCP_SEQ_FLAG
// * @brief Sequence Flag
// * @note 2bit
// * @note Packet Sequence Flag for each ADU もこれを用いる.
// * その場合, component を segment と読み替える.
// */
// typedef enum
// {
// TCP_SEQ_CONT = 0, // 00b: Continuation component of higher data structure.
// TCP_SEQ_FIRST = 1, // 01b: First component of higher data structure.
// TCP_SEQ_LAST = 2, // 10b: Last component of higher data structure.
// TCP_SEQ_SINGLE = 3 // 11b: Standalone packet.
// } TCP_SEQ_FLAG;

/**
* @enum TCP_CMD_FMT_ID
Expand Down
13 changes: 13 additions & 0 deletions TlmCmd/Ccsds/cmd_space_packet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma section REPRO
/**
* @file
* @brief CCSDS で規定される Space Packet の コマンド版の実装
* @brief C ではテンプレートが使えないため,別で定義する
* @note 詳細は space_packet.h を参照
*/

#include "cmd_space_packet.h"
#include "space_packet.h"


#pragma section
75 changes: 75 additions & 0 deletions TlmCmd/Ccsds/cmd_space_packet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* @file
* @brief CCSDS で規定される Space Packet の コマンド版の実装
* @brief C ではテンプレートが使えないため,別で定義する
* @note 詳細は space_packet.h を参照
* @note packet 構造
* |---------+-------+-------+------------------|
* | Pos | Pos | size | name |
* | [octet] | [bit] | [bit] | |
* |---------+-------+-------+------------------|
* | === Primary Header ======================= |
* |---------+-------+-------+------------------|
* | 0 | 0 | 3 | Version No |
* | 0 | 3 | 1 | Packet Type |
* | 0 | 4 | 1 | Sec. HDR Flag |
* | 0 | 5 | 11 | APID |
* | 2 | 0 | 2 | Sequence Flags |
* | 2 | 2 | 14 | Sequence Count |
* | 4 | 0 | 16 | Packet Data Len |
* |---------+-------+-------+------------------|
* | === Secondary Header ===================== |
* |---------+-------+-------+------------------|
* | 6 | 0 | 8 | Format ID | // TODO: これ,必要? 今後, Tlm と同様に, Version No にしたい?
* | 7 | 0 | 8 | Cmd Type |
* | 8 | 0 | 16 | Cmd ID |
* | 10 | 0 | 8 | Execution Type |
* | 11 | 0 | 32 | Time Indicator |
* |---------+-------+-------+------------------|
* | === User Data Field ====================== |
* |---------+-------+-------+------------------|
* | 15 | 0 | * | Cmd Param #0 |
* | * | 0 | * | Cmd Param #1 |
* | * | 0 | * | Cmd Param #2 |
* | * | 0 | * | ... |
* |---------+-------+-------+------------------|
*/
#ifndef CMD_SPACE_PACKET_H_
#define CMD_SPACE_PACKET_H_

// FIXME: 拡張性の高いように, Secondary Heaer の定義などを直していく
// https://github.com/ut-issl/c2a-core/issues/155

#include <src_user/Library/stdint.h>

#define SP_CMD_MAX_LEN (128) //!< CmdSpacePacket の最大パケット長.値は適当においている

// SP_CMD_MAX_LEN を再定義
#include <src_user/Settings/TlmCmd/Ccsds/space_packet_params.h>
// ここで APID を定義する
// 詳細は common_tlm_cmd_packet.h を参照
#include <src_user/Settings/TlmCmd/Ccsds/apid_define.h>

// TODO: 上に持ってきて,コンパイルが通らないことを確認する!!!!!!!!!!!!!!!!!!
// space_packet.h と相互 include になってしまっているので,最後のここで include する
#include "space_packet.h"

#if SP_CMD_MAX_LEN <= SP_PRM_HDR_LEN
#error SP_CMD_MAX_LEN is too small
#endif


/**
* @struct CmdSpacePacket
* @brief Space Packet (コマンド用)
* @note C ではテンプレートが使えないため,別で定義する
* https://github.com/ut-issl/c2a-core/issues/204
*/
typedef struct
{
uint8_t packet[SP_CMD_MAX_LEN];
} CmdSpacePacket;



#endif
102 changes: 102 additions & 0 deletions TlmCmd/Ccsds/space_packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,111 @@
* CommonCmdPacket -> CmdSpacePacket
* @note Packet Secondary Header は C2A 独自定義. いくつかのバージョンを用意している
* @note /Docs/Core/communication.md などを参照
* @note packet 構造
* |---------+-------+-------+------------------|
* | Pos | Pos | size | name |
* | [octet] | [bit] | [bit] | |
* |---------+-------+-------+------------------|
* | === Primary Header ======================= |
* |---------+-------+-------+------------------|
* | 0 | 0 | 3 | Version No |
* | 0 | 3 | 1 | Packet Type |
* | 0 | 4 | 1 | Sec. HDR Flag |
* | 0 | 5 | 11 | APID |
* | 2 | 0 | 2 | Sequence Flags |
* | 2 | 2 | 14 | Sequence Count |
* | 4 | 0 | 16 | Packet Data Len |
* |---------+-------+-------+------------------|
* | === Secondary Header ===================== |
* |---------+-------+-------+------------------|
* | 6 | 0 | * | User Defined |
* |---------+-------+-------+------------------|
* | === User Data Field ====================== |
* |---------+-------+-------+------------------|
* | * | 0 | * | User Defined |
* |---------+-------+-------+------------------|
*/
#ifndef SPACE_PACKET_H_
#define SPACE_PACKET_H_

#include "tlm_space_packet.h"
#include "cmd_space_packet.h"

#if SP_TLM_MAX_LEN > SP_CMD_MAX_LEN
#define SP_MAX_LEN SP_TLM_MAX_LEN
#else
#define SP_MAX_LEN SP_CMD_MAX_LEN
#endif

#define SP_PRM_HDR_LEN (6) //!< Packet Primary Header 長


/**
* @enum SP_VER
* @brief Space Packet Version Number
* @note 3 bit
*/
typedef enum
{
SP_VER_1 = 0, //!< 000b: Version-1
SP_VER_UNKNOWN
} SP_VER;

/**
* @enum SP_TYPE
* @brief Space Packet Type
* @note tlm or cmd を規定
* @note 0/1の 1 bit
*/
typedef enum
{
SP_TYPE_TLM = 0, //!< 0b: TELEMETRY
SP_TYPE_CMD = 1 //!< 1b: COMMAND
} SP_TYPE;

/**
* @enum SP_2ND_HDR_FLAG
* @brief Space Packet Secandary Header Flag
* @note Secondary Header の有無
* @note 0/1 の 1 bit
*/
typedef enum
{
SP_2ND_HDR_FLAG_ABSENT = 0, //!< 0b: Secondary Header Absent
SP_2ND_HDR_FLAG_PRESENT = 1 //!< 1b: Secondary Header Present
} SP_2ND_HDR_FLAG;

/**
* @enum SP_SEQ_FLAG
* @brief Space Packet Sequence Flag
* @note 2 bit
// FIXME
// * @note Packet Sequence Flag for each ADU もこれを用いる.
// * その場合, component を segment と読み替える.
*/
typedef enum
{
SP_SEQ_FLAG_CONT = 0, //!< 00b: Continuation component of higher data structure
SP_SEQ_FLAG_FIRST = 1, //!< 01b: First component of higher data structure
SP_SEQ_FLAG_LAST = 2, //!< 10b: Last component of higher data structure
SP_SEQ_FLAG_SINGLE = 3 //!< 11b: Standalone packet
} SP_SEQ_FLAG;


/**
* @struct SpacePacket
* @brief Space Packet
*/
typedef struct
{
uint8_t packet[SP_MAX_LEN];
} SpacePacket;








#endif
13 changes: 13 additions & 0 deletions TlmCmd/Ccsds/tlm_space_packet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma section REPRO
/**
* @file
* @brief CCSDS で規定される Space Packet の テレメ版の実装
* @brief C ではテンプレートが使えないため,別で定義する
* @note 詳細は space_packet.h を参照
*/

#include "tlm_space_packet.h"
#include "space_packet.h"


#pragma section
Loading

0 comments on commit 198b7bd

Please sign in to comment.