Feb 062016
 

Since putting this project on Youtube I’ve had a surprising amount of interest from across the world about the modifications I made to the original code from ON1ARF ( a radioamateur in Belgiรซ) to allow 1200 and 2400 bps pager transmissions as well as the default 512bps (I wanted to use the circuit to test commercial POCSAG pager receivers used at one site at my work).

The original code is here

https://github.com/on1arf/pocsag

To get 1200 and 2400 bps you must alter the radiohead libraries it depends on.

Two files must change – the first is RH_RF22.cpp. The code snippet is below (cut and paste this into your editor)

// These are indexed by the values of ModemConfigChoice // Canned modem configurations generated with // http://www.hoperf.com/upload/rf/RH_RF22B%2023B%2031B%2042B%2043B%20Register%20Settings_RevB1-v5.xls // Stored in flash (program) memory to save SRAM PROGMEM static const RH_RF22::ModemConfig MODEM_CONFIG_TABLE[] = { { 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x00, 0x08 }, // Unmodulated carrier { 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x33, 0x08 }, // FSK, PN9 random modulation, 2, 5 // All the following enable FIFO with reg 71 // 1c, 1f, 20, 21, 22, 23, 24, 25, 2c, 2d, 2e, 58, 69, 6e, 6f, 70, 71, 72 // FSK, No Manchester, Max Rb err <1%, Xtal Tol 20ppm { 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x22, 0x08 }, // 2, 5 { 0x1b, 0x03, 0x41, 0x60, 0x27, 0x52, 0x00, 0x07, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x22, 0x3a }, // 2.4, 36 { 0x1d, 0x03, 0xa1, 0x20, 0x4e, 0xa5, 0x00, 0x13, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x27, 0x52, 0x2c, 0x22, 0x48 }, // 4.8, 45 { 0x1e, 0x03, 0xd0, 0x00, 0x9d, 0x49, 0x00, 0x45, 0x40, 0x0a, 0x20, 0x80, 0x60, 0x4e, 0xa5, 0x2c, 0x22, 0x48 }, // 9.6, 45 { 0x2b, 0x03, 0x34, 0x02, 0x75, 0x25, 0x07, 0xff, 0x40, 0x0a, 0x1b, 0x80, 0x60, 0x9d, 0x49, 0x2c, 0x22, 0x0f }, // 19.2, 9.6 { 0x02, 0x03, 0x68, 0x01, 0x3a, 0x93, 0x04, 0xd5, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x09, 0xd5, 0x0c, 0x22, 0x1f }, // 38.4, 19.6 { 0x06, 0x03, 0x45, 0x01, 0xd7, 0xdc, 0x07, 0x6e, 0x40, 0x0a, 0x2d, 0x80, 0x60, 0x0e, 0xbf, 0x0c, 0x22, 0x2e }, // 57.6. 28.8 { 0x8a, 0x03, 0x60, 0x01, 0x55, 0x55, 0x02, 0xad, 0x40, 0x0a, 0x50, 0x80, 0x60, 0x20, 0x00, 0x0c, 0x22, 0xc8 }, // 125, 125 // { 0x2b, 0x03, 0xa1, 0xe0, 0x10, 0xc7, 0x00, 0x09, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x04, 0x32, 0x2c, 0x22, 0x04 }, // 512 baud, FSK, 2.5 Khz fd for POCSAG compatibility { 0x27, 0x03, 0xa1, 0xe0, 0x10, 0xc7, 0x00, 0x06, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x09, 0xd5, 0x2c, 0x22, 0x07 }, // 1200 baud, FSK, 4.5 Khz fd for POCSAG compatibility // { 0x27, 0x03, 0xa1, 0xe0, 0x10, 0xc7, 0x00, 0x06, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x04, 0x32, 0x2c, 0x22, 0x07 }, // 512 baud, FSK, 4.5 Khz fd for POCSAG compatibility // 2400 bps { 0x27, 0x03, 0xa1, 0xe0, 0x10, 0xc7, 0x00, 0x06, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x22, 0x07 },// 2400 baud, FSK, 4.5 Khz fd for POCSAG compatibility // GFSK, No Manchester, Max Rb err <1%, Xtal Tol 20ppm // These differ from FSK only in register 71, for the modulation type { 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x23, 0x08 }, // 2, 5 { 0x1b, 0x03, 0x41, 0x60, 0x27, 0x52, 0x00, 0x07, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x23, 0x3a }, // 2.4, 36 { 0x1d, 0x03, 0xa1, 0x20, 0x4e, 0xa5, 0x00, 0x13, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x27, 0x52, 0x2c, 0x23, 0x48 }, // 4.8, 45 { 0x1e, 0x03, 0xd0, 0x00, 0x9d, 0x49, 0x00, 0x45, 0x40, 0x0a, 0x20, 0x80, 0x60, 0x4e, 0xa5, 0x2c, 0x23, 0x48 }, // 9.6, 45 { 0x2b, 0x03, 0x34, 0x02, 0x75, 0x25, 0x07, 0xff, 0x40, 0x0a, 0x1b, 0x80, 0x60, 0x9d, 0x49, 0x2c, 0x23, 0x0f }, // 19.2, 9.6 { 0x02, 0x03, 0x68, 0x01, 0x3a, 0x93, 0x04, 0xd5, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x09, 0xd5, 0x0c, 0x23, 0x1f }, // 38.4, 19.6 { 0x06, 0x03, 0x45, 0x01, 0xd7, 0xdc, 0x07, 0x6e, 0x40, 0x0a, 0x2d, 0x80, 0x60, 0x0e, 0xbf, 0x0c, 0x23, 0x2e }, // 57.6. 28.8 { 0x8a, 0x03, 0x60, 0x01, 0x55, 0x55, 0x02, 0xad, 0x40, 0x0a, 0x50, 0x80, 0x60, 0x20, 0x00, 0x0c, 0x23, 0xc8 }, // 125, 125 // OOK, No Manchester, Max Rb err <1%, Xtal Tol 20ppm { 0x51, 0x03, 0x68, 0x00, 0x3a, 0x93, 0x01, 0x3d, 0x2c, 0x11, 0x28, 0x80, 0x60, 0x09, 0xd5, 0x2c, 0x21, 0x08 }, // 1.2, 75 { 0xc8, 0x03, 0x39, 0x20, 0x68, 0xdc, 0x00, 0x6b, 0x2a, 0x08, 0x2a, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x21, 0x08 }, // 2.4, 335 { 0xc8, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x29, 0x04, 0x29, 0x80, 0x60, 0x27, 0x52, 0x2c, 0x21, 0x08 }, // 4.8, 335 { 0xb8, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x28, 0x82, 0x29, 0x80, 0x60, 0x4e, 0xa5, 0x2c, 0x21, 0x08 }, // 9.6, 335 { 0xa8, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x28, 0x41, 0x29, 0x80, 0x60, 0x9d, 0x49, 0x2c, 0x21, 0x08 }, // 19.2, 335 { 0x98, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x28, 0x20, 0x29, 0x80, 0x60, 0x09, 0xd5, 0x0c, 0x21, 0x08 }, // 38.4, 335 { 0x98, 0x03, 0x96, 0x00, 0xda, 0x74, 0x00, 0xdc, 0x28, 0x1f, 0x29, 0x80, 0x60, 0x0a, 0x3d, 0x0c, 0x21, 0x08 }, // 40, 335 };
RH_RF22.cpp

Also the header file RH_RF22.h must change so the modemconfig table has values that reflect the changed modulation schemes.

typedef enum { UnmodulatedCarrier = 0, ///< Unmodulated carrier for testing FSK_PN9_Rb2Fd5, ///< FSK, No Manchester, Rb = 2kbs, Fd = 5kHz, PN9 random modulation for testing FSK_Rb2Fd5, ///< FSK, No Manchester, Rb = 2kbs, Fd = 5kHz FSK_Rb2_4Fd36, ///< FSK, No Manchester, Rb = 2.4kbs, Fd = 36kHz FSK_Rb4_8Fd45, ///< FSK, No Manchester, Rb = 4.8kbs, Fd = 45kHz FSK_Rb9_6Fd45, ///< FSK, No Manchester, Rb = 9.6kbs, Fd = 45kHz FSK_Rb19_2Fd9_6, ///< FSK, No Manchester, Rb = 19.2kbs, Fd = 9.6kHz FSK_Rb38_4Fd19_6, ///< FSK, No Manchester, Rb = 38.4kbs, Fd = 19.6kHz FSK_Rb57_6Fd28_8, ///< FSK, No Manchester, Rb = 57.6kbs, Fd = 28.8kHz FSK_Rb125Fd125, ///< FSK, No Manchester, Rb = 125kbs, Fd = 125kHz FSK_Rb_1200Fd4_5, ///< FSK, No Manchester, Rb = 1200bs, Fd = 4.5kHz, for POCSAG compatibility // FSK_Rb_512Fd4_5, ///< FSK, No Manchester, Rb = 512bs, Fd = 4.5kHz, for POCSAG compatibility FSK_Rb_2400Fd4_5, ///< FSK, No Manchester, Rb = 2400bs, Fd = 4.5kHz, for POCSAG compatibility GFSK_Rb2Fd5, ///< GFSK, No Manchester, Rb = 2kbs, Fd = 5kHz GFSK_Rb2_4Fd36, ///< GFSK, No Manchester, Rb = 2.4kbs, Fd = 36kHz GFSK_Rb4_8Fd45, ///< GFSK, No Manchester, Rb = 4.8kbs, Fd = 45kHz GFSK_Rb9_6Fd45, ///< GFSK, No Manchester, Rb = 9.6kbs, Fd = 45kHz GFSK_Rb19_2Fd9_6, ///< GFSK, No Manchester, Rb = 19.2kbs, Fd = 9.6kHz GFSK_Rb38_4Fd19_6, ///< GFSK, No Manchester, Rb = 38.4kbs, Fd = 19.6kHz GFSK_Rb57_6Fd28_8, ///< GFSK, No Manchester, Rb = 57.6kbs, Fd = 28.8kHz GFSK_Rb125Fd125, ///< GFSK, No Manchester, Rb = 125kbs, Fd = 125kHz OOK_Rb1_2Bw75, ///< OOK, No Manchester, Rb = 1.2kbs, Rx Bandwidth = 75kHz OOK_Rb2_4Bw335, ///< OOK, No Manchester, Rb = 2.4kbs, Rx Bandwidth = 335kHz OOK_Rb4_8Bw335, ///< OOK, No Manchester, Rb = 4.8kbs, Rx Bandwidth = 335kHz OOK_Rb9_6Bw335, ///< OOK, No Manchester, Rb = 9.6kbs, Rx Bandwidth = 335kHz OOK_Rb19_2Bw335, ///< OOK, No Manchester, Rb = 19.2kbs, Rx Bandwidth = 335kHz OOK_Rb38_4Bw335, ///< OOK, No Manchester, Rb = 38.4kbs, Rx Bandwidth = 335kHz OOK_Rb40Bw335 ///< OOK, No Manchester, Rb = 40kbs, Rx Bandwidth = 335kHz } ModemConfigChoice;
RH_RF22.h

the rest can then be used as normal – remember to alter the main Arduino sketch code to select these new bps rates.

NB: I am based in the UK/Europe; we always use wide deviation for POCSAG signals (although much other PMR traffic is now on narrow deviation).

If your country’s Communications Ministry requires narrow deviation to be used you will have to recalculate the modem settings using the spreadsheet referred to in the library files. (Its not as bad as it might seem; I had to use it to get the 1200/2400bps settings and I am not an RF nor a coding expert by any means)

 

Aug 082015
 

gcc can compile either c source or assembler (.s extension) or even a combination of both.

As I had the assembler source, decided to experiment with altering the string data (I don’t yet know enough to do anything else).

ARM asm source with some slight alterations

it still worked ๐Ÿ™‚

asm source output

note how the addresses of the array pointer change, as the strings have grown by a few characters…

below is the original code

WP_20150807_19_14_07_Rich

of course this is basic easy stuff; those strings are static/constant data and declared at compile time. if your code is dealing with strings that can change their length, it must always have sufficient free memory allocated to wherever the string data ends up, enough for the largest of the data. Otherwise you get a buffer overflow and your goose is cooked…

Aug 082015
 

I wanted to remind myself about C coding and how pointers work – never quite got my head round them at sons.

One of these was experimenting with C code so flawed it caused buffer overflows that crashed the kernel on multi user systems. That means the whole computer must be rebooted and other users would have their projects/data disrupted (it was in 1991, so a 32 bit machine was still known as a minicomputer and often used proprietary flavours of Unix and multiple users logged on using VT100 type terminals). I was already becoming disaffected with the place the profs thought I’d done it deliberately!

Todays Raspberry PI Model 2, placed in a suitable box (use a dark one as strong light can crash it due to a flaw in the chip design) is about the size of two packs of cigarettes; costs way less than they now do in the UK and is less unhealthy.

Aside: I can understand why younger people still smoke as I certainly did back then; but tobacco will knacker your insides and you become very ill as you get past your middle age. it has finished off a lot of my older friends on the electronics/radio scene. So at least try to stop with smoking when you get past age 30 if not before..

Back to the RPi – this amazing device is as powerful as the multi user computer I was using in 1991! The biggest advantage is if I screw up and hose the kernel it is only myself who gets affected by it. and I have done at least once, although most likely via accidental hard shutdowns i.e accidentally disconnecting the DC input whilst it is writing to the SD-card.

It is more tolerant of flawed code (I have made a silly mistake below; who can spot it?)

I used the console (having set the framebuffer font larger using sudo dpkg-reconfigure-console-setup as I couldn’t get the codeblocks debugger to play nicely and I find the GUI IDE more distracting when coding (probably because I am old ๐Ÿ˜‰ )

Tip: To get a console from X-windows on RPI press CTRL-ALT-F2, this opens a separate virtual terminal. (you can use CTRL-ALT-Fn) up to F6CTRL-ALT-F7 returns you to the X-window and CTRL-ALT-F1 has some odd error because it is in use as part of the X-windows system.

oeps

This version is better.

WP_20150807_18_59_49_Rich

It works.

WP_20150807_19_14_07_Rich

OK the code doesn’t do much but it reminds me that in C strings are an array of char, so each string has a char * to point to it. The contents of the char* are, as you would expect, a memory address where the string starts!

I then wanted to see what was going on at lower level, so used gdb. You must compile the code with gcc -g for the debugger to work.

WP_20150808_01_37_45_Rich

back in the day (1986-1990!) I even knew a bit about Assembler, but left high school just as Acorn ARM computers were available. So I thought I’d see if I could still remember any of it today. If you compile with gcc -S you get assembler code.

WP_20150808_01_40_53_Rich

this is what the source looks like, I can see the char* array, and its contents ๐Ÿ™‚

WP_20150808_01_43_02_Rich

This bit I do not quite understand as well yet but I can grasp the fact it is part of the main loop..

WP_20150808_01_44_09_Rich

Of course I need to learn much more about how ARM works (especially as you can only work with registers rather than put memory addresses directly in opcodes) and I am clearly no smarter than I was in my teens but at least my brain hasn’t deteriorated too much over the years ๐Ÿ™‚

 

PS: letting random geese loose in Groningen Netherlands (the message is partly in the Gronings dialect) is not just silly but (quite rightly) illegal under their animal welfare rules.

There would no one to look after it and there are plenty of stray ones already.

However if they were going to be otherwise eaten or put down and I’d arranged with the good folk at Akka’s Ganzenparadijs that the birdies had somewhere suitable to stay it would be a good deed. Emden geese aren’t that expensive (Emden is only just the other side in Germany anyway) and are cheaper alive than dead (a friend of mine farms them).

Although the Ganzenparadijs are a Buddhist animal sanctuary and I am baptised as a Catholic (not a very good one though); sparing the lives of these creatures to atone for someone else’s sin is the sort of thing many religions encourage.

I don’t expect this would get me to Heaven on a chariot towed by geese, but it would be sufficiently silly that all the various Gods would have a good laugh about it and I might even get one of those electric trolleys used at airports and large stations to haul the various heavy items through Purgatory required for the maintenance work I am tasked with.