Navigation


RSS / Atom



Chibios/RT docset for dash.app/zeal

2014-12-05 , , , Comment

The dash.app is a great little offline API/documentation browser (there’s also zeal, which compiles on Unix/Linux and Windows). It’s fairly easy to produce your own docset so I put together one for ChibiOS/RT version 2.2.6, the open source RTOS I’m working with. Download (11MB) org.chibios.tgz from Google Drive.

Comment


D Language

2014-04-19 , , , Comment

I recently had to write a moderate amount of C around vendor libraries and get things working in three days. The effort resulted in about 3200 lines of ugly, hastily written code that compiled under gcc and clang with -Wall -Werror -pedantic and looked reasonably leak-free in Valgrind. I whittled it down over the following week as time permitted to a bit over 2000 lines.

Lines of code is a lousy metric, but it’s easy to extract using available tools. Here are the counts from cloc for the original two projects in C:

-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
C                                3            298            193           1869
C/C++ Header                     3             32              0            178
-------------------------------------------------------------------------------
SUM:                             6            330            193           2047
-------------------------------------------------------------------------------

Quick passes with grep counts 11, 13, and 16 functions.

A better metric might be complexity. Running it through the cyclomatic complexity checker cyclo results in scores of 79, 99, and 110. These seem completely off the charts (10-15 is the recommended range for a “module”). Quick runs against some code I had lying around shows that these numbers are high (OpenBSD’s strncpy and a naive CRC-16 implementation I had both score a 5, SolarDesigner’s concat function scores a 12) but we can use them for comparison. Let’s torture the numbers by averaging, 13.3 functions and a score of 96, for about 7.2 complexity per function.

I’m always on the look out for an advantage (I need them…) and saw a recent announcement of a release of the D Language compiler. The features piqued my interest: native compilation, garbage collection and dynamic memory, types, classes, interfaces, mixins, exceptions, extensive standard library, and an easy interface to C. Walter Bright, the language designer and writer of the reference compiler, is well known. There’s a decent website, a tutorial, and C++ guru Andrei Alexandrescu wrote the book on the language. Cool, I thought, a better C++. I bought the book, started coding familiar tasks, and dug in during my little free time.

It went easily and I had a satisfactory result in a few days. The equivalent in D:

-------------------------------------------------------------------------------
Language          files     blank   comment      code    scale   3rd gen. equiv
-------------------------------------------------------------------------------
D                     2       109        96       709 x   1.70 =        1205.30
-------------------------------------------------------------------------------
SUM:                  2       109        96       709 x   1.70 =        1205.30
-------------------------------------------------------------------------------

Notice that I’ve reduced the number of files, I’ll get to that. The pass through grep counts 8 and 13 functions, of which 3 of them in each source file are two-line logging routines to replace the classic C preprocessor macros dbgprintf and errprintf. cyclo doesn’t perfectly handle D, but it’s reasonably close in syntax to C/C++, producing scores of 45 and 61. Twisting numbers again gives 10.5 and 53 for a score of about 5 per function. The improvement in complexity is on par with the reduction in lines of code.

The kicker is that not only are the D versions are shorter and easier to comprehend, they do more and have more robust error-checking and exception-handling. Overall I’m more confident they behave correctly. I replaced two independent programs with a single one. I replaced a throttled fork()-ing server with a fixed pool of workers. I leveraged associative arrays, JSON, and Base64 without rolling my own or borrowing from other Open Source libraries. None of this is stuff I couldn’t implement or find somewhere but I didn’t have to. Classic force multiplier of a programming language.

Comment


Burst Battery

2013-05-19 , , , Comment

The spare Macbook Pro battery burst overnight. It was sitting on my desk fully charged.



I’m glad it wasn’t in the laptop.

Comment


VoIP, SIP registration, and timeouts

2013-05-08 , , , Comment

Quick comment… Everyone in the family has multiple devices— phones, tablets, game consoles, computers— and these tend to make network connections that linger. If you have a firewall like I do, the default TCP and UDP timeouts are probably too high (often 3600 seconds) and when everyone is around on the weekend you get poor performance and strange complaints about how things don’t work. Separately, I have an OBI100 VoIP device providing phone to the house. The OBI100 has a default SIP registration period of 60 seconds and re-registers after half the interval, this is a bit too frequent so I have mine set to 300 seconds. As I’ve found, if the firewall expires the connection quickly you can end up with what looks like a valid registration at the SIP provider and can make outgoing calls but incoming calls fail. I’ve worked around it by expiring connections at 360 seconds for TCP and 180 seconds for UDP.

Comment


Ruby debugger in 1.9.3

2013-04-03 , , , Comment

I decided to really dig into Ruby and its ecosystem. It’s quick to get things started using RVM and the language is fun (and for what it’s worth, on my system Ruby 1.9.3 is slightly faster than Perl 5.12 on my favorite trivial string parsing test of extracting fields from 500,000 lines of Apache combined log) but coming from Python and Perl I find frustrating quirks in the tools. Today’s example is that the debugger is broken on 1.9.x and searching turns up hundreds of “fixes” that don’t work or only build for specific releases of ruby and the dependencies. I realize it isn’t “core”— there is a debug module in the 1.9.3 stdlib that is kind of undocumented— but it is the sort of thing you expect to work or get flagged as broken. It seems that the authors/maintainers of the debugger gave up on it, but Gabriel Horner has a fork that works.

Comment


Switching to VoIP with the OBi100

2012-07-15 , , , Comment

We’ve had telephone service through the local cable company for the past four years in a digital tv-phone-internet package. The “digital voice” service from Time Warner is voice-over-DOCIS but otherwise unexceptional and runs on the same cable network as the TV and internet services. We’ve seen our monthly price of the package climbing up and annual offers to new customers for the same package sliding down and received very little satisfaction from customer service. The whole bundle costs too much for the value we get. Cutting cable is a topic for the future, but I think I can do better for our very modest home phone usage.

I bought an Obihai OBi100 VoIP device. A colleague raved about how great his was and I found it selling new for less than $50 with tax and shipping. The first thing that struck me was how tiny it is, pictured here with a pack of gum and a pen for comparison:
OBI100 size
The device is about the size of a deck of playing cards, but a bit thicker. The second thing to know is that once it picks up an IP address with DHCP, the web-based interface offers both a “wizard” guided setup and a do-it-yourself mode where you input the configuration. I spent an hour reading the PDF documentation and forums on the vendor site, fiddling with Google two-step authentication, setting QoS on my router, and flashing the device with the most recent firmware before setting it up. The “wizard” is, at least for me, easier and I had the device working perfectly inbound and outbound as line #2 on my desk phone with Google Voice in five minutes.

My next step is to select a SIP provider and configure it as a second service.

Comment


« Older Posts   

invention-contempt