Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Makeing communication table (http://www.go4expert.com/forums/makeing-communication-table-t8959/)

boschow 21Feb2008 04:36

Makeing communication table

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:


typedef struct
  TNSA_DigitalInputs    DigitalInputs;
  TNSA_DigitalOutputs  DigitalOutputs;
  TNSA_AnalogInputs    AnalogInputs;
  TNSA_AnalogOutputs  AnalogOutputs;

typedef struct
  TNSA_MainModule    MainModule;       
  TNSA_Module01      Module01;
  TNSA_Module02      Module02;
  TNSA_Module03      Module03;

Each of this "sub" structures has registers and bits as show in the example for digital inputs:

typedef union
    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
  unsigned int all; // i put here 16 bits beacuse maybe i will need to add addicional bits ...
typedef struct
TNSA_DigitalInputs_BBN bb_var;
unsigned int t_od; //timer on delay
unsigned long t_al;  //alarm timer

My idea of communication table for bits is :

#define NUMBER_OF_COILS 1600

typedef struct _PDU_COIL_MAP
    unsigned char *base_addr;
    unsigned char byte_index;
    unsigned char bit_index;

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}

My idea of communication table for registers is :

#define NUMBER_OF_REG 2000

typedef struct _PDU_REG_MAP
    unsigned int *reg;

TNNvar registers;

PDU_REG_MAP server_reg_map[NUMBER_OF_REG]={

The function for data transher has a prototype like this:

signed int CSS_SocketSent(int socket, const unsigned char  *data, unsigned int length);
My problem is thati dont know how to make the pointer for data transfering, and if my idea of communication tables is the correct one. Can somebody help me with this.

Best regards,

All times are GMT +5.5. The time now is 05:47.