00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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 <configuration.h>
00043 #include <sensor_device.h>
00044 #include <virtual_time.h>
00045 #include <mac_lib.h>
00046 #include <sim_if.h>
00047 #include <daemon.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 ctl_fd, ctl, paused = 0, do_pause = 0;
00074 oq_req_resp_t *rr = new_req_resp();
00075
00076 ctl_fd = open("/dev/orbisquartus0", O_RDONLY);
00077 ctl = ioctl(ctl_fd, OQ_RESP_INIT, rr);
00078
00079
00080 struct avlnode *list;
00081 for (list = avl_find_min(¤t_config.nodes); list != NULL;
00082 list = list->next)
00083 ((Sensor_node *) list->element)->launch();
00084
00085
00086 while (!oq_quitting() && !oq_shuttingdown()) {
00087 if (do_pause) {
00088 paused = 0;
00089 ctl = ioctl(ctl_fd, OQ_RESP_PAUSE);
00090 continue;
00091 }
00092 if (paused && !do_pause)
00093 ctl = ioctl(ctl_fd, OQ_RESP_REINIT, rr);
00094
00095 switch (ctl) {
00096 case 0:
00097 if (strcmp(rr->type, "radio") == 0) {
00098 node_t *node;
00099 if (radio_request(rr) < 0) {
00101 }
00102 if ((node = (node_t *)
00103 avl_retrieve(rr->node_id,
00104 ¤t_config.nodes))
00105 == NULL) {
00107 }
00108 if (protocol_filter(node->radio.protocol,
00109 rr) < 0) {
00111 }
00112 if (rr == NULL) {
00114 }
00115 } else {
00116 if (sense_request(rr) < 0) {
00118 rr->data[0] = 0;
00119 rr->timestamp.tv_sec = 0;
00120 rr->timestamp.tv_nsec = 0;
00121 }
00122 }
00123 ctl = ioctl(ctl_fd, OQ_RESP_RESULT, rr);
00124 break;
00125
00126 case OQ_REQ_REPEAT:
00127 ctl = ioctl(ctl_fd, OQ_RESP_RESULT, rr);
00128 break;
00129
00130
00131
00132
00133
00134
00135
00136
00137 default:
00138 free(rr);
00139 rr = new_req_resp();
00140 ctl = ioctl(ctl_fd, OQ_RESP_REINIT, rr);
00141 break;
00142 }
00143 }
00144
00145 close(ctl_fd);
00146 }