PDA

View Full Version : UIRT2 Protocol for Jon Rhees v.1.6 firmware



jon_rhees
October 13th, 2002, 04:55 PM
For those of you who where interested in the UIRT2 protocol enhancements, here they are (sorry for the poor formatting, but I haven't a place to post the .doc at the moment):

UIRT2 Command Protocol

By Jon Rhees

Copyright © 2002

All Rights Reserved


Abstract

The UIRT2 discussed herein represents a derivative of the original UIRT design created by Ruud V Gessel (see http://people.a2000.nl/rwvgesse/FixFrame.htm?Uirt.htm)

Significant modification and improvements in functionality have been added to the original design and corresponding firmware to allow for the following:

- Operation on 4MHz and 10MHz PIC Microcontrollers
- Ability to capture and re-transmit multi-pattern IR codes
- Ability to capture and re-transmit longer IR code-strings
- Ability to control GPIO pins from host or IR events
- Ability for GPIO pins to generate events
- Ability to operate stand-alone without host control
- Improvements in IR sensing algorithms
- Etc.

The following represents the UIR command protocol to date for control of the UIRT2 firmware developed by Jon Rhees.

Current firmware revision detailed: 1.6


Protocol Detail
Initialization:
After reset of the PIC Microcontroller, the UIRT2 will be ready for normal operation and IR reception. The UIRT2 interface will configure itself as follows:
Baud Rate: 115,200
Data Bits: 8
Parity: None
Stop Bits: 1
Any IR data received by the UIRT2 will be sent to the host in UIR format mode by default.
IR Reception:
IR Data received by the UIRT2 firmware will be interpreted and sent to the host. Data can be collected in three formats: 1) UIR, 2) STRUCTURED, and 3) RAW. These data formats are as follows:
UIR:
This format is compatible with UIR receivers. It consists of a six-byte data packet intended to uniquely represent the received IR code. It is not intended to carry sufficient data to recreate the IR transmission. When in UIR reception mode, each IR reception will be transformed into a 6-byte data string and sent to the host as a stream of six consecutive bytes. No additional data will be sent (terminators, etc.). However, due to the speed of IR transmissions, a space of multiple milliseconds (at least) will separate each 6-byte transmission to the host.

STRUCTURED:
This format is similar to Ruud’s original UIRT design. It is included for compatibility only and to my knowledge has never been practically used and is therefore untested. It is recommended that host interfaces utilize RAW mode for learning IR commands and UIR mode for normal event reception. This allows the host to use a more sophisticated algorithm to translate RAW IR data to a REMSTRUCT structure suitable for re-transmission.
All timing is expressed in 50uS per unit.
typedef struct { BYTE bCmd,bBits,bHdr1,bHdr0;
BYTE bOff0,bOff1,bOn0,bOn1;
BYTE bDatBits [16];
BYTE bCheck;
} REMSTRUCT;
Where :
bBits = Number of data bits in the package (excluding the first 2)
bHdr1 = width of first pulse
bHdr0 = width of first pause
bOff0 = width corresponding with a data bit of 0 for a pause
bOff1 = width corresponding with a data bit of 1 for a pause
bOn0 = width corresponding with a data bit of 0 for a pulse
bOn1 = width corresponding with a data bit of 1 for a pulse
bDatBits = 16 bytes which hold the actual data, lsb in bit 0
If the UIRT2 is in structured mode it will send a package as described above to the PC if IR data is received. The bCmd will contain 0.

RAW:
This format is intended for allowing a host computer connected to the UIRT2 to ‘learn’ IR code-strings. When in RAW mode, very little filtering is performed on received IR signals. Instead, the on/off timing information is sent to the host for processing. RAW format is a variable-length format, and can generate data streams of unlimited (theoretically) length to the host. RAW format follows the following format:
Byte 0 Interspace Hi-Byte High byte of time (in 50uS increments) since final pulse of last RAW IR reception
Byte 1 Interspace Lo-Byte High byte of time (in 50uS increments) since final pulse of last RAW IR reception
Byte 2 Pulse Width (1) Width in 50uS units of IR ‘on’ time
Byte 3 Space Width (1) Width in 50uS units of IR ‘off’ time
Byte 4 Pulse Width (2)
Byte 5 Space Width (2)
… … …
Byte n-1 Pulse Width (last) Width of final pulse
Byte n 0xFF Terminator
Each IR reception will stream data to the host in the above format until approximately 10mS of time elapses with no received IR energy, at which point a terminator byte (0xFF) will be transmitted.
GPIO Events:
The UIRT2 is capable of monitoring GPIO pins configured as inputs and generating UIR style pseudo-events when these pins change state. Currently the UIRT2 has PortB.0 defined as an input. When a pin changes state, a six-byte UIR ‘code’ will be created and sent to the host. This code is intended to utilize the same parsing algorithms on the host as the UIR interpreter, so 6 bytes will be transmitted. For GPIO events, bytes 2 through 5 will be 0xFF. Byte 1 (first byte sent) will be of the format:
bit 7 = Polarity:
0 --> Pin sensed a H->L transition
1 --> Pin sensed a L->H transition
bits 6..5 = reserved
bits 4..0 = Pin #:
0..7 --> Port A pins 0..7
8..15 --> Port B pins 0..7
16..23 --> Port C pins 0..7
24..31 --> Port D pins 0..7

IR Transmission:
IR Data may be sent from the host to the UIRT2 for transmission. Data can be defined in two formats: 1) STRUCTURED, and 2) RAW. These data formats are as follows:
STRUCTURED:
This format is a modification of Ruud’s original UIRT REMSTRUCT format. It consists of either 27 bytes or 49 bytes of structured data defining the IR pulse stream.
All timing is expressed in 50uS per unit.
Typedef struct { BYTE bCmd;
BYTE bISDlyHi,bISDlyLo;
BYTE bBits,bHdr1,bHdr0;
BYTE bOff0,bOff1,bOn0,bOn1;
BYTE bDatBits [16];
BYTE bCheck;
} REMSTRUCT1;
-or-
Typedef struct { BYTE bCmd;
BYTE bISDlyHi,bISDlyLo;
BYTE bBits,bHdr1,bHdr0;
BYTE bOff0,bOff1,bOn0,bOn1;
BYTE bDatBits[16];
BYTE bCmd2;
BYTE bISDlyHi2,bISDlyLo2;
BYTE bBits2,bHdr21,bHdr20;
BYTE bOff20,bOff21,bOn20,bOn21;
BYTE bDatBits2[12];
BYTE bCheck;
} REMSTRUCT2;
Where :
bCmd/bCmd2 = the command byte, bit 5 of this byte must be 0
bit 6,7 = 00 --> 40KHz mode
01 --> 38KHz mode
10 --> 38KHz mode
11 --> 36KHz mode
bit 0-4 repeat counter (number of times the package is transmitted). This value must be zero (0) for multi-code transmissions using REMSTRUCT2. In the case of multi-code transmissions, the pulse stream defined by bCmd, bISDlyHi/Lo, bBits, bHdr1, bHdr0, bOff0, bOff1, bOn0, bOn1, and bDatBits will be sent exactly once, followed by the pulse stream defined by bCmd2, bISDlyHi2/Lo2, bBits2, bHdr21, bHdr20, bOff20, bOff21, bOn20, bOn21, and bDatBits2 repeated the number of times specified in bCmd2.
bISDlyHi/bISDlyHi2, bISDlyLo/bISDlyLo2 = inter-transmission delay in 50uS units.
bBits/bBits2 = Number of data bits in the package (excluding the first 2)
bHdr1/bHdr21 = width of first pulse
bHdr0/bHdr20 = width of first pause
bOff0/bOff20 = width corresponding with a data bit of 0 for a pause
bOff1/bOff21 = width corresponding with a data bit of 1 for a pause
bOn0/bOn20 = width corresponding with a data bit of 0 for a pulse
bOn1/bOn21 = width corresponding with a data bit of 1 for a pulse
bDatBits/bDatBits2 = 16/12 bytes which hold the actual data, lsb in bit 0

RAW:
This format is allows maximum flexibility for IR transmission but is limited as to the length of IR pulse streams. With this format, up to 23 unique pulse/space combinations can be defined and transmitted/repeated. RAW mode transmissions follow the format:
Byte 0 Interspace Hi-Byte High byte of time (in 50uS increments) since final pulse of last RAW IR reception
Byte 1 Interspace Lo-Byte High byte of time (in 50uS increments) since final pulse of last RAW IR reception
Byte 2 Pulse Width (1) Width in 50uS units of IR ‘on’ time
Byte 3 Space Width (1) Width in 50uS units of IR ‘off’ time
Byte 4 Pulse Width (2)
Byte 5 Space Width (2)
… … …
Byte n-1 Pulse Width (last) Width of final pulse
Byte n(n<=50) Freq/RptCnt Frequency/Repeat Count = bit 6,7 = 00 --> 40KHz mode 01 --> 38KHz mode 10 --> 38KHz mode 11 --> 36KHz mode bit 0-4 repeat counter (number of times the package is transmitted).
Note that RAW transmission requests MUST be encapsulated in the extended command structure defined below!
UIRT2 Commands:
The general command format of Ruud’s original design has been extended over time and bears some similarities to the original command structure:
SIMPLE COMMANDS:
Simple commands are simple 2-byte commands issued by sending the command code (e.g., 0x20) followed by the single-byte checksum, except in the case of TRANSMITSTRUC which consists of the a command code with bit 5 cleared followed by the rest of REMSTRUCT as defined above.
SETMODEUIR = 0x20 + checksum
Sets the mode of the transceiver to UIR code, meaning that on reception of IR data, a 6 bytes UIR compatible code will be sent to the PC as defined above. The UIRT2 replies with CMDOK or an error code.
SETMODERAW = 0x21 + checksum
Sets the mode of the transceiver to RAW code, meaning that on reception of IR data, every pulsewidth and pause width is sent to the PC as defined above. The UIRT2 replies with CMDOK or an error code.
SETMODESTRUC = 0x22 + checksum
Sets the mode of the transceiver to STRUCTURED code, meaning that on reception of IR data, a REMSTRUC structure is sent to the PC as defined above. The UIRT2 replies with CMDOK or an error code.
GETVERSION = 0x23 + checksum
On this command, the UIRT2 will send 2 bytes of version info followed by a checksum byte. For the enhanced UIRT2 defined here, the expected response is: 0x01 followed by 0x04 followed by checksum.
TRANSMITSTRUC = REMSTRUCT (see definition above)
Note that it is the responsibility of the host to hold off further requests or transmissions to the UIRT2 for the expected duration of the IR transmission.

EXTENDED COMMANDS:
Extended commands are variable-length commands issued by sending the command code (e.g., 0x31) followed by a length byte bLen followed by the variable-length command data followed by the single-byte checksum. As always, the checksum includes all data bytes. The length byte bLen = the number of data bytes in the command data + 1.
GETGPIOCAPS = 0x30 + 0x01 (length) + checksum
Retrieves the GPIO capabilities defined by the UIRT2. This may vary on different UIRT2 designs and therefore should be queried by the host if any GPIO features are used. The UIRT2 responds with 6 bytes as follows:
bNumSlots + bPAMask + bPBMask + bPCMask + bPDMask + checksum;
where bNumSlots indicates the number of programmable slots available in the UIRT2’s nonvolatile event memory, and bPxMask represents a bitmask of available outputs on a particular port.
GETGPIOCFG = 0x31 + 0x02 (length) + bSlot + checksum
Retrieves the GPIO event control data for a particular slot from NVRAM, where bSlot is 0..bNumSlots-1. The UIRT2 responds with 9 bytes as follows: bUIRCode[6] + bAction + bDuration + checksum. The six-byte bUIRCode represents the IR code to trigger the event and is in the same six-byte format as UIR codes described in IR Reception above. The bytes bAction and bDuration are defined as:
bAction:
bit 7,6 = Pin Action:
00 --> Pulse Pin
01 --> Set Pin
10 --> Clear Pin
11 --> Toggle Pin
bit 5 = reserved
bit 4,3 = Port:
00 --> Port A
01 --> Port B
10 --> Port C
11 --> Port D
bit 2,1,0 = Port Pin:
000 --> Pin 0

111 --> Pin 7
bDuration:
Duration of event in 5mS increments.

SETGPIOCFG = 0x32 + 0x0A (length) + bSlot + bUIRCode[6] + bAction + bDuration + checksum
Programs the GPIO event control data for a particular slot into NVRAM, where bSlot is 0..bNumSlots-1 and bUIRCode[6], bAction, and bDuration are as described in GETGPIOCFG above. The UIRT2 responds CMDOK (0x21) when programming is complete.

GETGPIO = 0x33 + 0x01 (length) + checksum
Retrieves the current state of all four GPIO ports on the PIC (varies by design). The UIRT2 responds with 5 bytes as follows: bPortA + bPortB + bPortC + bPortD + checksum.

SETGPIO = 0x34 + 0x03 (length) + bAction + bDuration + checksum
Manually triggers a GPIO event with bAction and bDuration defined as in GETGPIOCFG above. The UIRT2 responds with TRANSMITTING (0x20). Note it is the responsibility of the host to hold off further transmissions to the UIRT2 for the expected duration of the event.

REFRESHGPIO = 0x35 + 0x01 (length) + checksum
Forces the UIRT2’s internal trigger on GPIO’s which are configured as event inputs (currently only PB.0). This will cause the UIRT2 to immediately generate a GPIO event to the host (see GPIO Events above).

DOTXRAW = 0x36 + bLength + RAWSTRUCT + checksum
Initiates an IR transmission of raw data based on RAWSTRUCT (defined in IR Transmission (RAW) above. Command length bLength = 1 + length of RAWSTRUCT, in bytes. Note that it is the responsibility of the host to hold off further requests or transmissions to the UIRT2 for the expected duration of the IR transmission ([IR transmit time + InterCode Delay] * repeatCount).

Generic Response codes:
TRANSMITTING = 0x20
CMDOK=0x21
CSERROR = 0x80 (checksum error)
TOERROR= 0x81 (Time out error)
CMDERROR=0x82 (Command error undefined command)
All checksums in this description are 1 byte which make the sum of the sent or received package 0.... eg a command 0x22 would need a checksum of 0xde since 0xde+0x22 adds up to 0x00 (byte of course).