-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathccp_dump.c
149 lines (119 loc) · 3.81 KB
/
ccp_dump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#pragma section REPRO
/**
* @file
* @brief TL や CDIS などの PacketList や BCT の CCP をダンプする (GS から内容を確認できるようにする) ための App
*/
#include "ccp_dump.h"
#include <stddef.h>
#include <string.h>
#include "../tlm_cmd/command_dispatcher_manager.h"
#include "../system/time_manager/time_manager.h"
/**
* @brief App 初期化関数
* @param void
* @return RESULT
*/
static RESULT CCP_DUMP_init_(void);
static RESULT CCP_DUMP_cdis_(const CommandDispatcher* cdis);
static RESULT CCP_DUMP_bct_(void);
static CcpDump ccp_dump_;
const CcpDump* const ccp_dump = &ccp_dump_;
AppInfo CCP_DUMP_create_app(void)
{
return AI_create_app_info("ccpdump", CCP_DUMP_init_, NULL);
}
static RESULT CCP_DUMP_init_(void)
{
memset(&ccp_dump_, 0x00, sizeof(CcpDump));
// 初回はなにもダンプしてないので
ccp_dump_.dump.status = CCP_DUMP_STATUS_NOT_FOUND;
return RESULT_OK;
}
CCP_CmdRet Cmd_CCP_DUMP_CDIS(const CommonCmdPacket* packet)
{
CCP_DUMP_CdisDump* cdis_dump = &ccp_dump_.info.cdis;
const CommandDispatcher* cdis;
cdis_dump->cdis_idx = CCP_get_param_from_packet(packet, 0, uint8_t);
cdis_dump->queue_idx = CCP_get_param_from_packet(packet, 1, uint16_t);
cdis = CDIS_MGR_get_cdis(cdis_dump->cdis_idx);
ccp_dump_.dump.target = CCP_DUMP_TARGET_CDIS;
if (cdis == NULL)
{
ccp_dump_.dump.status = CCP_DUMP_STATUS_NOT_FOUND;
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, 1);
}
if (PL_count_active_nodes(cdis->pl) <= cdis_dump->queue_idx)
{
ccp_dump_.dump.status = CCP_DUMP_STATUS_NOT_FOUND;
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, 2);
}
if (CCP_DUMP_cdis_(cdis) == RESULT_OK)
{
ccp_dump_.dump.status = CCP_DUMP_STATUS_OK;
ccp_dump_.dump.dump_time = TMGR_get_master_clock();
return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}
else
{
ccp_dump_.dump.status = CCP_DUMP_STATUS_NOT_FOUND;
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, 3);
}
}
static RESULT CCP_DUMP_cdis_(const CommandDispatcher* cdis)
{
const CCP_DUMP_CdisDump* cdis_dump = &ccp_dump_.info.cdis;
const PacketList* pl = cdis->pl;
const PL_Node* node = PL_get_head(pl);
const CommonCmdPacket* ccp;
uint16_t i;
for (i = 0; i < cdis_dump->queue_idx; ++i)
{
node = PL_get_next(node);
}
if (node == NULL)
{
return RESULT_ERR;
}
ccp = (const CommonCmdPacket*)PL_get_packet(node);
// CCP_copy_packet はパケット長しかコピーしない.ここではダンプなので,末端の不定もふくめてコピーする
memcpy(ccp_dump_.dump.ccp.packet, ccp->packet, CSP_MAX_LEN);
return RESULT_OK;
}
CCP_CmdRet Cmd_CCP_DUMP_BCT(const CommonCmdPacket* packet)
{
CCP_DUMP_BctDump* bct_dump = &ccp_dump_.info.bct;
bct_dump->pos.block = (bct_id_t)CCP_get_param_from_packet(packet, 0, uint16_t);
bct_dump->pos.cmd = CCP_get_param_from_packet(packet, 1, uint8_t);
ccp_dump_.dump.target = CCP_DUMP_TARGET_BCT;
if (BCT_check_position(&bct_dump->pos) != BCT_SUCCESS)
{
ccp_dump_.dump.status = CCP_DUMP_STATUS_NOT_FOUND;
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, 1);
}
if (CCP_DUMP_bct_() == RESULT_OK)
{
ccp_dump_.dump.status = CCP_DUMP_STATUS_OK;
ccp_dump_.dump.dump_time = TMGR_get_master_clock();
return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}
else
{
ccp_dump_.dump.status = CCP_DUMP_STATUS_NOT_FOUND;
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, 2);
}
}
static RESULT CCP_DUMP_bct_(void)
{
CCP_DUMP_BctDump* bct_dump = &ccp_dump_.info.bct;
// BCT は CCP 長さが短いので,末尾を 0 埋めしておく
memset(&ccp_dump_.dump.ccp, 0x00, sizeof(CommonCmdPacket));
if (BCT_load_cmd(&bct_dump->pos, &ccp_dump_.dump.ccp) == BCT_SUCCESS)
{
return RESULT_OK;
}
else
{
return RESULT_ERR;
}
}
#pragma section