Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M_PDU をコード規約に合わせるなどのリファクタ #197

Merged
merged 8 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
### Fixed

- [#193](https://github.com/arkedge/c2a-core/pull/193): VCDU を AOS transfer frame に rename する
- [#197](https://github.com/arkedge/c2a-core/pull/197): M_PDU をコード規約に合わせるなどのリファクタ

### Migration Guide
- [#193](https://github.com/arkedge/c2a-core/pull/193): 影響範囲は MOBC のみ
1. `src_user/tlm_cmd/ccsds/vcdu.{c,h}` を消し,`src_user/tlm_cmd/ccsds/aos_transfer_frame.{c,h}` を `examples/mobc` からコピーする.CMakeLists.txt も修正する.
1. `src_user/tlm_cmd/ccsds/vcdu.{c,h}` を消し,`src_user/tlm_cmd/ccsds/aos_transfer_frame.{c,h}` を `examples/mobc` からコピーする. `CMakeLists.txt` も修正する.
1. `VCDU` を `AOSTF` に置換する(TLM DB の csv なども).
1. `vcdu` を `aostf` に置換する(TLM DB の csv なども).
1. `vcdu.h` を `aos_transfer_frame.h` に置換する(include の修正).
1. コンパイルが通らないところを直す.想定されるものは以下.
- `VCDU` 構造体 が `AosTransferFrame` 構造体に変わったので,変数定義の型名が変わっているはず.
- [#197](https://github.com/arkedge/c2a-core/pull/197): 影響範囲は MOBC のみ
1. `src_user/tlm_cmd/ccsds/m_pdu.{c,h}` を消し,`src_user/tlm_cmd/ccsds/multiplexing_protocol_data_unit.{c,h}` を `examples/mobc` からコピーする. `CMakeLists.txt` も修正する.
1. `m_pdu.h` を `multiplexing_protocol_data_unit.h` に置換する(include の修正).
1. コンパイルが通らないところを直す.想定されるものは以下.
- `M_PDU` 構造体 が `MultiplexingProtocolDataUnit` 構造体に変わったので,変数定義の型名が変わっているはず.

## v4.0.1 (2023-11-09)

Expand Down
2 changes: 1 addition & 1 deletion examples/mobc/src/src_user/tlm_cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(C2A_SRCS
normal_block_command_definition/nbc_respond_eh_for_test.c
normal_block_command_definition/nbc_test_bcl.c
ccsds/aos_transfer_frame.c
ccsds/m_pdu.c
ccsds/multiplexing_protocol_data_unit.c
ccsds/tc_transfer_frame.c
ccsds/tcp_to_m_pdu.c
ccsds/tc_segment.c
Expand Down
8 changes: 4 additions & 4 deletions examples/mobc/src/src_user/tlm_cmd/ccsds/aos_transfer_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#ifndef AOS_TRANSFER_FRAME_H_
#define AOS_TRANSFER_FRAME_H_

#include "m_pdu.h"
#include "multiplexing_protocol_data_unit.h"

#define AOSTF_HEADER_SIZE (6u)
#define AOSTF_TRAILER_SIZE (4u)
Expand All @@ -49,9 +49,9 @@

typedef struct
{
uint8_t header[AOSTF_HEADER_SIZE];
M_PDU m_pdu;
uint8_t trailer[AOSTF_TRAILER_SIZE];
uint8_t header[AOSTF_HEADER_SIZE];
MultiplexingProtocolDataUnit m_pdu;
uint8_t trailer[AOSTF_TRAILER_SIZE];
} AosTransferFrame;

typedef enum
Expand Down
42 changes: 0 additions & 42 deletions examples/mobc/src/src_user/tlm_cmd/ccsds/m_pdu.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#pragma section REPRO
#include "m_pdu.h"

/**
* @file
* @brief CCSDS で規定される M_PDU (Multiplexing Protocol Data Unit) の実装
* @note 詳細は multiplexing_protocol_data_unit.h を参照
*/
#include "multiplexing_protocol_data_unit.h"
#include "string.h" // for memcpy

static void M_PDU_clear_spare_(M_PDU* m_pdu);
static void M_PDU_clear_spare_(MultiplexingProtocolDataUnit* m_pdu);

void M_PDU_generate_byte_stream(const M_PDU* m_pdu,
uint8_t byte_stream[M_PDU_LEN])
void M_PDU_generate_byte_stream(const MultiplexingProtocolDataUnit* m_pdu, uint8_t byte_stream[M_PDU_LEN])
{
memcpy(byte_stream, m_pdu->header, M_PDU_HEADER_SIZE);
byte_stream += M_PDU_HEADER_SIZE;

memcpy(byte_stream, m_pdu->data, M_PDU_DATA_SIZE);
}

void M_PDU_setup_idle_m_pdu(M_PDU* m_pdu)
void M_PDU_setup_idle_m_pdu(MultiplexingProtocolDataUnit* m_pdu)
{
static uint8_t temp_fill_aostf_data_[432] = {
0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
Expand Down Expand Up @@ -50,15 +52,15 @@ void M_PDU_setup_idle_m_pdu(M_PDU* m_pdu)
memcpy(&m_pdu->data[0], &temp_fill_aostf_data_[0], 432);
}

static void M_PDU_clear_spare_(M_PDU* m_pdu)
static void M_PDU_clear_spare_(MultiplexingProtocolDataUnit* m_pdu)
{
unsigned int pos = 0;
uint8_t mask = 0xf8; // 11111000b

m_pdu->header[pos] &= (uint8_t)(~mask);
}

uint16_t M_PDU_get_1st_hdr_ptr(const M_PDU* m_pdu)
uint16_t M_PDU_get_1st_hdr_ptr(const MultiplexingProtocolDataUnit* m_pdu)
{
unsigned int pos = 0;
uint8_t mask = 0x3f; // 00111111b
Expand All @@ -70,8 +72,7 @@ uint16_t M_PDU_get_1st_hdr_ptr(const M_PDU* m_pdu)
return ptr;
}

void M_PDU_set_1st_hdr_ptr(M_PDU* m_pdu,
uint16_t ptr)
void M_PDU_set_1st_hdr_ptr(MultiplexingProtocolDataUnit* m_pdu, uint16_t ptr)
{
unsigned int pos = 0;
uint8_t mask = 0x3f; // 00111111b
Expand All @@ -81,10 +82,7 @@ void M_PDU_set_1st_hdr_ptr(M_PDU* m_pdu,
m_pdu->header[pos + 1] = (uint8_t)(ptr & 0xff);
}

void M_PDU_set_data(M_PDU* m_pdu,
const uint8_t* data,
size_t offset,
size_t len)
void M_PDU_set_data(MultiplexingProtocolDataUnit* m_pdu, const uint8_t* data, size_t offset, size_t len)
{
// 指定されたデータ長が上限値を超過する場合は上限値に制限
if (offset + len > M_PDU_DATA_SIZE)
Expand All @@ -95,4 +93,5 @@ void M_PDU_set_data(M_PDU* m_pdu,
// offset以降にデータを書き込む
memcpy(m_pdu->data + offset, data, len);
}

#pragma section
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* @file
* @brief CCSDS で規定される M_PDU (Multiplexing Protocol Data Unit) の実装
* @note packet 構造
* |---------+-------+-------+--------------------------|
* | Pos | Pos | Size | Name |
* | [octet] | [bit] | [bit] | |
* |---------+-------+-------+--------------------------|
* | === Header ========================================|
* |---------+-------+-------+--------------------------|
* | 0 | 0 | 5 | Reserved Spare |
* | 0 | 5 | 11 | First Header Pointer |
* |---------+-------+-------+--------------------------|
* | === Packet Zone ===================================|
* |---------+-------+-------+--------------------------|
* | 2 | 0 | * | いくつかの Space Packet |
* |---------+-------+-------+--------------------------|
*/
#ifndef MULTIPLEXING_PROTOCOL_DATA_UNIT_H_
#define MULTIPLEXING_PROTOCOL_DATA_UNIT_H_

#include <stddef.h>
#include <stdint.h>

#define M_PDU_HEADER_SIZE (2u)
#define M_PDU_DATA_SIZE (432u)
#define M_PDU_LEN (M_PDU_HEADER_SIZE + M_PDU_DATA_SIZE)

typedef struct
{
uint8_t header[M_PDU_HEADER_SIZE];
uint8_t data[M_PDU_DATA_SIZE];
} MultiplexingProtocolDataUnit;

typedef enum
{
M_PDU_PTR_NO_HDR = 0x07ff, // 11111111111b
M_PDU_PTR_IDLE = 0x7fe // 11111111110b
} M_PDU_PTR;

void M_PDU_generate_byte_stream(const MultiplexingProtocolDataUnit* m_pdu, uint8_t byte_stream[M_PDU_LEN]);

void M_PDU_setup_idle_m_pdu(MultiplexingProtocolDataUnit* m_pdu);

uint16_t M_PDU_get_1st_hdr_ptr(const MultiplexingProtocolDataUnit* m_pdu);

void M_PDU_set_1st_hdr_ptr(MultiplexingProtocolDataUnit* m_pdu, uint16_t ptr);

// FIXME: 存在しなかったためコメントアウトした
// const uint8_t* M_PDU_get_data_head(const MultiplexingProtocolDataUnit* m_pdu);

void M_PDU_set_data(MultiplexingProtocolDataUnit* m_pdu, const uint8_t* data, size_t offset, size_t len);

#endif
3 changes: 2 additions & 1 deletion examples/mobc/src/src_user/tlm_cmd/ccsds/tcp_to_m_pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/**
* @file
* @brief PacketList から TCPacket を取ってきてそれを送信可能な M_PDU へと変換する
* @note FIXME: これはリファクタしてなんとかしたい・・・
*/

#include "tcp_to_m_pdu.h"
Expand All @@ -23,7 +24,7 @@ void T2M_initialize(TcpToMPdu* tcp_to_m_pdu)
return;
}

T2M_ACK T2M_form_m_pdu(TcpToMPdu* tcp_to_m_pdu, PacketList* pl, M_PDU* m_pdu)
T2M_ACK T2M_form_m_pdu(TcpToMPdu* tcp_to_m_pdu, PacketList* pl, MultiplexingProtocolDataUnit* m_pdu)
{
// M_PDUが完成する or TC Packetがなくなるまで実施
while (tcp_to_m_pdu->m_pdu_wp != M_PDU_DATA_SIZE)
Expand Down
5 changes: 3 additions & 2 deletions examples/mobc/src/src_user/tlm_cmd/ccsds/tcp_to_m_pdu.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @file
* @brief PacketList から TCPacket を取ってきてそれを送信可能な M_PDU へと変換する
* @note FIXME: これはリファクタしてなんとかしたい・・・
*/
#ifndef TCP_TO_M_PDU_H_
#define TCP_TO_M_PDU_H_
Expand All @@ -10,7 +11,7 @@
#include <stddef.h> // for size_t

#include <src_core/tlm_cmd/packet_list.h>
#include "m_pdu.h"
#include "multiplexing_protocol_data_unit.h"
#include <src_core/system/time_manager/time_manager.h>

/**
Expand Down Expand Up @@ -52,6 +53,6 @@ void T2M_initialize(TcpToMPdu* tcp_to_m_pdu);
* @param[out] m_pdu: 生成される M_PDU
* @return T2M_ACK
*/
T2M_ACK T2M_form_m_pdu(TcpToMPdu* tcp_to_m_pdu, PacketList* pl, M_PDU* m_pdu);
T2M_ACK T2M_form_m_pdu(TcpToMPdu* tcp_to_m_pdu, PacketList* pl, MultiplexingProtocolDataUnit* m_pdu);

#endif
Loading