C2A_Core
gs.c
[詳解]
1 #pragma section REPRO
7 #include "gs.h"
8 
9 #include <string.h>
10 #include <stdint.h>
11 
12 #include "../../IfWrapper/ccsds_user.h"
13 #include "../../TlmCmd/Ccsds/tc_transfer_frame.h"
17 
18 
19 #define GS_RX_HEADER_SIZE (2)
20 #define GS_RX_FRAMELENGTH_TYPE_SIZE (2)
21 #define GS_TX_STREAM (0) // どれでも良いがとりあえず 0 で
22 
23 #if GS_RX_HEADER_NUM > DS_STREAM_MAX
24 #error GS RX HEADER NUM TOO MANY
25 #endif
26 
27 // それぞれ AD, BD, BC
29 static uint8_t GS_tx_frame_[VCDU_LEN];
30 
37 
44 
50 
57 static DS_ERR_CODE GS_analyze_rec_data_(DS_StreamConfig* p_stream_config, void* p_driver);
58 
60  uint8_t uart_ch,
61  DS_StreamRecBuffer* ccsds_rx_buffers[DS_STREAM_MAX],
62  DS_StreamRecBuffer* uart_rx_buffers[DS_STREAM_MAX])
63 {
64  DS_ERR_CODE ret_uart, ret_ccsds;
65  int i;
66  int stream;
67 
68  memset(gs_driver, 0x00, sizeof(GS_Driver));
69 
71 
74 
80 
81  memset(GS_rx_header_, 0x00, sizeof(GS_rx_header_));
82  GS_rx_header_[0][0] |= (uint8_t)((TCTF_TYPE_AD & 0x0f) << 4);
83  GS_rx_header_[1][0] |= (uint8_t)((TCTF_TYPE_BD & 0x0f) << 4);
84  GS_rx_header_[2][0] |= (uint8_t)((TCTF_TYPE_BC & 0x0f) << 4);
85  for (stream = 0; stream < GS_RX_HEADER_NUM; ++stream)
86  {
87  GS_rx_header_[stream][0] |= (uint8_t)((TCTF_SCID_SAMPLE_SATELLITE & 0x3ff) >> 8);
88  GS_rx_header_[stream][1] |= (uint8_t)(TCTF_SCID_SAMPLE_SATELLITE & 0xff);
89  }
90 
93  ccsds_rx_buffers,
97  uart_rx_buffers,
99  if (ret_ccsds != DS_ERR_CODE_OK || ret_uart != DS_ERR_CODE_OK) return DS_INIT_DS_INIT_ERR;
102 
103  for (i = 0; i < GS_PORT_TYPE_NUM; ++i)
104  {
108  gs_driver->info[i].rx.last_rec_time = 0;
110 
111  gs_driver->info[i].rx.tctf.last_rec_tctf_type = TCTF_TYPE_UNKNOWN;
112  gs_driver->info[i].rx.tctf.ad_rec_status = GS_VALIDATE_ERR_OK;
113  gs_driver->info[i].rx.tctf.bd_rec_status = GS_VALIDATE_ERR_OK;
114  gs_driver->info[i].rx.tctf.bd_rec_status = GS_VALIDATE_ERR_OK;
115 
116  gs_driver->info[i].tx.send_cycle = 0;
118  gs_driver->info[i].tx.vcdu_counter = 0;
119  }
120 
123 
124  return DS_INIT_OK;
125 }
126 
128 {
129  p_super->interface = CCSDS;
131 
132  return DS_ERR_CODE_OK;
133 }
134 
136 {
137  p_super->interface = UART;
139 
140  return DS_ERR_CODE_OK;
141 }
142 
144 {
145  DS_StreamConfig* p_stream_config;
146  int stream;
147 
148  for (stream = 0; stream < GS_RX_HEADER_NUM; ++stream)
149  {
150  p_stream_config = &(p_super->stream_config[stream]);
151  DSSC_enable(p_stream_config);
152  DSSC_enable_strict_frame_search(p_stream_config); // 複数ストリームがあり,かつ論理的な受信漏れを0にするため.
153 
154  DSSC_set_tx_frame(p_stream_config, GS_tx_frame_); // 全 stream, uart, ccsds に関わらず共通
155  DSSC_set_tx_frame_size(p_stream_config, VCDU_LEN); // VCDU を送信
156 
157  DSSC_set_rx_header(p_stream_config, GS_rx_header_[stream], GS_RX_HEADER_SIZE);
158  DSSC_set_rx_frame_size(p_stream_config, -1); // 可変長
161  DSSC_set_rx_framelength_offset(p_stream_config, 1); // TCTF の framelength は 0 起算
163  }
164 }
165 
167 {
168  uint8_t i, stream;
169 
170  for (i = 0; i < GS_PORT_TYPE_NUM; ++i)
171  {
172  DriverSuper* ds;
173 
174  if (i == GS_PORT_TYPE_CCSDS)
175  {
177  }
178  else
179  {
180  ds = &gs_driver->driver_uart.super;
181  }
182 
183  // TODO: これはエラー情報をきちんと把握したいので,アノマリ発行を入れる
186 
187  if (gs_driver->info[i].rx.rec_status != DS_ERR_CODE_OK) continue;
188 
189  for (stream = 0; stream < GS_RX_HEADER_NUM; ++stream)
190  {
191  DS_StreamConfig* p_stream_config;
192 
193  p_stream_config = &ds->stream_config[stream];
194  if (DSSC_get_rec_status(p_stream_config)->status_code != DS_STREAM_REC_STATUS_FIXED_FRAME) continue;
195 
197  }
198  }
199 
200  // TODO: 常に OK を返すのでいいのか検討
201  return DS_REC_OK;
202 }
203 
204 static DS_ERR_CODE GS_analyze_rec_data_(DS_StreamConfig* p_stream_config, void* p_driver)
205 {
206  const uint8_t* gs_rx_data = DSSC_get_rx_frame(p_stream_config);
207  const TcTransferFrame* tctf = TCTF_convert_from_bytes_to_tctf(gs_rx_data);
208  GS_Driver* gs_driver = (GS_Driver*)p_driver;
209  GS_PORT_TYPE driver_index;
210  GS_VALIDATE_ERR tctf_validate_status;
211  const TcSegment* tcs;
212  const CmdSpacePacket* csp;
213 
214  // アドレス計算で CCSDS か UART か判別
215  if ((uint32_t)p_stream_config < (uint32_t)&gs_driver->driver_uart)
216  {
217  driver_index = GS_PORT_TYPE_CCSDS;
218  }
219  else
220  {
221  driver_index = GS_PORT_TYPE_UART;
222  }
223 
224  tctf_validate_status = GS_validate_tctf(tctf);
225 
226  gs_driver->info[driver_index].rx.tctf.last_rec_tctf_type = TCTF_get_type(tctf);
227  switch (gs_driver->info[driver_index].rx.tctf.last_rec_tctf_type)
228  {
229  case TCTF_TYPE_AD:
230  gs_driver->info[driver_index].rx.tctf.ad_rec_status = tctf_validate_status;
231  break;
232 
233  case TCTF_TYPE_BC:
234  gs_driver->info[driver_index].rx.tctf.bc_rec_status = tctf_validate_status;
235  break;
236 
237  case TCTF_TYPE_BD:
238  gs_driver->info[driver_index].rx.tctf.bd_rec_status = tctf_validate_status;
239  break;
240 
241  default:
242  // not reached
243  break;
244  }
245 
246  if (tctf_validate_status != GS_VALIDATE_ERR_OK) return DS_ERR_CODE_ERR;
247 
248  tcs = TCTF_get_tc_segment(tctf);
249  csp = TCS_get_command_space_packet(tcs);
250  gs_driver->info[driver_index].rx.last_dest_type = CSP_get_dest_type(csp);
252  gs_driver->info[driver_index].rx.cmd_ack = PH_analyze_cmd_packet(csp); // 受信コマンドパケット解析
253 
254  return DS_ERR_CODE_OK;
255 }
256 
258 {
259  DS_ERR_CODE ret_ccsds = DS_ERR_CODE_OK;
260  DS_ERR_CODE ret_uart = DS_ERR_CODE_OK;
261  size_t vcdu_size = sizeof(VCDU);
262 
263  // パディングが無ければ元を GS_tx_frame_ にコピーさせる (444Byte) のコピーが無駄
264  if (vcdu_size == VCDU_LEN)
265  {
268  }
269  else
270  {
271  VCDU_generate_byte_stream(vcdu, GS_tx_frame_); // 送信元にセット 消したいなぁ...
274  }
275 
276  // CCSDS
279  {
283 
284  // DS 側の名称が cmd なだけで送信しているのは TLM
286  }
287 
288  // UART
290  {
294 
295  // DS 側の名称が cmd なだけで送信しているのは TLM
297  }
298 
299  if (ret_ccsds != DS_ERR_CODE_OK || ret_uart != DS_ERR_CODE_OK)
300  {
302  }
303 
304  return DS_CMD_OK;
305 }
306 
307 #pragma section
uint8_t CCSDS_get_buffer_num(void)
CCSDS TX の残り buffer をカウントするAPI を呼びだす
Definition: ccsds_sils.cpp:68
CCP_DEST_TYPE CSP_get_dest_type(const CmdSpacePacket *csp)
Destination Type を取得
@ CCP_DEST_TYPE_TO_UNKOWN
const GS_Driver *const gs_driver
Definition: di_gs.c:29
void DSSC_enable_strict_frame_search(DS_StreamConfig *p_stream_config)
void DSSC_set_rx_frame_size(DS_StreamConfig *p_stream_config, const int16_t rx_frame_size)
void DSSC_set_rx_framelength_type_size(DS_StreamConfig *p_stream_config, const uint16_t rx_framelength_type_size)
void DSSC_set_tx_frame(DS_StreamConfig *p_stream_config, uint8_t *tx_frame)
DS_ERR_CODE DS_analyze_rec_data(DriverSuper *p_super, uint8_t stream, void *p_driver)
data_analyzer_ を呼び出し,受信データを解析する.
Definition: driver_super.c:486
const DS_StreamRecStatus * DSSC_get_rec_status(const DS_StreamConfig *p_stream_config)
const DS_RecStatus * DSC_get_rec_status(const DriverSuper *p_super)
void DSSC_set_rx_framelength_offset(DS_StreamConfig *p_stream_config, const uint16_t rx_framelength_offset)
void DSSC_set_tx_frame_size(DS_StreamConfig *p_stream_config, const uint16_t tx_frame_size)
void DSSC_set_rx_header(DS_StreamConfig *p_stream_config, const uint8_t *rx_header, const uint16_t rx_header_size)
DS_ERR_CODE DS_receive(DriverSuper *p_super)
継承先の機器からテレメトリを受信する
Definition: driver_super.c:355
DS_ERR_CODE DS_init_streams(DriverSuper *p_super, void *if_config, DS_StreamRecBuffer *rx_buffers[DS_STREAM_MAX], DS_ERR_CODE(*load_init_setting)(DriverSuper *p_super))
継承先の機器より DriverSuper を初期化する(複数の stream を使用する場合)
Definition: driver_super.c:254
void DSSC_set_data_analyzer(DS_StreamConfig *p_stream_config, DS_ERR_CODE(*data_analyzer)(DS_StreamConfig *p_stream_config, void *p_driver))
const uint8_t * DSSC_get_rx_frame(const DS_StreamConfig *p_stream_config)
確定したフレームを取得
DS_ERR_CODE DS_send_general_cmd(DriverSuper *p_super, uint8_t stream)
継承先の機器に一般コマンドを発行する
Definition: driver_super.c:496
void DSSC_enable(DS_StreamConfig *p_stream_config)
void DSSC_set_rx_framelength_pos(DS_StreamConfig *p_stream_config, const int16_t rx_framelength_pos)
各制御センサ・アクチュエータ等とのインターフェースドライバ群のスーパークラス
@ DS_STREAM_REC_STATUS_FIXED_FRAME
Definition: driver_super.h:179
DS_INIT_ERR_CODE
Driver の初期化関数のエラーコード
Definition: driver_super.h:70
@ DS_INIT_OK
OK
Definition: driver_super.h:71
@ DS_INIT_DS_INIT_ERR
DS_init でのエラー
Definition: driver_super.h:72
#define DS_STREAM_MAX
Definition: driver_super.h:31
DS_REC_ERR_CODE
Driver の受信関数のエラーコード
Definition: driver_super.h:84
@ DS_REC_OK
OK
Definition: driver_super.h:85
DS_CMD_ERR_CODE
各DIが Driver にコマンドを送るときに,統一的に使うコード
Definition: driver_super.h:100
@ DS_CMD_OK
OKは0であることを保証する
Definition: driver_super.h:101
@ DS_CMD_DRIVER_SUPER_ERR
DriverSuper 側,つまり配送の低レイヤーでエラーが起きた場合
Definition: driver_super.h:105
DS_ERR_CODE
DriverSuper の汎用エラーコード
Definition: driver_super.h:116
@ DS_ERR_CODE_ERR
Definition: driver_super.h:118
@ DS_ERR_CODE_OK
返り値は継承先や IF 先で上書きされるため,OK は 0 であることが必須
Definition: driver_super.h:117
static DS_ERR_CODE GS_load_ccsds_driver_super_init_settings_(DriverSuper *p_super)
CCSDS 側 Driver の DS 上での初期化設定
Definition: gs.c:127
DS_CMD_ERR_CODE GS_send_vcdu(GS_Driver *gs_driver, const VCDU *vcdu)
地上に向けて TLM を送信. 形式は VCDU
Definition: gs.c:257
DS_REC_ERR_CODE GS_rec_tctf(GS_Driver *gs_driver)
地上から CMD を受信する. 形式は TC Transer Frame
Definition: gs.c:166
static DS_ERR_CODE GS_analyze_rec_data_(DS_StreamConfig *p_stream_config, void *p_driver)
地上からの受信データ解析関数
Definition: gs.c:204
static void GS_load_default_driver_super_init_settings_(DriverSuper *p_super)
上記初期化の共通部分をまとめた関数
Definition: gs.c:143
#define GS_RX_HEADER_SIZE
Definition: gs.c:19
static DS_ERR_CODE GS_load_uart_driver_super_init_settings_(DriverSuper *p_super)
UART 側 Driver の DS 上での初期化設定
Definition: gs.c:135
#define GS_RX_FRAMELENGTH_TYPE_SIZE
Definition: gs.c:20
static uint8_t GS_rx_header_[GS_RX_HEADER_NUM][GS_RX_HEADER_SIZE]
Definition: gs.c:28
DS_INIT_ERR_CODE GS_init(GS_Driver *gs_driver, uint8_t uart_ch, DS_StreamRecBuffer *ccsds_rx_buffers[DS_STREAM_MAX], DS_StreamRecBuffer *uart_rx_buffers[DS_STREAM_MAX])
Driver の初期化
Definition: gs.c:59
#define GS_TX_STREAM
Definition: gs.c:21
static uint8_t GS_tx_frame_[VCDU_LEN]
Definition: gs.c:29
Ground Station との通信用の Driver
GS_PORT_TYPE
GS の通信ポートは CCSDS と UART の 2 つある
Definition: gs.h:24
@ GS_PORT_TYPE_NUM
port 数
Definition: gs.h:27
@ GS_PORT_TYPE_UART
UART
Definition: gs.h:26
@ GS_PORT_TYPE_CCSDS
CCSDS
Definition: gs.h:25
#define GS_RX_HEADER_NUM
Definition: gs.h:16
void GS_validate_init(void)
GS_ValiateInfo の初期化
Definition: gs_validate.c:42
GS_VALIDATE_ERR GS_validate_tctf(const TcTransferFrame *tctf)
tctf の検証
Definition: gs_validate.c:51
GS_VALIDATE_ERR
gs_validate 関数の返り値
Definition: gs_validate.h:25
@ GS_VALIDATE_ERR_OK
Definition: gs_validate.h:26
@ CCSDS
Definition: if_list.h:10
@ UART
Definition: if_list.h:11
PH_ACK PH_analyze_cmd_packet(const CommonCmdPacket *packet)
CCP を解析する
C2A 全体を流れる Common Packet の配送を制御する
@ PH_ACK_SUCCESS
OK
SpacePacket 類 と CommonTlmCmdPacket 類が相互参照するのを回避するためのヘッダ
C89 環境用 stdint.h
uint32_t bitrate
継承先の機器のビットレート値 (bps)
Definition: ccsds.h:24
uint8_t ch
将来的にchが追加されることを想定して
Definition: ccsds.h:23
uint8_t buffer_num
送信バッファの残り数. 最大 CCSDS_FIFO_SIZE
Definition: ccsds_user.h:34
Space Packet (コマンド用)
int ret_from_if_rx
IF_RX の返り値
Definition: driver_super.h:138
DriverSuperStream の設定
Definition: driver_super.h:281
フレーム受信バッファ
Definition: driver_super.h:222
DriverSuper の設定 各 IF はこれを継承してつかう.
Definition: driver_super.h:407
IF_LIST_ENUM interface
継承先の機器の使用 IF
Definition: driver_super.h:409
DS_StreamConfig stream_config[DS_STREAM_MAX]
Definition: driver_super.h:414
GroundStation Driver
Definition: gs.h:66
struct GS_Driver::@72 driver_ccsds
CCSDS_Config ccsds_config
Definition: gs.h:71
const GS_Info * latest_info
Definition: gs.h:83
GS_Info info[GS_PORT_TYPE_NUM]
CCSDS 用と UART 用 2 つ
Definition: gs.h:82
uint8_t is_tlm_on
UART に TLM を流すかどうか, CCSDS では許容でも UART に TLM を送りすぎると詰まってしまうため
Definition: gs.h:79
CCSDS_Info ccsds_info
Definition: gs.h:84
GS_PORT_TYPE tlm_tx_port_type
Definition: gs.h:85
struct GS_Driver::@73 driver_uart
UART_Config uart_config
Definition: gs.h:78
DriverSuper super
Definition: gs.h:70
VCDU_VCID vcid
送信した TLM のタイプ
Definition: gs.h:56
cycle_t last_rec_time
最後に受信した時刻
Definition: gs.h:41
struct GS_Info::@69::@71 tctf
struct GS_Info::@69 rx
struct GS_Info::@70 tx
uint32_t vcdu_counter
VCDU counter
Definition: gs.h:57
CCP_DEST_TYPE last_dest_type
最後に受信したパケットの dest type
Definition: gs.h:40
PH_ACK cmd_ack
受信した CMD の実行結果
Definition: gs.h:42
int ret_from_if_rx
UART or CCSDS からの返り値
Definition: gs.h:39
cycle_t send_cycle
最後に送信したときの時刻
Definition: gs.h:55
DS_ERR_CODE rec_status
DriverSuper からの受信結果
Definition: gs.h:38
TC Segment のパケット構造体
Definition: tc_segment.h:34
TC Transfer Frame のパケット構造体
PARITY_SETTINGS parity_settings
パリティ設定
Definition: uart.h:85
UART_DATA_LENGTH data_length
データ長
Definition: uart.h:86
uint32_t baudrate
継承先の機器のボーレート値
Definition: uart.h:84
uint8_t ch
継承先の機器がつながっているポート番号
Definition: uart.h:82
UART_STOP_BIT stop_bit
ストップビット
Definition: uart.h:87
Definition: vcdu.h:12
const CmdSpacePacket * TCS_get_command_space_packet(const TcSegment *tcs)
Command space packet 開始ポインタを取得
Definition: tc_segment.c:35
const TcSegment * TCTF_get_tc_segment(const TcTransferFrame *tctf)
TC Segment を取得
const TcTransferFrame * TCTF_convert_from_bytes_to_tctf(const uint8_t *byte)
受信 byte 列を TcTransferFrame* に変換
TCTF_TYPE TCTF_get_type(const TcTransferFrame *tctf)
command type を取得
@ TCTF_SCID_SAMPLE_SATELLITE
@ TCTF_TYPE_BD
@ TCTF_TYPE_AD
@ TCTF_TYPE_UNKNOWN
@ TCTF_TYPE_BC
cycle_t TMGR_get_master_total_cycle(void)
現在の total_cycle を返す
Definition: time_manager.c:97
@ UART_DATA_LENGTH_8BIT
Definition: uart.h:37
@ PARITY_SETTINGS_NONE
パリティチェックをしない
Definition: uart.h:23
@ UART_STOP_BIT_1BIT
Definition: uart.h:46
uint32_t VCDU_get_vcdu_counter(const VCDU *vcdu)
Definition: vcdu.c:151
void VCDU_generate_byte_stream(const VCDU *vcdu, uint8_t byte_stream[VCDU_LEN])
Definition: vcdu.c:9
VCDU_VCID VCDU_get_vcid(const VCDU *vcdu)
Definition: vcdu.c:122
@ VCDU_VCID_UNKNOWN
Definition: vcdu.h:35
#define VCDU_LEN
Definition: vcdu.h:8