i am trying to make some sort of communication between two home made PLC's "micro controllers". Since my communication protocol will send the bits first and only then the registers i need two tables one for bits and the other for registers. In my code there is a single structure called TNNvvar. This structure can access to other structures like inputs, outputs , pid ... See example below:
Code:
typedef struct
{
TNSA_DigitalInputs DigitalInputs;
TNSA_DigitalOutputs DigitalOutputs;
TNSA_AnalogInputs AnalogInputs;
TNSA_AnalogOutputs AnalogOutputs;
}TNSA_MainModule;
typedef struct
{
TNSA_MainModule MainModule;
TNSA_Module01 Module01;
TNSA_Module02 Module02;
TNSA_Module03 Module03;
}TNNvar;
Code:
typedef union
{
struct
{
unsigned a_bs:1; //digital input status
unsigned s_ac:1; // digital input active simulation
unsigned s_enb:1; // digital input simulation enable
unsigned alm_enb:1; // digital input alarm enable
unsigned t_od_enb:1; // digital input enable timer on delay
}bit;
unsigned int all; // i put here 16 bits beacuse maybe i will need to add addicional bits ...
}TNSA_DigitalInputs_BBN;
typedef struct
{
TNSA_DigitalInputs_BBN bb_var;
unsigned int t_od; //timer on delay
unsigned long t_al; //alarm timer
}TNSA_DigitalInputs;
Code:
#define NUMBER_OF_COILS 1600
typedef struct _PDU_COIL_MAP
{
unsigned char *base_addr;
unsigned char byte_index;
unsigned char bit_index;
}PDU_COIL_MAP;
TNNvar coils;
PDU_COIL_MAP server_coil_map[NUMBER_OF_COILS]={
{&coils.MainModule.DigitalInput.bb_var.bit, 0, 0},
{&coils.MainModule.DigitalInput.bb_var.bit, 0, 1},
{&coils.MainModule.DigitalInput.bb_var.bit, 0, 2},
{&coils.MainModule.DigitalInput.bb_var.bit, 0, 3},
{&coils.MainModule.DigitalInput.bb_var.bit, 0, 4},
{&coils.MainModule.DigitalInput.bb_var.bit, 0, 5}
};
Code:
#define NUMBER_OF_REG 2000
typedef struct _PDU_REG_MAP
{
unsigned int *reg;
}PDU_REG_MAP;
TNNvar registers;
PDU_REG_MAP server_reg_map[NUMBER_OF_REG]={
{®isters.MainModule.DigitalInput.t_od},
{®isters.MainModule.DigitalInput.t_al}
};
Code:
signed int CSS_SocketSent(int socket, const unsigned char *data, unsigned int length);
Best regards,
BoSCHoW.
