Do hardware hackers need a new programming language? Your first answer might be no, but hold off a bit until you hear about a new language called Rust before you decide for sure.
We all know real hackers use assembly language to program CPUs directly, right? Well, most of us don’t do as much assembly language as we used to do. Languages like C can generate tight, predictable code and are easier to manage.
Although some people use more abstract languages in some embedded systems, it is no secret that for real-time systems, device driver development, and other similar tasks, you want a language that doesn’t obscure underlying details or generate code that’s difficult to reason about (like, for example, garbage collection). It is possible to use special techniques (like the Real-Time Java Specification) to help languages, but in the general case a lean language is still what most programmers reach for when you have to program bare metal.
Even C++, which is very popular, obscures some details if you use things like virtual functions (a controversial subject) although it is workable. It is attractive to get the benefit of modern programming tools even if it does conceal some of the underlying code more than straight C.
About Rust
That’s where Rust comes in. I could describe what Rust attempts to achieve, but it is probably easier to just quote the first part of the Rust documentation:
Rust is a systems programming language focused on three goals: safety, speed, and concurrency. It maintains these goals without having a garbage collector, making it a useful language for a number of use cases other languages aren’t good at: embedding in other languages, programs with specific space and time requirements, and writing low-level code, like device drivers and operating systems. It improves on current languages targeting this space by having a number of compile-time safety checks that produce no runtime overhead, while eliminating all data races. Rust also aims to achieve ‘zero-cost abstractions’ even though some of these abstractions feel like those of a high-level language. Even then, Rust still allows precise control like a low-level language would.
Here at Hackaday we see a lot of technological hoaxes looking for funding. Some are on Kickstarter, others are firms looking for investors. And unlike a lot of the press, we’re both skeptical and experienced enough to smell the snake oil. When you read about a laser-powered razor blade that looks too good to be true, you know we’ve got your back.
The background: [Zachary Feinstein] is a professor at Washington University in St. Louis who studies financial engineering, and in particular systemic financial risk in the banking sectors. So he’s just exactly the guy you’d tap to write a paper on the financial repercussions of the destruction of the Death Stars in Star Wars (PDF). Wait, what?
The central argument of the paper is that, since the Empire has so much money wrapped up in building the Death Stars, it’s economic suicide for the Rebels to destroy it. To quantify any of this, [Feinstein] runs financial crisis models. The idea is that the Rebels win, but they inherit an economy that’s so dysfunctional that they’d have been better off not destroying the Death Stars.
We’re not saying that the rest of the press is gullible, but we are saying that they’re not putting their best economists onto articles about financing Death Stars. But here at Hackaday, we are. And we’re calling it a hoax. So let’s look into what the paper gets right, and what makes less sense even than Chewbacca’s infernal growling. Spoiler: we’ll get wrapped up in numbers because it’s fun, but the whole thing is moot for Econ 101-style reasons.
Converting mains voltage down to 12 or 24VDC to drive a heating element makes no sense. To get 120 watts at 12 volts requires thick wires that can handle 10 amps, whereas at 120V, tiny 1A wires will do. If you’ve ever felt the MOSFET that switches your heated bed on and off, you know it’s working hard to pass that much current. [Makertum] is of the opinion this is a dumb idea. He’s creating a 110 / 230 V, mains-powered heated bed.
Creating a PCB heat bed isn’t an art – it’s a science. There are equations and variables to calculate, possibly some empirical measurements by measuring the resistance of a trace, but Ohm’s Law is a law for a reason. If you do things right, you can make a PCB heat bed perfectly suited for the task. You can even design in safety features like overcurrent protection and fuses. It can’t be that hard. After all, your house is full of devices that are plugged into the wall.
However, there’s a reason we use 12V and 24V heated beds – they give us, at the very least, the illusion of safety. Therefore, [Makertum] is looking for a few comments from specialists and people who know what they’re doing.
Although a mains powered heated bed sounds scary for a hobbyist-built 3D printer, there are a number of positives to the design. It would heat up faster, thin down a few parts, and significantly reduce the overall cost of the printer by not requiring another 100 Watts delivered from a 12V power supply. It’s a great idea if it doesn’t burn down the house. Anyone want to help?
Winston Churchill once told Joseph Stalin “In wartime, truth is so precious that she should always be attended by a bodyguard of lies”. During World War II, the power of these bodyguards, in the form of military deception, became strikingly apparent. The German military was the most technologically advanced force ever encountered. The Germans were the first to use jet-powered aircraft on the battlefield. They created the enigma machine, which proved to be an extremely difficult system to break. How could the Allies possibly fool them? The answer was a mix of technology and some incredibly talented soldiers.
The men were the 23rd Headquarters Special Troops, better known as the Ghost Army. This unit was the first of its kind specifically created to deceive the enemy. Through multiple operations, they did exactly that. These 1100 soldiers created a diversion that drew German attention and gunfire to them, instead of the thousands of Allied troops they were impersonating.
The Ghost Army consisted of 4 distinct groups:
The 406th Engineer Combat Company Special were 166 “regular” soldiers – these men handled security, construction, and demolition.
603rd Camouflage Engineers were the largest group at 379. As the name implies, the 603rd was created to engineer camouflage.
3132 Signal Service Company consisted of 145 men in charge of half-tracks loaded down with massive 500 watt speakers which could be heard for 15 miles.
The Signal Company Special Formerly the 244th signal company, The 296 men of the Signal Company Special handled spoof radio communications. The Germans heavily relied on captured and decoded radio messages to determine the Allies’ next move.
The 900-pound gorilla in the corner of the Internet of Things (IoT) hype that everyone is trying to ignore is interoperability. In the Internet of Internets (IoI) everything works on a few standards that are widely accepted: IP and HTML. The discrepancies are in the details and the standards wars are in the past. Websites are largely interoperable. Not so in the wild-west ethos of the IoT.
Philips makes a line of ZigBee-enabled RGB lightbulbs that took the enthusiast community by storm. And initially, Philips was very friendly to other devices — it makes a ZigBee-to-WiFi bridge that would let you control all of your ZigBee-based lights, regardless of their manufacturer, from your phone. Until now.
Philips has just rolled out a “Friends of Hue” certification process, and has since pushed out a firmware update where their Hue bridges stop interoperating with non-certified devices. You can read Philips’ version of the story here.
Philips Locks Out 3rd Party ZigBee Hardware
The hub shown on the right is what’s being locked down.
The short version is that, ZigBee standards be damned, your future non-Philips lights won’t be allowed to associate with the Philips bridge. Your GE and Osram bulbs aren’t Friends of Hue. DIY RGB strips in your lighting mix? Not Friends of Hue. In fact, you won’t be surprised to know who the “Friends of Hue” are: other Philips products, and Apple. That’s it. If you were used to running a mixed lighting system, those days are over. If you’re not on the friends list, you are an Enemy of Hue.
Their claim is that third party products may display buggy behavior on a Philips network, and that this loads up their customer-response hotlines and makes people think that Philips is responsible. Of course, they could simply tell people to disable the “other” devices and see how it works, putting the blame where it belongs. Or they could open up a “developer mode” that made it clear that the user was doing something “innovative”. But neither of these strategies prevent consumers from buying other firms’ bulbs, which cost only 30-50% of Philips’ Hue line.
While Philips is very careful to not couch it as such, the Friends of Hue program really looks like an attempt to shut out their competitors; Philips got an early lead in the RGB LED game and has a large share of the market. As they say themselves in their own press release “Today these 3rd party bulbs represent a minimal fraction of the total product connected to our bridges so the percentage of our users affected is minimal.” And they’d like to keep it that way, even though the people they’re hurting are probably their most vocal and dedicated customers.
And while we, with our manual light switches, laugh comfortably at the first-world problems of Hue consumers, we have to ask ourselves whether we’re next. Today they come for our RGB lightbulbs, but tomorrow it might be our networked toasters. A chilling thought!
Snark aside, the IoT brings two of the saddest realities of the software world into your home appliances: Where there’s code, there’s vulnerabilities, and when you can’t control the code yourself you aren’t really in control. You may own the lightbulb, but you’re merely licensing the firmware that runs it. The manufacturer can change the rules of the game, or go out of the product line entirely, and you’re high and dry. What can you do? Pull out your JTAG debugger.
Of course it’s insane to suggest that everyone needs to become an embedded-device firmware hacker just to keep their fridge running. As we’ve written before, we need to come up with some solution that puts a little more control in the hands of the ostensible owners of the devices, while at the same time keeping the baddies out. We suggest a press-to-revert-firmware button, for instance. When Philips pushes a non-consumer-friendly upgrade, you could vote with your fingertips — but then you’d miss out on bug fixes as well. Maybe it’s better to just give in an learn to love Windows 10.
There are no easy solutions and no perfect software. The industry is still young and we’ll see a lot of companies staking out their turf as with any new technology. It seems to us that IoT devices leave consumers with even less choice and control than in the past, because they are driven by firmware that’s supposed to be invisible. It’s just a lightbulb, right?
What do you think? Any ideas about how to put the power back in the hands of the “owner” of the device without everyone’s refrigerators becoming botnet zombies? Let us know in the comments.
“We underestimated the impact this would have upon the small number of our customers who currently use uncertified lights from other brands in the Philips Hue system. We have decided to continue to enable our customers who wish to integrate these uncertified products within their Philips Hue system.”
“Everything should be made as simple as possible, but not simpler.”
Albert Einstein
Our journey begins with a fictitious character whom we shall call [John Doe]. He represents the average professional worker who can be found in cities and towns across the world. Most everyday, [John] wakes up to his alarm clock and drives his car to work. He takes an elevator to his office and logs on to his computer. And he does these things without the slightest clue of how any of them work. While he may be interested in learning about the inner workings of the machines and devices he uses on a daily basis, [John] does not have the time and energy to invest in doing so. To him cars, elevators, computers and alarm clocks are completely different and complicated machines with hardly any similarities. It is simply not possible to understand how each of them work without years of study.
The regular readers of Hackaday might see things a bit differently than our [John Doe]. They would know that the electric motor that moves the elevator is very similar to the alternator in his car. They would know that the PLC that controls the electric motor that moves the elevator is very similar to the computer he logs in to. They would know that on a fundamental level, the PLC, alarm clock and computer are all based on relatively simple transistor theory. What is a vast complicated mess to [John Doe] and the average person is nothing but the use of simple mechanical and electrical principles to the hacker. The complication resides in how those principles are applied. Abstracting the fundamental principles from complicated ideas allows us to simplify and understand them in a way that pays homage to Einstein’s off-the-cuff advice, quoted above.
Zeno of Elea 490 – 430BC
Many of you look at The Calculus the same way [John Doe] looks at machines. You see the same vast, complicated mess that would require a great deal of time and effort to understand. But what if I told you that calculus shares a commonality in much the same way many different machines do. That there are a few basic principles that anyone can understand, and once you do, it will unlock a new way of looking at the world and how it works.
The average calculus course book is a thousand pages long. The [John Does] of the world will see a thousand difficult things to learn. The hacker, however, will see two basic principles and 998 examples of those principles. In this series of articles, I’m going to show you what these two principles – the derivative and the integral – are. Based on work done by Professor [Michael Starbird] of The University of Texas at Austin for The Teaching Company, we’ll use everyday examples that anyone can understand. The Calculus reveals a particular beauty of our world — a beauty that arises when you’re able to view it dynamically as opposed to statically. It is my hope to give you this view.
Before we get started, it pays to understand a little of the history of how The Calculus came about, and how its roots lie in the very careful analysis of change and motion.
Zeno’s Paradox
Zeno of Elea was a philosopher in the fourth century BC. He posed several subtle but profound paradoxes, two of which would eventually give rise to The Calculus. It would take over 2,000 years for man’s ingenuity to solve the paradoxes. As you can imagine, it wasn’t easy. The difficulties largely revolved around the idea of infinity. How do you deal with infinity from a mathematical perspective? Sir Isaac Newton and Gottfried Leibniz would go on to independently invent The Calculus in the mid 17th century, finally putting the paradoxes to rest. Let us take a close look at them and see what the fuss was all about.
The Arrow
Consider the arrow flying through the air. We can say with reasonable and competent assurance that the arrow is in motion. Now consider the arrow at any given instant in time. The arrow is no longer in motion. It is at rest. But we know the arrow is in motion, how can it be at rest! This is the paradox. It might seem silly, but it’s a very challenging concept to deal with it from a mathematical point of view.
We’ll find out later that what we’re really dealing with is the concept of an instantaneous rate of change, which we will elaborate on with the idea of one of the two principles of calculus – the derivative. It will allow us to calculate the velocity of the arrow at an instant in time – a monumental feat that took over two millennia for mankind to reach.
The Dichotomy
Let us consider the same arrow again. This time let’s say the arrow is coming at us. Zeno says we don’t have to move, because it can never hit us. Imagine that as the arrow is in flight, it has to cover half the distance between the bow and the target. Once it reaches the half way point, it has to do this again – move half the distance between it and the target. Imagine that we keep doing this. The arrow is constantly moving halfway between its origin and target. By doing this, the arrow can never hit us! In real life, the arrow does eventually hit the target, leaving us with the paradox.
As with the first paradox, we’ll see how to resolve this issue with one of the two principles of calculus – the integral. The integral allows us to deal with the concept of infinity as a mathematical function. It is an extremely powerful tool to scientists and engineers.
The Two Principles of Calculus
The two main ideas of The Calculus will be demonstrated by using them to solve Zeno’s paradoxes.
The Derivative – The derivative is a technique that will allow us to calculate the velocity of the arrow in “The Arrow” paradox. We will do this by looking at positions of the arrow through incrementally smaller amounts of time, such that the precise velocity will be known when the time between measurements is infinitely small.
The Integral – The integral is a technique that will allow us to calculate the position of the arrow in the Dichotomy paradox. We will do this by looking at velocities of the arrow through incrementally smaller amounts of time, such that the precise position will be known when the time between measurements is infinitely small.
It’s not difficult to notice some similarity between the derivative and integral. Both values are calculated by examining the arrow with increasingly finer time intervals. We will learn later that the integral and derivative are in fact two sides of the same ceramic capacitor.
Why Should I Learn Calculus?
We are all familiar with Ohm’s Law, which relates current, voltage and resistance in a simple equation. However, let us consider “Ohm’s Law” for a capacitor. A current flow through a capacitor is dependent on the voltage across it and time. Time is the critical variable here, and must be taken into account in any dynamic event. Calculus lets us understand and measure how things change over time. In the case of a capacitor, the current through it is equal to the capacitance multiplied by volts per second, or: i = C(dv/dt) where:
i = current (instantaneous)
C = Capacitance in Farads
dv = change in voltage
dt = change in time
In this circuit, there is no current flow through the capacitor. The volt meter will read the battery voltage and the ammeter will read zero amps. So long as the potentiometer is not moved, the voltage on the meter will be steady. Our equation would say that i = C(0/dt) = 0 amps. But what happens when we adjust the potentiometer? Our equation says there will be a resulting current flow in the capacitor. This current flow will be dependent on the rate the voltage changes, which is tied to how fast we move the potentiometer.
These graphs show the casual relationships between the voltage across the capacitor, the current through the capacitor and the speed we turn the potentiometer. It starts with the potentiometer turning slowly. An increase in speed results in a faster changing voltage which in turn results in a dramatic increase in current. At all points, the current through the capacitor is proportional to the rate of change of the voltage across it.
Calculus, or more specifically the derivative, gives us the ability to quantify this rate of change, so that we can know the exact value of current running through the capacitor at any given instant in time. The same way we can know the instantaneous velocity of Zeno’s arrow. It is an incredibly powerful tool to have in your hacking arsenal.
In the next article, we will go into deep detail of how we calculate the derivative using a modern but still simple representation of Zeno’s “The Arrow” paradox and some basic algebra. A following article will do the same for the integral using the Dichotomy paradox. Then we will tie things up by showing how the two are related, something known as The Fundamental Theorem of Calculus.
We had to giggle at this one when it came down the tips line. Last week, a woman involved in a hit-and-run fled the scene — only to have her car call 911 for her.
The woman hit two vehicles and then attempted to drive home when her Ford vehicle called 911 using the Sync Emergency Assistance Technology. When asked by the dispatcher if everything was okay she lied about being in the accident — but the dispatcher did not believe her. After all, the sync feature only calls if the car has seen significant damage, and in this case, the air bag had been deployed. Continue reading “Alleged Hit-and-Run Driver Arrested After Her Car Rats Her Out”→