00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00036 #include <sys/ioctl.h>
00037 #include <sys/types.h>
00038 #include <sys/stat.h>
00039 #include <fcntl.h>
00040 #include <unistd.h>
00041
00042 #include <sim_if.h>
00043 #include <virtual_time.h>
00044 #include <mac_lib.h>
00045 #include <sensor_node.h>
00046 #include <daemon.h>
00047 #include <configuration.h>
00048
00049
00050
00051 static int radio_request(oq_req_resp_t *rr)
00052 {
00053
00054
00055
00056
00057
00058
00059
00060 return 0;
00061 }
00062
00063
00064 static int sense_request(oq_req_resp_t *rr)
00065 {
00066 return 0;
00067 }
00068
00069
00070
00071 void sim_if_service(int nodes[], int num_nodes)
00072 {
00073 int paused = 0, do_pause = 0;
00074 oq_req_resp_t *rr = new_req_resp();
00075
00076
00077 AvlNode *list;
00078 for (list = avl_find_min(¤t_config.nodes); list != NULL;
00079 list = list->next)
00080 launch((Sensor_node *) list->element);
00081
00082
00083 while (!oq_quitting() && !oq_shuttingdown()) {
00084 if (do_pause) {
00085 paused = 0;
00086 ctl = ioctl(ctl_fd, OQ_RESP_PAUSE);
00087 continue;
00088 }
00089 if (paused && !do_pause)
00090 ctl = ioctl(ctl_fd, OQ_RESP_REINIT, rr);
00091
00092 switch (ctl) {
00093 case 0:
00094 if (strcmp(rr->type, "radio") == 0) {
00095 Sensor_node *node;
00096 if (radio_request(rr) < 0) {
00098 }
00099 if ((node = (Sensor_node *)
00100 avl_retrieve(rr->node_id,
00101 ¤t_config.nodes))
00102 == NULL) {
00104 }
00105 if (protocol_filter(node->radio.protocol,
00106 rr) < 0) {
00108 }
00109 if (rr == NULL) {
00111 }
00112 } else {
00113 if (sense_request(rr) < 0) {
00115 rr->data[0] = 0;
00116 rr->timestamp.tv_sec = 0;
00117 rr->timestamp.tv_nsec = 0;
00118 }
00119 }
00120 ctl = ioctl(ctl_fd, OQ_RESP_RESULT, rr);
00121 break;
00122
00123 case OQ_REQ_REPEAT:
00124 ctl = ioctl(ctl_fd, OQ_RESP_RESULT, rr);
00125 break;
00126
00127
00128
00129
00130
00131
00132
00133
00134 default:
00135 free(rr);
00136 rr = new_req_resp();
00137 ctl = ioctl(ctl_fd, OQ_RESP_REINIT, rr);
00138 break;
00139 }
00140 }
00141 }