코드 정리

- 주석 영문으로 변경
- Allman 스타일로 통일
This commit is contained in:
2026-04-16 12:01:51 +09:00
parent c98d9ae14e
commit 2861cb9815
35 changed files with 2406 additions and 2557 deletions

View File

@@ -74,11 +74,11 @@ static bool dr_tag_eq(const char *tag, const char *key4)
bool dr_get_u16(const ParsedCmd *cmd, uint8_t word_index, uint16_t *out)
{
uint8_t pos = (uint8_t)(word_index * 2);
if (cmd->data_len < (uint8_t)(pos + 2)) {
if (cmd->data_len < (uint8_t)(pos + 2))
{
return false;
}
*out = (uint16_t)((uint16_t)cmd->data[pos] << 8)
| (uint16_t)cmd->data[pos + 1];
*out = (uint16_t)((uint16_t)cmd->data[pos] << 8) | (uint16_t)cmd->data[pos + 1];
return true;
}
@@ -87,17 +87,20 @@ void dr_get_ascii(const ParsedCmd *cmd, uint8_t offset, char *out, uint8_t max_l
uint8_t i;
uint8_t remain;
if (offset >= cmd->data_len) {
if (offset >= cmd->data_len)
{
out[0] = '\0';
return;
}
remain = (uint8_t)(cmd->data_len - offset);
if (remain > max_len) {
if (remain > max_len)
{
remain = max_len;
}
for (i = 0; i < remain; i++) {
for (i = 0; i < remain; i++)
{
out[i] = (char)cmd->data[offset + i];
}
out[remain] = '\0';
@@ -113,7 +116,8 @@ uint16_t dr_crc16_compute(const uint8_t *p_data, uint32_t size, const uint16_t *
uint32_t i;
uint16_t crc = (p_crc == NULL) ? 0xFFFF : *p_crc;
for (i = 0; i < size; i++) {
for (i = 0; i < size; i++)
{
crc = (uint8_t)(crc >> 8) | (crc << 8);
crc ^= p_data[i];
crc ^= (uint8_t)(crc & 0xFF) >> 4;
@@ -134,7 +138,8 @@ static bool dr_crc16_check_packet(const uint8_t *packet, uint32_t packet_len)
uint16_t expected_crc;
uint32_t data_len;
if (packet_len < 2) {
if (packet_len < 2)
{
return false;
}
@@ -154,7 +159,8 @@ static bool dr_crc16_check_packet(const uint8_t *packet, uint32_t packet_len)
*============================================================================*/
static void dr_send_error(const char *err_tag, const char *cmd_tag)
{
if (g_plat.tx_bin) {
if (g_plat.tx_bin)
{
uint8_t err_buf[8];
memcpy(&err_buf[0], err_tag, 4);
memcpy(&err_buf[4], cmd_tag, 4);
@@ -173,9 +179,11 @@ static bool dr_parse_cmd(const uint8_t *buffer, uint8_t length, ParsedCmd *out)
uint8_t data_len;
/* Less than 4 bytes -> TAG cannot be identified */
if (length < 4) {
if (length < 4)
{
dr_send_error("rxs:", "????");
if (g_plat.log && g_log_enable) {
if (g_plat.log && g_log_enable)
{
g_plat.log("[parser] too short (%u bytes) -> rxs:\r\n", length);
}
return false;
@@ -185,18 +193,23 @@ static bool dr_parse_cmd(const uint8_t *buffer, uint8_t length, ParsedCmd *out)
dr_copy_tag(buffer, out->tag);
/* CRC verification */
if (g_plat.crc_check) {
if (length < 7) {
if (g_plat.crc_check)
{
if (length < 7)
{
dr_send_error("rxs:", out->tag);
if (g_plat.log && g_log_enable) {
if (g_plat.log && g_log_enable)
{
g_plat.log("[parser] CRC enabled but too short (%u) -> rxs:\r\n", length);
}
return false;
}
if (!dr_crc16_check_packet(buffer, length)) {
if (!dr_crc16_check_packet(buffer, length))
{
dr_send_error("rxc:", out->tag);
if (g_plat.log && g_log_enable) {
if (g_plat.log && g_log_enable)
{
g_plat.log("[parser] CRC mismatch '%s' -> rxc:\r\n", out->tag);
}
return false;
@@ -204,15 +217,18 @@ static bool dr_parse_cmd(const uint8_t *buffer, uint8_t length, ParsedCmd *out)
data_len = (uint8_t)(length - 4 - 2); /* strip TAG and CRC */
}
else {
else
{
data_len = (uint8_t)(length - 4);
}
if (data_len > DR_MAX_DATA) {
if (data_len > DR_MAX_DATA)
{
data_len = DR_MAX_DATA;
}
if (data_len > 0) {
if (data_len > 0)
{
memcpy(out->data, buffer + 4, data_len);
}
out->data_len = data_len;
@@ -232,33 +248,43 @@ static int dr_cmd_dispatch(const ParsedCmd *cmd)
uint16_t i;
char tag_lower[5];
if (m_cmd_table == NULL) {
if (m_cmd_table == NULL)
{
dr_send_error("rxn:", cmd->tag);
if (g_plat.log) g_plat.log("[parser] table not initialized -> rxn:\n");
if (g_plat.log)
{
g_plat.log("[parser] table not initialized -> rxn:\n");
}
return 0;
}
/* Case-insensitive matching */
for (i = 0; i < 4 && cmd->tag[i]; i++) {
tag_lower[i] = (cmd->tag[i] >= 'A' && cmd->tag[i] <= 'Z')
? (cmd->tag[i] + 32) : cmd->tag[i];
for (i = 0; i < 4 && cmd->tag[i]; i++)
{
tag_lower[i] = (cmd->tag[i] >= 'A' && cmd->tag[i] <= 'Z') ? (cmd->tag[i] + 32) : cmd->tag[i];
}
tag_lower[i] = '\0';
for (i = 0; i < m_cmd_count; i++) {
if (dr_tag_eq(tag_lower, m_cmd_table[i].tag)) {
for (i = 0; i < m_cmd_count; i++)
{
if (dr_tag_eq(tag_lower, m_cmd_table[i].tag))
{
if (!m_cmd_table[i].enabled) {
if (!m_cmd_table[i].enabled)
{
dr_send_error("rxd:", cmd->tag);
if (g_plat.log && g_log_enable) {
if (g_plat.log && g_log_enable)
{
g_plat.log("Command '%s' disabled -> rxd:\n", cmd->tag);
}
return 0;
}
if (m_cmd_table[i].handler == NULL) {
if (m_cmd_table[i].handler == NULL)
{
dr_send_error("rxn:", cmd->tag);
if (g_plat.log) {
if (g_plat.log)
{
g_plat.log("[parser] NULL handler for '%s' -> rxn:\n", cmd->tag);
}
return 0;
@@ -270,7 +296,8 @@ static int dr_cmd_dispatch(const ParsedCmd *cmd)
/* TAG not found in table */
dr_send_error("rxx:", cmd->tag);
if (g_plat.log && g_log_enable) {
if (g_plat.log && g_log_enable)
{
g_plat.log("Unknown TAG '%s' -> rxx:\n", cmd->tag);
}
return 0;
@@ -299,7 +326,8 @@ int dr_cmd_parser(const uint8_t *buf, uint8_t len)
{
ParsedCmd cmd;
if (!dr_parse_cmd(buf, len, &cmd)) {
if (!dr_parse_cmd(buf, len, &cmd))
{
if (g_plat.log) g_plat.log("[PARSER] PARSE FAIL\r\n");
return -1;
}