<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Hilfe beim Kommentieren eines C-Codes]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe einen C-Code gefunden,der zur Uhrsynchronisierung mittels TDMA-Verfahren dient,das Programm ist ein Teil von RTnet-Projekt(Open Source Echtzeitsystem). Leider ist der Code überhaupt nicht kommentiert, man findet zwar eine Erklärungsdatei dazu, sie ist aber sehr allgemein.<br />
ich brauche das sehr dringend, Kann mir jemand helfen?, oder soll ich das vergessen..</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/188927/hilfe-beim-kommentieren-eines-c-codes</link><generator>RSS for Node</generator><lastBuildDate>Wed, 01 Jul 2026 08:19:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/188927.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 06 Aug 2007 11:59:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Hilfe beim Kommentieren eines C-Codes on Mon, 06 Aug 2007 11:59:12 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe einen C-Code gefunden,der zur Uhrsynchronisierung mittels TDMA-Verfahren dient,das Programm ist ein Teil von RTnet-Projekt(Open Source Echtzeitsystem). Leider ist der Code überhaupt nicht kommentiert, man findet zwar eine Erklärungsdatei dazu, sie ist aber sehr allgemein.<br />
ich brauche das sehr dringend, Kann mir jemand helfen?, oder soll ich das vergessen..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1339499</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1339499</guid><dc:creator><![CDATA[Monim]]></dc:creator><pubDate>Mon, 06 Aug 2007 11:59:12 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Kommentieren eines C-Codes on Mon, 06 Aug 2007 13:02:20 GMT]]></title><description><![CDATA[<p>Wobei helfen ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1339570</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1339570</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Mon, 06 Aug 2007 13:02:20 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Kommentieren eines C-Codes on Mon, 06 Aug 2007 13:48:11 GMT]]></title><description><![CDATA[<p>beim Kommentieren von diesem Code</p>
<pre><code>/***
 *
 *  tools/tdmacfg.c
 *  Configuration tool for the RTmac/TDMA discipline
 *
 *  RTmac - real-time networking media access control subsystem
 *  Copyright (C) 2002      Marc Kleine-Budde &lt;kleine-budde@gmx.de&gt;,
 *                2003-2005 Jan Kiszka &lt;Jan.Kiszka@web.de&gt;
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include &lt;errno.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;unistd.h&gt;
#include &lt;sys/ioctl.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;arpa/inet.h&gt;

#include &lt;tdma_chrdev.h&gt;

static int                  f;
static struct tdma_config   tdma_cfg;

static void help(void)
{
    fprintf(stderr, &quot;Usage:\n&quot;
        &quot;\ttdmacfg &lt;dev&gt; master &lt;cycle_period&gt; [-b &lt;backup_offset&gt;]\n&quot;
        &quot;\t        [-c calibration_rounds] [-i max_slot_id]\n&quot;
        &quot;\t        [-m max_calibration_requests]\n&quot;
        &quot;\ttdmacfg &lt;dev&gt; slave [-c calibration_rounds] [-i max_slot_id]\n&quot;
        &quot;\ttdmacfg &lt;dev&gt; slot &lt;id&gt; [&lt;offset&gt; [-p &lt;phasing&gt;/&lt;period&gt;] &quot;
            &quot;[-s &lt;size&gt;]\n&quot;
        &quot;\t         [-j &lt;joint_slot_id&gt;] [-l calibration_log_file]\n&quot;
        &quot;\t         [-t calibration_timeout&rsqb;&rsqb;\n&quot;
        &quot;\ttdmacfg &lt;dev&gt; detach\n&quot;);

    exit(1);
}

int getintopt(int argc, int pos, char *argv[], int min)
{
    int result;

    if (pos &gt;= argc)
        help();
    if ((sscanf(argv[pos], &quot;%i&quot;, &amp;result) != 1) || (result &lt; min)) {
        fprintf(stderr, &quot;invalid parameter: %s %s\n&quot;, argv[pos-1], argv[pos]);
        exit(1);
    }

    return result;
}

void write_calibration_log(char *log_filename, unsigned int rounds,
                           uint64_t *cal_results)
{
    char    str_buf[32];
    int     log_file;
    int     i;
    int     r;

    log_file = open(log_filename, O_CREAT | O_WRONLY | O_TRUNC,
                    S_IREAD | S_IWRITE);
    if (log_file &lt; 0) {
        perror(&quot;create output file&quot;);
        free(cal_results);
        exit(1);
    }

    for (i = rounds-1; i &gt;= 0; i--) {
        r = sprintf(str_buf, &quot;%llu\n&quot;, (unsigned long long)cal_results[i]);
        if (write(log_file, str_buf, r) &lt; 0) {
            perror(&quot;write output file&quot;);
            free(cal_results);
            exit(1);
        }
    }

    close(log_file);
    free(cal_results);
}

void do_master(int argc, char *argv[])
{
    int     r;
    int     i;

    if (argc &lt; 4)
        help();

    if ((sscanf(argv[3], &quot;%u&quot;, &amp;r) != 1) || (r &lt;= 0)) {
        fprintf(stderr, &quot;invalid cycle period: %s\n&quot;, argv[3]);
        exit(1);
    }
    tdma_cfg.args.master.cycle_period = ((uint64_t)r) * 1000;

    tdma_cfg.args.master.backup_sync_offset = 0;
    tdma_cfg.args.master.cal_rounds         = 100;
    tdma_cfg.args.master.max_cal_requests   = 64;
    tdma_cfg.args.master.max_slot_id        = 7;

    for (i = 4; i &lt; argc; i++) {
        if (strcmp(argv[i], &quot;-b&quot;) == 0)
            tdma_cfg.args.master.backup_sync_offset =
                getintopt(argc, ++i, argv, 0) * 1000;
        else if (strcmp(argv[i], &quot;-c&quot;) == 0)
            tdma_cfg.args.master.cal_rounds = getintopt(argc, ++i, argv, 0);
        else if (strcmp(argv[i], &quot;-i&quot;) == 0)
            tdma_cfg.args.master.max_slot_id = getintopt(argc, ++i, argv, 0);
        else if (strcmp(argv[i], &quot;-m&quot;) == 0)
            tdma_cfg.args.master.max_cal_requests =
                getintopt(argc, ++i, argv, 1);
        else
            help();
    }

    r = ioctl(f, TDMA_IOC_MASTER, &amp;tdma_cfg);
    if (r &lt; 0) {
        perror(&quot;ioctl&quot;);
        exit(1);
    }
    exit(0);
}

void do_slave(int argc, char *argv[])
{
    int     i;
    int     r;

    if (argc &lt; 3)
        help();

    tdma_cfg.args.slave.cal_rounds  = 100;
    tdma_cfg.args.slave.max_slot_id = 7;

    for (i = 3; i &lt; argc; i++) {
        if (strcmp(argv[i], &quot;-c&quot;) == 0)
            tdma_cfg.args.slave.cal_rounds = getintopt(argc, ++i, argv, 0);
        else if (strcmp(argv[i], &quot;-i&quot;) == 0)
            tdma_cfg.args.slave.max_slot_id = getintopt(argc, ++i, argv, 0);
        else
            help();
    }

    r = ioctl(f, TDMA_IOC_SLAVE, &amp;tdma_cfg);
    if (r &lt; 0) {
        perror(&quot;ioctl&quot;);
        exit(1);
    }
    exit(0);
}

void do_slot(int argc, char *argv[])
{
    char            *log_filename = NULL;
    int             result_size = 0;
    unsigned int    ioc;
    int             r;
    int             i;

    if (argc &lt; 4)
        help();

    if ((sscanf(argv[3], &quot;%u&quot;, &amp;r) != 1) || (r &lt; 0)) {
        fprintf(stderr, &quot;invalid slot id: %s\n&quot;, argv[3]);
        exit(1);
    }

    if (argc &gt; 4) {
        tdma_cfg.args.set_slot.id = r;

        if ((sscanf(argv[4], &quot;%u&quot;, &amp;r) != 1) || (r &lt; 0)) {
            fprintf(stderr, &quot;invalid slot offset: %s\n&quot;, argv[4]);
            exit(1);
        }
        tdma_cfg.args.set_slot.offset = ((uint64_t)r) * 1000;

        tdma_cfg.args.set_slot.period      = 1;
        tdma_cfg.args.set_slot.phasing     = 0;
        tdma_cfg.args.set_slot.size        = 0;
        tdma_cfg.args.set_slot.cal_timeout = 0;
        tdma_cfg.args.set_slot.joint_slot  = -1;
        tdma_cfg.args.set_slot.cal_results = NULL;

        for (i = 5; i &lt; argc; i++) {
            if (strcmp(argv[i], &quot;-l&quot;) == 0) {
                if (++i &gt;= argc)
                    help();
                log_filename = argv[i];
            } else if (strcmp(argv[i], &quot;-p&quot;) == 0) {
                if (++i &gt;= argc)
                    help();
                if ((sscanf(argv[i], &quot;%u/%u&quot;,
                            &amp;tdma_cfg.args.set_slot.phasing,
                            &amp;tdma_cfg.args.set_slot.period) != 2) ||
                    (tdma_cfg.args.set_slot.phasing &lt; 1) ||
                    (tdma_cfg.args.set_slot.period &lt; 1) ||
                    (tdma_cfg.args.set_slot.phasing &gt;
                        tdma_cfg.args.set_slot.period)) {
                    fprintf(stderr, &quot;invalid parameter: %s %s\n&quot;, argv[i-1],
                            argv[i]);
                    exit(1);
                }
                tdma_cfg.args.set_slot.phasing--;
            } else if (strcmp(argv[i], &quot;-s&quot;) == 0)
                tdma_cfg.args.set_slot.size =
                    getintopt(argc, ++i, argv, MIN_SLOT_SIZE);
            else if (strcmp(argv[i], &quot;-t&quot;) == 0)
                tdma_cfg.args.set_slot.cal_timeout =
                    getintopt(argc, ++i, argv, 0);
            else if (strcmp(argv[i], &quot;-j&quot;) == 0)
                tdma_cfg.args.set_slot.joint_slot =
                    getintopt(argc, ++i, argv, 0);
            else
                help();
        }

        if (log_filename) {
            /* note: we can reuse tdma_cfg here as the head is the same and
             *       will remain unmodified */
            result_size = ioctl(f, TDMA_IOC_CAL_RESULT_SIZE, &amp;tdma_cfg);
            if (result_size &gt; 0) {
                tdma_cfg.args.set_slot.cal_results =
                    (uint64_t *)malloc(result_size * sizeof(uint64_t));
                if (!tdma_cfg.args.set_slot.cal_results) {
                    fprintf(stderr, &quot;insufficient memory\n&quot;);
                    exit(1);
                }
            } else
                log_filename = NULL;
        }

        ioc = TDMA_IOC_SET_SLOT;
    } else {
        tdma_cfg.args.remove_slot.id = r;

        ioc = TDMA_IOC_REMOVE_SLOT;
    }

    r = ioctl(f, ioc, &amp;tdma_cfg);
    if (r &lt; 0) {
        perror(&quot;ioctl&quot;);
        exit(1);
    }

    if (log_filename)
        write_calibration_log(log_filename, result_size,
                              tdma_cfg.args.set_slot.cal_results);
    exit(0);
}

void do_detach(int argc, char *argv[])
{
    int r;

    if (argc != 3)
        help();

    r = ioctl(f, TDMA_IOC_DETACH, &amp;tdma_cfg);
    if (r &lt; 0) {
        perror(&quot;ioctl&quot;);
        exit(1);
    }
    exit(0);
}

int main(int argc, char *argv[])
{
    if ((argc &lt; 3) || (strcmp(argv[1], &quot;--help&quot;) == 0))
        help();

    f = open(&quot;/dev/rtnet&quot;, O_RDWR);

    if (f &lt; 0) {
        perror(&quot;/dev/rtnet&quot;);
        exit(1);
    }

    strncpy(tdma_cfg.head.if_name, argv[1], IFNAMSIZ);

    if (strcmp(argv[2], &quot;master&quot;) == 0)
        do_master(argc, argv);
    if (strcmp(argv[2], &quot;slave&quot;) == 0)
        do_slave(argc, argv);
    if (strcmp(argv[2], &quot;slot&quot;) == 0)
        do_slot(argc, argv);
    if (strcmp(argv[2], &quot;detach&quot;) == 0)
        do_detach(argc, argv);

    help();

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1339599</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1339599</guid><dc:creator><![CDATA[Monim]]></dc:creator><pubDate>Mon, 06 Aug 2007 13:48:11 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Kommentieren eines C-Codes on Mon, 06 Aug 2007 14:13:13 GMT]]></title><description><![CDATA[<p>Also meinst du, dass sich jetzt jemand hinsetzt und fein säuberlich Kommentare dazuschreibt? Kannst du genauso vergessen wie kompletten Code. Hilfe zur Selbsthilfe, ja! Die komplette Arbeit übernehmen, nein!</p>
<p>Am besten du setztest dich hin, fängst mit der main() an und arbeitest dich durch die Funktionen, versuchst zu verstehen, was da passiert und nimmst <a href="http://google.de" rel="nofollow">google.de</a>, wenn du es nicht verstehst. Wenn du bei Google nichts findest (Mindestsuchzeit &gt; 15min), kannst du hier fragen (je nach Frage, am ehesten im C-Forumsteil). Dabei lernst du auch noch was.</p>
<p>gruß<br />
Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1339614</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1339614</guid><dc:creator><![CDATA[mad_martin]]></dc:creator><pubDate>Mon, 06 Aug 2007 14:13:13 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Kommentieren eines C-Codes on Mon, 06 Aug 2007 14:19:35 GMT]]></title><description><![CDATA[<p>Monim schrieb:</p>
<blockquote>
<p>beim Kommentieren von diesem Code...</p>
</blockquote>
<p>Wieso sollte irgendjemand diesen Code kommentieren ? ... und für wen ?<br />
Irgendwie erschließt sich mir immer noch nicht der programmiertechnische Sinn dieses Threads.<br />
Nicht missverstehen: Ich beantworte gerne Fragen und gebe Hilfestellungen, aber hier sehe ich mich außerstande, etwas beizutragen.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1339620</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1339620</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Mon, 06 Aug 2007 14:19:35 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Kommentieren eines C-Codes on Mon, 06 Aug 2007 14:39:36 GMT]]></title><description><![CDATA[<p>Na komm schon, der Code ist doch recht übersichtlich. Fang mal in der main-Funktion an. Dann siehste, dass sich alles auf 4 oder 5 unabhängige Funktionen verteilt. Die sind zwar lang aber trotzdem vergleichsweise übersichtlich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1339634</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1339634</guid><dc:creator><![CDATA[Jester]]></dc:creator><pubDate>Mon, 06 Aug 2007 14:39:36 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Kommentieren eines C-Codes on Mon, 06 Aug 2007 15:55:59 GMT]]></title><description><![CDATA[<p>habs doch gesagt Playstation 3, aber wurde ja gelöscht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1339683</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1339683</guid><dc:creator><![CDATA[ich..]]></dc:creator><pubDate>Mon, 06 Aug 2007 15:55:59 GMT</pubDate></item></channel></rss>