From 55386ecd992de3bb7fb543ecc61896ade0ee3214 Mon Sep 17 00:00:00 2001 From: flap1 Date: Wed, 8 Jun 2022 18:43:49 +0900 Subject: [PATCH 1/6] support linux --- .../src/src_user/IfWrapper/CMakeLists.txt | 2 + .../IfWrapper/Sils/ccsds_sils_sci_if.cpp | 98 +--------- .../IfWrapper/Sils/ccsds_sils_sci_if.hpp | 20 +- .../src_user/IfWrapper/Sils/sils_sci_if.cpp | 181 ++++++++++++++++++ .../src_user/IfWrapper/Sils/sils_sci_if.hpp | 41 ++++ .../IfWrapper/Sils/uart_sils_sci_if.cpp | 98 +--------- .../IfWrapper/Sils/uart_sils_sci_if.hpp | 16 +- Script/CI/check_coding_rule.json | 3 +- 8 files changed, 250 insertions(+), 209 deletions(-) create mode 100644 Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp create mode 100644 Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.hpp diff --git a/Examples/minimum_user/src/src_user/IfWrapper/CMakeLists.txt b/Examples/minimum_user/src/src_user/IfWrapper/CMakeLists.txt index bd5328f01..b26829c84 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/CMakeLists.txt +++ b/Examples/minimum_user/src/src_user/IfWrapper/CMakeLists.txt @@ -31,6 +31,7 @@ if(USE_SCI_COM_WINGS AND NOT USE_SILS_MOCKUP) add_definitions(-DUSE_SCI_COM_WINGS) #target_sources(${PROJECT_NAME} PUBLIC list(APPEND C2A_SRCS + Sils/sils_sci_if.cpp Sils/ccsds_sils_sci_if.cpp ) message("USE SCI_COM_WINGS") @@ -40,6 +41,7 @@ if(USE_SCI_COM_UART AND NOT USE_SILS_MOCKUP) add_definitions(-DUSE_SCI_COM_UART) #target_sources(${PROJECT_NAME} PUBLIC list(APPEND C2A_SRCS + Sils/sils_sci_if.cpp Sils/uart_sils_sci_if.cpp ) message("USE SCI_COM_UART") diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.cpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.cpp index 6a40e5e53..ba77df80e 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.cpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.cpp @@ -3,15 +3,17 @@ * @file * @brief ccsds_sils_sci_if * @details WINGS TMTC IFとCCSDSのTransfer FrameをSCI COMでやりとりするIF - Windows上でcom0comを使うことを想定 - SCIComPort classは基本的にEQU ZEUSのコードを流用 */ #include "ccsds_sils_sci_if.hpp" // 最初だけ初期化して、プログラム終了時にポートを閉じるようにしたい -static SCIComPort sci_com_; +#ifdef WIN32 +static SCIComPortCcsds SILS_SCI_IF_sci_com_(11); +#else +static SCIComPortCcsds SILS_SCI_IF_sci_com_(1); +#endif int SILS_SIC_IF_init(void) { @@ -20,99 +22,13 @@ int SILS_SIC_IF_init(void) int SILS_SIC_IF_TX(unsigned char* data_v, int count) { - sci_com_.Send(data_v, 0, count); + SILS_SCI_IF_sci_com_.Send(data_v, 0, count); return 0; } int SILS_SIC_IF_RX(unsigned char* data_v, int count) { - return sci_com_.Receive(data_v, 0, count); -} - - -SCIComPort::SCIComPort(void) -{ - // ビルド通らなかったので,ZEUSからちょっと変えた - myHComPort_ = CreateFile("\\\\.\\COM11", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - - if ((int)myHComPort_ == -1) - { - // 正常にポートオープンできていない場合は終了 - CloseHandle(myHComPort_); - init_success = false; - return; - } - - // どうやら正常ポートopenにならないっぽく,これが必要 - init_success = true; - - // ポートのボーレート、パリティ等を設定 - config_.BaudRate = 115200; - config_.Parity = PARITY_NONE; - config_.ByteSize = 8; - config_.StopBits = STOPBITS_10; - - // Parity、StopBits、DataBitsも同様に設定 - SetCommState(myHComPort_, &config_); -} - -SCIComPort::~SCIComPort(void) -{ - if (init_success == true) - { - CloseHandle(myHComPort_); - } -} - -int SCIComPort::Send(unsigned char* buffer, size_t offset, size_t count) -{ - DWORD toWriteBytes = count; // 送信したいバイト数 - DWORD writeBytes; // 実際に送信されたバイト数 - - if (init_success == true) - { - WriteFile(myHComPort_, buffer + offset, toWriteBytes, &writeBytes, NULL); - - return writeBytes; - } - else - { - return 0; - } -} - -int SCIComPort::Receive(unsigned char* buffer, size_t offset, size_t count) -{ - DWORD fromReadBytes = count; // 受信したいバイト数 - DWORD dwErrors; - COMSTAT ComStat; - DWORD dwCount; // 受信したバイト数 - - if (init_success == true) - { - ClearCommError(myHComPort_, &dwErrors, &ComStat); - dwCount = ComStat.cbInQue; - - if (dwCount > 0) - { - if (dwCount < count) - { - fromReadBytes = dwCount; - ReadFile(myHComPort_, buffer + offset, fromReadBytes, &dwCount, NULL); - } - else - { - fromReadBytes = count; // 読み込みすぎるとデータが失われるので読み込む量を制御 - ReadFile(myHComPort_, buffer + offset, fromReadBytes, &dwCount, NULL); - } - } - - return dwCount; - } - else - { - return 0; - } + return SILS_SCI_IF_sci_com_.Receive(data_v, 0, count); } #pragma section diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.hpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.hpp index 5119340a0..1361eeba2 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.hpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.hpp @@ -2,28 +2,18 @@ * @file * @brief ccsds_sils_sci_if * @details WINGS TMTC IFとCCSDSのTransfer FrameをSCI COMでやりとりするIF - Windows上でcom0comを使うことを想定 - SCIComPort classは基本的にEQU ZEUSのコードを流用 */ #ifndef CCSDS_SILS_SCI_IF_HPP_ #define CCSDS_SILS_SCI_IF_HPP_ -#include +#include +#include "sils_sci_if.hpp" -// ZEUS SILSからのコピー -class SCIComPort +class SCIComPortCcsds : public SCIComPort { public: - SCIComPort(void); - ~SCIComPort(void); - - int Send(unsigned char* buffer, size_t length, size_t offset); - int Receive(unsigned char* buffer, size_t length, size_t offset); - -private: - HANDLE myHComPort_; - DCB config_; - bool init_success; + SCIComPortCcsds(int port) : SCIComPort(port) {}; + ~SCIComPortCcsds(void) {}; }; int SILS_SIC_IF_init(); diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp new file mode 100644 index 000000000..4d306dfa6 --- /dev/null +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp @@ -0,0 +1,181 @@ +#pragma section REPRO +/** + * @file + * @brief sils_sci_if + * @details SCI COMでやりとりするIF + */ + +#include "sils_sci_if.hpp" + +#ifdef WIN32 +SCIComPort::SCIComPort(int port) +{ + char port_settings[15]; + snprintf(port_settings, 15, "%s%d", "\\\\.\\COM", port); + myHComPort_ = CreateFile(port_settings, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + if ((int)myHComPort_ == -1) + { + // 正常にポートオープンできていない場合は終了 + CloseHandle(myHComPort_); + init_success = false; + return; + } + + // どうやら正常ポートopenにならないっぽく,これが必要 + init_success = true; + + // ポートのボーレート、パリティ等を設定 + config_.BaudRate = 115200; + config_.Parity = PARITY_NONE; + config_.ByteSize = 8; + config_.StopBits = STOPBITS_10; + + // Parity、StopBits、DataBitsも同様に設定 + SetCommState(myHComPort_, &config_); +} + +SCIComPort::~SCIComPort(void) +{ + if (init_success == true) + { + CloseHandle(myHComPort_); + } +} + +int SCIComPort::Send(unsigned char* buffer, size_t offset, size_t count) +{ + DWORD toWriteBytes = count; // 送信したいバイト数 + DWORD writeBytes; // 実際に送信されたバイト数 + + if (init_success == true) + { + WriteFile(myHComPort_, buffer + offset, toWriteBytes, &writeBytes, NULL); + return writeBytes; + } + else + { + return 0; + } +} + +int SCIComPort::Receive(unsigned char* buffer, size_t offset, size_t count) +{ + DWORD fromReadBytes = count; // 受信したいバイト数 + DWORD dwErrors; + COMSTAT ComStat; + DWORD dwCount; // 受信したバイト数 + + if (init_success == true) + { + ClearCommError(myHComPort_, &dwErrors, &ComStat); + dwCount = ComStat.cbInQue; + + if (dwCount > 0) + { + if (dwCount < count) + { + fromReadBytes = dwCount; + ReadFile(myHComPort_, buffer + offset, fromReadBytes, &dwCount, NULL); + } + else + { + fromReadBytes = count; // 読み込みすぎるとデータが失われるので読み込む量を制御 + ReadFile(myHComPort_, buffer + offset, fromReadBytes, &dwCount, NULL); + } + } + + return dwCount; + } + else + { + return 0; + } +} + +#else + +SCIComPort::SCIComPort(int port) +{ + char port_settings[13]; + snprintf(port_settings, 13, "%s%d", "/dev/tnt", port); + if ((myHComPort_ = open(port_settings, O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0) + { + close(myHComPort_); + init_success = false; + return; + } + + // どうやら正常ポートopenにならないっぽく,これが必要 + init_success = true; + + cfsetispeed(&config_, 115200); + cfsetospeed(&config_, 115200); + config_.c_cflag &= ~PARENB; // No Parity + config_.c_cflag &= ~CSTOPB; // 1 Stop Bit + config_.c_cflag &= ~CSIZE; + config_.c_cflag |= CS8; // 8 Bits + tcsetattr(myHComPort_, TCSANOW, &config_); +} + +SCIComPort::~SCIComPort(void) +{ + if (init_success == true) + { + close(myHComPort_); + } +} + +int SCIComPort::Send(unsigned char* buffer, size_t offset, size_t count) +{ + unsigned long toWriteBytes = count; // 送信したいバイト数 + unsigned long writeBytes; // 実際に送信されたバイト数 + + if (init_success == true) + { + writeBytes = write(myHComPort_, buffer + offset, toWriteBytes); + return writeBytes; + } + else + { + return 0; + } +} + +int SCIComPort::Receive(unsigned char* buffer, size_t offset, size_t count) +{ + unsigned long fromReadBytes = count; // 受信したいバイト数 + unsigned long dwErrors; + unsigned long ComStat_cbInQue; + unsigned long dwCount; // 受信したバイト数 + + if (init_success == true) + { + dwCount = ComStat_cbInQue; + + if (dwCount > 0) + { + if (dwCount < count) + { + fromReadBytes = dwCount; + dwCount = read(myHComPort_, buffer + offset, fromReadBytes); + } + else + { + fromReadBytes = count; // 読み込みすぎるとデータが失われるので読み込む量を制御 + dwCount = read(myHComPort_, buffer + offset, fromReadBytes); + } + } + + return dwCount; + } + else + { + return 0; + } +} + +#endif + +#pragma section + diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.hpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.hpp new file mode 100644 index 000000000..6f9dd694f --- /dev/null +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.hpp @@ -0,0 +1,41 @@ +/** + * @file + * @brief sils_sci_if + * @details SCI COMでやりとりするIF + */ +#ifndef SILS_SCI_IF_HPP_ +#define SILS_SCI_IF_HPP_ + +#ifdef WIN32 +#include +#else +#include +#include +#include +#endif + +#include +#include + +class SCIComPort +{ +public: + SCIComPort(int port); + virtual ~SCIComPort(void); + + int Send(unsigned char* buffer, size_t length, size_t offset); + int Receive(unsigned char* buffer, size_t length, size_t offset); + +private: +#ifdef WIN32 + HANDLE myHComPort_; + DCB config_; +#else + int myHComPort_; + struct termios config_; +#endif + bool init_success; +}; + +#endif + diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.cpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.cpp index 9bcb379d6..5ef70143b 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.cpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.cpp @@ -3,14 +3,18 @@ * @file * @brief uart_sils_sci_if * @details SILSでDriverのテストをするように作った - ccsds_sils_sci_if.c/hのほぼコピー */ #include "uart_sils_sci_if.hpp" // 最初だけ初期化して、プログラム終了時にポートを閉じるようにしたい -static SCIComPortUart sci_com_uart_; +#ifdef WIN32 +static SCIComPortUart SILS_SCI_IF_sci_com_uart_(13); +#else +static SCIComPortUart SILS_SCI_IF_sci_com_uart_(3); +#endif + int SILS_SCI_UART_IF_init(void) { @@ -19,99 +23,13 @@ int SILS_SCI_UART_IF_init(void) int SILS_SCI_UART_IF_TX(unsigned char* data_v, int count) { - sci_com_uart_.Send(data_v, 0, count); + SILS_SCI_IF_sci_com_uart_.Send(data_v, 0, count); return 0; } int SILS_SCI_UART_IF_RX(unsigned char* data_v, int count) { - return sci_com_uart_.Receive(data_v, 0, count); -} - - -SCIComPortUart::SCIComPortUart(void) -{ - // ビルド通らなかったので,ZEUSからちょっと変えた - myHComPort_ = CreateFile("\\\\.\\COM13", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - - if ((int)myHComPort_ == -1) - { - // 正常にポートオープンできていない場合は終了 - CloseHandle(myHComPort_); - init_success = false; - return; - } - - // どうやら正常ポートopenにならないっぽく,これが必要 - init_success = true; - - // ポートのボーレート、パリティ等を設定 - config_.BaudRate = 115200; - config_.Parity = PARITY_NONE; - config_.ByteSize = 8; - config_.StopBits = STOPBITS_10; - - // Parity、StopBits、DataBitsも同様に設定 - SetCommState(myHComPort_, &config_); -} - -SCIComPortUart::~SCIComPortUart(void) -{ - if (init_success == true) - { - CloseHandle(myHComPort_); - } -} - -int SCIComPortUart::Send(unsigned char* buffer, size_t offset, size_t count) -{ - DWORD toWriteBytes = count; // 送信したいバイト数 - DWORD writeBytes; // 実際に送信されたバイト数 - - if (init_success == true) - { - WriteFile(myHComPort_, buffer + offset, toWriteBytes, &writeBytes, NULL); - - return writeBytes; - } - else - { - return 0; - } -} - -int SCIComPortUart::Receive(unsigned char* buffer, size_t offset, size_t count) -{ - DWORD fromReadBytes = count; // 受信したいバイト数 - DWORD dwErrors; - COMSTAT ComStat; - DWORD dwCount; // 受信したバイト数 - - if (init_success == true) - { - ClearCommError(myHComPort_, &dwErrors, &ComStat); - dwCount = ComStat.cbInQue; - - if (dwCount > 0) - { - if (dwCount < count) - { - fromReadBytes = dwCount; - ReadFile(myHComPort_, buffer + offset, fromReadBytes, &dwCount, NULL); - } - else - { - fromReadBytes = count; // 読み込みすぎるとデータが失われるので読み込む量を制御 - ReadFile(myHComPort_, buffer + offset, fromReadBytes, &dwCount, NULL); - } - } - - return dwCount; - } - else - { - return 0; - } + return SILS_SCI_IF_sci_com_uart_.Receive(data_v, 0, count); } #pragma section diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.hpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.hpp index e6ff4550c..d58e33124 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.hpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.hpp @@ -7,21 +7,13 @@ #ifndef UART_SILS_SCI_IF_HPP_ #define UART_SILS_SCI_IF_HPP_ -#include +#include "sils_sci_if.hpp" -class SCIComPortUart +class SCIComPortUart : public SCIComPort { public: - SCIComPortUart(void); - ~SCIComPortUart(void); - - int Send(unsigned char* buffer, size_t length, size_t offset); - int Receive(unsigned char* buffer, size_t length, size_t offset); - -private: - HANDLE myHComPort_; - DCB config_; - bool init_success; + SCIComPortUart(int port) : SCIComPort(port) {}; + ~SCIComPortUart(void) {}; }; int SILS_SCI_UART_IF_init(); diff --git a/Script/CI/check_coding_rule.json b/Script/CI/check_coding_rule.json index d5cda639f..767f80560 100644 --- a/Script/CI/check_coding_rule.json +++ b/Script/CI/check_coding_rule.json @@ -11,7 +11,8 @@ "src_core/Script" ], "ignore_files" : [ - "src_user/TlmCmd/telemetry_definitions.c" + "src_user/TlmCmd/telemetry_definitions.c", + "src_user/IfWrapper/Sils/sils_sci_if.hpp" ], "ignore_rules" : [ ], From 76ee7133d68d4a34de6cea21d3d34129e43860ec Mon Sep 17 00:00:00 2001 From: Yoshinari Gyu <50069930+yngyu@users.noreply.github.com> Date: Wed, 12 Oct 2022 19:43:01 +0900 Subject: [PATCH 2/6] delete unnecessary line --- .../minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp index 4d306dfa6..a3109651f 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp @@ -178,4 +178,3 @@ int SCIComPort::Receive(unsigned char* buffer, size_t offset, size_t count) #endif #pragma section - From ceba402ecc0727d5898f3080069b74570eb2a410 Mon Sep 17 00:00:00 2001 From: flap1 Date: Wed, 26 Oct 2022 12:20:02 +0900 Subject: [PATCH 3/6] fix var names --- .../src/src_user/IfWrapper/CMakeLists.txt | 4 +-- .../src_user/IfWrapper/Sils/ccsds_sils.cpp | 8 ++--- .../IfWrapper/Sils/ccsds_sils_sci_if.cpp | 34 ------------------ .../IfWrapper/Sils/ccsds_sils_sci_if.hpp | 23 ------------ .../IfWrapper/Sils/sils_sci_ccsds_if.cpp | 36 +++++++++++++++++++ .../IfWrapper/Sils/sils_sci_ccsds_if.hpp | 25 +++++++++++++ .../src_user/IfWrapper/Sils/sils_sci_if.cpp | 14 ++++---- .../src_user/IfWrapper/Sils/sils_sci_if.hpp | 4 +-- ...t_sils_sci_if.cpp => sils_sci_uart_if.cpp} | 14 ++++---- ...t_sils_sci_if.hpp => sils_sci_uart_if.hpp} | 8 ++--- .../src/src_user/IfWrapper/Sils/uart_sils.cpp | 2 +- 11 files changed, 88 insertions(+), 84 deletions(-) delete mode 100644 Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.cpp delete mode 100644 Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.hpp create mode 100644 Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.cpp create mode 100644 Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.hpp rename Examples/minimum_user/src/src_user/IfWrapper/Sils/{uart_sils_sci_if.cpp => sils_sci_uart_if.cpp} (59%) rename Examples/minimum_user/src/src_user/IfWrapper/Sils/{uart_sils_sci_if.hpp => sils_sci_uart_if.hpp} (74%) diff --git a/Examples/minimum_user/src/src_user/IfWrapper/CMakeLists.txt b/Examples/minimum_user/src/src_user/IfWrapper/CMakeLists.txt index b26829c84..e8f38e502 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/CMakeLists.txt +++ b/Examples/minimum_user/src/src_user/IfWrapper/CMakeLists.txt @@ -32,7 +32,7 @@ if(USE_SCI_COM_WINGS AND NOT USE_SILS_MOCKUP) #target_sources(${PROJECT_NAME} PUBLIC list(APPEND C2A_SRCS Sils/sils_sci_if.cpp - Sils/ccsds_sils_sci_if.cpp + Sils/sils_sci_ccsds_if.cpp ) message("USE SCI_COM_WINGS") endif() @@ -42,7 +42,7 @@ if(USE_SCI_COM_UART AND NOT USE_SILS_MOCKUP) #target_sources(${PROJECT_NAME} PUBLIC list(APPEND C2A_SRCS Sils/sils_sci_if.cpp - Sils/uart_sils_sci_if.cpp + Sils/sils_sci_uart_if.cpp ) message("USE SCI_COM_UART") endif() diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils.cpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils.cpp index c4412d369..2a5074c79 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils.cpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils.cpp @@ -14,7 +14,7 @@ #include "../ccsds_user.h" #ifdef USE_SCI_COM_WINGS -#include "ccsds_sils_sci_if.hpp" +#include "sils_sci_ccsds_if.hpp" #endif #define CCSDS_TX_VALID_SIZE (444) @@ -26,7 +26,7 @@ int CCSDS_init(void* my_ccsds_v) CCSDS_set_rate(0xAD, my_ccsds); // 初期値 230.4 [kbps] #ifdef USE_SCI_COM_WINGS - SILS_SIC_IF_init(); + SILS_SCI_CCSDS_IF_init(); #endif return CCSDS_ERR_OK; } @@ -37,7 +37,7 @@ int CCSDS_rx(void* my_ccsds_v, void* data_v, int buffer_size) (CCSDS_Config*)my_ccsds_v; #ifdef USE_SCI_COM_WINGS - return SILS_SIC_IF_RX(data, buffer_size); + return SILS_SCI_CCSDS_IF_RX(data, buffer_size); #endif return 0; @@ -53,7 +53,7 @@ int CCSDS_tx(void* my_ccsds_v, void* data_v, int data_size) if (!CCSDS_get_buffer_num()) return CCSDS_ERR_TX_NO_BUFFER; #ifdef USE_SCI_COM_WINGS - ret = SILS_SIC_IF_TX(data, data_size); + ret = SILS_SCI_CCSDS_IF_TX(data, data_size); #endif if (ret == 0) return CCSDS_ERR_TX_INVALID; diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.cpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.cpp deleted file mode 100644 index ba77df80e..000000000 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma section REPRO -/** - * @file - * @brief ccsds_sils_sci_if - * @details WINGS TMTC IFとCCSDSのTransfer FrameをSCI COMでやりとりするIF - */ - -#include "ccsds_sils_sci_if.hpp" - - -// 最初だけ初期化して、プログラム終了時にポートを閉じるようにしたい -#ifdef WIN32 -static SCIComPortCcsds SILS_SCI_IF_sci_com_(11); -#else -static SCIComPortCcsds SILS_SCI_IF_sci_com_(1); -#endif - -int SILS_SIC_IF_init(void) -{ - return 0; -} - -int SILS_SIC_IF_TX(unsigned char* data_v, int count) -{ - SILS_SCI_IF_sci_com_.Send(data_v, 0, count); - return 0; -} - -int SILS_SIC_IF_RX(unsigned char* data_v, int count) -{ - return SILS_SCI_IF_sci_com_.Receive(data_v, 0, count); -} - -#pragma section diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.hpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.hpp deleted file mode 100644 index 1361eeba2..000000000 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils_sci_if.hpp +++ /dev/null @@ -1,23 +0,0 @@ -/** - * @file - * @brief ccsds_sils_sci_if - * @details WINGS TMTC IFとCCSDSのTransfer FrameをSCI COMでやりとりするIF - */ -#ifndef CCSDS_SILS_SCI_IF_HPP_ -#define CCSDS_SILS_SCI_IF_HPP_ - -#include -#include "sils_sci_if.hpp" - -class SCIComPortCcsds : public SCIComPort -{ -public: - SCIComPortCcsds(int port) : SCIComPort(port) {}; - ~SCIComPortCcsds(void) {}; -}; - -int SILS_SIC_IF_init(); -int SILS_SIC_IF_TX(unsigned char* data_v, int count); -int SILS_SIC_IF_RX(unsigned char* data_v, int count); - -#endif diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.cpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.cpp new file mode 100644 index 000000000..74fcf6db5 --- /dev/null +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.cpp @@ -0,0 +1,36 @@ +#pragma section REPRO +/** + * @file + * @brief sils_sci_ccsds_if + * @details WINGS TMTC IFとCCSDSのTransfer FrameをSCI COMでやりとりするIF + * Windows上でcom0comを使うことを想定 + * SCIComPort classは基本的にEQU ZEUSのコードを流用 + */ + +#include "sils_sci_ccsds_if.hpp" + + +// 最初だけ初期化して、プログラム終了時にポートを閉じるようにしたい +#ifdef _WIN32 +static SCIComPortCcsds SILS_SCI_CCSDS_IF_sci_com_(11); +#else +static SCIComPortCcsds SILS_SCI_CCSDS_IF_sci_com_(1); +#endif + +int SILS_SCI_CCSDS_IF_init(void) +{ + return 0; +} + +int SILS_SCI_CCSDS_IF_TX(unsigned char* data_v, int count) +{ + SILS_SCI_CCSDS_IF_sci_com_.Send(data_v, 0, count); + return 0; +} + +int SILS_SCI_CCSDS_IF_RX(unsigned char* data_v, int count) +{ + return SILS_SCI_CCSDS_IF_sci_com_.Receive(data_v, 0, count); +} + +#pragma section diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.hpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.hpp new file mode 100644 index 000000000..6096cea0a --- /dev/null +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.hpp @@ -0,0 +1,25 @@ +/** + * @file + * @brief sils_sci_ccsds_if + * @details WINGS TMTC IFとCCSDSのTransfer FrameをSCI COMでやりとりするIF + * Windows上でcom0comを使うことを想定 + * SCIComPort classは基本的にEQU ZEUSのコードを流用 + */ +#ifndef SILS_SCI_CCSDS_IF_HPP_ +#define SILS_SCI_CCSDS_IF_HPP_ + +#include +#include "sils_sci_if.hpp" + +class SCIComPortCcsds : public SCIComPort +{ +public: + SCIComPortCcsds(int port) : SCIComPort(port) {}; + ~SCIComPortCcsds(void) {}; +}; + +int SILS_SCI_CCSDS_IF_init(); +int SILS_SCI_CCSDS_IF_TX(unsigned char* data_v, int count); +int SILS_SCI_CCSDS_IF_RX(unsigned char* data_v, int count); + +#endif diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp index a3109651f..37b218820 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp @@ -7,12 +7,12 @@ #include "sils_sci_if.hpp" -#ifdef WIN32 +#ifdef _WIN32 SCIComPort::SCIComPort(int port) { - char port_settings[15]; - snprintf(port_settings, 15, "%s%d", "\\\\.\\COM", port); - myHComPort_ = CreateFile(port_settings, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + char port_name[15]; + snprintf(port_name, 15, "%s%d", "\\\\.\\COM", port); + myHComPort_ = CreateFile(port_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if ((int)myHComPort_ == -1) { @@ -97,9 +97,9 @@ int SCIComPort::Receive(unsigned char* buffer, size_t offset, size_t count) SCIComPort::SCIComPort(int port) { - char port_settings[13]; - snprintf(port_settings, 13, "%s%d", "/dev/tnt", port); - if ((myHComPort_ = open(port_settings, O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0) + char port_name[13]; + snprintf(port_name, 13, "%s%d", "/dev/tnt", port); + if ((myHComPort_ = open(port_name, O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0) { close(myHComPort_); init_success = false; diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.hpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.hpp index 6f9dd694f..568bf6099 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.hpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_if.hpp @@ -6,7 +6,7 @@ #ifndef SILS_SCI_IF_HPP_ #define SILS_SCI_IF_HPP_ -#ifdef WIN32 +#ifdef _WIN32 #include #else #include @@ -27,7 +27,7 @@ class SCIComPort int Receive(unsigned char* buffer, size_t length, size_t offset); private: -#ifdef WIN32 +#ifdef _WIN32 HANDLE myHComPort_; DCB config_; #else diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.cpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.cpp similarity index 59% rename from Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.cpp rename to Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.cpp index 5ef70143b..10dcc38bd 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.cpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.cpp @@ -1,18 +1,18 @@ #pragma section REPRO /** * @file - * @brief uart_sils_sci_if + * @brief sils_sci_uart_if * @details SILSでDriverのテストをするように作った */ -#include "uart_sils_sci_if.hpp" +#include "sils_sci_uart_if.hpp" // 最初だけ初期化して、プログラム終了時にポートを閉じるようにしたい -#ifdef WIN32 -static SCIComPortUart SILS_SCI_IF_sci_com_uart_(13); +#ifdef _WIN32 +static SCIComPortUart SILS_SCI_UART_IF_sci_com_(13); #else -static SCIComPortUart SILS_SCI_IF_sci_com_uart_(3); +static SCIComPortUart SILS_SCI_UART_IF_sci_com_(3); #endif @@ -23,13 +23,13 @@ int SILS_SCI_UART_IF_init(void) int SILS_SCI_UART_IF_TX(unsigned char* data_v, int count) { - SILS_SCI_IF_sci_com_uart_.Send(data_v, 0, count); + SILS_SCI_UART_IF_sci_com_.Send(data_v, 0, count); return 0; } int SILS_SCI_UART_IF_RX(unsigned char* data_v, int count) { - return SILS_SCI_IF_sci_com_uart_.Receive(data_v, 0, count); + return SILS_SCI_UART_IF_sci_com_.Receive(data_v, 0, count); } #pragma section diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.hpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.hpp similarity index 74% rename from Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.hpp rename to Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.hpp index d58e33124..4ee7127dd 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.hpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.hpp @@ -1,11 +1,11 @@ /** * @file - * @brief uart_sils_sci_if + * @brief sils_sci_uart_if * @details SILSでDriverのテストをするように作った - ccsds_sils_sci_if.c/hのほぼコピー + sils_sci_ccsds_if.c/hのほぼコピー */ -#ifndef UART_SILS_SCI_IF_HPP_ -#define UART_SILS_SCI_IF_HPP_ +#ifndef SILS_SCI_UART_IF_HPP_ +#define SILS_SCI_UART_IF_HPP_ #include "sils_sci_if.hpp" diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils.cpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils.cpp index 2209d1b39..f289a7e9a 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils.cpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils.cpp @@ -3,7 +3,7 @@ #include "../../Settings/port_config.h" #ifdef USE_SCI_COM_UART -#include "uart_sils_sci_if.hpp" +#include "sils_sci_urat_if.hpp" #endif int OBC_C2A_SendFromObc(int port_id, unsigned char* buffer, int offset, int count); From 9fe58472200472b88a102ee16f6800b97200beb3 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 30 Oct 2022 17:52:42 +0900 Subject: [PATCH 4/6] fix func name --- .../minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils.cpp | 4 ++-- .../src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.cpp | 4 ++-- .../src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.hpp | 4 ++-- .../src/src_user/IfWrapper/Sils/sils_sci_uart_if.cpp | 4 ++-- .../src/src_user/IfWrapper/Sils/sils_sci_uart_if.hpp | 4 ++-- .../minimum_user/src/src_user/IfWrapper/Sils/uart_sils.cpp | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils.cpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils.cpp index 2a5074c79..051b58101 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils.cpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/ccsds_sils.cpp @@ -37,7 +37,7 @@ int CCSDS_rx(void* my_ccsds_v, void* data_v, int buffer_size) (CCSDS_Config*)my_ccsds_v; #ifdef USE_SCI_COM_WINGS - return SILS_SCI_CCSDS_IF_RX(data, buffer_size); + return SILS_SCI_CCSDS_IF_rx(data, buffer_size); #endif return 0; @@ -53,7 +53,7 @@ int CCSDS_tx(void* my_ccsds_v, void* data_v, int data_size) if (!CCSDS_get_buffer_num()) return CCSDS_ERR_TX_NO_BUFFER; #ifdef USE_SCI_COM_WINGS - ret = SILS_SCI_CCSDS_IF_TX(data, data_size); + ret = SILS_SCI_CCSDS_IF_tx(data, data_size); #endif if (ret == 0) return CCSDS_ERR_TX_INVALID; diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.cpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.cpp index 74fcf6db5..7f183ebce 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.cpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.cpp @@ -22,13 +22,13 @@ int SILS_SCI_CCSDS_IF_init(void) return 0; } -int SILS_SCI_CCSDS_IF_TX(unsigned char* data_v, int count) +int SILS_SCI_CCSDS_IF_tx(unsigned char* data_v, int count) { SILS_SCI_CCSDS_IF_sci_com_.Send(data_v, 0, count); return 0; } -int SILS_SCI_CCSDS_IF_RX(unsigned char* data_v, int count) +int SILS_SCI_CCSDS_IF_rx(unsigned char* data_v, int count) { return SILS_SCI_CCSDS_IF_sci_com_.Receive(data_v, 0, count); } diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.hpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.hpp index 6096cea0a..d9f808634 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.hpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_ccsds_if.hpp @@ -19,7 +19,7 @@ class SCIComPortCcsds : public SCIComPort }; int SILS_SCI_CCSDS_IF_init(); -int SILS_SCI_CCSDS_IF_TX(unsigned char* data_v, int count); -int SILS_SCI_CCSDS_IF_RX(unsigned char* data_v, int count); +int SILS_SCI_CCSDS_IF_tx(unsigned char* data_v, int count); +int SILS_SCI_CCSDS_IF_rx(unsigned char* data_v, int count); #endif diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.cpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.cpp index 10dcc38bd..69e9b241e 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.cpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.cpp @@ -21,13 +21,13 @@ int SILS_SCI_UART_IF_init(void) return 0; } -int SILS_SCI_UART_IF_TX(unsigned char* data_v, int count) +int SILS_SCI_UART_IF_tx(unsigned char* data_v, int count) { SILS_SCI_UART_IF_sci_com_.Send(data_v, 0, count); return 0; } -int SILS_SCI_UART_IF_RX(unsigned char* data_v, int count) +int SILS_SCI_UART_IF_rx(unsigned char* data_v, int count) { return SILS_SCI_UART_IF_sci_com_.Receive(data_v, 0, count); } diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.hpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.hpp index 4ee7127dd..f2c32132a 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.hpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.hpp @@ -17,7 +17,7 @@ class SCIComPortUart : public SCIComPort }; int SILS_SCI_UART_IF_init(); -int SILS_SCI_UART_IF_TX(unsigned char* data_v, int count); -int SILS_SCI_UART_IF_RX(unsigned char* data_v, int count); +int SILS_SCI_UART_IF_tx(unsigned char* data_v, int count); +int SILS_SCI_UART_IF_rx(unsigned char* data_v, int count); #endif diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils.cpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils.cpp index f289a7e9a..4a633ba01 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils.cpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils.cpp @@ -24,7 +24,7 @@ int UART_rx(void* my_uart_v, void* data_v, int buffer_size) } #ifdef USE_SCI_COM_UART - return SILS_SCI_UART_IF_RX((unsigned char*)data_v, buffer_size); + return SILS_SCI_UART_IF_rx((unsigned char*)data_v, buffer_size); #else return OBC_C2A_ReceivedByObc(my_uart->ch, (unsigned char*)data_v, 0, buffer_size); #endif @@ -46,7 +46,7 @@ int UART_tx(void* my_uart_v, void* data_v, int data_size) } } #ifdef USE_SCI_COM_UART - SILS_SCI_UART_IF_TX((unsigned char*)data_v, data_size); + SILS_SCI_UART_IF_tx((unsigned char*)data_v, data_size); #else if (OBC_C2A_SendFromObc(my_uart->ch, (unsigned char*)data_v, 0, data_size) < 0) { From 5ec415e32c5f13ba37fc66274b83d06a86fd7af4 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Mon, 31 Oct 2022 02:24:01 +0900 Subject: [PATCH 5/6] fix for 2nd obc --- .../src/src_user/IfWrapper/CMakeLists.txt | 3 +- .../src_user/IfWrapper/Sils/sils_sci_if.cpp | 180 ++++++++++++++++++ .../src_user/IfWrapper/Sils/sils_sci_if.hpp | 41 ++++ .../IfWrapper/Sils/sils_sci_uart_if.cpp | 35 ++++ .../IfWrapper/Sils/sils_sci_uart_if.hpp | 23 +++ .../src/src_user/IfWrapper/Sils/uart_sils.cpp | 6 +- .../IfWrapper/Sils/uart_sils_sci_if.cpp | 117 ------------ .../IfWrapper/Sils/uart_sils_sci_if.hpp | 31 --- .../2nd_obc_user/sync_with_minimum_user.bat | 4 +- 9 files changed, 287 insertions(+), 153 deletions(-) create mode 100644 Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp create mode 100644 Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_if.hpp create mode 100644 Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.cpp create mode 100644 Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.hpp delete mode 100644 Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.cpp delete mode 100644 Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.hpp diff --git a/Examples/2nd_obc_user/src/src_user/IfWrapper/CMakeLists.txt b/Examples/2nd_obc_user/src/src_user/IfWrapper/CMakeLists.txt index ae8bb4c18..7377a963f 100644 --- a/Examples/2nd_obc_user/src/src_user/IfWrapper/CMakeLists.txt +++ b/Examples/2nd_obc_user/src/src_user/IfWrapper/CMakeLists.txt @@ -29,7 +29,8 @@ if(USE_SCI_COM_WINGS AND NOT USE_SILS_MOCKUP) add_definitions(-DUSE_SCI_COM_WINGS) #target_sources(${PROJECT_NAME} PUBLIC list(APPEND C2A_SRCS - Sils/uart_sils_sci_if.cpp + Sils/sils_sci_if.cpp + Sils/sils_sci_uart_if.cpp ) message("USE SCI_COM_UART") endif() diff --git a/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp b/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp new file mode 100644 index 000000000..37b218820 --- /dev/null +++ b/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_if.cpp @@ -0,0 +1,180 @@ +#pragma section REPRO +/** + * @file + * @brief sils_sci_if + * @details SCI COMでやりとりするIF + */ + +#include "sils_sci_if.hpp" + +#ifdef _WIN32 +SCIComPort::SCIComPort(int port) +{ + char port_name[15]; + snprintf(port_name, 15, "%s%d", "\\\\.\\COM", port); + myHComPort_ = CreateFile(port_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + if ((int)myHComPort_ == -1) + { + // 正常にポートオープンできていない場合は終了 + CloseHandle(myHComPort_); + init_success = false; + return; + } + + // どうやら正常ポートopenにならないっぽく,これが必要 + init_success = true; + + // ポートのボーレート、パリティ等を設定 + config_.BaudRate = 115200; + config_.Parity = PARITY_NONE; + config_.ByteSize = 8; + config_.StopBits = STOPBITS_10; + + // Parity、StopBits、DataBitsも同様に設定 + SetCommState(myHComPort_, &config_); +} + +SCIComPort::~SCIComPort(void) +{ + if (init_success == true) + { + CloseHandle(myHComPort_); + } +} + +int SCIComPort::Send(unsigned char* buffer, size_t offset, size_t count) +{ + DWORD toWriteBytes = count; // 送信したいバイト数 + DWORD writeBytes; // 実際に送信されたバイト数 + + if (init_success == true) + { + WriteFile(myHComPort_, buffer + offset, toWriteBytes, &writeBytes, NULL); + return writeBytes; + } + else + { + return 0; + } +} + +int SCIComPort::Receive(unsigned char* buffer, size_t offset, size_t count) +{ + DWORD fromReadBytes = count; // 受信したいバイト数 + DWORD dwErrors; + COMSTAT ComStat; + DWORD dwCount; // 受信したバイト数 + + if (init_success == true) + { + ClearCommError(myHComPort_, &dwErrors, &ComStat); + dwCount = ComStat.cbInQue; + + if (dwCount > 0) + { + if (dwCount < count) + { + fromReadBytes = dwCount; + ReadFile(myHComPort_, buffer + offset, fromReadBytes, &dwCount, NULL); + } + else + { + fromReadBytes = count; // 読み込みすぎるとデータが失われるので読み込む量を制御 + ReadFile(myHComPort_, buffer + offset, fromReadBytes, &dwCount, NULL); + } + } + + return dwCount; + } + else + { + return 0; + } +} + +#else + +SCIComPort::SCIComPort(int port) +{ + char port_name[13]; + snprintf(port_name, 13, "%s%d", "/dev/tnt", port); + if ((myHComPort_ = open(port_name, O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0) + { + close(myHComPort_); + init_success = false; + return; + } + + // どうやら正常ポートopenにならないっぽく,これが必要 + init_success = true; + + cfsetispeed(&config_, 115200); + cfsetospeed(&config_, 115200); + config_.c_cflag &= ~PARENB; // No Parity + config_.c_cflag &= ~CSTOPB; // 1 Stop Bit + config_.c_cflag &= ~CSIZE; + config_.c_cflag |= CS8; // 8 Bits + tcsetattr(myHComPort_, TCSANOW, &config_); +} + +SCIComPort::~SCIComPort(void) +{ + if (init_success == true) + { + close(myHComPort_); + } +} + +int SCIComPort::Send(unsigned char* buffer, size_t offset, size_t count) +{ + unsigned long toWriteBytes = count; // 送信したいバイト数 + unsigned long writeBytes; // 実際に送信されたバイト数 + + if (init_success == true) + { + writeBytes = write(myHComPort_, buffer + offset, toWriteBytes); + return writeBytes; + } + else + { + return 0; + } +} + +int SCIComPort::Receive(unsigned char* buffer, size_t offset, size_t count) +{ + unsigned long fromReadBytes = count; // 受信したいバイト数 + unsigned long dwErrors; + unsigned long ComStat_cbInQue; + unsigned long dwCount; // 受信したバイト数 + + if (init_success == true) + { + dwCount = ComStat_cbInQue; + + if (dwCount > 0) + { + if (dwCount < count) + { + fromReadBytes = dwCount; + dwCount = read(myHComPort_, buffer + offset, fromReadBytes); + } + else + { + fromReadBytes = count; // 読み込みすぎるとデータが失われるので読み込む量を制御 + dwCount = read(myHComPort_, buffer + offset, fromReadBytes); + } + } + + return dwCount; + } + else + { + return 0; + } +} + +#endif + +#pragma section diff --git a/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_if.hpp b/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_if.hpp new file mode 100644 index 000000000..568bf6099 --- /dev/null +++ b/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_if.hpp @@ -0,0 +1,41 @@ +/** + * @file + * @brief sils_sci_if + * @details SCI COMでやりとりするIF + */ +#ifndef SILS_SCI_IF_HPP_ +#define SILS_SCI_IF_HPP_ + +#ifdef _WIN32 +#include +#else +#include +#include +#include +#endif + +#include +#include + +class SCIComPort +{ +public: + SCIComPort(int port); + virtual ~SCIComPort(void); + + int Send(unsigned char* buffer, size_t length, size_t offset); + int Receive(unsigned char* buffer, size_t length, size_t offset); + +private: +#ifdef _WIN32 + HANDLE myHComPort_; + DCB config_; +#else + int myHComPort_; + struct termios config_; +#endif + bool init_success; +}; + +#endif + diff --git a/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.cpp b/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.cpp new file mode 100644 index 000000000..1dd3c65ac --- /dev/null +++ b/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.cpp @@ -0,0 +1,35 @@ +#pragma section REPRO +/** + * @file + * @brief sils_sci_uart_if + * @details SILSでDriverのテストをするように作った + */ + +#include "sils_sci_uart_if.hpp" + + +// 最初だけ初期化して、プログラム終了時にポートを閉じるようにしたい +#ifdef _WIN32 +static SCIComPortUart SILS_SCI_UART_IF_sci_com_(14); +#else +static SCIComPortUart SILS_SCI_UART_IF_sci_com_(4); +#endif + + +int SILS_SCI_UART_IF_init(void) +{ + return 0; +} + +int SILS_SCI_UART_IF_tx(unsigned char* data_v, int count) +{ + SILS_SCI_UART_IF_sci_com_.Send(data_v, 0, count); + return 0; +} + +int SILS_SCI_UART_IF_rx(unsigned char* data_v, int count) +{ + return SILS_SCI_UART_IF_sci_com_.Receive(data_v, 0, count); +} + +#pragma section diff --git a/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.hpp b/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.hpp new file mode 100644 index 000000000..f2c32132a --- /dev/null +++ b/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/sils_sci_uart_if.hpp @@ -0,0 +1,23 @@ +/** + * @file + * @brief sils_sci_uart_if + * @details SILSでDriverのテストをするように作った + sils_sci_ccsds_if.c/hのほぼコピー + */ +#ifndef SILS_SCI_UART_IF_HPP_ +#define SILS_SCI_UART_IF_HPP_ + +#include "sils_sci_if.hpp" + +class SCIComPortUart : public SCIComPort +{ +public: + SCIComPortUart(int port) : SCIComPort(port) {}; + ~SCIComPortUart(void) {}; +}; + +int SILS_SCI_UART_IF_init(); +int SILS_SCI_UART_IF_tx(unsigned char* data_v, int count); +int SILS_SCI_UART_IF_rx(unsigned char* data_v, int count); + +#endif diff --git a/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils.cpp b/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils.cpp index a8e7e0635..5bb7a46d0 100644 --- a/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils.cpp +++ b/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils.cpp @@ -3,7 +3,7 @@ #include "../../Settings/port_config.h" #ifdef USE_SCI_COM_WINGS -#include "uart_sils_sci_if.hpp" +#include "sils_sci_urat_if.hpp" #endif int OBC_C2A_SendFromObc(int port_id, unsigned char* buffer, int offset, int count); @@ -24,7 +24,7 @@ int UART_rx(void* my_uart_v, void* data_v, int buffer_size) } #ifdef USE_SCI_COM_WINGS - return SILS_SCI_UART_IF_RX((unsigned char*)data_v, buffer_size); + return SILS_SCI_UART_IF_rx((unsigned char*)data_v, buffer_size); #else return OBC_C2A_ReceivedByObc(my_uart->ch, (unsigned char*)data_v, 0, buffer_size); #endif @@ -46,7 +46,7 @@ int UART_tx(void* my_uart_v, void* data_v, int data_size) } } #ifdef USE_SCI_COM_WINGS - SILS_SCI_UART_IF_TX((unsigned char*)data_v, data_size); + SILS_SCI_UART_IF_tx((unsigned char*)data_v, data_size); #else if (OBC_C2A_SendFromObc(my_uart->ch, (unsigned char*)data_v, 0, data_size) < 0) { diff --git a/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.cpp b/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.cpp deleted file mode 100644 index 6fb389fe6..000000000 --- a/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#pragma section REPRO -/** - * @file - * @brief uart_sils_sci_if - * @details SILSでDriverのテストをするように作った - ccsds_sils_sci_if.c/hのほぼコピー - */ - -#include "uart_sils_sci_if.hpp" - - -// 最初だけ初期化して、プログラム終了時にポートを閉じるようにしたい -static SCIComPortUart sci_com_uart_; - -int SILS_SCI_UART_IF_init(void) -{ - return 0; -} - -int SILS_SCI_UART_IF_TX(unsigned char* data_v, int count) -{ - sci_com_uart_.Send(data_v, 0, count); - return 0; -} - -int SILS_SCI_UART_IF_RX(unsigned char* data_v, int count) -{ - return sci_com_uart_.Receive(data_v, 0, count); -} - - -SCIComPortUart::SCIComPortUart(void) -{ - // ビルド通らなかったので,ZEUSからちょっと変えた - myHComPort_ = CreateFile("\\\\.\\COM14", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - - if ((int)myHComPort_ == -1) - { - // 正常にポートオープンできていない場合は終了 - CloseHandle(myHComPort_); - init_success = false; - return; - } - - // どうやら正常ポートopenにならないっぽく,これが必要 - init_success = true; - - // ポートのボーレート、パリティ等を設定 - config_.BaudRate = 115200; - config_.Parity = PARITY_NONE; - config_.ByteSize = 8; - config_.StopBits = STOPBITS_10; - - // Parity、StopBits、DataBitsも同様に設定 - SetCommState(myHComPort_, &config_); -} - -SCIComPortUart::~SCIComPortUart(void) -{ - if (init_success == true) - { - CloseHandle(myHComPort_); - } -} - -int SCIComPortUart::Send(unsigned char* buffer, size_t offset, size_t count) -{ - DWORD toWriteBytes = count; // 送信したいバイト数 - DWORD writeBytes; // 実際に送信されたバイト数 - - if (init_success == true) - { - WriteFile(myHComPort_, buffer + offset, toWriteBytes, &writeBytes, NULL); - - return writeBytes; - } - else - { - return 0; - } -} - -int SCIComPortUart::Receive(unsigned char* buffer, size_t offset, size_t count) -{ - DWORD fromReadBytes = count; // 受信したいバイト数 - DWORD dwErrors; - COMSTAT ComStat; - DWORD dwCount; // 受信したバイト数 - - if (init_success == true) - { - ClearCommError(myHComPort_, &dwErrors, &ComStat); - dwCount = ComStat.cbInQue; - - if (dwCount > 0) - { - if (dwCount < count) - { - fromReadBytes = dwCount; - ReadFile(myHComPort_, buffer + offset, fromReadBytes, &dwCount, NULL); - } - else - { - fromReadBytes = count; // 読み込みすぎるとデータが失われるので読み込む量を制御 - ReadFile(myHComPort_, buffer + offset, fromReadBytes, &dwCount, NULL); - } - } - - return dwCount; - } - else - { - return 0; - } -} - -#pragma section diff --git a/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.hpp b/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.hpp deleted file mode 100644 index e6ff4550c..000000000 --- a/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils_sci_if.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @file - * @brief uart_sils_sci_if - * @details SILSでDriverのテストをするように作った - ccsds_sils_sci_if.c/hのほぼコピー - */ -#ifndef UART_SILS_SCI_IF_HPP_ -#define UART_SILS_SCI_IF_HPP_ - -#include - -class SCIComPortUart -{ -public: - SCIComPortUart(void); - ~SCIComPortUart(void); - - int Send(unsigned char* buffer, size_t length, size_t offset); - int Receive(unsigned char* buffer, size_t length, size_t offset); - -private: - HANDLE myHComPort_; - DCB config_; - bool init_success; -}; - -int SILS_SCI_UART_IF_init(); -int SILS_SCI_UART_IF_TX(unsigned char* data_v, int count); -int SILS_SCI_UART_IF_RX(unsigned char* data_v, int count); - -#endif diff --git a/Examples/2nd_obc_user/sync_with_minimum_user.bat b/Examples/2nd_obc_user/sync_with_minimum_user.bat index 5d125aa8a..579334215 100644 --- a/Examples/2nd_obc_user/sync_with_minimum_user.bat +++ b/Examples/2nd_obc_user/sync_with_minimum_user.bat @@ -14,7 +14,9 @@ call :sync_dir ".\src\src_user\Script\" "..\minimum_user\src\src_user\Script\" call :sync_dir ".\src\src_user\Settings\TlmCmd\Ccsds\" "..\minimum_user\src\src_user\Settings\TlmCmd\Ccsds\" call :sync_file ".\src\src_user\Applications\UserDefined\debug_apps.h" "..\minimum_user\src\src_user\Applications\UserDefined\debug_apps.h" -call :sync_file ".\src\src_user\IfWrapper\Sils\uart_sils_sci_if.hpp" "..\minimum_user\src\src_user\IfWrapper\Sils\uart_sils_sci_if.hpp" +call :sync_file ".\src\src_user\IfWrapper\Sils\sils_sci_uart_if.hpp" "..\minimum_user\src\src_user\IfWrapper\Sils\sils_sci_uart_if.hpp" +call :sync_file ".\src\src_user\IfWrapper\Sils\sils_sci_if.cpp" "..\minimum_user\src\src_user\IfWrapper\Sils\sils_sci_if.cpp" +call :sync_file ".\src\src_user\IfWrapper\Sils\sils_sci_if.hpp" "..\minimum_user\src\src_user\IfWrapper\Sils\sils_sci_if.hpp" call :sync_file ".\src\src_user\IfWrapper\Sils\wdt_sils.cpp" "..\minimum_user\src\src_user\IfWrapper\Sils\wdt_sils.cpp" call :sync_file ".\src\src_user\IfWrapper\SilsMockup\README.md" "..\minimum_user\src\src_user\IfWrapper\SilsMockup\README.md" call :sync_file ".\src\src_user\IfWrapper\SilsMockup\uart_sils.c" "..\minimum_user\src\src_user\IfWrapper\SilsMockup\uart_sils.c" From 66ef89b10ffba6d4cd76d3156bdfa80638f0774b Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Mon, 31 Oct 2022 02:28:08 +0900 Subject: [PATCH 6/6] fix typo --- Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils.cpp | 2 +- Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils.cpp b/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils.cpp index 5bb7a46d0..5a5d103ce 100644 --- a/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils.cpp +++ b/Examples/2nd_obc_user/src/src_user/IfWrapper/Sils/uart_sils.cpp @@ -3,7 +3,7 @@ #include "../../Settings/port_config.h" #ifdef USE_SCI_COM_WINGS -#include "sils_sci_urat_if.hpp" +#include "sils_sci_uart_if.hpp" #endif int OBC_C2A_SendFromObc(int port_id, unsigned char* buffer, int offset, int count); diff --git a/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils.cpp b/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils.cpp index 4a633ba01..bb7512d6a 100644 --- a/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils.cpp +++ b/Examples/minimum_user/src/src_user/IfWrapper/Sils/uart_sils.cpp @@ -3,7 +3,7 @@ #include "../../Settings/port_config.h" #ifdef USE_SCI_COM_UART -#include "sils_sci_urat_if.hpp" +#include "sils_sci_uart_if.hpp" #endif int OBC_C2A_SendFromObc(int port_id, unsigned char* buffer, int offset, int count);