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

Refactor driver directory structure #122

Merged
merged 7 commits into from
Oct 12, 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: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ set(C2A_CORE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

set(C2A_SRCS
c2a_core_main.c
Drivers/Protocol/common_tlm_cmd_packet_for_driver_super.c
Drivers/Protocol/eb90_frame_for_driver_super.c
Drivers/Protocol/eb90_packet_for_driver_super.c
Drivers/Super/driver_super.c
driver/common_tlm_cmd_packet_for_driver_super.c
driver/eb90_frame_for_driver_super.c
driver/eb90_packet_for_driver_super.c
driver/driver_super.c
meltingrabbit marked this conversation as resolved.
Show resolved Hide resolved
hal/i2c_common.c
system/application_manager/app_info.c
system/application_manager/app_manager.c
Expand Down
14 changes: 7 additions & 7 deletions docs/driver/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
## Driver
### 概要
Driver とは,各コンポーネントとの通信において, HW 依存部分を吸収するためのレイヤーである.
[DriverSuper](https://github.com/arkedge/c2a-core/blob/develop/Drivers/Super/) と呼ばれる共通の IF を各ドライバが継承することで,統一的で安全な実装が可能になる.
[DriverSuper](https://github.com/arkedge/c2a-core/blob/develop/driver/driver_super.h) と呼ばれる共通の IF を各ドライバが継承することで,統一的で安全な実装が可能になる.

また,これを Application へと抽象化したものが, Application Layer にある DI (Driver Instance) である.

実装方法は,基本的には [driver_super.h](https://github.com/arkedge/c2a-core/blob/develop/Drivers/Super/driver_super.h) をみればわかるようにしてあるが,現時点で
実装方法は,基本的には [driver_super.h](https://github.com/arkedge/c2a-core/blob/develop/driver/driver_super.h) をみればわかるようにしてあるが,現時点で

- UART test: https://github.com/arkedge/c2a-core/blob/develop/examples/mobc/src/src_user/Drivers/Etc/uart_test.c
- GS: https://github.com/arkedge/c2a-core/blob/develop/examples/mobc/src/src_user/Drivers/Com/gs.c
- UART test: https://github.com/arkedge/c2a-core/blob/develop/examples/mobc/src/src_user/driver/etc/uart_test.c
- GS: https://github.com/arkedge/c2a-core/blob/develop/examples/mobc/src/src_user/driver/com/gs.c
- C2A 間通信:
- https://github.com/arkedge/c2a-core/blob/develop/examples/mobc/src/src_user/Drivers/Aocs/aobc.c
- https://github.com/arkedge/c2a-core/blob/develop/examples/subobc/src/src_user/Drivers/Etc/mobc.c
- https://github.com/arkedge/c2a-core/blob/develop/examples/mobc/src/src_user/driver/aocs/aobc.c
- https://github.com/arkedge/c2a-core/blob/develop/examples/subobc/src/src_user/driver/etc/mobc.c

が実装されているので,それを参考のこと.
`load_init_setting` については下を参照.
Expand Down Expand Up @@ -43,7 +43,7 @@ typedef struct

## DriverSuper
### テレメとしておろしてもいいのではないかなと思う DriverSuper のメンバ
[driver_super.h](https://github.com/arkedge/c2a-core/blob/develop/Drivers/Super/driver_super.h) のメンバから抜粋する.
[driver_super.h](https://github.com/arkedge/c2a-core/blob/develop/driver/driver_super.h) のメンバから抜粋する.

`DriverSuper` の最上位には特に重要な情報はないので, `DriverSuper` の使っているstreamの `stream_config` のメンバを下ろす.
具体的には以下.( FIXME: 2021/12/04 現在,だいぶ情報が古い)
Expand Down
4 changes: 2 additions & 2 deletions docs/tips/parameter_settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ DriverSuperを継承したDriver数: 4
```

#### 定義
- core: [`/src_core/Drivers/Super/DriverSuper.h`](https://github.com/arkedge/c2a-core/blob/develop/Drivers/Super/DriverSuper.h)
- core: [`/src_core/driver/driver_super.h`](https://github.com/arkedge/c2a-core/blob/develop/driver/driver_super.h)
- user: `/src_user/Settings/DriverSuper/driver_super_params.h`

#### 詳細説明
[`/src_core/Drivers/Super/DriverSuper.h`](https://github.com/arkedge/c2a-core/blob/develop/Drivers/Super/DriverSuper.h) を参照.
[`/src_core/driver/Super/DriverSuper.h`](https://github.com/arkedge/c2a-core/blob/develop/driver/driver_super.h) を参照.


## メモリ使用量にあまり影響しない設定
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#define COMMON_TLM_CMD_PACKET_FOR_DRIVER_SUPER_H_

#include <stdint.h>
#include "../Super/driver_super.h"
#include "../../tlm_cmd/common_tlm_cmd_packet.h"
#include "driver_super.h"
#include "../tlm_cmd/common_tlm_cmd_packet.h"

/**
* @brief CommonTlmCmdPacket を受信データからコピーして取得する
Expand Down
4 changes: 2 additions & 2 deletions Drivers/Super/driver_super.c → driver/driver_super.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
*/

#include "driver_super.h"
#include "../../library/print.h"
#include "../library/print.h"
#include <string.h> // for memset などの mem 系
#include <stddef.h> // for NULL
#include "../../tlm_cmd/common_cmd_packet_util.h"
#include "../tlm_cmd/common_cmd_packet_util.h"

// #define DS_DEBUG // 適切なときにコメントアウトする
// #define DS_DEBUG_SHOW_REC_DATA // 適切なときにコメントアウトする
Expand Down
4 changes: 2 additions & 2 deletions Drivers/Super/driver_super.h → driver/driver_super.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

#include <src_user/hal/if_list.h>
#include <stdint.h>
#include "../../library/endian.h" // パスが不定な自動生成コード類で使えるように
#include "../../system/time_manager/time_manager.h"
#include "../library/endian.h" // パスが不定な自動生成コード類で使えるように
#include "../system/time_manager/time_manager.h"

#define DS_STREAM_MAX (3) /*!< DS_StreamConfig の最大数
uint8_t を想定 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* @brief コンポ間通信などで標準的に使う データリンク層 の EB90 Frame
*/
#include "eb90_frame_for_driver_super.h"
#include "../../library/endian.h"
#include "../../library/crc.h"
#include "../library/endian.h"
#include "../library/crc.h"

const uint8_t EB90_FRAME_kStx[EB90_FRAME_STX_SIZE] = {EB90_FRAME_STX_1ST_BYTE, EB90_FRAME_STX_2ND_BYTE};
const uint8_t EB90_FRAME_kEtx[EB90_FRAME_ETX_SIZE] = {EB90_FRAME_ETX_1ST_BYTE, EB90_FRAME_ETX_2ND_BYTE};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define EB90_FRAME_FOR_DRIVER_SUPER_H_

#include <stdint.h>
#include "../Super/driver_super.h"
#include "driver_super.h"

#define EB90_FRAME_STX_SIZE (2) //!< EB90 Frame の STX のサイズ
#define EB90_FRAME_ETX_SIZE (2) //!< EB90 Frame の ETX のサイズ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
#include "eb90_packet_for_driver_super.h"
#include "eb90_frame_for_driver_super.h"
#include "../../library/endian.h"
#include "../library/endian.h"

// FIXME: DS_StreamConfig.data_link_layer_ をちゃんと見る!

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

#include <stdint.h>
#include "../Super/driver_super.h"
#include "driver_super.h"

#define EB90_PACKET_HEADER_SIZE (4) //!< EB90 Packet のヘッダサイズ

Expand Down
2 changes: 1 addition & 1 deletion enum-loader/c2aenum/enum_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, c2a_src_path, encoding):
self.search_dirs = [
"/src_user/",
"/src_core/applications/",
"/src_core/Drivers/",
"/src_core/driver/",
"/src_core/hal/",
"/src_core/library/",
"/src_core/system/",
Expand Down
2 changes: 1 addition & 1 deletion hal/i2c_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef I2C_COMMON_H_
#define I2C_COMMON_H_

#include "../Drivers/Super/driver_super.h"
#include "../driver/driver_super.h"
#include "i2c.h"

/**
Expand Down
2 changes: 1 addition & 1 deletion script/add_section/settings.pl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sub GetSetting {
$SETTING{'LOG_FILE'} = './log.log';
$SETTING{'SEARCH_PATH'} = [
'applications',
'Drivers',
'driver',
'hal',
'library',
'System',
Expand Down
2 changes: 1 addition & 1 deletion script/ci/check_encoding.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"target_dirs" : [
"applications/",
"Drivers/",
"driver/",
"hal/",
"library/",
"System/",
Expand Down
48 changes: 48 additions & 0 deletions script/migration/v4-rename-driver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
# Script -> script

## c2a-core ref
echo "rename c2a-core ref: Drivers -> driver"
find . -name "*" -not -path "*/.git/*" -type f -print0 | xargs -0 sed -i -e "s#src_core/Drivers/Super#src_core/driver#g"
find . -name "*" -not -path "*/.git/*" -type f -print0 | xargs -0 sed -i -e "s#src_core\\\Drivers\\\Super#src_core\\\driver#g"

find . -name "*" -not -path "*/.git/*" -type f -print0 | xargs -0 sed -i -e "s#src_core/Drivers/Protocol#src_core/driver#g"
find . -name "*" -not -path "*/.git/*" -type f -print0 | xargs -0 sed -i -e "s#src_core\\\Drivers\\\Protocol#src_core\\\driver#g"

find . -name "*" -not -path "*/.git/*" -type f -print0 | xargs -0 sed -i -e "s#src_core/Drivers#src_core/driver#g"
find . -name "*" -not -path "*/.git/*" -type f -print0 | xargs -0 sed -i -e "s#src_core\\\Drivers#src_core\\\driver#g"

find . -name "*" -not -path "*/.git/*" -type f -print0 | xargs -0 sed -i -e "s#\${C2A_CORE_DIR}/Drivers#\${C2A_CORE_DIR}/driver#g"

# C2A user code
echo "rename C2A user code: Drivers -> driver"
mv src/src_user/Drivers src/src_user/driver

find . -name "*" -not -path "*/.git/*" -type f -print0 | xargs -0 sed -i -e "s#\${C2A_USER_DIR}/Drivers#\${C2A_USER_DIR}/driver#g"

drv_org=("Aocs" "Cdh" "Com" "Etc" "Mission" "Power" "Prop" "Thermal")
drv_new=("aocs" "cdh" "com" "etc" "mission" "power" "prop" "thermal")

echo "rename dir: driver/Drivers -> driver/driver"
for ((i=0; i<${#drv_org[@]}; i++)); do
echo " driver/${drv_org[i]} -> driver/${drv_new[i]}"
mv src/src_user/driver/${drv_org[i]} src/src_user/driver/${drv_new[i]}
done

echo "rename ref: Drivers -> driver"
for ((i=0; i<${#drv_org[@]}; i++)); do
echo " Driver/${drv_org[i]} -> driver/${drv_new[i]}"

find . -name "*" -not -path "*/.git/*" -type f -print0 | xargs -0 sed -i -e "s#Drivers/${drv_org[i]}#driver/${drv_new[i]}#g"
find . -name "*" -not -path "*/.git/*" -type f -print0 | xargs -0 sed -i -e "s#Drivers\\\${drv_org}#driver\\\${drv_new}#g"
done

# CMake
for ((i=0; i<${#drv_org[@]}; i++)); do
echo "rename ref: ${drv_org[i]} -> ${drv_new[i]}"

find . -name "*" -not -path "*/.git/*" -type f -print0 | xargs -0 sed -i -e "s#${drv_org[i]}/#${drv_new[i]}/#g"
done

# Script
find src/src_user/script -name "*" -not -path "*/.git/*" -type f -print0 | xargs -0 sed -i -e "s#Drivers#driver#g"
4 changes: 2 additions & 2 deletions tlm-cmd-code-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ $ python GenerateC2ACode.py
"path_to_db" : "../../c2a_sample_aobc/database/",
# MOBC で保持するテレメの TLM ID の最大値(=テレメ種類数)
"max_tlm_num" : 256,
"driver_path" : "Aocs/",
"driver_path" : "aocs/",
"driver_type" : "AOBC_Driver",
"driver_name" : "aobc",
"code_when_tlm_not_found" : "aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_TLM_NOT_FOUND;"
Expand All @@ -77,7 +77,7 @@ $ python GenerateC2ACode.py
"path_to_db" : ""../../c2a_sample_tobc/database/",
# MOBC で保持するテレメの TLM ID の最大値(=テレメ種類数)
"max_tlm_num" : 256,
"driver_path" : "Thermal/",
"driver_path" : "thermal/",
"driver_type" : "TOBC_Driver",
"driver_name" : "tobc",
"code_when_tlm_not_found" : "tobc_driver->info.comm.rx_err_code = TOBC_RX_ERR_CODE_TLM_NOT_FOUND;"
Expand Down
2 changes: 1 addition & 1 deletion tlm-cmd-code-generator/my_mod/cmd_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def GenerateOtherObcCmdDef(settings, other_obc_dbs):
# print(body_h)
output_file_path = (
settings["path_to_src"]
+ r"src_user/Drivers/"
+ r"src_user/driver/"
+ settings["other_obc_data"][i]["driver_path"]
+ name_lower
+ "_command_definitions.h"
Expand Down
6 changes: 3 additions & 3 deletions tlm-cmd-code-generator/my_mod/tlm_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs):

output_file_path = (
settings["path_to_src"]
+ r"src_user/Drivers/"
+ r"src_user/driver/"
+ settings["other_obc_data"][i]["driver_path"]
)
OutputTlmBufferC_(
Expand Down Expand Up @@ -368,7 +368,7 @@ def OutputTlmBufferC_(file_path, name, body, settings):
* @brief テレメトリバッファー(テレメ中継)
* @note このコードは自動生成されています!
*/
#include <src_core/Drivers/Protocol/common_tlm_cmd_packet_for_driver_super.h>
#include <src_core/driver/common_tlm_cmd_packet_for_driver_super.h>
#include "./{_obc_name_lower}_telemetry_definitions.h"
#include "./{_obc_name_lower}_telemetry_buffer.h"
#include "./{_obc_name_lower}.h"
Expand Down Expand Up @@ -410,7 +410,7 @@ def OutputTlmBufferH_(file_path, name, body, settings):
#define {_obc_name_upper}_TELEMETRY_BUFFER_H_

#include "./{_obc_name_lower}_telemetry_definitions.h"
#include <src_core/Drivers/Super/driver_super.h>
#include <src_core/driver/driver_super.h>
#include <src_core/tlm_cmd/common_tlm_packet.h>
#include <src_core/tlm_cmd/telemetry_frame.h>

Expand Down
2 changes: 1 addition & 1 deletion tlm-cmd-code-generator/my_mod/tlm_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def GenerateOtherObcTlmDef(settings, other_obc_dbs):
)
output_file_path = (
settings["path_to_src"]
+ r"src_user/Drivers/"
+ r"src_user/driver/"
+ settings["other_obc_data"][i]["driver_path"]
+ obc_name.lower()
+ "_telemetry_definitions.h"
Expand Down
2 changes: 1 addition & 1 deletion tlm-cmd-code-generator/settings_mobc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"input_file_encoding" : "utf-8",
"path_to_db" : "../examples/subobc/src/src_user/Settings/tlm_cmd/data_base/",
"max_tlm_num" : 256,
"driver_path" : "Aocs/",
"driver_path" : "aocs/",
"driver_type" : "AOBC_Driver",
"driver_name" : "aobc_driver",
"code_when_tlm_not_found" : "aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_TLM_NOT_FOUND;"
Expand Down
Loading