You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					81 lines
				
				1.8 KiB
			
		
		
			
		
	
	
					81 lines
				
				1.8 KiB
			| 
								 
											6 years ago
										 
									 | 
							
								#include <stdio.h>
							 | 
						||
| 
								 | 
							
								#include <stdlib.h>
							 | 
						||
| 
								 | 
							
								#include <unistd.h>
							 | 
						||
| 
								 | 
							
								#include <signal.h>
							 | 
						||
| 
								 | 
							
								#include <cassert>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "common/visionbuf.h"
							 | 
						||
| 
								 | 
							
								#include "common/visionipc.h"
							 | 
						||
| 
								 | 
							
								#include "common/swaglog.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								#include "models/dmonitoring.h"
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifndef PATH_MAX
							 | 
						||
| 
								 | 
							
								#include <linux/limits.h>
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								volatile sig_atomic_t do_exit = 0;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								static void set_do_exit(int sig) {
							 | 
						||
| 
								 | 
							
								  do_exit = 1;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								int main(int argc, char **argv) {
							 | 
						||
| 
								 | 
							
								  int err;
							 | 
						||
| 
								 | 
							
								  set_realtime_priority(1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  // messaging
							 | 
						||
| 
								 | 
							
								  Context *msg_context = Context::create();
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  PubSocket *dmonitoring_sock = PubSocket::create(msg_context, "driverState");
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								  // init the models
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  DMonitoringModelState dmonitoringmodel;
							 | 
						||
| 
								 | 
							
								  dmonitoring_init(&dmonitoringmodel);
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								  // loop
							 | 
						||
| 
								 | 
							
								  VisionStream stream;
							 | 
						||
| 
								 | 
							
								  while (!do_exit) {
							 | 
						||
| 
								 | 
							
								    VisionStreamBufs buf_info;
							 | 
						||
| 
								 | 
							
								    err = visionstream_init(&stream, VISION_STREAM_YUV_FRONT, true, &buf_info);
							 | 
						||
| 
								 | 
							
								    if (err) {
							 | 
						||
| 
								 | 
							
								      printf("visionstream connect fail\n");
							 | 
						||
| 
								 | 
							
								      usleep(100000);
							 | 
						||
| 
								 | 
							
								      continue;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    LOGW("connected with buffer size: %d", buf_info.buf_len);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    double last = 0;
							 | 
						||
| 
								 | 
							
								    while (!do_exit) {
							 | 
						||
| 
								 | 
							
								      VIPCBuf *buf;
							 | 
						||
| 
								 | 
							
								      VIPCBufExtra extra;
							 | 
						||
| 
								 | 
							
								      buf = visionstream_get(&stream, &extra);
							 | 
						||
| 
								 | 
							
								      if (buf == NULL) {
							 | 
						||
| 
								 | 
							
								        printf("visionstream get failed\n");
							 | 
						||
| 
								 | 
							
								        break;
							 | 
						||
| 
								 | 
							
								      }
							 | 
						||
| 
								 | 
							
								      //printf("frame_id: %d %dx%d\n", extra.frame_id, buf_info.width, buf_info.height);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								      double t1 = millis_since_boot();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								      DMonitoringResult res = dmonitoring_eval_frame(&dmonitoringmodel, buf->addr, buf_info.width, buf_info.height);
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								      double t2 = millis_since_boot();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								      // send dm packet
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								      dmonitoring_publish(dmonitoring_sock, extra.frame_id, res);
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								      LOGD("dmonitoring process: %.2fms, from last %.2fms", t2-t1, t1-last);
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								      last = t1;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  visionstream_destroy(&stream);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  delete dmonitoring_sock;
							 | 
						||
| 
								 | 
							
								  dmonitoring_free(&dmonitoringmodel);
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								  return 0;
							 | 
						||
| 
								 | 
							
								}
							 |