00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #define PCR_DEBUG(_x)
00032
00033 typedef struct {
00034 TOS_MsgPtr msg;
00035 int success;
00036 } uart_send_done_data_t;
00037
00038 enum {
00039 UART_SEND_DELAY = 1600
00040 };
00041
00042
00043
00044 void NIDO_uart_send_done(TOS_MsgPtr fmsg, result_t fsuccess);
00045
00046 void event_uart_write_create(event_t* uevent, int mote, long long utime, TOS_MsgPtr msg, result_t success);
00047
00048 void event_uart_write_handle(event_t* uevent,
00049 struct TOS_state* state) {
00050
00051
00052 NIDO_uart_send_done((TOS_MsgPtr)((uart_send_done_data_t*)uevent->data)->msg,
00053 ((uart_send_done_data_t *)uevent->data)->success);
00054
00055
00056 ((uart_send_done_data_t*)uevent->data)->msg = NULL;
00057 event_cleanup(uevent);
00058 dbg(DBG_UART, "UART: packet transfer complete.\n");
00059 }
00060
00061 void event_uart_write_create(event_t* uevent, int mote, long long utime, TOS_MsgPtr msg, result_t success) {
00062 uart_send_done_data_t* data = (uart_send_done_data_t*)malloc(sizeof(uart_send_done_data_t));
00063 dbg(DBG_MEM, "malloc uart send done data event.\n");
00064
00065 ((uart_send_done_data_t *)data)->msg = msg;
00066 ((uart_send_done_data_t *)data)->success = success;
00067
00068 uevent->mote = mote;
00069 uevent->data = data;
00070 uevent->time = utime;
00071 uevent->handle = event_uart_write_handle;
00072 uevent->cleanup = event_total_cleanup;
00073 uevent->pause = 0;
00074 uevent->force = 0;
00075 }
00076
00077 void TOSH_uart_send(TOS_MsgPtr msg)
00078 {
00079 result_t success;
00080 event_t* uevent;
00081 UARTMsgSentEvent ev;
00082 char buf[1024];
00083 success = SUCCESS;
00084
00085 memcpy(&ev.message, msg, sizeof(ev.message));
00086 sendTossimEvent(NODE_NUM, AM_UARTMSGSENTEVENT, tos_state.tos_time, &ev);
00087
00088
00089 uevent = (event_t*)malloc(sizeof(event_t));
00090 event_uart_write_create(uevent, NODE_NUM, tos_state.tos_time + UART_SEND_DELAY, msg, success);
00091 TOS_queue_insert_event(uevent);
00092 printTime(buf, 1024);
00093 dbg(DBG_UART, "Enqueueing uart_send_event at %s for mote %i", buf, TOS_LOCAL_ADDRESS);
00094 }
00095
00096 #include <adjacency_list.c>
00097 #include <rfm_model.c>
00098 #include <packet_sim.c>