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

📄 gps_isr.c

📁 gps_isr.c pserver:anon@source.eecs.berkeley.edu:/home/cvs/cvsanon ptII
💻 C
字号:
#include "gps_isr.h"
#include "gps.h"
#include "socket.h"
#include "return.h"
#include "ports.h"
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/poll.h>

void GPS_ISR_init() {
  // do nothing.
}

void GPS_ISR_start() {
  // start a thread that admits GPS UDP packates.
  pthread_t gpsThread;
  int rc;

  rc = pthread_create(&gpsThread, NULL, runGPS, NULL);
  if (rc) {
    printf("ERROR; return code from pthread_create() is %d\n", rc);
    exit(-1);
  }
}


/** Create a UDP socket server and listen to request.
 *  For every request, create a GPS event that triggers the filer task.
 */
void* runGPS() {
  int gps_socket;
  struct pollfd await;
  gps_mesg_t gps_msg;
  PORT_GPS_t GPS_val;

#define CONTROLLER_GPS_PORT 49153

  if (OK != udp_server_init(&gps_socket, CONTROLLER_GPS_PORT)) {
    printf("In GPS_ISR: error in call to ");
    printf("udp_server_init for gps\n");
    printf("GPS_ISR exits.\n");
    pthread_exit(NULL);
  }

  printf("In GPS_ISR: GPS_ISR started.\n");

  await.fd = gps_socket;
  await.events = POLLIN | POLLPRI;

  while(1) {
    if (poll(&await, 1, -1) == -1) {
      printf("In GPS_ISR: error in call to ");
      printf("poll\n");
    }

    if (await.revents & (POLLIN | POLLPRI)) {
      printf("gps receives");

      if (OK != udp_receive(gps_socket,
          &gps_msg,
          sizeof(gps_mesg_t))) {
        printf("In GPS_ISR: ");
        printf("error in call to ");
        printf("udp_receive for gps\n");
      }
      GPS_val.v1 = gps_msg.this;
      GPS_val.v2 = gps_msg.that;
      setGPS(&GPS_val);
    }

  }
}







⌨️ 快捷键说明

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