/*
 * commonMsg.h
 *
 *  Created on: 2020/01/15
 *      Author: x.walter
 */

#ifndef COMMONMSG_H_
#define COMMONMSG_H_

#include "time.h"

typedef enum {
  DUMMY,
  BLE_COMM,
  CAN_COMM,
  OUTPUTS,
  AUTOMATION,
  LORA_COMM,
  ADC_MEAS
} MODULE_ID;

typedef enum {
  V_LIGHT, V_SETTINGS
} MsgType;

typedef enum {
  Z_ALL_OFF, Z_RESTART, Z_UPDATE, Z_START, Z_STOP, E_STOP, UPDATE_SETTINGS
} ActuatorStates;

typedef enum {
  OP_MAIN=0x0100, OP_RTC, OP_FEATURE, OP_OUTPUT_ONCHANGE, CAN_ECHO, CAN_NOECHO, OP_CAN, OP_LORA_EVENT1
} CommandOpcode;

typedef enum {
  IDLE = 0x00, PERIODIC, APERIODIC, ESTOP
} states;

typedef struct {
  CommandOpcode opcode;
  union {
	  uint16_t errorNo;
	  struct {
		  union {
			/*struct {
				uint16_t actuatorsBitField;
				ActuatorStates changeState;
			};*/
			struct {
				uint16_t outputs; // bit 0 to 7 and bit 15: 24VAC devices, bit 8 to 12: 230VAC devices according to ActuatorStates
				ActuatorStates changeState;
				uint8_t pumpRate;
			};
			uint16_t lParam[6];
			uint32_t wParam[3];
			char data[21]; // Data to transmit
		  };
	  };
  };
} MSG_STRUCT;

typedef struct {
	time_t currentDayCycle[4];			// Day cycle for each program
} PARAM_SYS_STRUCT;

#ifdef __cplusplus
extern "C" {
#endif

osMessageQId getQueueId(MODULE_ID moduleId);
MSG_STRUCT *allocMemoryPoolMessage();
void freeMemoryPoolMessage(MSG_STRUCT *p_message);

#ifdef __cplusplus
}
#endif


#endif /* COMMONMSG_H_ */
