C2A_Core
utility_counter.c
[詳解]
1 #pragma section REPRO
2 #include "utility_counter.h"
3 
4 // FIXME
5 // error: ISO C requires a translation unit to contain at least one declaration [-Werror,-Wempty-translation-unit]
6 // 対策のために,適当に宣言しておく
8 {
9  return 0;
10 }
11 #if 0
12 
13 #include "../TlmCmd/packet_handler.h"
14 #include "../System/AnomalyLogger/anomaly_logger.h"
15 #include <string.h> // for memcpy
16 #include "../TlmCmd/common_cmd_packet_util.h"
17 
18 static UtilityCounter utility_counter_;
19 const UtilityCounter* const utility_counter = &utility_counter_;
20 
21 static void UTIL_COUNTER_all_init_(void);
22 static void UTIL_COUNTER_clear_(UTIL_COUNTER_NAME num);
23 static void UTIL_COUNTER_incl_(UTIL_COUNTER_NAME num);
24 
25 // 汎用カウンタ関連ここから
26 AppInfo UTIL_COUNTER_create_app(void)
27 {
28  return AI_create_app_info("utility_counter", UTIL_COUNTER_all_init_, NULL);
29 }
30 
31 static void UTIL_COUNTER_all_init_(void)
32 {
33  int i;
34  for (i = 0; i < UTIL_COUNTER_MAX; i++)
35  {
36  utility_counter_.cnt[i].counter = 0;
37  utility_counter_.cnt[i].threshold = 0;
38  utility_counter_.cnt[i].anomaly_active = 0;
39  }
40 }
41 
42 static void UTIL_COUNTER_clear_(UTIL_COUNTER_NAME num)
43 {
44  utility_counter_.cnt[num].counter = 0;
45 }
46 
47 static void UTIL_COUNTER_incl_(UTIL_COUNTER_NAME num)
48 {
49  if (utility_counter_.cnt[num].counter == 0xffffffff)
50  {
51  utility_counter_.cnt[num].counter = 0;
52  }
53  else
54  {
55  utility_counter_.cnt[num].counter += 1;
56  }
57  if (utility_counter_.cnt[num].counter >= utility_counter_.cnt[num].threshold)
58  {
59  if (utility_counter_.cnt[num].anomaly_active)
60  {
61  // FIXME: utility counter のりファクタ時に直す
62 // #ifndef AL_DISALBE_AT_C2A_CORE
63  AL_add_anomaly(AL_GROUP_UTIL_CNT, (uint32_t)num); // カウンタが閾値超えたことを示してアノマリを発生させる
64 // #endif
65  utility_counter_.cnt[num].anomaly_active = 0; // アノマリを発生させたら無効化する
66  }
67  }
68 
69 }
70 
71 CCP_CmdRet Cmd_UTIL_COUNTER_INCREMENT(const CommonCmdPacket* packet)
72 {
73  UTIL_COUNTER_NAME index;
74 
75  // この代入方法は安全??
76  // index = (int32_t)(CCP_get_param_head(packet)[0] << 24 | CCP_get_param_head(packet)[1] << 16 | CCP_get_param_head(packet)[2] << 8 | CCP_get_param_head(packet)[3]);
77  memcpy(&index, &CCP_get_param_head(packet)[0], 4);
78 
79  if (index < UTIL_COUNTER_MAX)
80  {
81  // 範囲内ならインクリメント
82  UTIL_COUNTER_incl_(index);
83  }
84  else
85  {
87  }
89 
90 }
91 
92 CCP_CmdRet Cmd_UTIL_COUNTER_RESET(const CommonCmdPacket* packet)
93 {
94  UTIL_COUNTER_NAME index;
95 
96  // この代入方法は安全??
97  // index = (int32_t)(CCP_get_param_head(packet)[0] << 24 | CCP_get_param_head(packet)[1] << 16 | CCP_get_param_head(packet)[2] << 8 | CCP_get_param_head(packet)[3]);
98  memcpy(&index, &CCP_get_param_head(packet)[0], 4);
99 
100  if (index < UTIL_COUNTER_MAX)
101  {
102  // 範囲内なら該当のものをクリア
103  UTIL_COUNTER_clear_(index);
104  }
105  else if (index == 0xff)
106  {
107  // 0xff指定なら全クリア
108  UTIL_COUNTER_all_init_();
109  }
110  else
111  {
113  }
115 }
116 
117 CCP_CmdRet Cmd_UTIL_COUNTER_SET_PARAM(const CommonCmdPacket* packet)
118 {
119  UTIL_COUNTER_NAME index;
120 
121  // この代入方法は安全??
122  // index = (int32_t)(CCP_get_param_head(packet)[0] << 24 | CCP_get_param_head(packet)[1] << 16 | CCP_get_param_head(packet)[2] << 8 | CCP_get_param_head(packet)[3]);
123  memcpy(&index, &CCP_get_param_head(packet)[0], 4);
124 
125  if (index < UTIL_COUNTER_MAX)
126  {
127  memcpy(&utility_counter_.cnt[index].threshold, &CCP_get_param_head(packet)[4], 4);
128  memcpy(&utility_counter_.cnt[index].anomaly_active, &CCP_get_param_head(packet)[8], 1);
129  if (utility_counter_.cnt[index].anomaly_active > 1)
130  {
131  utility_counter_.cnt[index].anomaly_active = 0;
133  }
134  }
135  else
136  {
138  }
140 }
141 
142 #endif
143 
144 #pragma section
AppInfo AI_create_app_info(const char *name, void(*initializer)(void), void(*entry_point)(void))
AppInfo を作る
Definition: app_info.c:9
@ CCP_EXEC_SUCCESS
@ CCP_EXEC_ILLEGAL_PARAMETER
コマンド実行時のパラメタエラー
const uint8_t * CCP_get_param_head(const CommonCmdPacket *packet)
先頭のパラメタのポインタを取得
CCP_CmdRet CCP_make_cmd_ret_without_err_code(CCP_EXEC_STS exec_sts)
コマンド返り値である CCP_CmdRet を作成(エラーコード不使用版)
コマンド返り値
Space Packet (コマンド用)
int UTIL_COUNTER_dummy(void)