All posts by tallen

local backup

This runs a local backup to a mounted file system (ext4 or btrfs). It does de-duplication at the file level; that is, the first backup copies everything, subsequent backups only copy the changed files and hard link to the unchanged files. RAID storage systems like NetApp de-duplicate at the block level but the snapshot paradigm is very similar.

remote backup

This runs a remote backup via ssh to a mounted file system (ext4 or btrfs). It does de-duplication at the file level; that is, the first backup copies everything, subsequent backups only copy the changed files and hard link to the unchanged files. RAID storage systems like NetApp de-duplicate at the block level but the snapshot paradigm is very similar.

Google Pixel as an Android development box

Recently I bought a Google Pixel (2015 samus). Chrome OS is really just a Linux variant running the Chrome browser so I figured I could just get it to boot Debian or Ubuntu and I’d have a nice laptop; indeed, there is much to like about the Pixel. Alas, I’ve tried booting an Ubuntu variant natively and Crouton; neither were good experiences.

Ubuntu
There are plenty of step by step instructions out there on how to do this and to Google’s credit they don’t try to stop you from owning your hardware. Getting Linux to boot is not the problem, living with it is. I suspect things will improve over time but here is my list of fails:

The keyboard layout is rather simple, I think I could have learned to live with this, but I found no mappings for this unique keyboard.
– The top row of keys are just F1 through F10, no combination of ctrl, alt, shift will make them adjust brightness etc; I could have lived with this.
– WiFi randomly stops working requiring a reboot; I can’t live with this.
– Every-time you wake from sleep there is a finite chance that you will have to do a cold reboot to get the track-pad to work again; this is another show-stopper, this is Linux, we don’t reboot.
– It didn’t seem to know if it was on AC or battery so things like folding down the screen didn’t work well; when I’m on AC, just keep running, but when I’m on battery, sleep.

On the other hand, no lockups and I could run Android Studio reliably, it was almost good enough. Yes, I did try the git-hub stuff with the special kernel version and the fixes for some of the hardware, no joy.

Crouton
I reinstalled Chrome OS and tried Crouton next… uh a little better and then I tried to run Android Studio… eh, not good. With Crouton one runs xorg et al. in a kind of sandbox. One switches between X and Chrome OS by holding down shift, ctrl, alt F1 or F2. In X, the keyboard problems noted above are still there but one can easily switch to Chrome OS and adjust the brightness etc. Sleeping seems to work better, the track-pad is reliable, and AC/battery detection and battery life seem to be better. …and then Android Studio took over eight minutes to build a small app and it is at this point I threw up my hands. [see update below]

Conclusion
I know many of these things are fixable –I could wait for the hardware fixes which I suspect will be here soon and I could remap the keyboard– but I don’t have the time. I need a Linux Laptop experience that works reasonably well out of the box. Really Google 1200 bucks for a Chromebook? Yes the hardware is nice, there really is a lot to like there, but I needed a better experience running a real OS.

I tried to buy a Dell ultrabook, they have a line that comes with Ubuntu out of the box but their moronic marketing department and broken business process caused me to have contact with sales support… epic fail! I should note that their tech support has become legendarily bad in recent years too.

Finding a good Linux laptop sucks, but I’m going to put the blame where it belongs… on the hardware vendors. The hardware market has gone from bad to really broken. Hey vendors, I need an ultrabook that runs Linux out of the box.

In closing I am writing this on the Pixel, when I finish I’m going to do a factory reset, box it up, send it back. I’m not happy about this, I really want like this thing, there
is a lot to like.

update 02/09: I got Android Studio to build/ The problem was with aapt, the fix, install lib32z1.

fun differences betwixt Java and C++ containers

…and for my next rant I wax poetic about the joys of writing code in the morning using C++ containers and in the afternoon switching to Java!

So I’ve got me an array of, I dunno uint32_t’s, and I’m just happy as a clam with my fun member functions and I’m callin’ ’em and I’m doing all sorts of cleverness, and then it comes time to do something with my amusingly arranged array. I need to call something that takes a pointer to an array of uint32_t’ or better yet I need to manipulate my fancy C++ array very quickly. No problem, this is still C isn’t it, bloated and strange but I can still get a pointer, why yes I can. A quick call to array::data() and I get me a pointer to an array of uint32_t’s…but not just any array of uint32_t’s _the_ array, not a copy (that the cpu had to do a shit load of work to make) the real thing… and I can do what I want with this array, may not be wise but I’m good to go!

…and later that day I’m writing some Java; and I got me a SortedSet… clever… arrange… member functions… But now I gotta call some Android crap and it wants an array because it’s going to display it somewhere. So I go to the documentation and I read, “toArray() Returns an array containing all elements contained in this set.” and I’m having flashbacks to this morning and I think jammin! I’ll just use these cutesy member functions to cleverly arrange my set and then I’ll call this refresh (update whatever) method and I already passed Android a reference to the underlying array and viol-la! …and it doesn’t bloody work. Well, it works the first time but I make my member calls on the set and I call refresh and I get the same display I got last time. So I reread the docs, it says, “toArray() Returns an array containing all elements contained in this set,” so what’s the problem… wait for it… Returns an array containing all elements contained in this set not the array. Effing Java decided to copy the whole bloody thing to a new array and then has the temerity to hand me a reference to this useless (and CPU intensive) pile of crap. Arrrgghh, I hate Java. Yeah, yeah, yeah, copy on write whatever, memset this pal!

Java.util.Timer and java.util.TimerTask abomination

grrr. okay so your writing an Android app and you want some bit of code to run on a semi-regular basis. So, you create a Task, something like…

private TimerTask refreshTask = new TimerTask() {
public void run() {
//do something...
};
};

…looks like a familiar design pattern, right. So in my onResume I new a Task and schedule the bloody thing and in my onPause I call Task.cancel().

…and then you run the app and it doesn’t crash right away noooooo it waits until you have to present to your boss and then it pukes all over itself, ehhem why? Well this is just one of the many unintuitive &^%*$^ that come up all the time in Java. You spend the next couple hours borking with different ways to stop and start the timer, then you spend a bit more making sure onPause and onResume are really called when they’re supposed to, and then… You figure out that not only do you have to new a Timer every time you want to restart you also have to new a TimerTask. Why!, I don’t know why, I guess they store some state in the timer task.

STM32F1xx, some advice

I have worked with the ST Micro ARM Cortex-M3 micro-controllers. I think I like them but here is some advice to help you along.

  • Yes, you really need all those capacitors. These things run at 75MHz or better. Put the caps close to the pins.
  • These things are more easily damaged by ESD than one might think. Yes, I know they’re supposedly marketed for automotive applications. Yes, I know the data-sheet says class blah blah blah. You need to do more, I had a product whose only vulnerability was the battery compartment and I still had to do more. I found this helpful
  • Build your own cross compiler from scratch! You will learn things about C/C++ that you need to know to be a good embedded systems engineer. I have some stuff like crt0 and linker scripts on this site. Yes I cut and pasted them but I was about 3/4ths of the way through writing them from scratch before I found prettier ones on-line and no, I did not waste my clients time, I was able to solve deep problems with other people’s projects at the same client because I understood this stuff. I stood on the shoulders of giants and here’s a link to one of those giants 🙂 The Olimex site also has some info for building a cross compiler.
  • I like and recommend the Olimex boards but they have the same ESD problems I had so don’t be lulled into a false sense of security, add mitigation to your design. I used a TVP diode between VDD and VSS on the line coming from the battery clip.
  • I have the FlySwatterII and the Olimex ARM-USB-OCD-H, I prefer the latter mostly because it can provide power.
  • Use the ST micro provided libraries sparingly, sometimes it’s easier to understand the peripheral and write your own code than to try to sort out their library madness or HAL.
  • OpenOCD and gdb are awesome. Yes gdb has a steep learning curve, no it’s not pretty, but it is the most powerful debugger known to man… The only thing I’ve ever seen that was close ran on a VAX when I was a kid. I find cgdb helpful. I sometimes use the layout stuff but it’s a bit young (read buggy) but helpful. Seriously, learn to cope with gdb it can do things no other debugger can.
  • Read the errata these things have a surprising number of hardware bugs!

PIC Microchip, some advice

I like 8bit PICs but here’s some advice:

  • You want to use assembly. Really, don’t mess with whatever crazy (non-ANSI) c compiler these clowns are pushing. Assembly (particularly on these chips) is not hard.
  • MPLAB X is horrible, it takes all the things I love about PICs and makes it complicated.*
  • Don’t mess with the PICkit3 it only works with MPLAB X. You want the PICkit2, it works with pk2cmd. If you really need those debugging features then it’s time to move on to something with an ARM core (Serial Wire Debug gdb and all that)
  • If you need to do math use a lookup table (array). If your math is complicated then do it in C and use something with an 32 bit ARM core (read: not a PIC); these things don’t have FPUs. Really, most of them multiply by adding in a loop, an FPU is like a pocket calculator for your CPU.
  • Use the simplest chip you need to do the job, start out with something with with a modest number of peripherals lest you be overwhelmed.
  • Really, learn assembler your going to get stuck anyway and have to write some assembly anyway… and it’ll make you feel smart!

* What they’re really up to here is to immerse you in their marketing madness. Hey Microchip, if ya want me to use your high end chips than you need to contribute to gcc or clang or both, if it’s not an open source ANSI compiler I won’t use it, I am not going to learn your crazy dialect of C or pay you for the privilege of writing code that will create demand for your chip!

Beacons using a PIC10F200

Before there were standards like iBeacon and Eddystone we had to “roll our own.” This is a primitive beacon using a PIC10F200 (8pin DIP) along with a simple 315MHz OOK transmitter. Later versions, not shown here, use SDR.

beacon.asm

This is written in PIC assembly. It simply transmits my FCC Call sign with a number tacked on the end. Production versions would substitute a UUID and checksum in place of my Call sign. The signal is intentionally weak, we only want to know if the watch (wearable device) is within a few meters. Battery life is important too, this thing should be good for about 57 years on a couple AAA batteries.

The gist of what this code does is to set a timer and go to sleep. When the timer expires the chip wakes up and increments some counter (the timer durations are rather short) and we need some randomization to minimize the possibility of interference betwixt proximal beacons*. If it’s time to send a burst, my Call sign, then it does so, resets the counter and timer and goes back to sleep. The idea is to spend as much time asleep as possible to conserve batteries.

beacon.asm

Makefile

* This is a bit tough to explain so bare with me. The oscillators on these things are not precise. So imagine we were to send a burst every 30 wake-ups (e.g. no randomization). Okay so lets say you have two of these close together and we put batteries in them at the same time. Now every 30 wake-ups they both wake up and clobber each other (the wearable can’t hear either because they “talk” over each other). Now eventually, because the oscillators are imprecise, they drift apart but that may take hours; therefore, we introduce some randomization to keep them asynchronous. I’m skipping some nuance here but I hope you get the idea.

Cordova / PhoneGap

Exploration of Cordova for use with Point of Sale. A client has a POS web application written in LAMP, looking at writing the next generation using Cordova. In the near term Cordova probably has utility in replacing the client’s problematic and soon to be deprecated Java browser plug-in.

For now, I’m working through a primmer at: https://ccoenraets.github.io/cordova-tutorial/data-storage.html

I have done this for iOS, Android, and various browsers.

Looks like I’m going to really learn JavaScript and nodeJS, when do we get a real language front-end to the JavaScript “byte-code”.

AutoHell (automake)

Intro
I have been writing my own Makefiles for years. Lately I’ve been experimenting with using automake. I have used automake to compile various things from source for years. It’s a formidable beast but then again so was make and getting vim to work the way _I_ want, but those have proven well worth the effort, we’ll see…

run autoscan
This generates autoscan.log which you probably don’t care about and configure.scan which you will edit and rename to configure.ac

edit configure.scan and rename to configure.ac
add AC_INIT, AC_INIT_AUTOMAKE and AC_OUTPUT
example:

AC_INIT(magtek, 0.1, tallen@integsys.biz)
AM_INIT_AUTOMAKE
AC_OUTPUT(Makefile src/Makefile)

run aclocal

run autoconf

create/edit Makefile.am

AUTOMAKE_OPTIONS = foreign
SUBDIRS = src

foreign means non GNU
SUBDIRS could include things like src, doc, examples, man, scripts

create/edit src/Makefile.am

AM_CXXFLAGS=-g -I/usr/include/libusb-1.0 -lusb-1.0
LDADD = /usr/lib/x86_64-linux-gnu/libusb-1.0.so
AM_ETAGSFLAGS = -R --c++-kinds=+p --fields=+iaS --extra=+q --if0=yes . /usr/include/libusb-1.0/

bin_PROGRAMS = enumerate magtek
enumerate_SOURCES = enumerate.cc
magtek_SOURCES = magtek.cc

AM_CXXFLAGS adds will show up as CXXFLAGS in the generated Makefile
LDADD is library thats not mainstream required for this project
AM_ETAGSFLAGS are the flags for the tags target in the generated Makefile
the rest is for your targets and their dependencies

run autoheader
run automake –add-missing
run autoconf
run ./configure
run make

I used this page and naturally the documentation as a basis for working this out.