Additional Information

Site Information

 Loading... Please wait...

SAE J1939 Programming with Arduino - Hungarian Notation

Posted by Wilfried Voss on

This post is part of a series about SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino.

SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino

Hungarian notation is an identifier naming convention in computer programming, in which the name of a variable or function indicates its type or intended use. Hungarian notation was designed to be language-independent, and found its first major use with the BCPL programming language. Because BCPL has no data types other than the machine word, nothing in the language itself helps a programmer remember variables' types. Hungarian notation aims to remedy this by providing the programmer with explicit knowledge of each variable's data type.

In Hungarian notation, a variable name starts with a group of lower-case letters, which are mnemonics for the type or purpose of that variable, followed by whatever name the programmer has chosen; this last part is sometimes distinguished as the given name.

The original Hungarian notation, which would now be called Apps Hungarian, was invented by Charles Simonyi, a programmer who worked at Xerox PARC circa 1972–1981, and who later became Chief Architect at Microsoft. It may have been derived from the earlier principle of using the first letter of a variable name to set its type — for example, variables whose names started with letters I through N in FORTRAN are integers by default. (Source: Wikipedia.org)

In my programming, without following the “official” Hungarian Notation to the last detail, I use descriptive variable names to improve the code’s readability and they are preceded by one or two lower-case letters indicating the type of the variable.

For instance, I use n for integer and s for string. Just to list a few examples:

bool bCANDataReceived;
byte cSerialData;
int nJ1939Status;
char sJ1939Application[20];

I will refrain from providing an “official” list of my naming convention, because it does not exist. However, when you look at the programs I provide, you will get the idea (without the need of adapting the style for your applications). My mere intention is providing educational-style information based on great readability.


A Comprehensible Guide to J1939

SAE J1939 has become the accepted industry standard and the vehicle network technology of choice for off-highway machines in applications such as construction, material handling, and forestry machines. J1939 is a higher-layer protocol based on Controller Area Network (CAN). It provides serial data communications between microprocessor systems (also called Electronic Control Units - ECU) in any kind of heavy duty vehicles. The messages exchanged between these units can be data such as vehicle road speed, torque control message from the transmission to the engine, oil temperature, and many more.

A Comprehensible Guide to J1939 is the first work on J1939 besides the SAE J1939 standards collection. It provides profound information on the J1939 message format and network management combined with a high level of readability.

Read more...