Skip to content

[ADD] L3 역할 및 퀴즈 관련 기능 파일 추가 #1

@woojin-devv

Description

@woojin-devv

테스트용

역할 thisId destId 동작 설명
Host 1234 0000 register_node(1234) 자기 ID를 등록하여 접속 대기
User 4434 1234 is_valid_node(1234) → 1 (true) 기존에 존재하는 node → User로 인식됨
또 다른 Host 9999 8888 is_valid_node(8888) → 0 (false) 존재하지 않음 → Host로 인식됨

추가한 파일

추가한 File

  • L3_status.h

    #ifndef L3_STATE_H
    #define L3_STATE_H
    
    // 상태 정의
    typedef enum {
        IDLE, 
        WAIT_ANSWER,
        WAIT_QUIZ,
        SEND_ANSWER,
        CHAT_READY,
        TERMINATE
    
    } L3_State;
    
    // 상태 변수 선언 (외부 정의됨)
    extern L3_State l3_state;
    
    // 디버깅용 상태 문자열 변환 함수 
    static inline const char* L3_stateToStr(L3_State state) {
        switch (state) {
            case IDLE: return "IDLE";
            case WAIT_QUIZ: return "WAIT_QUIZ";
            case WAIT_ANSWER: return "WAIT_ANSWER";
            case SEND_ANSWER: return "SEND_ANSWER";
            case CHAT_READY: return "CHAT_READY";
            case TERMINATE: return "TERMINATE";
            default: return "UNKNOWN_STATE";
        }
    }
    
    #endif // L3_STATE_H
  • L3_role.h

    #ifndef L3_ROLE_H
    #define L3_ROLE_H
    
    #include <stdint.h>
    
    #define MAX_NODE_COUNT 10  // 등록 가능한 최대 노드 수
    
    extern uint16_t valid_node_ids[MAX_NODE_COUNT];
    extern uint8_t valid_node_count; 
    
    bool is_valid_node(uint16_t id);
    void register_node(uint16_t id);
    bool is_host_node(uint16_t thisId, uint16_t destId); 
    void clear_node_table(void);
    
    #endif // L3_ROLE_H
  • L3_role.cpp

    #include "L3_role.h"
    
    uint16_t valid_node_ids[MAX_NODE_COUNT] = {0000}; //node 최소값 = 0, 최대값 = 65535
    uint8_t valid_node_count = 0;
    
    bool is_valid_node(uint16_t id) {
        for (int i = 0; i < valid_node_count; i++) {
            if (valid_node_ids[i] == id) return true;
        }
        return false;
    }
    
    void register_node(uint16_t id) {
        if (valid_node_count >= MAX_NODE_COUNT) return;
    
        // 중복 방지
        if (!is_valid_node(id)) {
            valid_node_ids[valid_node_count++] = id;
        }
    }
    
    void clear_node_table(void) {
        valid_node_count = 0;
    }
  • L3_Quiz.h

    #ifndef L3_QUIZ_H
    #define L3_QUIZ_H
    
    #define MAX_PASSWORD_LEN 20
    #define QUIZ_COUNT 3
    
    extern const char* quiz_questions[QUIZ_COUNT];
    extern const char* quiz_answers[QUIZ_COUNT];
    extern int selected_quiz_index;
    extern char selected_answer[MAX_PASSWORD_LEN];
    
    void L3_quiz_showMenuToHost(Serial& pc);
    bool L3_quiz_select(Serial& pc);
    
    #endif
  • L3_Quiz.cpp

    #include "L3_Quiz.h"
    #include <string.h>
    
    const char* quiz_questions[QUIZ_COUNT] = {
        "1. 왕이 넘어지면? [킹콩]",
        "2. 바나나가 웃으면? [바나나킥]",
        "3. 맥주가 죽으면서 남긴말은? [유언비어]"
    };
    
    const char* quiz_answers[QUIZ_COUNT] = {
        "킹콩",
        "바나나킥",
        "유언비어"
    };
    
    int selected_quiz_index = -1;
    char selected_answer[MAX_PASSWORD_LEN] = {0};
    
    void L3_quiz_showMenuToHost(Serial& pc) {
        pc.printf("\n======================== 퀴즈 목록 ========================\n");
        for (int i = 0; i < QUIZ_COUNT; i++) {
            pc.printf("%s\n", quiz_questions[i]);
        }
        pc.printf("==========================================================\n");
    }
    
    bool L3_quiz_select(Serial& pc) {
        int quiz_choice = 0;
        pc.printf(":: 퀴즈 번호를 선택하세요 (1 ~ %d): ", QUIZ_COUNT);
        pc.scanf("%d", &quiz_choice);
        pc.getc();
    
        if (quiz_choice < 1 || quiz_choice > QUIZ_COUNT) {
            pc.printf("[ERROR] 잘못된 번호입니다.\n");
            return false;
        }
    
        selected_quiz_index = quiz_choice - 1;
        strncpy(selected_answer, quiz_answers[selected_quiz_index], MAX_PASSWORD_LEN);
        pc.printf(":: 선택된 퀴즈: %s\n", quiz_questions[selected_quiz_index]);
        return true;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions