-
Notifications
You must be signed in to change notification settings - Fork 14
connection setup
Bill Ryan edited this page Aug 13, 2014
·
2 revisions
For connection setup process is not the primary purpose of simulation, I simplify the connection setup process as following.
/* get the value of the BAN ID */
op_ima_obj_attr_get (node_attr.objid, "BAN ID", &node_attr.ban_id);
mac_attr.ban_id = node_attr.ban_id;
/* get the Sender Address of the node */
op_ima_obj_attr_get (node_attr.objid, "Sender Address", &node_attr.sender_address);
/* Sender Address is not specified - Auto Assigned(-2) from node objid */
if (node_attr.sender_address == AUTO_ASSIGNED_NID) {
node_attr.sender_address = node_attr.objid;
}
if (IAM_BAN_HUB) {
mac_attr.sender_id = node_attr.ban_id + 15; // set the value of HID=BAN ID + 15
mac_attr.recipient_id = BROADCAST_NID; // default value, usually overwritten
} else { /* if the node is not a Hub */
mac_attr.sender_id = UNCONNECTED_NID;
mac_attr.recipient_id = UNCONNECTED;
}
// if I'm a End Device, I get the information and synchronize myself
if (!IAM_BAN_HUB) {
if (UNCONNECTED_NID == mac_attr.sender_id) {
/* We will try to connect to this BAN if our scheduled access length
* is NOT set to unconnected (-1). If it is set to 0, it means we are
* establishing a sleeping pattern and waking up only to hear beacons
* and are only able to transmit in RAP periods.
*/
/* initialize the NID from 32 */
mac_attr.sender_id = current_free_connected_NID++; //current_free_connected_NID is global variable
log = fopen(log_name, "a");
fprintf(log, "t=%f,NODE_ID=%d,INIT,NODE_NAME=%s,NID=%d,", op_sim_time(), node_id, node_attr.name, mac_attr.sender_id);
fprintf(log, "SUPERFRAME_LENGTH=%d,RAP1_LENGTH=%d,B2_START=%d\n", beacon_attr.beacon_period_length, beacon_attr.rap1_length, beacon_attr.b2_start);
fclose(log);
printf("t=%f,NODE_ID=%d,INIT,NODE_NAME=%s,NID=%d\n", op_sim_time(), node_id, node_attr.name, mac_attr.sender_id);
op_prg_odb_bkpt("init");
}
}