⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 event.c

📁 MANTIS是由科罗拉多大学开发的传感器网络嵌入式操作系统。 这是mantis的0.9.5版本的源码。
💻 C
字号:
//  This file is part of MANTIS OS, Operating System//  See http://mantis.cs.colorado.edu/////  Copyright (C) 2003,2004,2005 University of Colorado, Boulder////  This program is free software; you can redistribute it and/or//  modify it under the terms of the mos license (see file LICENSE)/// Event #include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <errno.h>#include <string.h>#include <netdb.h>#include <sys/types.h>#include <netinet/in.h>#include <sys/socket.h>#include "event.h"#define PORT 1629#define MAXDATASIZE 256int sockfd;  int event_init() {   struct hostent *he;   struct sockaddr_in server_addr; // connector's address information    if ((he=gethostbyname("127.0.0.1")) == NULL) {  // get the host info       perror("event_init: gethostbyname");      exit(1);   }   if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {      perror("event_init: socket");      exit(1);   }   server_addr.sin_family = AF_INET;    // host byte order    server_addr.sin_port = htons(PORT);  // short, network byte order    server_addr.sin_addr = *((struct in_addr *)he->h_addr);   memset(&(server_addr.sin_zero), '\0', 8);  // zero the rest of the struct    if (connect(sockfd, (struct sockaddr *)&server_addr,	       sizeof(struct sockaddr)) == -1) {      perror("event_init: connect");      exit(1);   }   return sockfd;}void SendEvent(int sock, Event *ev){   send(sock, &ev->eid, sizeof(uint32_t), 0);}uint8_t mos_event_send(uint8_t *data, uint8_t size) {   printf("Byte[0]: %x\nByte[1]: %x\n", data[0], data[1]);   printf("Size: %d\n", size);   if(send(sockfd, data, size, 0) == -1)      perror("event_send: send");   return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -