modbus/mb_runtime.c
changeset 2655 d2b2ee04bfa1
parent 2654 7575050a80c5
child 2665 978cf239c689
equal deleted inserted replaced
2654:7575050a80c5 2655:d2b2ee04bfa1
   511 		// mb_nd with negative numbers indicate how far it has been initialised (or not)
   511 		// mb_nd with negative numbers indicate how far it has been initialised (or not)
   512 		//   -2  --> no modbus node created;  no thread  created
   512 		//   -2  --> no modbus node created;  no thread  created
   513 		//   -1  -->    modbus node created!; no thread  created
   513 		//   -1  -->    modbus node created!; no thread  created
   514 		//  >=0  -->    modbus node created!;    thread  created!
   514 		//  >=0  -->    modbus node created!;    thread  created!
   515 		server_nodes[index].mb_nd = -2; 
   515 		server_nodes[index].mb_nd = -2; 
       
   516         /* see comment in mb_runtime.h to understad why we need to initialize these entries */
       
   517         switch (server_nodes[index].node_address.naf) {
       
   518             case naf_tcp:
       
   519                 server_nodes[index].node_address.addr.tcp.host    = server_nodes[index].str1;
       
   520                 server_nodes[index].node_address.addr.tcp.service = server_nodes[index].str2;
       
   521                 break;
       
   522             case naf_rtu:
       
   523                 server_nodes[index].node_address.addr.rtu.device  = server_nodes[index].str1;
       
   524                 break;
       
   525         }
   516 	}
   526 	}
   517 
   527 
   518 	/* modbus library init */
   528 	/* modbus library init */
   519 	/* Note that TOTAL_xxxNODE_COUNT are the nodes required by _ALL_ the instances of the modbus
   529 	/* Note that TOTAL_xxxNODE_COUNT are the nodes required by _ALL_ the instances of the modbus
   520 	 *  extension currently in the user's project. This file (MB_xx.c) is handling only one instance,
   530 	 *  extension currently in the user's project. This file (MB_xx.c) is handling only one instance,
   917 int                __modbus_get_ClientNode_stop_bits  (int nodeid)  {return client_nodes[nodeid].node_address.addr.rtu.stop_bits;}
   927 int                __modbus_get_ClientNode_stop_bits  (int nodeid)  {return client_nodes[nodeid].node_address.addr.rtu.stop_bits;}
   918 u64                __modbus_get_ClientNode_comm_period(int nodeid)  {return client_nodes[nodeid].comm_period;                    }
   928 u64                __modbus_get_ClientNode_comm_period(int nodeid)  {return client_nodes[nodeid].comm_period;                    }
   919 const char *       __modbus_get_ClientNode_addr_type  (int nodeid)  {return addr_type_str[client_nodes[nodeid].node_address.naf];}
   929 const char *       __modbus_get_ClientNode_addr_type  (int nodeid)  {return addr_type_str[client_nodes[nodeid].node_address.naf];}
   920                                                                                                                         
   930                                                                                                                         
   921 const char *       __modbus_get_ServerNode_config_name(int nodeid)  {return server_nodes[nodeid].config_name;                    }
   931 const char *       __modbus_get_ServerNode_config_name(int nodeid)  {return server_nodes[nodeid].config_name;                    }
   922 const char *       __modbus_get_ServerNode_host       (int nodeid)  {return server_nodes[nodeid].node_address.addr.tcp.host;     }
   932 const char *       __modbus_get_ServerNode_host       (int nodeid)  {return server_nodes[nodeid].str1;                           }
   923 const char *       __modbus_get_ServerNode_port       (int nodeid)  {return server_nodes[nodeid].node_address.addr.tcp.service;  }
   933 const char *       __modbus_get_ServerNode_port       (int nodeid)  {return server_nodes[nodeid].str2;                           }
   924 const char *       __modbus_get_ServerNode_device     (int nodeid)  {return server_nodes[nodeid].node_address.addr.rtu.device;   }
   934 const char *       __modbus_get_ServerNode_device     (int nodeid)  {return server_nodes[nodeid].str1;                           }
   925 int                __modbus_get_ServerNode_baud       (int nodeid)  {return server_nodes[nodeid].node_address.addr.rtu.baud;     }
   935 int                __modbus_get_ServerNode_baud       (int nodeid)  {return server_nodes[nodeid].node_address.addr.rtu.baud;     }
   926 int                __modbus_get_ServerNode_parity     (int nodeid)  {return server_nodes[nodeid].node_address.addr.rtu.parity;   }
   936 int                __modbus_get_ServerNode_parity     (int nodeid)  {return server_nodes[nodeid].node_address.addr.rtu.parity;   }
   927 int                __modbus_get_ServerNode_stop_bits  (int nodeid)  {return server_nodes[nodeid].node_address.addr.rtu.stop_bits;}
   937 int                __modbus_get_ServerNode_stop_bits  (int nodeid)  {return server_nodes[nodeid].node_address.addr.rtu.stop_bits;}
       
   938 u8                 __modbus_get_ServerNode_slave_id   (int nodeid)  {return server_nodes[nodeid].slave_id;                       }
   928 const char *       __modbus_get_ServerNode_addr_type  (int nodeid)  {return addr_type_str[server_nodes[nodeid].node_address.naf];}
   939 const char *       __modbus_get_ServerNode_addr_type  (int nodeid)  {return addr_type_str[server_nodes[nodeid].node_address.naf];}
   929 
   940 
   930 
   941 
   931 void __modbus_set_ClientNode_host       (int nodeid, const char * value)  {__safe_strcnpy(client_nodes[nodeid].str1, value, MODBUS_PARAM_STRING_SIZE);}
   942 void __modbus_set_ClientNode_host       (int nodeid, const char * value)  {__safe_strcnpy(client_nodes[nodeid].str1, value, MODBUS_PARAM_STRING_SIZE);}
   932 void __modbus_set_ClientNode_port       (int nodeid, const char * value)  {__safe_strcnpy(client_nodes[nodeid].str2, value, MODBUS_PARAM_STRING_SIZE);}
   943 void __modbus_set_ClientNode_port       (int nodeid, const char * value)  {__safe_strcnpy(client_nodes[nodeid].str2, value, MODBUS_PARAM_STRING_SIZE);}
   935 void __modbus_set_ClientNode_parity     (int nodeid, int          value)  {client_nodes[nodeid].node_address.addr.rtu.parity    = value;}
   946 void __modbus_set_ClientNode_parity     (int nodeid, int          value)  {client_nodes[nodeid].node_address.addr.rtu.parity    = value;}
   936 void __modbus_set_ClientNode_stop_bits  (int nodeid, int          value)  {client_nodes[nodeid].node_address.addr.rtu.stop_bits = value;}
   947 void __modbus_set_ClientNode_stop_bits  (int nodeid, int          value)  {client_nodes[nodeid].node_address.addr.rtu.stop_bits = value;}
   937 void __modbus_set_ClientNode_comm_period(int nodeid, u64          value)  {client_nodes[nodeid].comm_period                     = value;}
   948 void __modbus_set_ClientNode_comm_period(int nodeid, u64          value)  {client_nodes[nodeid].comm_period                     = value;}
   938                                                                                                                         
   949                                                                                                                         
   939 
   950 
   940 
   951 void __modbus_set_ServerNode_host       (int nodeid, const char * value)  {__safe_strcnpy(server_nodes[nodeid].str1, value, MODBUS_PARAM_STRING_SIZE);}
       
   952 void __modbus_set_ServerNode_port       (int nodeid, const char * value)  {__safe_strcnpy(server_nodes[nodeid].str2, value, MODBUS_PARAM_STRING_SIZE);}
       
   953 void __modbus_set_ServerNode_device     (int nodeid, const char * value)  {__safe_strcnpy(server_nodes[nodeid].str1, value, MODBUS_PARAM_STRING_SIZE);}
       
   954 void __modbus_set_ServerNode_baud       (int nodeid, int          value)  {server_nodes[nodeid].node_address.addr.rtu.baud      = value;}
       
   955 void __modbus_set_ServerNode_parity     (int nodeid, int          value)  {server_nodes[nodeid].node_address.addr.rtu.parity    = value;}
       
   956 void __modbus_set_ServerNode_stop_bits  (int nodeid, int          value)  {server_nodes[nodeid].node_address.addr.rtu.stop_bits = value;}
       
   957 void __modbus_set_ServerNode_slave_id   (int nodeid, u8           value)  {server_nodes[nodeid].slave_id                        = value;}
       
   958