; ***************************************************************************
; copyright   : (C) 2023 by Martin Preuss
; email       : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome".                              *
; * Please see toplevel file COPYING of that project for license details.   *
; ***************************************************************************






; ***************************************************************************
; defines


; ---------------------------------------------------------------------------
; message codes

.equ CPRO_CMD_PING                   = 10
.equ CPRO_CMD_PONG                   = 11
.equ CPRO_CMD_COMSENDSTATS           = 20
.equ CPRO_CMD_COMRECVSTATS           = 21
.equ CPRO_CMD_TWIBUSMEMBER           = 30
.equ CPRO_CMD_DEBUG                  = 40

.equ CPRO_CMD_RESULT                 = 50

.equ CPRO_CMD_NEED_ADDRESS           = 60
.equ CPRO_CMD_HAVE_ADDRESS           = 61
.equ CPRO_CMD_CLAIM_ADDRESS          = 62
.equ CPRO_CMD_DENY_ADDRESS           = 63
.equ CPRO_CMD_ADDRESS_RANGE          = 64

.equ CPRO_CMD_FLASH_START            = 70
.equ CPRO_CMD_FLASH_END              = 71
.equ CPRO_CMD_FLASH_READY            = 72
.equ CPRO_CMD_FLASH_DATA             = 73
.equ CPRO_CMD_FLASH_RSP              = 74

.equ CPRO_CMD_DEVICE                 = 80
.equ CPRO_CMD_MEMSTATS               = 81
.equ CPRO_CMD_SYSSTATS               = 82

.equ CPRO_CMD_REBOOT_REQUEST         = 90
.equ CPRO_CMD_REBOOT_RESPONSE        = 91

.equ CPRO_CMD_VALUE_REPORT           = 100
.equ CPRO_CMD_VALUE_SET              = 101
.equ CPRO_CMD_VALUE_SET_ACK          = 102
.equ CPRO_CMD_VALUE_SET_NACK         = 103

.equ CPRO_CMD_DATA                   = 110


; ---------------------------------------------------------------------------
; offsets in CPRO_CMD_VALUE_* messages

.equ CPRO_PACKET_VALUE_OFFS_UID     = 4
.equ CPRO_PACKET_VALUE_OFFS_MSGID   = 8
.equ CPRO_PACKET_VALUE_OFFS_VALUEID = 10
.equ CPRO_PACKET_VALUE_OFFS_VALUE   = 12
.equ CPRO_PACKET_VALUE_OFFS_DENOM   = 14


; ---------------------------------------------------------------------------
; offsets in CPRO_*_ADDRESS messages

.equ CPRO_PACKET_HAVEADDR_OFFS_ADDRESS  = COM2_MSG_OFFS_PAYLOAD+4
.equ CPRO_PACKET_CLAIMADDR_OFFS_ADDRESS = COM2_MSG_OFFS_PAYLOAD+4
.equ CPRO_PACKET_DENYADDR_OFFS_ADDRESS  = COM2_MSG_OFFS_PAYLOAD+4
.equ CPRO_PACKET_REBOOTREQ_OFFS_UID     = COM2_MSG_OFFS_PAYLOAD+0


; ---------------------------------------------------------------------------
; wait times for address protocol

.equ CPRO_WAITTIME_INITIAL       = 100
.equ CPRO_WAITTIME_GETADDR       = 1300
.equ CPRO_WAITTIME_CLAIMADDR     = 170
.equ CPRO_WAITTIME_RECLAIMADDR   = 100


; ---------------------------------------------------------------------------
; modes of operation

.equ CPRO_MODE_NOADDRESS            = 0x00 ; no address, yet
.equ CPRO_MODE_NORMAL               = 0x01 ; normal operation
.equ CPRO_MODE_SEND_NEED_ADDR       = 0x02 ; wait to send need address
.equ CPRO_MODE_GETADDRSTARTED       = 0x03 ; waiting for HAVE_ADDRESS and ADDRESS_RANGE packets to arrive
.equ CPRO_MODE_SEND_CLAIM_ADDR1     = 0x04 ; send CLAIM_ADDRESS as part of reclaiming procedure
.equ CPRO_MODE_CLAIMING_ADDR1       = 0x05 ; CLAIM_ADDRESS sent, waiting for HAVE_ADDRESS packet to reject the claim
.equ CPRO_MODE_CLAIMING_ADDR2       = 0x06 ; CLAIM_ADDRESS sent, 2nd try
.equ CPRO_MODE_CLAIMING_ADDR3       = 0x07 ; CLAIM_ADDRESS sent, 3rd try
.equ CPRO_MODE_SENDING_HAVE_ADDR    = 0x08 ; waiting for our turn to send HAVE_ADDRESS packet
.equ CPRO_MODE_SEND_RECLAIM_ADDR    = 0x09 ; send CLAIM_ADDRESS as part of reclaiming procedure
.equ CPRO_MODE_RECLAIMING_ADDR      = 0x0a ; CLAIM_ADDRESS with the previously used address sent after bootup
.equ CPRO_MODE_SEND_DENY_ADDR       = 0x0b ; someone claimed our address, send a DENY_ADDR message
.equ CPRO_MODE_NEXT_FREE            = 0x0c ; next free mode




