/**********************************************************************
Project:    Automatic cat feeder
Date:       march 19 2006
Author:     Jean-François Martel
Target:     PIC 18F252
Compiler:   Microchip mcc18
Filename:	Protocol.h

File description:	Communication protocol implementation.


jean-francois.martel@polymtl.ca
**********************************************************************/

#ifndef PROTOCOLDEFS_H
#define PROTOCOLDEFS_H

//Protocol buffer specific definitionsazsdf

#define MAX_MESSAGE_SIZE 0xFFFF

#define FRAME_HEADER 0x8A
#define DATA_START 11
#define ACK	0xA3
#define NAK 0x90
#define BROADCAST_VALUE 0xFF

enum eFrameIndex
{
    FRAME_HEADER_INDEX = 0,
    FRAME_SENDER_ADDRESS_INDEX,
    FRAME_SENDER_DEVICE_ID_INDEX,
    FRAME_DEST_DEVICE_ID_INDEX,
    FRAME_DEST_ADDRESS_INDEX,
    FRAME_FLAGS_INDEX,
    FRAME_COMMAND_INDEX,
    FRAME_SIZE1_INDEX,
    FRAME_SIZE2_INDEX,
    FRAME_SIZE3_INDEX,
    FRAME_SIZE4_INDEX,
    FRAME_DATA_INDEX,

    FRAME_INDEX_NBR
};

enum DEVICES_IDS
{
    ID_MASTER,		//Master Controller
    ID_CONSOLE,		//LCD Console
    ID_PC,			//PC
    ID_AV_MUX,		//Audio Video Multiplexer
    ID_IR_REMOTE,	//Infra red transmitter
    ID_DEADBOLT_DEVICE,
    ID_AV_RECEIVER,
    ID_SMS_CLIENT,
    ID_ETHERNET_VIRTUAL,
    ID_SPRINKLER_DEVICE,
    ID_SPRINKLER_INTERFACE,
    ID_DEADBOLT_INTERFACE,
    ID_AVRECEIVER_INTERFACE,
    ID_CHALET_INTERFACE,
    ID_CHALET_DEVICE,
    ID_ISPINDEL_INTERFACE,
    ID_LORA_INTERFACE_DEVICE,
    ID_LORA_INTERFACE_INTERFACE,
    ID_AVRECEIVER_CONSOLE_INTERFACE,
    ID_AVRECEIVER_CONSOLE_DEVICE,
    ID_NB_DEVICE_ID

};

// Commands definitions

enum MASTER_CMD
{
    RX_MASTER_GET_STATUS,
    TX_MASTER_STATUS,
    TX_MASTER_ACK,
    RX_MASTER_SET_NET_INFO,
    RX_MASTER_GET_NET_INFO,
    TX_MASTER_NET_INFO,
    RX_MASTER_SEND_DEVICE_CMD,
    TX_MASTER_SEND_DEVICE_CMD_ACK,
    RX_MASTER_SET_WEATHER_INFO,
    TX_MASTER_SET_WEATHER_INFO_ACK,
    RX_MASTER_SET_MAIL_MSG,
    TX_MASTER_SET_MAIL_MSG_ACK,
    RX_MASTER_NEW_OUTLOOK_EMAILS,
    TX_MASTER_NEW_OUTLOOK_EMAILS_ACK,
    RX_MASTER_TODAYS_EVENTS,
    TX_MASTER_TODAYS_EVENTS_ACK
};


//CONSOLE
enum CONSOLE_CMD
{
    RX_CONSOLE_GET_STATUS,
    TX_CONSOLE_STATUS,
    TX_CONSOLE_ACK,
    RX_START_CALIBRATION,
    RX_GET_CONSOLE_EVENT_MSG,
    TX_CONSOLE_EVENT_MSG,
    RX_CONSOLE_SHOW_CALLER_ID,
    RX_SET_TIME,
    RX_SET_WEATHER,
    RX_SEND_NEW_MAIL_MSG,
    RX_SEND_NEW_MAIL_MSG_ACK,
    RX_NEW_OUTLOOK_EMAILS,
    TX_NEW_OUTLOOK_EMAILS_ACK,
    RX_TODAYS_EVENTS,
    TX_TODAYS_EVENTS_ACK,
    LAST_CONSOLE_CMD
};



enum IR_REMOTE_CMDS
{
    TX_IR_REMOTE_ACK = 1,
    RX_GET_STATUS,
    TX_REMOTE_STATUS,
    RX_TRANSMIT_CMD,
    RX_LEARN_IR_CMD,
    TX_LEARN_IR_CMD_FINISHED,
    RX_GET_IR_DATA,
    TX_SEND_IR_DATA,
    RX_SET_IR_CMD,
    RX_SET_IR_DATA,
    RX_GET_IR_CMD,
    TX_SEND_IR_CMD,
    MAX_IR_REMOTE_CMD
};

//The SMS remote interface commands
enum SMS_CLIENT_CMDS
{
    SMS_CLIENT_DEVICE_ACK = 1,
    SMS_CLIENT_DEVICE_STATUS_REQUEST,
    SMS_CLIENT_DEVICE_STATUS_RESPONSE,
    SMS_CLIENT_DEVICE_DID_INFO_REQUEST,
    SMS_CLIENT_DEVICE_DID_INFO_RESPONSE,
    SMS_CLIENT_DEVICE_GET_ALL_MSG_REQUEST,
    SMS_CLIENT_DEVICE_GET_ALL_MSG_RESPONSE,
    SMS_CLIENT_DEVICE_NEW_MSG_NOTIFICATION,
    SMS_CLIENT_DEVICE_SEND_SMS_REQUEST,
    SMS_CLIENT_DEVICE_SEND_SMS_ACK,
    SMS_CLIENT_DEVICE_GET_CONTACTS_REQUEST,
    SMS_CLIENT_DEVICE_GET_CONTACTS_RESPONSE,//12
    SMS_CLIENT_DEVICE_CONTACTS_CHANGED_NOTIFICATION,

    SMS_CLIENT_DEVICE_MAX_MSG

};

//The actual deadbolt device commands
enum DEADBOLT_CMDS
{
    DEADBOLT_DEVICE_ACK = 1,
    DEADBOLT_DEVICE_STATUS_REQUEST,
    DEADBOLT_DEVICE_STATUS_RESPONSE,
    DEADBOLT_DEVICE_GET_LOCKED_STATE_REQUEST,
    DEADBOLT_DEVICE_LOCKED_STATE_RESPONSE,
    DEADBOLT_DEVICE_GOTO_LOCKED_REQUEST,
    DEADBOLT_DEVICE_GOTO_LOCKED_ACK,
    DEADBOLT_DEVICE_GOTO_UNLOCKED_REQUEST,
    DEADBOLT_DEVICE_GOTO_UNLOCKED_ACK,
    DEADBOLT_DEVICE_GET_PASSWORDS_REQUEST,
    DEADBOLT_DEVICE_GET_PASSWORDS_RESPONSE,
    DEADBOLT_DEVICE_SET_PASSWORDS_REQUEST,
    DEADBOLT_DEVICE_SET_PASSWORDS_ACK,
    DEADBOLT_DEVICE_LOCK_EVENT,

    MAX_DEADBOLT_DEVICE_CMD
};

//The actual sprinkler module device commands
enum SPRINKLER_DEVICE_CMDS
{
    SPRINKLER_DEVICE_ACK = 1,
    SPRINKLER_DEVICE_STATUS_REQUEST,
    SPRINKLER_DEVICE_STATUS_RESPONSE,
    SPRINKLER_DEVICE_SET_SPRINKLER_STATE_REQUEST,
    SPRINKLER_DEVICE_SET_SPRINKLER_STATE_ACK,
    SPRINKLER_DEVICE_GET_SPRINKLER_STATE_REQUEST,
    SPRINKLER_DEVICE_GET_SPRINKLER_STATE_RESPONSE,
    SPRINKLER_DEVICE_GET_WATER_FLOW_REQUEST,
    SPRINKLER_DEVICE_GET_WATER_FLOW_RESPONSE,
    SPRINKLER_DEVICE_GET_MOISTURE_REQUEST,
    SPRINKLER_DEVICE_GET_MOISTURE_RESPONSE,
    SPRINKLER_DEVICE_SET_PROGRAM_REQUEST,
    SPRINKLER_DEVICE_SET_PROGRAM_ACK,
    SPRINKLER_DEVICE_GET_PROGRAM_REQUEST,
    SPRINKLER_DEVICE_GET_PROGRAM_RESPONSE,
    SPRINKLER_DEVICE_SET_PARAMETERS_REQUEST,
    SPRINKLER_DEVICE_SET_PARAMETERS_ACK,
    SPRINKLER_DEVICE_GET_PARAMETERS_REQUEST,
    SPRINKLER_DEVICE_GET_PARAMETERS_RESPONSE,


    MAX_SPRINKLER_DEVICE_CMD
};

//The sprinkler interface commands
enum SPRINKLER_INTERFACE_CMDS
{
    SPRINKLER_INTERFACE_ACK = 1,
    SPRINKLER_INTERFACE_STATUS_REQUEST,
    SPRINKLER_INTERFACE_STATUS_RESPONSE,
    SPRINKLER_INTERFACE_GET_SPRINKLERS_REQUEST,
    SPRINKLER_INTERFACE_GET_SPRINKLERS_RESPONSE,
    SPRINKLER_INTERFACE_GET_SPRINKLER_DATA_REQUEST,
    SPRINKLER_INTERFACE_GET_SPRINKLER_DATA_RESPONSE,
    SPRINKLER_INTERFACE_SET_SPRINKLER_DATA_REQUEST,
    SPRINKLER_INTERFACE_SET_SPRINKLER_DATA_ACK,
    SPRINKLER_INTERFACE_GET_SPRINKLER_STATE_REQUEST,
    SPRINKLER_INTERFACE_GET_SPRINKLER_STATE_RESPONSE,
    SPRINKLER_INTERFACE_SET_SPRINKLER_STATE_REQUEST,
    SPRINKLER_INTERFACE_SET_SPRINKLER_STATE_ACK,

    MAX_SPRINKLER_INTERFACE_CMD
};


enum ETHERNET_NETWORK_VIRTUAL_CMDS
{
    ETH_NETWK_DEVICE_INFO_REQUEST = 0xD0,
    ETH_NETWK_DEVICE_INFO_RESPONSE,
    ETH_NETWK_SET_DEVICE_INFO_ACK,
    ETH_NETWK_CONNECTION_REFUSED,

    MAX_ETHERNET_NETWORK_VIRTUAL_CMDS

};

enum AV_RECEIVER_INTERFACE_CMDS
{
    AV_RECEIVER_INTERFACE_ACK = 1,
    AV_RECEIVER_INTERFACE_GENERAL_STATUS_REQUEST,
    AV_RECEIVER_INTERFACE_GENERAL_STATUS_RESPONSE,
    AV_RECEIVER_INTERFACE_SET_MAIN_POWER_REQUEST,
    AV_RECEIVER_INTERFACE_SET_MAIN_POWER_RESPONSE,
    AV_RECEIVER_INTERFACE_SET_ZONE2_REQUEST,
    AV_RECEIVER_INTERFACE_SET_ZONE2_RESPONSE,
    AV_RECEIVER_INTERFACE_SET_MAIN_ZONE_REQUEST,
    AV_RECEIVER_INTERFACE_SET_MAIN_ZONE_RESPONSE,
    AV_RECEIVER_INTERFACE_SET_SPEAKERS_REQUEST,
    AV_RECEIVER_INTERFACE_SET_SPEAKERS_RESPONSE,
    AV_RECEIVER_INTERFACE_SEND_DIRECT_CMD_REQUEST,
    AV_RECEIVER_INTERFACE_SEND_DIRECT_CMD_RESPONSE,
    AV_RECEIVER_INTERFACE_SELECT_SCENE_REQUEST,
    AV_RECEIVER_INTERFACE_SELECT_SCENE_RESPONSE,
    AV_RECEIVER_INTERFACE_SET_MAIN_VOLUME_REQUEST,
    AV_RECEIVER_INTERFACE_SET_MAIN_VOLUME_RESPONSE,
    AV_RECEIVER_INTERFACE_SET_ZONE2_VOLUME_REQUEST,
    AV_RECEIVER_INTERFACE_SET_ZONE2_VOLUME_RESPONSE,
    AV_RECEIVER_INTERFACE_SET_ZONE2_INPUT_REQUEST,
    AV_RECEIVER_INTERFACE_SET_ZONE2_INPUT_RESPONSE,
    AV_RECEIVER_INTERFACE_SET_SYNC_Z2_WITH_Z1_REQUEST,
    AV_RECEIVER_INTERFACE_SET_SYNC_Z2_WITH_Z1_RESPONSE,
    AV_RECEIVER_INTERFACE_INCREMENT_MAIN_VOLUME_REQUEST,
    AV_RECEIVER_INTERFACE_INCREMENT_MAIN_VOLUME_RESPONSE,
    AV_RECEIVER_INTERFACE_INCREMENT_Z2_VOLUME_REQUEST,
    AV_RECEIVER_INTERFACE_INCREMENT_Z2_VOLUME_RESPONSE,


    MAX_AV_RECEIVER_INTERFACE_CMD
};

enum CHALET_INTERFACE_CMDS
{
    CHALET_INTERFACE_ACK = 1,
    CHALET_INTERFACE_GENERAL_STATUS_REQUEST,
    CHALET_INTERFACE_GENERAL_STATUS_RESPONSE,
    CHALET_INTERFACE_AC_POWER_STATE_STATUS_REQUEST,
    CHALET_INTERFACE_AC_POWER_STATE_STATUS_RESPONSE,
    CHALET_INTERFACE_AC_POWER_SET_STATE_REQUEST,
    CHALET_INTERFACE_AC_POWER_SET_STATE_RESPONSE,
    CHALET_INTERFACE_BATTERY_VOLTAGE_REQUEST,
    CHALET_INTERFACE_BATTERY_VOLTAGE_RESPONSE,
    CHALET_INTERFACE_WIFI_SET_STATE_REQUEST,
    CHALET_INTERFACE_WIFI_SET_STATE_RESPONSE,
    CHALET_INTERFACE_DO_HARAKIRI_REQUEST,
    CHALET_INTERFACE_DO_HARAKIRI_RESPONSE,
    CHALET_INTERFACE_REBOOT_CPU_REQUEST,
    CHALET_INTERFACE_REBOOT_CPU_RESPONSE,
    CHALET_INTERFACE_GET_TODAYS_DATA_LOG_REQUEST,
    CHALET_INTERFACE_GET_TODAYS_DATA_LOG_RESPONSE,
    CHALET_INTERFACE_CHALET_ACTIVITY_RESPONSE,
    CHALET_INTERFACE_GET_DATA_LOG_REQUEST,
    CHALET_INTERFACE_GET_DATA_LOG_RESPONSE,
    CHALET_INTERFACE_WIFI_GET_DEVICE_PARAMS_REQUEST,
    CHALET_INTERFACE_WIFI_GET_DEVICE_PARAMS_RESPONSE,
    CHALET_INTERFACE_WIFI_SET_DEVICE_PARAMS_REQUEST,
    CHALET_INTERFACE_WIFI_SET_DEVICE_PARAMS_RESPONSE,
    CHALET_INTERFACE_GET_FIRMWARE_VERSION_REQUEST,
    CHALET_INTERFACE_GET_FIRMWARE_VERSION_RESPONSE,
    CHALET_INTERFACE_CLEAR_COMMS_STATS_REQUEST,
    CHALET_INTERFACE_CLEAR_COMMS_STATS_RESPONSE,
    CHALET_INTERFACE_GET_WIFI_STATUS_REQUEST,
    CHALET_INTERFACE_GET_WIFI_STATUS_RESPONSE,



    MAX_CHALET_INTERFACE_CMD
};

enum CHALET_CMDS
{
    CHALET_ACK = 1,
    CHALET_GENERAL_STATUS_REQUEST,      //2
    CHALET_GENERAL_STATUS_RESPONSE,         //3
    CHALET_AC_POWER_STATE_STATUS_REQUEST,
    CHALET_AC_POWER_STATE_STATUS_RESPONSE,
    CHALET_AC_POWER_SET_STATE_REQUEST,
    CHALET_AC_POWER_SET_STATE_RESPONSE,
    CHALET_BATTERY_VOLTAGE_REQUEST,
    CHALET_BATTERY_VOLTAGE_RESPONSE,    //9
    CHALET_BATTERY_CURRENT_REQUEST,
    CHALET_BATTERY_CURRENT_RESPONSE,
    CHALET_WIFI_STATUS_REQUEST,
    CHALET_WIFI_STATUS_RESPONSE,        //D
    CHALET_WIFI_SET_STATE_REQUEST,
    CHALET_WIFI_SET_STATE_RESPONSE,     //F
    CHALET_DO_HARAKIRI_REQUEST,
    CHALET_DO_HARAKIRI_CONFIRMATION,
    CHALET_REBOOT_CPU_REQUEST,          //12
    CHALET_REBOOT_CPU_RESPONSE,
    CHALET_GET_STORED_WIFI_SETTINGS_REQUEST,    //14
    CHALET_GET_STORED_WIFI_SETTINGS_RESPONSE,
    CHALET_SET_STORED_WIFI_SETTINGS_REQUEST,    //
    CHALET_SET_STORED_WIFI_SETTINGS_RESPONSE,
    CHALET_GET_FIRMWARE_VERSION_REQUEST,
    CHALET_GET_FIRMWARE_VERSION_RESPONSE,
    CHALET_CLEAR_COMMS_STATISTICS_REQUEST,
    CHALET_CLEAR_COMMS_STATISTICS_RESPONSE,


    MAX_CHALET_CMD
};

enum BOOTLOADER_CMDS
{
    BOOTLOADER_ACK = 1,
    BOOTLOADER_HEARTBEAT_REQUEST,
    BOOTLOADER_HEARTBEAT_RESPONSE,
    BOOTLOADER_ERASE_BOOTLOADER_FLASH_REQUEST,
    BOOTLOADER_ERASE_BOOTLOADER_FLASH_RESPONSE,
    BOOTLOADER_ERASE_BOOTLOADER_FLASH_RESULT_RESPONSE,
    BOOTLOADER_INIT_UPLOAD_REQUEST,
    BOOTLOADER_INIT_UPLOAD_RESPONSE,
    BOOTLOADER_GET_STATE_REQUEST,
    BOOTLOADER_GET_STATE_RESPONSE,
    BOOTLOADER_READY_FOR_DATA_RESPONSE,
    BOOTLOADER_SEND_DATA_CHUNK_REQUEST,
    BOOTLOADER_SEND_DATA_CHUNK_RESPONSE,
    BOOTLOADER_UPLOAD_FINISHED_REQUEST,
    BOOTLOADER_UPLOAD_FINISHED_RESPONSE,
    BOOTLOADER_EXECUTE_UPGRAGE_REQUEST,
    BOOTLOADER_EXECUTE_UPGRADE_RESPONSE,
    BOOTLOADER_ABORT_OPERATION_REQUEST,
    BOOTLOADER_ABORT_OPERATION_RESPONSE,
    BOOTLOADER_SEND_FLASH_DATA_REQUEST,
    BOOTLOADER_SEND_FLASH_DATA_RESPONSE,
    BOOTLOADER_SEND_FLASH_DATA_CHUNK,
    BOOTLOADER_SEND_FLASH_DATA_CHUNK_RESPONSE,
    BOOTLOADER_CHECK_FLASH_FIRMW_INTEGRITY_REQUEST,
    BOOTLOADER_CHECK_FLASH_FIRMW_INTEGRITY_RESPONSE,
    BOOTLOADER_GET_STORED_FIRMWARE_INFO_REQUEST,
    BOOTLOADER_GET_STORED_FIRMWARE_INFO_RESPONSE,


    MAX_BOOTLOADER_CMD
};

enum ISPINDLE_CMDS
{
    ISPINDLE_ACK = 1,
    ISPINDLE_LATEST_DATA_REQUEST,
    ISPINDLE_LATEST_DATA_RESPONSE,
    ISPINDEL_GET_FULL_DATA_BUFFER_REQUEST,
    ISPINDEL_GET_FULL_DATA_BUFFER_RESPONSE,
    ISPINDEL_DELETE_SAMPLE_REQUEST,
    ISPINDEL_DELETE_SAMPLE_RESPONSE,

    MAX_ISPINDLE_CMDS
};

enum LORA_INTERFACE_CMDS
{
    LORA_IF_ACK = 1,
    LORA_IF_GET_STATUS_REQUEST,
    LORA_IF_GET_STATUS_RESPONSE,
    LORA_IF_SEND_FRAME_REQUEST,
    LORA_IF_SEND_FRAME_RESPONSE,
    LORA_IF_NEW_FRAME_RESPONSE,
    LORA_IF_GET_MODULE_CONFIG_REQUEST,
    LORA_IF_GET_MODULE_CONFIG_RESPONSE,
    LORA_IF_GET_RSSI_REQUEST,
    LORA_IF_GET_RSSI_RESPONSE,
    LORA_IF_SET_MODULE_CONFIG_REQUEST,
    LORA_IF_SET_MODULE_CONFIG_RESPONSE,
    
    MAX_LORA_IF_CMD
};

enum LORA_MODULE_IF_INTERFACE_CMDS
{
    LORA_MODULE_IF_INTERFACE_ACK = 1,
    LORA_MODULE_IF_INTERFACE_GENERAL_STATUS_REQUEST,
    LORA_MODULE_IF_INTERFACE_GENERAL_STATUS_RESPONSE,


    MAX_LORA_MODULE_IF_INTERFACE_CMD
};

#endif
