Author image Heikki Hannikainen
and 1 contributors


POCSAG::Encode - A perl module for encoding messages in the POCSAG binary protocol.


This module encodes text messages in the POCSAG protocol. It returns a binary string which can be fed synchronously to an FSK transmitter at 512 bit/s per second.


The module's generate function generates a single complete binary POCSAG transmission, which consists of:

  • A preamble consisting of Synchronisation Codewords (CWs)

  • One or more messages consisting of an Address Codeword and one or more Message Codewords

  • Synchronisation Codewords at regular intervals between the codeword batches, to keep the receivers in sync with the ongoing transmission

  • Idle Codewords before, between and after the messages, for mandatory padding to correctly place the Address Codewords in the correct frame boundaries.

Because the preamble is long, it makes sense to send a large amount of messages in a batch to minimize transmitter key-down time and save RF channel time. Also, having a larger number of messages to transmit in a single transmission makes it possible to reduce the amount of Idle Codewords in the transmission by optimizing the order in which the messages are sent.

This module currently has a very simple optimizer, which does not do a deeper search for the most optimal transmit order, but instead only considers the next message to be transmitted based on the minimum amount of Idle Codewords needed before the address frame for the next message can be sent.

Unless a debugging mode is enabled, all errors and warnings are reported through the API (as opposed to printing on STDERR or STDOUT), so that they can be reported nicely on the user interface of an application.



Generates a transmission binary string.

 # list of messages to send
 my @msgs = (
    # address, function, type, message
    [ '12345', 0, 'a', 'Hello, world!' ]

my($encoded, @left) = POCSAG::Encode::generate($piss_max_len, @msgs);

The function returns the binary string to be keyed over the air in FSK, and any messages which did not fit in the transmission, given the maximum transmission length (in bytes) given in the first parameter. They can be passed in the next generate() call and sent in the next brrraaaap.


Enables or disables debug printout in the module. Debug output goes to the standard error.