<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="/assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>graznik.de (Posts about BeagleBone)</title><link>https://graznik.de/</link><description>The BeagleBone Black as a second Linux board for the 433 MHz transmitter, driven through libgpiod.</description><atom:link href="https://graznik.de/categories/beaglebone.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Wed, 02 Dec 2026 13:19:23 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Remote Control Power Sockets: Part 9: Switching with librsswitch</title><link>https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/</link><dc:creator>Michael Hornung</dc:creator><description>&lt;figure&gt;&lt;img src="https://graznik.de/images/preview-power-sockets-librsswitch.png"&gt;&lt;/figure&gt; &lt;p&gt;In the first three parts we took the remote control apart on paper, with the oscilloscope and with an SDR. In &lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-arduino-proof-of-concept/"&gt;Part 4&lt;/a&gt;, &lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-stm32f0discovery/"&gt;Part 5&lt;/a&gt; and &lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-zephyr-proof-of-concept/"&gt;Part 6&lt;/a&gt; we switched the same sockets from an Arduino Uno, an STM32F0DISCOVERY and an STM32F429I-DISCO with Zephyr, each time with a small firmware of its own. In Parts 7 and 8 we set up a Raspberry Pi and a BeagleBone Black so that they can drive a 433 MHz transmitter. What is still missing is the piece that turns "switch socket 1 on" into the right pulses on the data pin. That piece is &lt;a class="reference external" href="https://github.com/graznik/librsswitch"&gt;librsswitch&lt;/a&gt;, a small C library that emulates the encoder chip of the remote control on a GPIO line. It knows two devices: the Pollin 2605 set of this series, whose remote control has the PT2262 (HX2262) encoder, and the REV 008342 with a PT2260.&lt;/p&gt;
&lt;section id="wiring"&gt;
&lt;h2&gt;Wiring&lt;/h2&gt;
&lt;p&gt;As the transmitter we use an FS1000A. We connect its data pin to the pin that &lt;code class="docutils literal"&gt;toggle&lt;/code&gt; switched in Part 7 and Part 8. The module gets its supply from a 5 V pin of the pin header, never from a GPIO pin. According to its datasheet, it works from 3 V to 12 V and draws up to about 40 mA. With 5 V it reaches further than with 3.3 V, but the 3.3 V signal of both boards is enough for the data input. We switch the board off before wiring.&lt;/p&gt;
&lt;p&gt;A wire of about 17 cm on the antenna pad ANT, a quarter of the wavelength at 433 MHz, improves the range considerably.&lt;/p&gt;
&lt;img alt="FS1000A 433 MHz transmitter module with the wires for data, VCC and ground" src="https://graznik.de/images/fs1000a.png" style="width: 233px; height: 332px;"&gt;
&lt;section id="raspberry-pi"&gt;
&lt;h3&gt;Raspberry Pi&lt;/h3&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;DATA to pin 11 (GPIO17)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;VCC to pin 2 (5 V)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;GND to pin 9&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id="beaglebone-black"&gt;
&lt;h3&gt;BeagleBone Black&lt;/h3&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;DATA to P9_23&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;VCC to P9_7 (SYS_5V)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;GND to P9_1&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;P9_7 carries 5 V whether the board gets its power from USB or from the barrel jack; P9_5 only with the barrel jack.&lt;/p&gt;
&lt;/section&gt;
&lt;/section&gt;
&lt;section id="getting-the-code"&gt;
&lt;h2&gt;Getting the code&lt;/h2&gt;
&lt;p&gt;librsswitch lives on GitHub. We clone it where we build: on the board or, when cross-compiling, on the host:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_b7318ffcf8e349429be9af3c26805f17-1" name="rest_code_b7318ffcf8e349429be9af3c26805f17-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_b7318ffcf8e349429be9af3c26805f17-1"&gt;&lt;/a&gt;git&lt;span class="w"&gt; &lt;/span&gt;clone&lt;span class="w"&gt; &lt;/span&gt;https://github.com/graznik/librsswitch.git
&lt;a id="rest_code_b7318ffcf8e349429be9af3c26805f17-2" name="rest_code_b7318ffcf8e349429be9af3c26805f17-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_b7318ffcf8e349429be9af3c26805f17-2"&gt;&lt;/a&gt;&lt;span class="nb"&gt;cd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;librsswitch
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The root directory holds the library, and &lt;code class="docutils literal"&gt;examples/basic&lt;/code&gt; holds the command-line program &lt;code class="docutils literal"&gt;rsssend&lt;/code&gt;, which sends exactly one command: &lt;code class="docutils literal"&gt;rsssend DEV GROUP SOCKET DATA&lt;/code&gt;. &lt;code class="docutils literal"&gt;DEV&lt;/code&gt; is 1 for the Pollin 2605 and 0 for the REV 008342. For the Pollin 2605, &lt;code class="docutils literal"&gt;GROUP&lt;/code&gt; and &lt;code class="docutils literal"&gt;SOCKET&lt;/code&gt; are numbers from 0 to 31; for the REV 008342, the group goes from 0 to 3 and the socket from 0 to 2. &lt;code class="docutils literal"&gt;DATA&lt;/code&gt; is 1 for on and 0 for off.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="how-the-codeword-comes-together"&gt;
&lt;h2&gt;How the codeword comes together&lt;/h2&gt;
&lt;p&gt;In &lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-info-gathering/"&gt;Part 1&lt;/a&gt; we found out that the encoder turns the DIP switches and the pressed button into a codeword of twelve tri-state bits. In &lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-protocol-analysis-with-oscilloscope/"&gt;Part 2&lt;/a&gt; we measured these codewords, and in &lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-protocol-analysis-with-sdr/"&gt;Part 3&lt;/a&gt; we read the same words from the radio signal. librsswitch assembles such a word from three parts:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th class="head"&gt;&lt;p&gt;Part&lt;/p&gt;&lt;/th&gt;
&lt;th class="head"&gt;&lt;p&gt;Bits&lt;/p&gt;&lt;/th&gt;
&lt;th class="head"&gt;&lt;p&gt;Meaning&lt;/p&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;p&gt;Group&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p&gt;5&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p&gt;DIP switches of the remote control (0 to 31)&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;p&gt;Socket&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p&gt;5&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p&gt;Button pair of the remote control (0 to 31)&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;p&gt;Data&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p&gt;2&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p&gt;&lt;code class="docutils literal"&gt;0F&lt;/code&gt; for on, &lt;code class="docutils literal"&gt;F0&lt;/code&gt; for off&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Group and socket are binary numbers with the lowest bit first. librsswitch writes a cleared bit as &lt;code class="docutils literal"&gt;F&lt;/code&gt; and a set bit as &lt;code class="docutils literal"&gt;0&lt;/code&gt;, exactly the pattern from Part 2. Socket 1 is therefore &lt;code class="docutils literal"&gt;0FFFF&lt;/code&gt;. librsswitch then turns the word into pulses. A short pulse lasts 350 µs, which is four oscillator periods of 87.5 µs from Part 2, and a long pulse is three times as long:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;A &lt;code class="docutils literal"&gt;0&lt;/code&gt; bit is short high, long low, short high, long low.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An &lt;code class="docutils literal"&gt;F&lt;/code&gt; bit is short high, long low, long high, short low.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A &lt;code class="docutils literal"&gt;1&lt;/code&gt; bit is long high, short low, long high, short low.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After the twelve bits comes a sync pulse, short high and then a low of 31 short pulses.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;librsswitch sends the whole word ten times, which takes about half a second.&lt;/p&gt;
&lt;p&gt;We can follow all of this without hardware. For this, librsswitch comes with a stub board: it sits in place of the GPIO line and prints the codeword instead of sending it. &lt;code class="docutils literal"&gt;make BOARD=stub&lt;/code&gt; builds the library with this board into &lt;code class="docutils literal"&gt;build/stub&lt;/code&gt;, and &lt;code class="docutils literal"&gt;make &lt;span class="pre"&gt;-C&lt;/span&gt; examples/basic BOARD=stub&lt;/code&gt; builds &lt;code class="docutils literal"&gt;rsssend&lt;/code&gt; against it:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_70fec047a13b439dab4cabb7fb8ec224-1" name="rest_code_70fec047a13b439dab4cabb7fb8ec224-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_70fec047a13b439dab4cabb7fb8ec224-1"&gt;&lt;/a&gt;make&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;BOARD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;stub
&lt;a id="rest_code_70fec047a13b439dab4cabb7fb8ec224-2" name="rest_code_70fec047a13b439dab4cabb7fb8ec224-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_70fec047a13b439dab4cabb7fb8ec224-2"&gt;&lt;/a&gt;make&lt;span class="w"&gt; &lt;/span&gt;-C&lt;span class="w"&gt; &lt;/span&gt;examples/basic&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;BOARD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;stub
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class="docutils literal"&gt;rsssend&lt;/code&gt; links the library dynamically and has no built-in search path. When we run it from the repository, we therefore tell the loader the directory with &lt;code class="docutils literal"&gt;LD_LIBRARY_PATH&lt;/code&gt;:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code text"&gt;&lt;a id="rest_code_f405a8ddc0554d1da3f3e517e94cc78a-1" name="rest_code_f405a8ddc0554d1da3f3e517e94cc78a-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_f405a8ddc0554d1da3f3e517e94cc78a-1"&gt;&lt;/a&gt;$ LD_LIBRARY_PATH=build/stub examples/basic/rsssend 1 0 1 1
&lt;a id="rest_code_f405a8ddc0554d1da3f3e517e94cc78a-2" name="rest_code_f405a8ddc0554d1da3f3e517e94cc78a-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_f405a8ddc0554d1da3f3e517e94cc78a-2"&gt;&lt;/a&gt;FFFFF0FFFF0F
&lt;a id="rest_code_f405a8ddc0554d1da3f3e517e94cc78a-3" name="rest_code_f405a8ddc0554d1da3f3e517e94cc78a-3" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_f405a8ddc0554d1da3f3e517e94cc78a-3"&gt;&lt;/a&gt;$ LD_LIBRARY_PATH=build/stub examples/basic/rsssend 1 0 1 0
&lt;a id="rest_code_f405a8ddc0554d1da3f3e517e94cc78a-4" name="rest_code_f405a8ddc0554d1da3f3e517e94cc78a-4" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_f405a8ddc0554d1da3f3e517e94cc78a-4"&gt;&lt;/a&gt;FFFFF0FFFFF0
&lt;a id="rest_code_f405a8ddc0554d1da3f3e517e94cc78a-5" name="rest_code_f405a8ddc0554d1da3f3e517e94cc78a-5" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_f405a8ddc0554d1da3f3e517e94cc78a-5"&gt;&lt;/a&gt;$ LD_LIBRARY_PATH=build/stub examples/basic/rsssend 1 1 1 1
&lt;a id="rest_code_f405a8ddc0554d1da3f3e517e94cc78a-6" name="rest_code_f405a8ddc0554d1da3f3e517e94cc78a-6" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_f405a8ddc0554d1da3f3e517e94cc78a-6"&gt;&lt;/a&gt;0FFFF0FFFF0F
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The first call is group 0, socket 1, on: &lt;code class="docutils literal"&gt;FFFFF&lt;/code&gt; for the group, &lt;code class="docutils literal"&gt;0FFFF&lt;/code&gt; for the socket and &lt;code class="docutils literal"&gt;0F&lt;/code&gt; for on. That is the codeword we measured first in Part 2, &lt;code class="docutils literal"&gt;FFFFF 0FFFF 0F&lt;/code&gt;. librsswitch counts the sockets the same way: socket 1 is the socket that this first codeword from Part 2 belongs to. The second call changes only the last two characters to &lt;code class="docutils literal"&gt;F0&lt;/code&gt;, which is off. The third call sets group 1 and turns the first five characters into &lt;code class="docutils literal"&gt;0FFFF&lt;/code&gt;, as in the group 1 example from Part 2.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="raspberry-pi-1"&gt;
&lt;h2&gt;Raspberry Pi&lt;/h2&gt;
&lt;p&gt;On the Pi, librsswitch needs the libgpiod headers from Part 7. Without &lt;code class="docutils literal"&gt;BOARD&lt;/code&gt;, &lt;code class="docutils literal"&gt;make&lt;/code&gt; builds the library for libgpiod into &lt;code class="docutils literal"&gt;build/gpiod&lt;/code&gt;, and &lt;code class="docutils literal"&gt;make &lt;span class="pre"&gt;-C&lt;/span&gt; examples/basic&lt;/code&gt; builds &lt;code class="docutils literal"&gt;rsssend&lt;/code&gt; against it:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_981487e72e474393af5aa510cc4f34dc-1" name="rest_code_981487e72e474393af5aa510cc4f34dc-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_981487e72e474393af5aa510cc4f34dc-1"&gt;&lt;/a&gt;sudo&lt;span class="w"&gt; &lt;/span&gt;apt&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;build-essential&lt;span class="w"&gt; &lt;/span&gt;libgpiod-dev
&lt;a id="rest_code_981487e72e474393af5aa510cc4f34dc-2" name="rest_code_981487e72e474393af5aa510cc4f34dc-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_981487e72e474393af5aa510cc4f34dc-2"&gt;&lt;/a&gt;make
&lt;a id="rest_code_981487e72e474393af5aa510cc4f34dc-3" name="rest_code_981487e72e474393af5aa510cc4f34dc-3" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_981487e72e474393af5aa510cc4f34dc-3"&gt;&lt;/a&gt;make&lt;span class="w"&gt; &lt;/span&gt;-C&lt;span class="w"&gt; &lt;/span&gt;examples/basic
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The same build serves a 32-bit and a 64-bit Raspberry Pi OS and the BeagleBone Black as well; only the compiler determines the architecture. On the 64-bit system, &lt;code class="docutils literal"&gt;file examples/basic/rsssend&lt;/code&gt; shows &lt;code class="docutils literal"&gt;ELF &lt;span class="pre"&gt;64-bit&lt;/span&gt; LSB&lt;/code&gt; and &lt;code class="docutils literal"&gt;ARM aarch64&lt;/code&gt;. &lt;code class="docutils literal"&gt;rsssend&lt;/code&gt; links &lt;code class="docutils literal"&gt;librsswitch.so.1&lt;/code&gt;, and the library links &lt;code class="docutils literal"&gt;libgpiod.so.3&lt;/code&gt;, the library of libgpiod 2.x. From the repository we start &lt;code class="docutils literal"&gt;rsssend&lt;/code&gt; with &lt;code class="docutils literal"&gt;LD_LIBRARY_PATH=build/gpiod&lt;/code&gt;. After &lt;code class="docutils literal"&gt;sudo make install&lt;/code&gt;, the library is in &lt;code class="docutils literal"&gt;/usr/local/lib&lt;/code&gt;, and the loader finds it without this variable too.&lt;/p&gt;
&lt;p&gt;To cross-compile on the Debian 13 host from Part 7, we install the multiarch libgpiod package for the target architecture, &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;libgpiod-dev:arm64&lt;/span&gt;&lt;/code&gt; for a 64-bit and &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;libgpiod-dev:armhf&lt;/span&gt;&lt;/code&gt; for a 32-bit Raspberry Pi OS. We pass the prefix of the cross-compiler to both calls in &lt;code class="docutils literal"&gt;CROSS_COMPILE&lt;/code&gt;, for a 64-bit system like this:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_76d23e5a0b98428a88298dc710bbc5fb-1" name="rest_code_76d23e5a0b98428a88298dc710bbc5fb-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_76d23e5a0b98428a88298dc710bbc5fb-1"&gt;&lt;/a&gt;make&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;CROSS_COMPILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;aarch64-linux-gnu-
&lt;a id="rest_code_76d23e5a0b98428a88298dc710bbc5fb-2" name="rest_code_76d23e5a0b98428a88298dc710bbc5fb-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_76d23e5a0b98428a88298dc710bbc5fb-2"&gt;&lt;/a&gt;make&lt;span class="w"&gt; &lt;/span&gt;-C&lt;span class="w"&gt; &lt;/span&gt;examples/basic&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;CROSS_COMPILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;aarch64-linux-gnu-
&lt;a id="rest_code_76d23e5a0b98428a88298dc710bbc5fb-3" name="rest_code_76d23e5a0b98428a88298dc710bbc5fb-3" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_76d23e5a0b98428a88298dc710bbc5fb-3"&gt;&lt;/a&gt;file&lt;span class="w"&gt; &lt;/span&gt;examples/basic/rsssend
&lt;a id="rest_code_76d23e5a0b98428a88298dc710bbc5fb-4" name="rest_code_76d23e5a0b98428a88298dc710bbc5fb-4" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_76d23e5a0b98428a88298dc710bbc5fb-4"&gt;&lt;/a&gt;scp&lt;span class="w"&gt; &lt;/span&gt;examples/basic/rsssend&lt;span class="w"&gt; &lt;/span&gt;user@raspberrypi.local:
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;For a 32-bit system the prefix is &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;arm-linux-gnueabihf-&lt;/span&gt;&lt;/code&gt;, and &lt;code class="docutils literal"&gt;file&lt;/code&gt; shows &lt;code class="docutils literal"&gt;ELF &lt;span class="pre"&gt;32-bit&lt;/span&gt; LSB&lt;/code&gt; and &lt;code class="docutils literal"&gt;ARM, EABI5&lt;/code&gt;. An &lt;code class="docutils literal"&gt;rsssend&lt;/code&gt; built this way needs &lt;code class="docutils literal"&gt;librsswitch.so.1&lt;/code&gt; on the Pi. So there we build the library with &lt;code class="docutils literal"&gt;make&lt;/code&gt; and install it with &lt;code class="docutils literal"&gt;sudo make install&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The default line is &lt;code class="docutils literal"&gt;gpiochip0:17&lt;/code&gt;, that is GPIO17, the pin of the wiring above. We choose a different pin with &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;--gpio&lt;/span&gt;&lt;/code&gt; in the form chip:line, for example &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;--gpio&lt;/span&gt; gpiochip0:17&lt;/code&gt;.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="beaglebone-black-1"&gt;
&lt;h2&gt;BeagleBone Black&lt;/h2&gt;
&lt;p&gt;On the BeagleBone Black we build the same way, natively on the board:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_bb19e030281049ea9b10e348284d5fd8-1" name="rest_code_bb19e030281049ea9b10e348284d5fd8-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_bb19e030281049ea9b10e348284d5fd8-1"&gt;&lt;/a&gt;make
&lt;a id="rest_code_bb19e030281049ea9b10e348284d5fd8-2" name="rest_code_bb19e030281049ea9b10e348284d5fd8-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_bb19e030281049ea9b10e348284d5fd8-2"&gt;&lt;/a&gt;make&lt;span class="w"&gt; &lt;/span&gt;-C&lt;span class="w"&gt; &lt;/span&gt;examples/basic
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To cross-compile, we pass &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;CROSS_COMPILE=arm-linux-gnueabihf-&lt;/span&gt;&lt;/code&gt; to both calls and use the armhf compiler and &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;libgpiod-dev:armhf&lt;/span&gt;&lt;/code&gt; from Part 8; then, too, the library must be installed on the board. &lt;code class="docutils literal"&gt;file examples/basic/rsssend&lt;/code&gt; shows &lt;code class="docutils literal"&gt;ELF &lt;span class="pre"&gt;32-bit&lt;/span&gt; LSB&lt;/code&gt; and &lt;code class="docutils literal"&gt;ARM, EABI5&lt;/code&gt;. The default line is &lt;code class="docutils literal"&gt;gpiochip0:17&lt;/code&gt;, which on Debian 13 is P9_23, the pin of the wiring above; we do not need &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;--gpio&lt;/span&gt;&lt;/code&gt; there. On other kernels P9_23 can belong to a different chip. &lt;code class="docutils literal"&gt;gpioinfo P9_23&lt;/code&gt; from Part 8 tells us which one, and &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;--gpio&lt;/span&gt;&lt;/code&gt; takes the chip in the form chip:line. If it is &lt;code class="docutils literal"&gt;gpiochip1&lt;/code&gt;, the call looks like this:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_80666ad6a35440618fde49fadc61c0d6-1" name="rest_code_80666ad6a35440618fde49fadc61c0d6-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_80666ad6a35440618fde49fadc61c0d6-1"&gt;&lt;/a&gt;&lt;span class="nv"&gt;LD_LIBRARY_PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;build/gpiod&lt;span class="w"&gt; &lt;/span&gt;examples/basic/rsssend&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--gpio&lt;span class="w"&gt; &lt;/span&gt;gpiochip1:17
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class="docutils literal"&gt;rsssend&lt;/code&gt; rejects a bare number such as &lt;code class="docutils literal"&gt;49&lt;/code&gt;, the format of the earlier sysfs version: the program exits with status 1 and prints &lt;code class="docutils literal"&gt;malformed &lt;span class="pre"&gt;--gpio&lt;/span&gt; '49'&lt;/code&gt;.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="switching-a-socket"&gt;
&lt;h2&gt;Switching a socket&lt;/h2&gt;
&lt;p&gt;Now for the real thing. We tested with the REV socket from Part 4, its dial set to D 1, that is group 3, socket 0. With the transmitter connected, the first call switches it on, and the second switches it off again:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_d54b3f02da704ac4bc0ecbd733fa1ff3-1" name="rest_code_d54b3f02da704ac4bc0ecbd733fa1ff3-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_d54b3f02da704ac4bc0ecbd733fa1ff3-1"&gt;&lt;/a&gt;&lt;span class="nv"&gt;LD_LIBRARY_PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;build/gpiod&lt;span class="w"&gt; &lt;/span&gt;examples/basic/rsssend&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;
&lt;a id="rest_code_d54b3f02da704ac4bc0ecbd733fa1ff3-2" name="rest_code_d54b3f02da704ac4bc0ecbd733fa1ff3-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/#rest_code_d54b3f02da704ac4bc0ecbd733fa1ff3-2"&gt;&lt;/a&gt;&lt;span class="nv"&gt;LD_LIBRARY_PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;build/gpiod&lt;span class="w"&gt; &lt;/span&gt;examples/basic/rsssend&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;An &lt;code class="docutils literal"&gt;rsssend&lt;/code&gt; that we cross-compiled and copied to the board runs there as &lt;code class="docutils literal"&gt;./rsssend 0 3 0 1&lt;/code&gt; once the library is installed. For socket 1 of group 0 of the Pollin set, the arguments are &lt;code class="docutils literal"&gt;1 0 1 1&lt;/code&gt; and &lt;code class="docutils literal"&gt;1 0 1 0&lt;/code&gt;. These calls send the codewords that we measured on the remote control in Part 2. We have not tried librsswitch on a Pollin socket for this part, though.&lt;/p&gt;
&lt;p&gt;&lt;code class="docutils literal"&gt;rsssend&lt;/code&gt; exits with status 0 when it has sent the codeword, with 1 when the library could not send, and with 2 for wrong arguments. The radio link goes one way only: status 0 says that a codeword has left the transmitter, not that the socket has switched. If a socket does not react, we run the command again: librsswitch times the pulses with sleeps on a normal Linux kernel, and a receiver may ignore a slightly stretched word.&lt;/p&gt;
&lt;p&gt;On a Raspberry Pi 3 Model B Rev 1.2 with the 64-bit Raspberry Pi OS and on a BeagleBone Black revision A5C with the Debian 13 image from Part 8, &lt;code class="docutils literal"&gt;rsssend&lt;/code&gt; switched the lamp on the REV socket on and off again, each time with status 0, without &lt;code class="docutils literal"&gt;sudo&lt;/code&gt; and without &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;--gpio&lt;/span&gt;&lt;/code&gt;. The oscilloscope in the background shows the pulses of a codeword:&lt;/p&gt;
&lt;img alt="The Raspberry Pi 3 in its acrylic case, the FS1000A transmitter on a breadboard, behind them the oscilloscope with the pulses of a codeword; the lamp on the REV socket is on" src="https://graznik.de/images/power-sockets-rpi-switch.jpg" style="width: 600px; height: 450px;"&gt;
&lt;img alt="The same setup with the BeagleBone Black instead of the Raspberry Pi; the lamp on the REV socket is on" src="https://graznik.de/images/power-sockets-bbb-switch.jpg" style="width: 600px; height: 450px;"&gt;
&lt;/section&gt;
&lt;section id="stopping-safely"&gt;
&lt;h2&gt;Stopping safely&lt;/h2&gt;
&lt;p&gt;While &lt;code class="docutils literal"&gt;rsssend&lt;/code&gt; is sending, we never stop it with SIGKILL (&lt;code class="docutils literal"&gt;kill &lt;span class="pre"&gt;-9&lt;/span&gt;&lt;/code&gt;). After that, no code runs any more that could pull the data pin low. A 433 MHz transmitter whose data pin stays high transmits its carrier continuously and blocks the band for everyone else until the next transmission starts, because every transmission first pulls the line low. A crash or a power cut in the middle of a transmission has the same effect. &lt;code class="docutils literal"&gt;rsssend&lt;/code&gt; has no signal handler, so Ctrl-C is hardly better. A transmission takes about half a second; we wait that long.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="what-comes-next"&gt;
&lt;h2&gt;What comes next&lt;/h2&gt;
&lt;p&gt;Next we switch the sockets over the network: with the rsswitchd daemon and a small web app from the librsswitch repository.&lt;/p&gt;
&lt;/section&gt;</description><category>BeagleBone</category><category>Hardware Hacking</category><category>Radio</category><category>Raspberry Pi</category><category>Reverse Engineering</category><guid>https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/</guid><pubDate>Wed, 02 Dec 2026 13:00:00 GMT</pubDate></item><item><title>Remote Control Power Sockets: Part 8: Setting Up a BeagleBone Black</title><link>https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/</link><dc:creator>Michael Hornung</dc:creator><description>&lt;figure&gt;&lt;img src="https://graznik.de/images/preview-power-sockets-bbb.png"&gt;&lt;/figure&gt; &lt;p&gt;In this part we set up the BeagleBone Black as the second target next to the Raspberry Pi from &lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-4-setting-up-a-development-environment-for-the-raspberry-pi/"&gt;Part 7&lt;/a&gt;. Both are small Linux boards, so the steps are very similar: we install a current image, get a compiler and toggle a GPIO pin.&lt;/p&gt;
&lt;p&gt;The BeagleBone Black drives the same 433 MHz transmitter as the Raspberry Pi and uses the same GPIO library, libgpiod. At the end of this part we have a first program that controls a pin on the pin header. That is all the transmitter needs to switch a remote control power socket.&lt;/p&gt;
&lt;section id="host-system-x86-64"&gt;
&lt;h2&gt;Host system (x86_64)&lt;/h2&gt;
&lt;p&gt;We cross-compile on a Debian 13 (Trixie) host, where Debian installs the ARM packages next to the native ones via multiarch. Alternatively, we build natively on the BeagleBone (see "Building and running" below), which works from any host.&lt;/p&gt;
&lt;section id="gpio-library-libgpiod"&gt;
&lt;h3&gt;GPIO library (libgpiod)&lt;/h3&gt;
&lt;p&gt;The Linux kernel exposes every GPIO controller as a &lt;a class="reference external" href="https://linux-kernel-labs.github.io/refs/heads/master/labs/device_drivers.html"&gt;character device&lt;/a&gt; (&lt;code class="docutils literal"&gt;/dev/gpiochip0&lt;/code&gt;, &lt;code class="docutils literal"&gt;/dev/gpiochip1&lt;/code&gt;, ...). From userspace, a program can open the device and request individual lines with &lt;code class="docutils literal"&gt;ioctl()&lt;/code&gt;. For this the kernel returns a separate file descriptor, through which the program sets and reads the lines. When the program closes the descriptor, explicitly or simply because it exits, the kernel releases the lines again. &lt;a class="reference external" href="https://libgpiod.readthedocs.io/"&gt;libgpiod&lt;/a&gt; wraps this ioctl interface in a C API and comes with the command line tools &lt;code class="docutils literal"&gt;gpiodetect&lt;/code&gt;, &lt;code class="docutils literal"&gt;gpioinfo&lt;/code&gt; and &lt;code class="docutils literal"&gt;gpioset&lt;/code&gt;. The libgpiod API works the same on every board, so it is the same library we use on the Raspberry Pi in &lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-4-setting-up-a-development-environment-for-the-raspberry-pi/"&gt;Part 7&lt;/a&gt;. The kernel has marked the old sysfs GPIO interface as deprecated, and we do not use it in this series.&lt;/p&gt;
&lt;p&gt;The API of libgpiod 2.x is not compatible with version 1.x. Debian 13 (Trixie) ships libgpiod 2.2.1, Debian 12 (Bookworm) still ships 1.6.3. The current BeagleBoard.org image is based on Debian 13, but installs libgpiod from BeagleBoard.org's own package repository, at the time of writing this post in version 2.2.5. The program &lt;code class="docutils literal"&gt;toggle.c&lt;/code&gt; below is written for libgpiod 2.x.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="debian-13-multiarch"&gt;
&lt;h3&gt;Debian 13: multiarch&lt;/h3&gt;
&lt;section id="cross-toolchain"&gt;
&lt;h4&gt;Cross toolchain&lt;/h4&gt;
&lt;p&gt;Cross-compiling means building the program on the fast host instead of on the BeagleBone. Debian ships the compiler as a package. The BeagleBone Black contains an ARM Cortex-A8, which implements the ARMv7 architecture. The armhf compiler &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;gcc-arm-linux-gnueabihf&lt;/span&gt;&lt;/code&gt; (32-bit ARM with support for the hardware floating-point unit) is therefore the right choice. There is no 64-bit image for this board.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_624b4f74fc7d4203880a137b09012bff-1" name="rest_code_624b4f74fc7d4203880a137b09012bff-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_624b4f74fc7d4203880a137b09012bff-1"&gt;&lt;/a&gt;sudo&lt;span class="w"&gt; &lt;/span&gt;apt&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;make&lt;span class="w"&gt; &lt;/span&gt;gcc-arm-linux-gnueabihf
&lt;/pre&gt;&lt;/div&gt;
&lt;/section&gt;
&lt;section id="libgpiod-for-the-target"&gt;
&lt;h4&gt;libgpiod for the target&lt;/h4&gt;
&lt;p&gt;To cross-compile, the libgpiod headers and library for the target architecture must be present on the host. Debian solves this with multiarch, which installs packages of a foreign architecture next to the native ones:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_54629ab156b942e6883d98960209d177-1" name="rest_code_54629ab156b942e6883d98960209d177-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_54629ab156b942e6883d98960209d177-1"&gt;&lt;/a&gt;sudo&lt;span class="w"&gt; &lt;/span&gt;dpkg&lt;span class="w"&gt; &lt;/span&gt;--add-architecture&lt;span class="w"&gt; &lt;/span&gt;armhf
&lt;a id="rest_code_54629ab156b942e6883d98960209d177-2" name="rest_code_54629ab156b942e6883d98960209d177-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_54629ab156b942e6883d98960209d177-2"&gt;&lt;/a&gt;sudo&lt;span class="w"&gt; &lt;/span&gt;apt&lt;span class="w"&gt; &lt;/span&gt;update
&lt;a id="rest_code_54629ab156b942e6883d98960209d177-3" name="rest_code_54629ab156b942e6883d98960209d177-3" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_54629ab156b942e6883d98960209d177-3"&gt;&lt;/a&gt;sudo&lt;span class="w"&gt; &lt;/span&gt;apt&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;libgpiod-dev:armhf
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The following command shows which version a host would install:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_a88910edc76f42c5a11dd6219203d161-1" name="rest_code_a88910edc76f42c5a11dd6219203d161-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_a88910edc76f42c5a11dd6219203d161-1"&gt;&lt;/a&gt;apt-cache&lt;span class="w"&gt; &lt;/span&gt;policy&lt;span class="w"&gt; &lt;/span&gt;libgpiod-dev:armhf
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The candidate version must start with 2, as on Debian 13. A host that only offers 1.x, for example Debian 12, cannot cross-compile &lt;code class="docutils literal"&gt;toggle.c&lt;/code&gt; this way. In that case we build natively on the BeagleBone.&lt;/p&gt;
&lt;/section&gt;
&lt;/section&gt;
&lt;section id="hello-world-program"&gt;
&lt;h3&gt;Hello world program&lt;/h3&gt;
&lt;p&gt;The "hello world" of GPIO programming switches a pin on and off. The program &lt;code class="docutils literal"&gt;toggle&lt;/code&gt; configures pin P9_23 of the BeagleBone Black's pin header as an output and alternately drives it high and low for 1 ms each. On the oscilloscope we expect a square wave with a period of about 2 ms. P9_23 is also the pin that librsswitch uses by default for the transmitter in Part 9. Until then we leave the transmitter disconnected: with &lt;code class="docutils literal"&gt;toggle&lt;/code&gt; running, it would send a meaningless square wave on 433 MHz into the neighbourhood. All signals on the BeagleBone's pin header use 3.3 V logic levels.&lt;/p&gt;
&lt;p&gt;&lt;code class="docutils literal"&gt;toggle&lt;/code&gt; is the program from Part 7 with a different chip and a different line. It is written against the libgpiod 2.x API; librsswitch supports libgpiod 1.x and 2.x.&lt;/p&gt;
&lt;section id="makefile"&gt;
&lt;h4&gt;Makefile&lt;/h4&gt;
&lt;p&gt;The Makefile has one native target and one cross target: &lt;code class="docutils literal"&gt;make&lt;/code&gt; builds directly on the BeagleBone and &lt;code class="docutils literal"&gt;make clean cross&lt;/code&gt; produces a 32-bit ARM binary (&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;arm-linux-gnueabihf-&lt;/span&gt;&lt;/code&gt;). The &lt;code class="docutils literal"&gt;clean&lt;/code&gt; before the cross target is important, because &lt;code class="docutils literal"&gt;make&lt;/code&gt; does not notice that a leftover &lt;code class="docutils literal"&gt;toggle&lt;/code&gt; belongs to a different architecture. The recipe for &lt;code class="docutils literal"&gt;toggle&lt;/code&gt; comes from make's built-in rule that turns &lt;code class="docutils literal"&gt;toggle.c&lt;/code&gt; into &lt;code class="docutils literal"&gt;toggle&lt;/code&gt;. That is why this Makefile gets by without a single line indented with a tab, and we can copy it from the page unchanged.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code make"&gt;&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-1" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-1"&gt;&lt;/a&gt;&lt;span class="c"&gt;# Native build: make&lt;/span&gt;
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-2" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-2"&gt;&lt;/a&gt;&lt;span class="c"&gt;# Cross build: make clean cross&lt;/span&gt;
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-3" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-3" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-3"&gt;&lt;/a&gt;&lt;span class="nv"&gt;CROSS_COMPILE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;?=&lt;/span&gt;
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-4" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-4" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-4"&gt;&lt;/a&gt;&lt;span class="nv"&gt;CC&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;CROSS_COMPILE&lt;span class="k"&gt;)&lt;/span&gt;gcc
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-5" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-5" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-5"&gt;&lt;/a&gt;&lt;span class="nv"&gt;CFLAGS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;?=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-O2&lt;span class="w"&gt; &lt;/span&gt;-Wall&lt;span class="w"&gt; &lt;/span&gt;-Wextra
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-6" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-6" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-6"&gt;&lt;/a&gt;&lt;span class="nv"&gt;LDLIBS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-lgpiod
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-7" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-7" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-7"&gt;&lt;/a&gt;
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-8" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-8" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-8"&gt;&lt;/a&gt;&lt;span class="c"&gt;# make's built-in rule turns toggle.c into toggle (CC, CFLAGS, LDLIBS)&lt;/span&gt;
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-9" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-9" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-9"&gt;&lt;/a&gt;&lt;span class="nf"&gt;toggle&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;toggle&lt;/span&gt;.&lt;span class="n"&gt;c&lt;/span&gt;
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-10" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-10" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-10"&gt;&lt;/a&gt;
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-11" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-11" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-11"&gt;&lt;/a&gt;&lt;span class="c"&gt;# Target-specific values also apply to the prerequisite toggle&lt;/span&gt;
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-12" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-12" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-12"&gt;&lt;/a&gt;&lt;span class="nf"&gt;cross&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;CROSS_COMPILE&lt;/span&gt; = &lt;span class="n"&gt;arm&lt;/span&gt;-&lt;span class="n"&gt;linux&lt;/span&gt;-&lt;span class="n"&gt;gnueabihf&lt;/span&gt;-
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-13" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-13" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-13"&gt;&lt;/a&gt;&lt;span class="nf"&gt;cross&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;toggle&lt;/span&gt;
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-14" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-14" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-14"&gt;&lt;/a&gt;
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-15" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-15" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-15"&gt;&lt;/a&gt;&lt;span class="nf"&gt;clean&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;; &lt;span class="n"&gt;rm&lt;/span&gt; -&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="n"&gt;toggle&lt;/span&gt;
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-16" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-16" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-16"&gt;&lt;/a&gt;
&lt;a id="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-17" name="rest_code_b14b8abf69dd4e8a9fb2057b337c6766-17" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_b14b8abf69dd4e8a9fb2057b337c6766-17"&gt;&lt;/a&gt;&lt;span class="nf"&gt;.PHONY&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;cross&lt;/span&gt; &lt;span class="n"&gt;clean&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/section&gt;
&lt;section id="toggle-c"&gt;
&lt;h4&gt;toggle.c&lt;/h4&gt;
&lt;p&gt;As soon as we connect the transmitter to this pin in Part 9, the line must not stay high: a 433 MHz transmitter whose data pin stays high permanently sends an unbroken carrier and blocks the band. That is why &lt;code class="docutils literal"&gt;toggle&lt;/code&gt; does not simply "die" on Ctrl-C: SIGINT and SIGTERM only set a flag, the loop ends, the program drives the line low, releases it first and then frees the configuration objects.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code c"&gt;&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-1" name="rest_code_4082489259b64fad85e24b5102e95ef4-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-1"&gt;&lt;/a&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;errno.h&amp;gt;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-2" name="rest_code_4082489259b64fad85e24b5102e95ef4-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-2"&gt;&lt;/a&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;gpiod.h&amp;gt;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-3" name="rest_code_4082489259b64fad85e24b5102e95ef4-3" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-3"&gt;&lt;/a&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;signal.h&amp;gt;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-4" name="rest_code_4082489259b64fad85e24b5102e95ef4-4" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-4"&gt;&lt;/a&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-5" name="rest_code_4082489259b64fad85e24b5102e95ef4-5" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-5"&gt;&lt;/a&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-6" name="rest_code_4082489259b64fad85e24b5102e95ef4-6" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-6"&gt;&lt;/a&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;string.h&amp;gt;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-7" name="rest_code_4082489259b64fad85e24b5102e95ef4-7" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-7"&gt;&lt;/a&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;unistd.h&amp;gt;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-8" name="rest_code_4082489259b64fad85e24b5102e95ef4-8" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-8"&gt;&lt;/a&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-9" name="rest_code_4082489259b64fad85e24b5102e95ef4-9" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-9"&gt;&lt;/a&gt;&lt;span class="cp"&gt;#define CHIP "/dev/gpiochip0"&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-10" name="rest_code_4082489259b64fad85e24b5102e95ef4-10" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-10"&gt;&lt;/a&gt;&lt;span class="cp"&gt;#define LINE 17 &lt;/span&gt;&lt;span class="cm"&gt;/* P9_23 */&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-11" name="rest_code_4082489259b64fad85e24b5102e95ef4-11" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-11"&gt;&lt;/a&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-12" name="rest_code_4082489259b64fad85e24b5102e95ef4-12" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-12"&gt;&lt;/a&gt;&lt;span class="k"&gt;static&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;volatile&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;sig_atomic_t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-13" name="rest_code_4082489259b64fad85e24b5102e95ef4-13" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-13"&gt;&lt;/a&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-14" name="rest_code_4082489259b64fad85e24b5102e95ef4-14" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-14"&gt;&lt;/a&gt;&lt;span class="k"&gt;static&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;on_signal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sig&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-15" name="rest_code_4082489259b64fad85e24b5102e95ef4-15" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-15"&gt;&lt;/a&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-16" name="rest_code_4082489259b64fad85e24b5102e95ef4-16" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-16"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;sig&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-17" name="rest_code_4082489259b64fad85e24b5102e95ef4-17" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-17"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;stop&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-18" name="rest_code_4082489259b64fad85e24b5102e95ef4-18" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-18"&gt;&lt;/a&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-19" name="rest_code_4082489259b64fad85e24b5102e95ef4-19" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-19"&gt;&lt;/a&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-20" name="rest_code_4082489259b64fad85e24b5102e95ef4-20" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-20"&gt;&lt;/a&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-21" name="rest_code_4082489259b64fad85e24b5102e95ef4-21" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-21"&gt;&lt;/a&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-22" name="rest_code_4082489259b64fad85e24b5102e95ef4-22" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-22"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;gpiod_chip&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;chip&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-23" name="rest_code_4082489259b64fad85e24b5102e95ef4-23" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-23"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;gpiod_line_settings&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-24" name="rest_code_4082489259b64fad85e24b5102e95ef4-24" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-24"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;gpiod_line_config&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;line_cfg&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-25" name="rest_code_4082489259b64fad85e24b5102e95ef4-25" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-25"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;gpiod_request_config&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;req_cfg&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-26" name="rest_code_4082489259b64fad85e24b5102e95ef4-26" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-26"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;gpiod_line_request&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-27" name="rest_code_4082489259b64fad85e24b5102e95ef4-27" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-27"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;sigaction&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sa&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-28" name="rest_code_4082489259b64fad85e24b5102e95ef4-28" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-28"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="kt"&gt;unsigned&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;offset&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;LINE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-29" name="rest_code_4082489259b64fad85e24b5102e95ef4-29" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-29"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ret&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;EXIT_FAILURE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-30" name="rest_code_4082489259b64fad85e24b5102e95ef4-30" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-30"&gt;&lt;/a&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-31" name="rest_code_4082489259b64fad85e24b5102e95ef4-31" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-31"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="cm"&gt;/* Ctrl-C and kill end the loop instead of killing the program */&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-32" name="rest_code_4082489259b64fad85e24b5102e95ef4-32" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-32"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;memset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;sa&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;sizeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sa&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-33" name="rest_code_4082489259b64fad85e24b5102e95ef4-33" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-33"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;sa&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sa_handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;on_signal&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-34" name="rest_code_4082489259b64fad85e24b5102e95ef4-34" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-34"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;sigemptyset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;sa&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sa_mask&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-35" name="rest_code_4082489259b64fad85e24b5102e95ef4-35" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-35"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;sigaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SIGINT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;sa&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-36" name="rest_code_4082489259b64fad85e24b5102e95ef4-36" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-36"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;sigaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SIGTERM&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;sa&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-37" name="rest_code_4082489259b64fad85e24b5102e95ef4-37" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-37"&gt;&lt;/a&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-38" name="rest_code_4082489259b64fad85e24b5102e95ef4-38" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-38"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;chip&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;gpiod_chip_open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CHIP&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-39" name="rest_code_4082489259b64fad85e24b5102e95ef4-39" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-39"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;chip&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-40" name="rest_code_4082489259b64fad85e24b5102e95ef4-40" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-40"&gt;&lt;/a&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="n"&gt;fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stderr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"cannot open %s: %s&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;CHIP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;strerror&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;errno&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-41" name="rest_code_4082489259b64fad85e24b5102e95ef4-41" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-41"&gt;&lt;/a&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;EXIT_FAILURE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-42" name="rest_code_4082489259b64fad85e24b5102e95ef4-42" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-42"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-43" name="rest_code_4082489259b64fad85e24b5102e95ef4-43" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-43"&gt;&lt;/a&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-44" name="rest_code_4082489259b64fad85e24b5102e95ef4-44" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-44"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;gpiod_line_settings_new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-45" name="rest_code_4082489259b64fad85e24b5102e95ef4-45" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-45"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;line_cfg&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;gpiod_line_config_new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-46" name="rest_code_4082489259b64fad85e24b5102e95ef4-46" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-46"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;req_cfg&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;gpiod_request_config_new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-47" name="rest_code_4082489259b64fad85e24b5102e95ef4-47" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-47"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;line_cfg&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;req_cfg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-48" name="rest_code_4082489259b64fad85e24b5102e95ef4-48" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-48"&gt;&lt;/a&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="n"&gt;fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stderr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"out of memory&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-49" name="rest_code_4082489259b64fad85e24b5102e95ef4-49" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-49"&gt;&lt;/a&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="k"&gt;goto&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-50" name="rest_code_4082489259b64fad85e24b5102e95ef4-50" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-50"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-51" name="rest_code_4082489259b64fad85e24b5102e95ef4-51" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-51"&gt;&lt;/a&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-52" name="rest_code_4082489259b64fad85e24b5102e95ef4-52" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-52"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="cm"&gt;/* One output line, low until the loop starts */&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-53" name="rest_code_4082489259b64fad85e24b5102e95ef4-53" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-53"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gpiod_line_settings_set_direction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;GPIOD_LINE_DIRECTION_OUTPUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-54" name="rest_code_4082489259b64fad85e24b5102e95ef4-54" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-54"&gt;&lt;/a&gt;&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="n"&gt;gpiod_line_settings_set_output_value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;GPIOD_LINE_VALUE_INACTIVE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-55" name="rest_code_4082489259b64fad85e24b5102e95ef4-55" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-55"&gt;&lt;/a&gt;&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="n"&gt;gpiod_line_config_add_line_settings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line_cfg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-56" name="rest_code_4082489259b64fad85e24b5102e95ef4-56" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-56"&gt;&lt;/a&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="n"&gt;fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stderr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"cannot configure line %u: %s&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;strerror&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;errno&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-57" name="rest_code_4082489259b64fad85e24b5102e95ef4-57" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-57"&gt;&lt;/a&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="k"&gt;goto&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-58" name="rest_code_4082489259b64fad85e24b5102e95ef4-58" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-58"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-59" name="rest_code_4082489259b64fad85e24b5102e95ef4-59" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-59"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;gpiod_request_config_set_consumer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req_cfg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"toggle"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-60" name="rest_code_4082489259b64fad85e24b5102e95ef4-60" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-60"&gt;&lt;/a&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-61" name="rest_code_4082489259b64fad85e24b5102e95ef4-61" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-61"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;gpiod_chip_request_lines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chip&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;req_cfg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;line_cfg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-62" name="rest_code_4082489259b64fad85e24b5102e95ef4-62" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-62"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-63" name="rest_code_4082489259b64fad85e24b5102e95ef4-63" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-63"&gt;&lt;/a&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="n"&gt;fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stderr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"cannot request line %u: %s&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;strerror&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;errno&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-64" name="rest_code_4082489259b64fad85e24b5102e95ef4-64" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-64"&gt;&lt;/a&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="k"&gt;goto&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-65" name="rest_code_4082489259b64fad85e24b5102e95ef4-65" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-65"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-66" name="rest_code_4082489259b64fad85e24b5102e95ef4-66" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-66"&gt;&lt;/a&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-67" name="rest_code_4082489259b64fad85e24b5102e95ef4-67" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-67"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-68" name="rest_code_4082489259b64fad85e24b5102e95ef4-68" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-68"&gt;&lt;/a&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gpiod_line_request_set_value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;GPIOD_LINE_VALUE_ACTIVE&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-69" name="rest_code_4082489259b64fad85e24b5102e95ef4-69" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-69"&gt;&lt;/a&gt;&lt;span class="w"&gt;                        &lt;/span&gt;&lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-70" name="rest_code_4082489259b64fad85e24b5102e95ef4-70" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-70"&gt;&lt;/a&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="n"&gt;usleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-71" name="rest_code_4082489259b64fad85e24b5102e95ef4-71" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-71"&gt;&lt;/a&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gpiod_line_request_set_value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;GPIOD_LINE_VALUE_INACTIVE&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-72" name="rest_code_4082489259b64fad85e24b5102e95ef4-72" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-72"&gt;&lt;/a&gt;&lt;span class="w"&gt;                        &lt;/span&gt;&lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-73" name="rest_code_4082489259b64fad85e24b5102e95ef4-73" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-73"&gt;&lt;/a&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="n"&gt;usleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-74" name="rest_code_4082489259b64fad85e24b5102e95ef4-74" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-74"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-75" name="rest_code_4082489259b64fad85e24b5102e95ef4-75" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-75"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-76" name="rest_code_4082489259b64fad85e24b5102e95ef4-76" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-76"&gt;&lt;/a&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="n"&gt;ret&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;EXIT_SUCCESS&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-77" name="rest_code_4082489259b64fad85e24b5102e95ef4-77" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-77"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-78" name="rest_code_4082489259b64fad85e24b5102e95ef4-78" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-78"&gt;&lt;/a&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="n"&gt;fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stderr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"cannot set line %u: %s&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;strerror&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;errno&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-79" name="rest_code_4082489259b64fad85e24b5102e95ef4-79" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-79"&gt;&lt;/a&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-80" name="rest_code_4082489259b64fad85e24b5102e95ef4-80" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-80"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="cm"&gt;/* Leave the line low, so a transmitter on it does not stay keyed */&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-81" name="rest_code_4082489259b64fad85e24b5102e95ef4-81" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-81"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;gpiod_line_request_set_value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;GPIOD_LINE_VALUE_INACTIVE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-82" name="rest_code_4082489259b64fad85e24b5102e95ef4-82" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-82"&gt;&lt;/a&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-83" name="rest_code_4082489259b64fad85e24b5102e95ef4-83" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-83"&gt;&lt;/a&gt;&lt;span class="nl"&gt;out&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-84" name="rest_code_4082489259b64fad85e24b5102e95ef4-84" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-84"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;gpiod_line_request_release&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-85" name="rest_code_4082489259b64fad85e24b5102e95ef4-85" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-85"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;gpiod_request_config_free&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req_cfg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-86" name="rest_code_4082489259b64fad85e24b5102e95ef4-86" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-86"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;gpiod_line_config_free&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line_cfg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-87" name="rest_code_4082489259b64fad85e24b5102e95ef4-87" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-87"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;gpiod_line_settings_free&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-88" name="rest_code_4082489259b64fad85e24b5102e95ef4-88" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-88"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;gpiod_chip_close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chip&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-89" name="rest_code_4082489259b64fad85e24b5102e95ef4-89" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-89"&gt;&lt;/a&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ret&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_4082489259b64fad85e24b5102e95ef4-90" name="rest_code_4082489259b64fad85e24b5102e95ef4-90" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4082489259b64fad85e24b5102e95ef4-90"&gt;&lt;/a&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;libgpiod addresses a line by chip and line number, and the chip number is the weak spot: on the BeagleBone Black it has changed between kernel versions. On the current image, P9_23 is line 17 of &lt;code class="docutils literal"&gt;/dev/gpiochip0&lt;/code&gt;, and that is what &lt;code class="docutils literal"&gt;toggle.c&lt;/code&gt; uses. We should still not take this number on trust. &lt;code class="docutils literal"&gt;gpioinfo P9_23&lt;/code&gt; asks the board and prints the chip and line of the named pin. If the pin is on a different chip on our board, we change &lt;code class="docutils literal"&gt;CHIP&lt;/code&gt;. The section "Finding the line" further below shows how.&lt;/p&gt;
&lt;p&gt;Both ways, native and &lt;code class="docutils literal"&gt;make clean cross&lt;/code&gt;, need the libgpiod headers and library: on the host from the multiarch package above, on the BeagleBone from &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;libgpiod-dev&lt;/span&gt;&lt;/code&gt; (see the target system further below). &lt;code class="docutils literal"&gt;file&lt;/code&gt; shows whether the build worked:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_daad54b70fbb45068a5399ec4aee7ead-1" name="rest_code_daad54b70fbb45068a5399ec4aee7ead-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_daad54b70fbb45068a5399ec4aee7ead-1"&gt;&lt;/a&gt;file&lt;span class="w"&gt; &lt;/span&gt;toggle
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The BeagleBone is a 32-bit ARM board, so the output starts with &lt;code class="docutils literal"&gt;ELF &lt;span class="pre"&gt;32-bit&lt;/span&gt; LSB&lt;/code&gt; and &lt;code class="docutils literal"&gt;ARM, EABI5&lt;/code&gt;, both for the native build and after &lt;code class="docutils literal"&gt;make clean cross&lt;/code&gt;.&lt;/p&gt;
&lt;/section&gt;
&lt;/section&gt;
&lt;/section&gt;
&lt;section id="target-system-beagleboard-org-debian"&gt;
&lt;h2&gt;Target system (BeagleBoard.org Debian)&lt;/h2&gt;
&lt;section id="installing-the-operating-system"&gt;
&lt;h3&gt;Installing the operating system&lt;/h3&gt;
&lt;p&gt;The BeagleBone Black runs a Debian image from &lt;a class="reference external" href="https://www.beagleboard.org/distros"&gt;beagleboard.org&lt;/a&gt;. We use the current Debian 13 image without a desktop for the BeagleBone Black; at the time of writing this post, that is &lt;a class="reference external" href="https://www.beagleboard.org/distros/beaglebone-black-debian-13-7-2026-09-20-iot-v6-18-x"&gt;Debian 13.7 with kernel 6.18&lt;/a&gt;. We download the image together with its checksum and verify it:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_2457ee5a569943919e131fc5f1747155-1" name="rest_code_2457ee5a569943919e131fc5f1747155-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_2457ee5a569943919e131fc5f1747155-1"&gt;&lt;/a&gt;&lt;span class="nv"&gt;URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://files.beagle.cc/file/beagleboard-public-2021/images
&lt;a id="rest_code_2457ee5a569943919e131fc5f1747155-2" name="rest_code_2457ee5a569943919e131fc5f1747155-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_2457ee5a569943919e131fc5f1747155-2"&gt;&lt;/a&gt;&lt;span class="nv"&gt;IMG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;am335x-debian-13.7-base-v6.18-armhf-2026-09-20-4gb.img.xz
&lt;a id="rest_code_2457ee5a569943919e131fc5f1747155-3" name="rest_code_2457ee5a569943919e131fc5f1747155-3" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_2457ee5a569943919e131fc5f1747155-3"&gt;&lt;/a&gt;wget&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$URL&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;$IMG&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$URL&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;$IMG&lt;/span&gt;&lt;span class="s2"&gt;.sha256sum"&lt;/span&gt;
&lt;a id="rest_code_2457ee5a569943919e131fc5f1747155-4" name="rest_code_2457ee5a569943919e131fc5f1747155-4" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_2457ee5a569943919e131fc5f1747155-4"&gt;&lt;/a&gt;sha256sum&lt;span class="w"&gt; &lt;/span&gt;-c&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$IMG&lt;/span&gt;&lt;span class="s2"&gt;.sha256sum"&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class="docutils literal"&gt;sha256sum &lt;span class="pre"&gt;-c&lt;/span&gt;&lt;/code&gt; must report &lt;code class="docutils literal"&gt;OK&lt;/code&gt;. Otherwise the download is corrupt; in that case we delete the file and download it again. Then we write the image to a microSD card of at least 4 GB. &lt;code class="docutils literal"&gt;lsblk&lt;/code&gt; shows which device the card is. Caution: &lt;code class="docutils literal"&gt;dd&lt;/code&gt; overwrites whatever we name, without asking:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_a0e763ec58cc458cbaa68166c186016c-1" name="rest_code_a0e763ec58cc458cbaa68166c186016c-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_a0e763ec58cc458cbaa68166c186016c-1"&gt;&lt;/a&gt;lsblk
&lt;a id="rest_code_a0e763ec58cc458cbaa68166c186016c-2" name="rest_code_a0e763ec58cc458cbaa68166c186016c-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_a0e763ec58cc458cbaa68166c186016c-2"&gt;&lt;/a&gt;xzcat&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$IMG&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;sudo&lt;span class="w"&gt; &lt;/span&gt;dd&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/sdX&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;4M&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;progress&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;conv&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;fsync
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The image has no default password. Before the first boot, we create a user in &lt;code class="docutils literal"&gt;sysconf.txt&lt;/code&gt; on the small FAT partition &lt;code class="docutils literal"&gt;BOOT&lt;/code&gt; of the card (&lt;code class="docutils literal"&gt;/dev/sdX1&lt;/code&gt;); the image reads the file at boot and then removes the password from it. A key for SSH is optional:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_fa05eae1e0df41f78a5213ba0c5432bf-1" name="rest_code_fa05eae1e0df41f78a5213ba0c5432bf-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_fa05eae1e0df41f78a5213ba0c5432bf-1"&gt;&lt;/a&gt;sudo&lt;span class="w"&gt; &lt;/span&gt;mount&lt;span class="w"&gt; &lt;/span&gt;-o&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;id&lt;span class="w"&gt; &lt;/span&gt;-u&lt;span class="k"&gt;)&lt;/span&gt;,gid&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;id&lt;span class="w"&gt; &lt;/span&gt;-g&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;/dev/sdX1&lt;span class="w"&gt; &lt;/span&gt;/mnt
&lt;a id="rest_code_fa05eae1e0df41f78a5213ba0c5432bf-2" name="rest_code_fa05eae1e0df41f78a5213ba0c5432bf-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_fa05eae1e0df41f78a5213ba0c5432bf-2"&gt;&lt;/a&gt;nano&lt;span class="w"&gt; &lt;/span&gt;/mnt/sysconf.txt
&lt;a id="rest_code_fa05eae1e0df41f78a5213ba0c5432bf-3" name="rest_code_fa05eae1e0df41f78a5213ba0c5432bf-3" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_fa05eae1e0df41f78a5213ba0c5432bf-3"&gt;&lt;/a&gt;sudo&lt;span class="w"&gt; &lt;/span&gt;umount&lt;span class="w"&gt; &lt;/span&gt;/mnt
&lt;/pre&gt;&lt;/div&gt;
&lt;div class="code"&gt;&lt;pre class="code text"&gt;&lt;a id="rest_code_dcdd5b94cbc243d8994f325dac6b940f-1" name="rest_code_dcdd5b94cbc243d8994f325dac6b940f-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_dcdd5b94cbc243d8994f325dac6b940f-1"&gt;&lt;/a&gt;user_name=beagle
&lt;a id="rest_code_dcdd5b94cbc243d8994f325dac6b940f-2" name="rest_code_dcdd5b94cbc243d8994f325dac6b940f-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_dcdd5b94cbc243d8994f325dac6b940f-2"&gt;&lt;/a&gt;user_password=&amp;lt;your password&amp;gt;
&lt;a id="rest_code_dcdd5b94cbc243d8994f325dac6b940f-3" name="rest_code_dcdd5b94cbc243d8994f325dac6b940f-3" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_dcdd5b94cbc243d8994f325dac6b940f-3"&gt;&lt;/a&gt;user_authorized_key=&amp;lt;content of ~/.ssh/id_ed25519.pub&amp;gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;We put the microSD card into the BeagleBone, connect it to the Ethernet and power it on. The BeagleBone used here boots from the card on its own. If it boots from the internal eMMC instead, we hold down the boot button S2 (the small push-button next to the microSD slot), apply power and release the button after a few seconds. Then we log in via SSH with the user and host name that the image documents:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_fab33d47e1dd4544b798589978122e8d-1" name="rest_code_fab33d47e1dd4544b798589978122e8d-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_fab33d47e1dd4544b798589978122e8d-1"&gt;&lt;/a&gt;ssh&lt;span class="w"&gt; &lt;/span&gt;beagle@beaglebone.local
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As in Part 7, Linux is not a real-time system. The kernel can interrupt the program at any time, and the oscilloscope shows these interruptions as jitter (see below).&lt;/p&gt;
&lt;/section&gt;
&lt;section id="tools-and-libgpiod"&gt;
&lt;h3&gt;Tools and libgpiod&lt;/h3&gt;
&lt;p&gt;On the BeagleBone we install the compiler, libgpiod including the header files and the libgpiod command line tools, and check which libgpiod version apt installed:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_94dfb621485041e8914a79682bf05856-1" name="rest_code_94dfb621485041e8914a79682bf05856-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_94dfb621485041e8914a79682bf05856-1"&gt;&lt;/a&gt;sudo&lt;span class="w"&gt; &lt;/span&gt;apt&lt;span class="w"&gt; &lt;/span&gt;update
&lt;a id="rest_code_94dfb621485041e8914a79682bf05856-2" name="rest_code_94dfb621485041e8914a79682bf05856-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_94dfb621485041e8914a79682bf05856-2"&gt;&lt;/a&gt;sudo&lt;span class="w"&gt; &lt;/span&gt;apt&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;build-essential&lt;span class="w"&gt; &lt;/span&gt;libgpiod-dev&lt;span class="w"&gt; &lt;/span&gt;gpiod
&lt;a id="rest_code_94dfb621485041e8914a79682bf05856-3" name="rest_code_94dfb621485041e8914a79682bf05856-3" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_94dfb621485041e8914a79682bf05856-3"&gt;&lt;/a&gt;apt-cache&lt;span class="w"&gt; &lt;/span&gt;policy&lt;span class="w"&gt; &lt;/span&gt;libgpiod-dev
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The installed version must start with 2 (2.2.5 on the image from above). If the release still ships libgpiod 1.x, the compiler aborts on &lt;code class="docutils literal"&gt;toggle.c&lt;/code&gt; with &lt;code class="docutils literal"&gt;implicit declaration of function 'gpiod_line_settings_new'&lt;/code&gt;.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="finding-the-line"&gt;
&lt;h3&gt;Finding the line&lt;/h3&gt;
&lt;p&gt;The AM335x chip of the BeagleBone has four GPIO banks, and the kernel turns each of them into a GPIO chip. Which &lt;code class="docutils literal"&gt;gpiochipN&lt;/code&gt; number a bank gets depends on the kernel version, so we verify it on our board. &lt;code class="docutils literal"&gt;gpiodetect&lt;/code&gt; lists the chips, and &lt;code class="docutils literal"&gt;gpioinfo P9_23&lt;/code&gt; searches for the line named after the header pin and prints the chip and line number:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_4adb300e6ddc481683bf103f2c8ee4a0-1" name="rest_code_4adb300e6ddc481683bf103f2c8ee4a0-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4adb300e6ddc481683bf103f2c8ee4a0-1"&gt;&lt;/a&gt;gpiodetect
&lt;a id="rest_code_4adb300e6ddc481683bf103f2c8ee4a0-2" name="rest_code_4adb300e6ddc481683bf103f2c8ee4a0-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_4adb300e6ddc481683bf103f2c8ee4a0-2"&gt;&lt;/a&gt;gpioinfo&lt;span class="w"&gt; &lt;/span&gt;P9_23
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;On the image used here, the output looks like this:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code text"&gt;&lt;a id="rest_code_3f1425e6fefa41cd98ebf32b123bccf4-1" name="rest_code_3f1425e6fefa41cd98ebf32b123bccf4-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_3f1425e6fefa41cd98ebf32b123bccf4-1"&gt;&lt;/a&gt;$ gpiodetect
&lt;a id="rest_code_3f1425e6fefa41cd98ebf32b123bccf4-2" name="rest_code_3f1425e6fefa41cd98ebf32b123bccf4-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_3f1425e6fefa41cd98ebf32b123bccf4-2"&gt;&lt;/a&gt;gpiochip0 [gpio-0-31] (32 lines)
&lt;a id="rest_code_3f1425e6fefa41cd98ebf32b123bccf4-3" name="rest_code_3f1425e6fefa41cd98ebf32b123bccf4-3" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_3f1425e6fefa41cd98ebf32b123bccf4-3"&gt;&lt;/a&gt;gpiochip1 [gpio-32-63] (32 lines)
&lt;a id="rest_code_3f1425e6fefa41cd98ebf32b123bccf4-4" name="rest_code_3f1425e6fefa41cd98ebf32b123bccf4-4" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_3f1425e6fefa41cd98ebf32b123bccf4-4"&gt;&lt;/a&gt;gpiochip2 [gpio-64-95] (32 lines)
&lt;a id="rest_code_3f1425e6fefa41cd98ebf32b123bccf4-5" name="rest_code_3f1425e6fefa41cd98ebf32b123bccf4-5" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_3f1425e6fefa41cd98ebf32b123bccf4-5"&gt;&lt;/a&gt;gpiochip3 [gpio-96-127] (32 lines)
&lt;a id="rest_code_3f1425e6fefa41cd98ebf32b123bccf4-6" name="rest_code_3f1425e6fefa41cd98ebf32b123bccf4-6" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_3f1425e6fefa41cd98ebf32b123bccf4-6"&gt;&lt;/a&gt;$ gpioinfo P9_23
&lt;a id="rest_code_3f1425e6fefa41cd98ebf32b123bccf4-7" name="rest_code_3f1425e6fefa41cd98ebf32b123bccf4-7" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_3f1425e6fefa41cd98ebf32b123bccf4-7"&gt;&lt;/a&gt;gpiochip0 17    "P9_23"             input
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The chip labels only give the range of GPIO numbers, so the chip number from &lt;code class="docutils literal"&gt;gpioinfo&lt;/code&gt; is what counts: P9_23 is line 17 of &lt;code class="docutils literal"&gt;gpiochip0&lt;/code&gt;. If &lt;code class="docutils literal"&gt;gpioinfo&lt;/code&gt; reports a different chip on our board, we enter that chip at &lt;code class="docutils literal"&gt;CHIP&lt;/code&gt; in &lt;code class="docutils literal"&gt;toggle.c&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A pin on the pin header must also be in GPIO mode. On this image, P9_23 is a GPIO right after boot, so we do not have to do anything. The &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;config-pin&lt;/span&gt;&lt;/code&gt; tool of older images no longer exists; a different pin function would need a device tree overlay, which this series does not use.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="building-and-running"&gt;
&lt;h3&gt;Building and running&lt;/h3&gt;
&lt;p&gt;Natively on the BeagleBone: we copy &lt;code class="docutils literal"&gt;Makefile&lt;/code&gt; and &lt;code class="docutils literal"&gt;toggle.c&lt;/code&gt; from the host to the BeagleBone and build the program there.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_f42128ee04304c39ac47b94550e6d674-1" name="rest_code_f42128ee04304c39ac47b94550e6d674-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_f42128ee04304c39ac47b94550e6d674-1"&gt;&lt;/a&gt;ssh&lt;span class="w"&gt; &lt;/span&gt;beagle@beaglebone.local&lt;span class="w"&gt; &lt;/span&gt;mkdir&lt;span class="w"&gt; &lt;/span&gt;-p&lt;span class="w"&gt; &lt;/span&gt;toggle
&lt;a id="rest_code_f42128ee04304c39ac47b94550e6d674-2" name="rest_code_f42128ee04304c39ac47b94550e6d674-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_f42128ee04304c39ac47b94550e6d674-2"&gt;&lt;/a&gt;scp&lt;span class="w"&gt; &lt;/span&gt;Makefile&lt;span class="w"&gt; &lt;/span&gt;toggle.c&lt;span class="w"&gt; &lt;/span&gt;beagle@beaglebone.local:toggle/
&lt;a id="rest_code_f42128ee04304c39ac47b94550e6d674-3" name="rest_code_f42128ee04304c39ac47b94550e6d674-3" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_f42128ee04304c39ac47b94550e6d674-3"&gt;&lt;/a&gt;ssh&lt;span class="w"&gt; &lt;/span&gt;beagle@beaglebone.local
&lt;a id="rest_code_f42128ee04304c39ac47b94550e6d674-4" name="rest_code_f42128ee04304c39ac47b94550e6d674-4" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_f42128ee04304c39ac47b94550e6d674-4"&gt;&lt;/a&gt;&lt;span class="nb"&gt;cd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;toggle
&lt;a id="rest_code_f42128ee04304c39ac47b94550e6d674-5" name="rest_code_f42128ee04304c39ac47b94550e6d674-5" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_f42128ee04304c39ac47b94550e6d674-5"&gt;&lt;/a&gt;make
&lt;a id="rest_code_f42128ee04304c39ac47b94550e6d674-6" name="rest_code_f42128ee04304c39ac47b94550e6d674-6" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_f42128ee04304c39ac47b94550e6d674-6"&gt;&lt;/a&gt;./toggle
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Cross-compiling on the host: we build with &lt;code class="docutils literal"&gt;make clean cross&lt;/code&gt;, copy the binary to the BeagleBone and run it there.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_5d6ba0a05c5f4769aac42bb029f70f4d-1" name="rest_code_5d6ba0a05c5f4769aac42bb029f70f4d-1" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_5d6ba0a05c5f4769aac42bb029f70f4d-1"&gt;&lt;/a&gt;make&lt;span class="w"&gt; &lt;/span&gt;clean&lt;span class="w"&gt; &lt;/span&gt;cross
&lt;a id="rest_code_5d6ba0a05c5f4769aac42bb029f70f4d-2" name="rest_code_5d6ba0a05c5f4769aac42bb029f70f4d-2" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_5d6ba0a05c5f4769aac42bb029f70f4d-2"&gt;&lt;/a&gt;scp&lt;span class="w"&gt; &lt;/span&gt;toggle&lt;span class="w"&gt; &lt;/span&gt;beagle@beaglebone.local:
&lt;a id="rest_code_5d6ba0a05c5f4769aac42bb029f70f4d-3" name="rest_code_5d6ba0a05c5f4769aac42bb029f70f4d-3" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/#rest_code_5d6ba0a05c5f4769aac42bb029f70f4d-3"&gt;&lt;/a&gt;ssh&lt;span class="w"&gt; &lt;/span&gt;beagle@beaglebone.local&lt;span class="w"&gt; &lt;/span&gt;./toggle
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;We stop the program with Ctrl-C. Whether a normal user may open the chip depends on the group that owns the device. &lt;code class="docutils literal"&gt;ls &lt;span class="pre"&gt;-l&lt;/span&gt; /dev/gpiochip0&lt;/code&gt; shows the group &lt;code class="docutils literal"&gt;gpio&lt;/code&gt;, and &lt;code class="docutils literal"&gt;groups&lt;/code&gt; shows that the user created through &lt;code class="docutils literal"&gt;sysconf.txt&lt;/code&gt; is already a member. For other users, we run &lt;code class="docutils literal"&gt;sudo usermod &lt;span class="pre"&gt;-aG&lt;/span&gt; gpio $USER&lt;/code&gt; and log in again. We could of course also start the program as root, but for security reasons we do not.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="oscilloscope"&gt;
&lt;h3&gt;Oscilloscope&lt;/h3&gt;
&lt;p&gt;We shut down the BeagleBone and disconnect it from the power. Then we connect the probe tip to P9_23 and the ground clip to a ground pin of the pin header, for example P9_1. We power the BeagleBone on again, log in and start &lt;code class="docutils literal"&gt;toggle&lt;/code&gt;:&lt;/p&gt;
&lt;img alt="Oscilloscope: P9_23 switches between high and low with a period of 2.70 ms" src="https://graznik.de/images/power-sockets-bbb-toggle.png" style="width: 320px; height: 234px;"&gt;
&lt;p&gt;The line toggles between high and low. With 1 ms each for high and low, we expect a period of about 2 ms. Because &lt;code class="docutils literal"&gt;usleep&lt;/code&gt; is not exact and Linux is not a real-time system, the edges wander from period to period: that is the jitter mentioned above. On the BeagleBone Black used here, the oscilloscope measures about 2.70 ms instead of 2 ms: every &lt;code class="docutils literal"&gt;usleep&lt;/code&gt; sleeps a little longer than requested, and the calls into libgpiod and the kernel add to that.&lt;/p&gt;
&lt;p&gt;With &lt;code class="docutils literal"&gt;toggle&lt;/code&gt; running, the BeagleBone is ready. In &lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/"&gt;Part 9&lt;/a&gt; we switch the real sockets with librsswitch.&lt;/p&gt;
&lt;p&gt;We tested everything with a BeagleBone Black revision A5C and the Debian 13.7 image from above. The revision is in the board's EEPROM; &lt;code class="docutils literal"&gt;sudo hexdump &lt;span class="pre"&gt;-C&lt;/span&gt; &lt;span class="pre"&gt;/sys/bus/i2c/devices/0-0050/eeprom&lt;/span&gt; | head &lt;span class="pre"&gt;-1&lt;/span&gt;&lt;/code&gt; shows it after &lt;code class="docutils literal"&gt;A335BNLT&lt;/code&gt;.&lt;/p&gt;
&lt;/section&gt;
&lt;/section&gt;</description><category>BeagleBone</category><category>Hardware Hacking</category><category>Reverse Engineering</category><guid>https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/</guid><pubDate>Wed, 02 Dec 2026 12:00:00 GMT</pubDate></item><item><title>Reverse Engineering Remote Control Power Sockets</title><link>https://graznik.de/posts/reverse-engineering-remote-control-power-sockets/</link><dc:creator>Michael Hornung</dc:creator><description>&lt;figure&gt;&lt;img src="https://graznik.de/images/preview-power-sockets-overview.png"&gt;&lt;/figure&gt; &lt;div class="note docutils container"&gt;
&lt;p&gt;&lt;strong&gt;Updated 2026:&lt;/strong&gt; In Part 4 we switch a socket straight from an Arduino Uno, in Part 5 from an STM32F0DISCOVERY and in Part 6 with Zephyr from an STM32F429I-DISCO. The series ends with librsswitch, a small C library that lets a Raspberry Pi or a BeagleBone Black switch the sockets (Parts 7 to 9).&lt;/p&gt;
&lt;/div&gt;
&lt;img alt="Pollin set, front" class="align-left" src="https://graznik.de/images/pollin_bundle_front.png" style="width: 195px; height: 251.8px;"&gt;
&lt;img alt="Pollin set, back" class="align-right" src="https://graznik.de/images/pollin_bundle_back.png" style="width: 200px; height: 265.4px;"&gt;
&lt;p&gt;For about 13 EUR, the electronics mail-order shop Pollin sells a set of &lt;a class="reference external" href="https://www.pollin.de/productdownloads/D550666B.PDF"&gt;remote control power sockets&lt;/a&gt;: home automation on a budget. We can combine four sockets into one group, and the remote control switches them on and off.&lt;/p&gt;
&lt;p&gt;An article in &lt;a class="reference external" href="https://shop.heise.de/zeitschriften/hardware-hacks"&gt;c't Hacks&lt;/a&gt; (3/2012) gave us the idea. In this series of posts we reverse engineer the remote control and replace it with a low-cost &lt;a class="reference external" href="https://www.amazon.de/433-mhz-sender-empf%C3%A4nger/s?k=433+mhz+sender"&gt;433 MHz transmitter&lt;/a&gt;, driven by an Arduino Uno, an STM32F0DISCOVERY, an STM32F429I-DISCO with Zephyr, a Raspberry Pi or a BeagleBone Black. On the two Linux boards this is the job of &lt;a class="reference external" href="https://github.com/graznik/librsswitch"&gt;librsswitch&lt;/a&gt;, a small C library that imitates the encoder chip of the remote control on a GPIO line. The transmitter modules cost a few euros, for example on Amazon; directly from China they are even cheaper, but shipping takes weeks.&lt;/p&gt;
&lt;p&gt;For a later part we are planning a Linux kernel module that does the same job.&lt;/p&gt;
&lt;section id="tools-and-materials"&gt;
&lt;h2&gt;Tools and materials&lt;/h2&gt;
&lt;p&gt;To follow the posts or rebuild one of the projects, we need:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;Arduino Uno, STM32F0DISCOVERY, STM32F429I-DISCO, Raspberry Pi or BeagleBone Black&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;433 MHz transmitter (e.g. from &lt;a class="reference external" href="https://www.amazon.de/433-mhz-sender-empf%C3%A4nger/s?k=433+mhz+sender"&gt;Amazon&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Linux PC or VM with Debian 13 for cross-compiling&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Multimeter (optional, e.g. &lt;a class="reference external" href="https://www.batronix.com/versand/multimeter/multimeter-ut61c.html"&gt;UNI-T UT61C&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Oscilloscope (optional, e.g. &lt;a class="reference external" href="https://www.batronix.com/versand/oszilloskope/Rigol-DS1052E.html"&gt;RIGOL DS1052E&lt;/a&gt;) or&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Software-defined radio that works with &lt;a class="reference external" href="http://osmocom.org/projects/sdr/wiki/rtl-sdr"&gt;rtl-sdr&lt;/a&gt; (e.g. &lt;a class="reference external" href="https://www.noxon.ch/download/NOXON_DAB_Stick/TechnicalData/NOXON_DAB_Stick_Technical_Data_DE.pdf"&gt;Noxon DAB Stick&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Phillips screwdriver&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id="posts"&gt;
&lt;h2&gt;Posts&lt;/h2&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-info-gathering/"&gt;Part 1: Information gathering&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-protocol-analysis-with-oscilloscope/"&gt;Part 2: Protocol analysis with the oscilloscope&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-protocol-analysis-with-sdr/"&gt;Part 3: Protocol analysis with SDR&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-arduino-proof-of-concept/"&gt;Part 4: Arduino proof of concept&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-stm32f0discovery/"&gt;Part 5: STM32 proof of concept&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-zephyr-proof-of-concept/"&gt;Part 6: Zephyr proof of concept&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-4-setting-up-a-development-environment-for-the-raspberry-pi/"&gt;Part 7: Setting up a Raspberry Pi&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-5-setting-up-a-development-environment-for-the-bbb/"&gt;Part 8: Setting up a BeagleBone Black&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://graznik.de/posts/reverse-engineering-remote-control-power-sockets-part-6-switching-sockets-with-librsswitch/"&gt;Part 9: Switching with librsswitch&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Later: a Linux kernel module&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;</description><category>Arduino</category><category>BeagleBone</category><category>Hardware Hacking</category><category>Radio</category><category>Raspberry Pi</category><category>Reverse Engineering</category><category>STM32</category><category>Zephyr</category><guid>https://graznik.de/posts/reverse-engineering-remote-control-power-sockets/</guid><pubDate>Sat, 01 Apr 2017 17:55:52 GMT</pubDate></item></channel></rss>