Linux Fu: Mapping Files

If you use C or C++, you have probably learned how to open a file and read data from it. Usually, we read a character or a line at a time. At least, it seems that way. The reality is there are usually quite a number of buffers between you and the hard drive, so your request for a character might trigger a read for 2,048 characters and then your subsequent calls return from the buffer. There may even be layers of buffers feeding buffers.

A modern computer can do so much better than reading using things using old calls like fgetc. Given that your program has a huge virtual address space and that your computer has a perfectly good memory management unit within it, you can ask the operating system to simply map the file into your memory space. Then you can treat it like any other array of characters and let the OS do the rest.

The operating system doesn’t necessarily read the entire file in at one time, it just reserves space for you. Any time you hit a page that isn’t in memory, the operating system grabs it for you invisibly. Pages that you don’t use very often may be discarded and reloaded later. Behind the scenes, the OS does a lot so you can work on very large files with no real effort. The call that does it all is mmap.

Continue reading “Linux Fu: Mapping Files”

How To Get Into Cars: Handling Mods

As a budding automotive enthusiast, you finally took the plunge and scored yourself a sweet project car. After going through it from top to toe, you’ve done your basic maintenance and it’s now running like a top. Now you’re getting comfortable, you’ve set your sights on turning your humble ride into a corner carving machine. Here’s a guide to get yourself started.

It’s All About Grip

When it comes to creating a handling monster, the aim is to create a car that sticks to the road like glue, and is controllable when it does break loose. Having a car that handles predictably at the limit is a big help when you’re pushing hard on track, particularly for an inexperienced driver. And, whether you’re hitting the canyons on the weekend or trying to slash your laptimes, it’s always nice to have more grip. Through selecting the right parts and getting the set up right, it’s possible to hone your car’s cornering ability to make it a rewarding experience to drive fast and hard. Continue reading “How To Get Into Cars: Handling Mods”

Write Once, Run Everywhere: Cross-Platform Programming Done Right

One of the goals of programming languages back in the 1950s was to create a way to write assembly language concepts in an abstract, high-level manner. This would allow the same code to be used across the wildly different system architectures of that era and subsequent decades, requiring only a translator unit (compiler) that would transform the source code into the machine instructions for the target architecture.

Other languages, like BASIC, would use a runtime that provided an even more abstract view of the underlying hardware, yet at the cost of a lot of performance. Although the era of 8-bit home computers is long behind us, the topic of cross-platform development is still highly relevant today, whether one talks about desktop, embedded or server development. Or all of them at the same time.

Let’s take a look at the cross-platform landscape today, shall we?

Continue reading “Write Once, Run Everywhere: Cross-Platform Programming Done Right”

Learning Morse Code The Ludwig Koch Way

Most countries have dropped the requirement for learning Morse code to become a ham radio operator. Because of that, you might think Morse code is dead. But it isn’t. Some people like the nostalgia. Some like that you can build simple equipment to send and receive Morse code. Others like that Morse code is much more reliable than voice and some older digital modes. Regardless of the reason, many people want to learn Morse code and it is still a part of the ham radio scene. The code has a reputation of being hard to learn, but it turns out that is mostly because people haven’t been taught code in smart ways.

I don’t know if they still do, but some youth organizations used to promote some particularly bad ways to learn the code. The second worse way is to learn “dots and dashes” and many people did learn that way. The very worst way was using an image like the adjacent one to try to map the dots and dashes into letter shapes. This chart dates back to at least 1918 when a Girl Guides handbook printed it.

Even if you are a visual learner, this is a bad idea. The problem is, it is nearly impossible to hear sounds at 20 or 30 words per minute and map them to this visual representation. Another visual method is to use a binary tree where left branches are dots and right branches are dashes.

If you only need to master 5 words per minute to get a merit badge, you might get away with this. But for real use, 5 words a minute is very slow. For example, this sentence would take about 3 minutes to send at that speed. Just that one sentence.

So what are the better ways? Let’s take a look.

Continue reading “Learning Morse Code The Ludwig Koch Way”

How To Hack A Portable Bluetooth Speaker By Skipping The Bluetooth

Portable Bluetooth speakers have joined the club of ubiquitous personal electronics. What was once an expensive luxury is now widely accessible thanks to a prolific landscape of manufacturers mass producing speakers to fit every taste and budget. Some have even become branded promotional giveaway items. As a consequence, nowadays it’s not unusual to have a small collection of them, a fertile field for hacking.

But many surplus speakers are put on a shelf for “do something with it later” only to collect dust. Our main obstacle is a side effect of market diversity: with so many different speakers, a hack posted for one speaker wouldn’t apply to another. Some speakers are amenable to custom firmware, but only a small minority have attracted a software development community. It doesn’t help that most Bluetooth audio modules are opaque, their development toolchains difficult to obtain.

So what if we just take advantage of the best parts of these speakers: great audio fidelity, portability, and the polished look of a consumer good, to serves as the host for our own audio-based hacks. Let’s throw the Bluetooth overboard but embrace all those other things. Now hacking these boxes just requires a change of mindset and a little detective work. I’ll show you how to drop an Arduino into a cheap speaker as the blueprint for your own audio adventures.

Continue reading “How To Hack A Portable Bluetooth Speaker By Skipping The Bluetooth”

Automate Your Life With Node-RED (Plus A Dash Of MQTT)

For years we’ve seen a trickle of really interesting home automation projects that use the Node-RED package. Each time, the hackers behind these projects have raved about Node-RED and now I’ve joined those ranks as well.

This graphic-based coding platform lets you quickly put together useful operations and graphic user interfaces (GUIs), whether you’re the freshest greenhorn or a seasoned veteran. You can use it to switch your internet-connected lights on schedule, or at the touch of a button through a web-app available to any device on your home network. You can use it as an information dashboard for the weather forecast, latest Hackaday articles, bus schedules, or all of them at once. At a glance it abstracts away the complexity of writing Javascript, while also making it simple to dive under hood and use your 1337 haxor skills to add your own code.

You can get this up and running in less than an hour and I’m going to tackle that as well as examples for playing with MQTT, setting up a web GUI, and writing to log files. To make Node-RED persistent on your network you need a server, but it’s lean enough to run from a Raspberry Pi without issue, and it’s even installed by default in BeagleBone distributions. Code for all examples in this guide can be found in the tutorial repository. Let’s dive in!

Continue reading “Automate Your Life With Node-RED (Plus A Dash Of MQTT)”

A Vintage Phone In 2020

When we make a telephone call in 2020 it is most likely to be made using a smartphone over a cellular or IP-based connection rather than a traditional instrument on a pair of copper wires to an exchange. As we move inexorably towards a wireless world in which the telephone line serves only as a vehicle for broadband Internet, it’s easy to forget the last hundred years or more of telephone technology that led up to the present.

The iconic British telephone of the 1960s and 1970s, the GPO model 746. Mine is from 1971.
The iconic British telephone of the 1960s and 1970s, the GPO model 746. Mine is from 1971. (That isn’t my phone number)

In a manner of speaking though, your telephone wall socket hasn’t forgotten. If you like old phones, you can still have one, and picture yourself in a 1950s movie as you twirl the handset cord round your finger while you speak. Continue reading “A Vintage Phone In 2020”