siwicom/C/pcprotocol.h

146 lines
5.5 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef PC_PROTOCOL_H
#define PC_PROTOCOL_H
/*================================================================================================
pcProtocol.h SiWiCom copyright 2006 v1.0 (2006-06-22)
Name: Christoffer Martinsson E-mail: cm@cmtec.se
Name: Joakim Nilsson E-mail: mail@jopin.se
Description: Routines for pcProtocol. Uses usart.h as tranceiver
BytePos: 0 1 2 6 7
----------- --------- ------ ------ ----------
Name: | startbyte | command | data | ... | data | checksum |
----------- --------- ------ ------ ----------
---------------------------------------------------------------------------------------------
Name: nrOfBytes: Value: PC: SiWiCom:
---------------------------------------------------------------------------------------------
Start byte 1 0x0A R/W R/W
Command 1 0x11 GET_LOCAL_DATA W R
0x22 LOCAL_DATA R W
0x33 REMOTE_DATA R W
0x44 LOCAL_UPDATE W R
0x55 REMOTE_UPDATE W R
0xFE ACK R/W R/W
Data 5 Value for the specified command above. R/W R/W
GET_LOCAL_DATA Byte0 0x55
Byte1 0x55
Byte2 0x55
Byte3 0x55
Byte4 0x55
LOCAL_DATA: Byte0 Device address
Byte1 Temp value
Byte2 Battery value
Byte3 AUX vaule
Byte4 0x00 (not used)
REMOTE_DATA: Byte0 Device address
Byte1 Temp value
Byte2 Battery value
Byte3 AUX vaule
Byte4 RSSI value
LOCAL_UPDATE: Byte0 New master address (0x00 = no change)
Byte1 New device address (0x00 = no change)
Byte2 New wakeup time (0x00 = no change)
Byte3 ProgramMode
0x00 = no change
0x01 = IDLE
0x02 = MASTER
0x03 = SLAVE
0x04 = NOICEMAKER
Byte4 0x55 (not used)
REMOTE_UPDATE: Byte0 Device address
Byte1 New master address (0x00 = no change)
Byte2 New device address (0x00 = no change)
Byte3 New wakeup time (0x00 = no change)
Byte4 0x55 (not used)
ACK: Byte0 0x55
Byte1 0x55
Byte2 0x55
Byte3 0x55
Byte4 0x55
Checksum 1 Sum of the previous byte in the packet. R/W R/W
================================================================================================*/
#define PC_START_BYTE 0x0A
#define PC_COMMAND_GET_LOCAL_DATA 0x11
#define PC_COMMAND_LOCAL_DATA 0x22
#define PC_COMMAND_REMOTE_DATA 0x33
#define PC_COMMAND_LOCAL_UPDATE 0x44
#define PC_COMMAND_REMOTE_UPDATE 0x55
#define PC_COMMAND_ACK 0xFE
#define PC_PADDING 0x55
/*================================================================================================
Functions
================================================================================================*/
/*================================================================================================
pcProtocolSendData
Description: Writes a data packet to the usart (command = DATA).
Input: dataType (LOCAL_DATA or REMOTE_DATA)
deviceAddr (address for the slave device),
tempValue (value of the temperature sensor),
batteryValue (value of the battery level),
rssiValue (value of the RSSI value)
Return: -
------------------------------------------------------------------------------------------------*/
void pcProtocolSendData(uint8_t dataType, uint8_t deviceAddr, uint8_t tempValue,
uint8_t batteryValue, uint8_t auxValue, uint8_t rssiValue);
/*================================================================================================
pcProtocolSendACK
Description: Write a data packet to the usart (command = ACK).
Input: -
Return: -
------------------------------------------------------------------------------------------------*/
void pcProtocolSendACK(void);
/*================================================================================================
pcProtocolAddByteToBuffer
Description: Add one byte to the input buffer and validate packet when buffer is full.
Input: data (uint8_t data byte to be added)
Return: 1 if packet received complete, 0 if not.
------------------------------------------------------------------------------------------------*/
uint8_t pcProtocolAddByteToBuffer(uint8_t data);
/*================================================================================================
pcProtocolGetData
Description: Return validated incoming data.
Input: *dataBuffer (pointer to buffer storing the data)
Return: -
------------------------------------------------------------------------------------------------*/
void pcProtocolGetData(uint8_t *dataBuffer);
/*================================================================================================
pcProtocolClearBuffer
Description: Clear the incoming buffer counter
Input: -
Return: -
------------------------------------------------------------------------------------------------*/
void pcProtocolClearBuffer(void);
/*================================================================================================
End
================================================================================================*/
#endif // PC_PROTOCOL_H