Linked Lists ๐Ÿ”—๋กœ ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ ๊ธฐ์ˆ ์„ ํ–ฅ์ƒ์‹œํ‚ค์„ธ์š”.

6978 ๋‹จ์–ด microcontrollercmemoryprogramming
Embedded C์—์„œ ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ๋Š” ์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ์—์„œ ๋งˆ์Šคํ„ฐํ•˜๊ธฐ ๊ฐ€์žฅ ์–ด๋ ค์šด ๊ฒƒ ์ค‘ ํ•˜๋‚˜์˜€์Šต๋‹ˆ๋‹ค. ๋‚˜๋Š” ๋ฒ„ํผ ํฌ๊ธฐ์™€ ๊ณต์œ  ๋ฉ”๋ชจ๋ฆฌ์— ๋Œ€ํ•œ ์•ก์„ธ์Šค๋ฅผ ํŒŒ์•…ํ•˜๋ ค๊ณ  ๋Š์ž„์—†์ด ๋…ธ๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค.

"Embedded Linked Lists"์— ๋Œ€ํ•ด ์•Œ๊ธฐ ์ „๊นŒ์ง€! ๊ทธ๋“ค์€ ์ง„์ •ํ•œ ๊ฒŒ์ž„ ์ฒด์ธ์ €์˜€์Šต๋‹ˆ๋‹ค!

์—ฐ๊ฒฐ๋œ ๋ชฉ๋ก



์‹œ์ž‘ํ•˜๊ธฐ ์ „์— Wikipedia์—์„œ ์•ฝ๊ฐ„์˜ ๋ณต์Šต์ด ์žˆ์Šต๋‹ˆ๋‹ค(๋” "C์™€ ๊ฐ™์€"์†Œ๋ฆฌ๋ฅผ ๋‚ด๊ธฐ ์œ„ํ•ด ๋ช‡ ๊ฐ€์ง€ ๋ณ€๊ฒฝ ์‚ฌํ•ญ ํฌํ•จ).


A linked list [is a struct with] two fields: a value and a [pointer] to the next node. The last node is linked to [NULL] used to signify the end of the list.



Linked List๋Š” ๋ฏธ๋ฆฌ ํ• ๋‹น๋œ ํฐ ๋ฉ”๋ชจ๋ฆฌ ๋ธ”๋ก์ด ํ•„์š”ํ•˜์ง€ ์•Š๋‹ค๋Š” ํฐ ์ด์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋Œ€์‹  Linked List๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋ฉ”๋ชจ๋ฆฌ ์œ„์น˜์— ๋ถ„์‚ฐ๋จ
  • ๋™์ ์œผ๋กœ ํ• ๋‹น๋จ

  • ๊ทธ๋Ÿฌ๋‚˜ Embedded C์—์„œ ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ์ •์  ๋ฉ”๋ชจ๋ฆฌ์—์„œ๋„ ์—ฐ๊ฒฐ ๋ชฉ๋ก์€ ๋งค์šฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

    ๊ฐ„๋‹จํ•œ HTTP ํด๋ผ์ด์–ธํŠธ



    ์˜ˆ๋ฅผ ๋“ค์–ด ํ•œ ๋ฒˆ์— ํ•˜๋‚˜์˜ ์š”์ฒญ๋งŒ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ๋ณด๋ฅ˜ ์ค‘์ธ ์š”์ฒญ์„ ๋Œ€๊ธฐ์—ด์— ๋„ฃ์–ด์•ผ ํ•˜๋Š” HTTP ํด๋ผ์ด์–ธํŠธ๋ฅผ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

    ๊ทธ๋Ÿฌ๋‚˜: ๋Œ€๊ธฐ์—ด์ด ์–ผ๋งˆ๋‚˜ ๊ธธ์–ด์•ผ ํ•ฉ๋‹ˆ๊นŒ? ๐Ÿค”
    ์ž…๋ ฅ: ์—ฐ๊ฒฐ๋œ ๋ชฉ๋ก! ๐Ÿ’ก

    // http_client.h
    
    /**
     * Do a HTTP GET on the given request
     *
     * Params:
     * - new_request: A struct with the Request data
     *   (URL, custom header fields, etc)
     *
     * Returns:
     * - 0 if the request was accepted and started immediately 
     * - 1 if the request was queued
     * - < 0 on error
     */
    int http_get(struct http_request *new_request);
    


    ์—ฐ๊ฒฐ๋œ ๋ชฉ๋ก์„ struct http_request์— ํฌํ•จ



    Embedded C์—์„œ ์—ฐ๊ฒฐ ๋ชฉ๋ก์„ ์‚ฌ์šฉํ•˜๋Š” ์š”๋ น์€ ํฌ์ธํ„ฐ๋ฅผ ๊ตฌ์กฐ์ฒด ๋‚ด๋ถ€์˜ ๋‹ค์Œ ๋…ธ๋“œ์— ๋‘๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ์‹์œผ๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ๋ฅผ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•˜๋ฉฐ ๋” ์ด์ƒ HTTP ํด๋ผ์ด์–ธํŠธ ์ธก์—์„œ ์ถ”์ธกํ•˜์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค. ๐Ÿ™Œ

    // http_client.h
    
    /** 
     * A struct that contains all the data 
     * for the HTTP request such as the URL 
     */
    struct http_request {
        /** A pointer to the next HTTP request to perform */
        struct http_request *next_request;
    
        /** The URL to GET */
        char *url;
        // ...
        // Other field omitted for brevity
    };
    


    http_get์—์„œ ์š”์ฒญ ๋ชฉ๋ก ์ฒ˜๋ฆฌ



    HTTP ํด๋ผ์ด์–ธํŠธ ๋‚ด์—์„œ ๋ชฉ๋ก ์‹œ์ž‘์— ๋Œ€ํ•œ ์ฐธ์กฐ๋ฅผ ์œ ์ง€ํ•˜๊ณ  ๋ชจ๋“  ์ƒˆ ์š”์ฒญ์„ ๋ชฉ๋ก ๋์— ์ถ”๊ฐ€ํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

    // http_client.c
    
    /** 
     * A pointer to the current HTTP request or NULL if 
     * no request is pending
     */
    static struct http_request *current_request = NULL;
    
    int http_get(struct http_request *new_request) {
        // Check if we have an ongoing HTTP request
        if(NULL != current_request) {
            // We have a request ongoing and will add the
            // new request to the end of the list
            struct http_request *req = current_request;
            while(NULL != req->next_request) {
                req = req->next_request;
            }
            req->next_request = new_request
        } else {
            // No ongoing HTTP request, can start with current_request
        }
    }
    


    ํ˜„์žฌ ์š”์ฒญ์ด ์™„๋ฃŒ๋˜๋ฉด ๋ชจ๋“  ์š”์ฒญ์ด ์™„๋ฃŒ๋  ๋•Œ๊นŒ์ง€ ๋ชฉ๋ก์—์„œ ๋‹ค์Œ ํ•ญ๋ชฉ์„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.

    // http_client.c
    
    int http_get(struct http_request *new_request) {
        // ...
    
        // Finished current HTTP request,
        // check if there is another one queued
        current_request = current_request->next_request;
        if(NULL != current_request) {
            // Have an HTTP request queued, start with it now
        }
    }
    


    ๊ฒฐ๋ก 



    ๊ทธ๋ฆฌ๊ณ  ๊ทธ๊ฒŒ ๋‹ค์•ผ. ์ด ๊ฐ„๋‹จํ•˜์ง€๋งŒ ํšจ๊ณผ์ ์ธ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ”๋ชจ๋ฆฌ ์˜ค๋ฒ„ํ—ค๋“œ ์—†์ด ๊ฐ•๋ ฅํ•œ ๋Œ€๊ธฐ์—ด ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    ์ž„๋ฒ ๋””๋“œ ์šด์˜ ์ฒด์ œ์—์„œ ์—ฐ๊ฒฐ๋œ ๋ชฉ๋ก์˜ ์‹ค์ œ ์‚ฌ์šฉ์— ๊ด€์‹ฌ์ด ์žˆ๋Š” ๊ฒฝ์šฐ ์˜ˆ๋ฅผ ๋“ค์–ด Contiki OS ๋ฐ Contiki-NG์—์„œ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Zephyr ์ฝ”๋“œ ๊ธฐ๋ฐ˜์„ ๋” ์ž˜ ์•Œ๊ณ  ์žˆ๋‹ค๋ฉด ๊ฑฐ๊ธฐ๋„ ์œ™ํฌํ•˜๋Š” ์–ผ๊ตด)

    ์—ฌ๊ธฐ๊นŒ์ง€ ํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ์—ฌ๊ธฐ์—์„œ ๋ฌด์–ธ๊ฐ€๋ฅผ ๋ฐฐ์› ๋‹ค๋ฉด ์—ฌ๊ธฐ์—์„œ ๋” ๋งŽ์€ IoT ๋ฐ ์ž„๋ฒ ๋””๋“œ ์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ ์ฝ˜ํ…์ธ ๋ฅผ ๋ณด๋ ค๋ฉด ์ €๋ฅผ ํŒ”๋กœ์šฐํ•˜๊ณ  ! ๐Ÿ‘‹

    Ioan Sameli์˜ ํ‘œ์ง€ ์ด๋ฏธ์ง€

    ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ