예제 #1
0
/////////////////////////////////////////////////////////////////////////////
// This hook is called after startup to initialize the application
/////////////////////////////////////////////////////////////////////////////
void APP_Init(void)
{
  // initialize all LEDs
  MIOS32_BOARD_LED_Init(0xffffffff);

  // turn off gate LED
  MIOS32_BOARD_LED_Set(1, 0);

  // create semaphores
  xSDCardSemaphore = xSemaphoreCreateRecursiveMutex();

  // initialize file functions
  FILE_Init(0);
  
  // initialize MIDI handler
  SEQ_MIDI_OUT_Init(0);

  // initialize sequencer
  SEQ_Init(0);

  // install MIDI Rx callback function
  MIOS32_MIDI_DirectRxCallback_Init(NOTIFY_MIDI_Rx);

  // install sequencer task
  xTaskCreate(TASK_SEQ, (signed portCHAR *)"SEQ", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_SEQ, NULL);
}
예제 #2
0
파일: main.c 프로젝트: shmily/backup
int main(void)
{
    // initial image transmit
    Open_ImageFIFO(ImageFIFO);

    // uart initial
	fprintf(stderr, "This is a test for the Contex-A8...\n");
	serial_initial("/dev/ttySAC1", &GsmDevice, 9600);
	AtTransmitInit(&GsmDevice);
	usleep(10000);

    // buzzer init
//    buzzer_init();
//    buzzer_beep(100000);

	// GPS uart init
	GPS_Init(); 

	// load the connection param
	DevParam_Init();
	
	SEQ_Init();

#ifdef	_EN_INITIAL_GSM_
	// config the gprs network
	NetWork_Connection_Config(Param_IP(), Param_Port(), Param_APN());
#endif
	
	// get the CSQ	
	if(GSM_GetCSQ(&CSQ)!=ERR_NONE){
		fprintf(stderr, "Can't get the CSQ...\n");
	} else{
		fprintf(stderr, "CSQ = %d\n",CSQ);
	}

	sleep(5);

    // create the thread
    pthread_create(&Thread_ID[0], NULL, (void *)AsyncUpdate, NULL);
    pthread_create(&Thread_ID[1], NULL, (void *)HeartBeat,   NULL);

    PositionMonitor_init();
    pthread_create(&Thread_ID[2], NULL, (void *)PositionMonitor, NULL);

    SpeedMonitor_init();
    pthread_create(&Thread_ID[3], NULL, (void *)SpeedMonitor, NULL);

    InZoneMonitor_init();
    pthread_create(&Thread_ID[4], NULL, (void *)InZoneMonitor, NULL);
    
    OutZoneMonitor_init();
    pthread_create(&Thread_ID[5], NULL, (void *)OutZoneMonitor, NULL);

    CrossTrackMonitor_init();
    pthread_create(&Thread_ID[6], NULL, (void *)CrossTrackMonitor, NULL);

//    // initial image transmit
//    Open_ImageFIFO(ImageFIFO);
  
    TypeD_Transmit_Init();
    ImageTransmit_Init(); 
    pthread_create(&Thread_ID[7], NULL, (void *)ImageTransmit_Thread, NULL);

    // Emergency report
    EmergencyMonitor_init();
    pthread_create(&Thread_ID[8], NULL, (void *)EmergencyMonitor, NULL);

    // Fatigue report
    FatigueMonitor_init();
    pthread_create(&Thread_ID[9], NULL, (void *)FatigueMonitor, NULL);

    // GPS parse thread.
    pthread_create(&GPS_Threadid, NULL, (void *)GPS_Parse_thread, NULL);

    // try to login server
    while( Try_Login() != 0 );
//    buzzer_beep(100000);

	while(1){

        GSM_mutex_lock();
        InputPacket_Process();
        GPS_Infomation();
        GSM_mutex_unlock();

        if( isNeed_Updata_Position() ){
            Position_update_after_Call();
        }

        if(is_lose_connection() == 1){
            exit(-1);
        }

        sleep(1);
	}

	serial_close(&GsmDevice);
	
	return 0;
}
예제 #3
0
int main(void)
{
	int i;	

	// uart initial
	fprintf(stderr, "This is a test for the Contex-A8...\n");
	serial_initial("/dev/ttySAC1", &GsmDevice, 9600);
	AtTransmitInit(&GsmDevice);
	usleep(10000);
	SEQ_Init();	

	// GPS uart init
	GPS_Init();

	// FIFO initial
	Open_ImageFIFO(ImageFIFO);	

#ifdef	_EN_INITIAL_GSM_
	// config the gprs network
	NetWork_Connection_Config();
#endif
	
	// printf the CSQ info
	GSM_GetPacketInfo(&unread_sum, &packet_sum);
	fprintf(stderr, "Unread packet sum = %d\n",unread_sum);
	fprintf(stderr, "total packet sum  = %d\n",packet_sum);
	
	if(GSM_GetCSQ(&CSQ)!=ERR_NONE){
		fprintf(stderr, "Can't get the CSQ...\n");
	} else{
		fprintf(stderr, "CSQ = %d\n",CSQ);
	}

	for(i=0;i<20;i++){
		usleep(10000);
	}		

	Login_Process(gRxBuff);


	fprintf(stderr, "========= start transmit =========\n");
	
	for(i=0;i<100;i++){
		usleep(10000);
	}


	// =====================================
	GPS_Debug.lat = MSEC2NDeg( (double)81678360 ); 
	GPS_Debug.lon = MSEC2NDeg( (double)409628128 );
	GPS_Debug.speed = 60;	
	GPS_InfoPrintf(&GPS_Debug);
	// =====================================



	// image updata process

	//ImageTransmit_init("/home/plg/linux.jpg");	

	// packet process
	fprintf(stderr,"\r\n****************************\r\n");
	PositionUpdateRule_Initial(&RuleList);
	InZoneCondition_Initial(&InZone_List);
	OutZoneCondition_Initial(&OutZone_List);
	TDSA_Condition_Initial(&TDSA_List);

	Interval_Locate_Init();				// initial the position update process
	ZoneInfo_Report_Init();				// initial the Zone information update process
	Speed_Report_Init();				// initial the speed information update process 

	// task initial
	Task_Init();	
	SetTimeOut(_Task_Heartbeat_,   6);	// execute every 60 seconds
	SetTimeOut(_Task_GPS_Display_, 6);	// execute every 60 seconds
	SetTimeOut(_Task_RE_Login_,   15);	// if we did not receive the heart beat ack in 150 seconds, re login...

	while(1){
		GSM_GetPacketInfo(&unread_sum, &packet_sum);
	
		G_PacketType = TypeX;	
		if(unread_sum>0){
			memset(gRxBuff,'\0',1024);
			UDP_ReceivePacket(&link_num, &data_index, &data_len, gRxBuff);	
			
			fprintf(stderr, "Receive Packet ...\n");
			fprintf(stderr, "link num    = %d\n",link_num);
			fprintf(stderr, "data index  = %d\n",data_index);
			fprintf(stderr, "data length = %d\n",data_len);

			Packet.length = data_len;
			memcpy(&(Packet.Data[0]), gRxBuff, data_len);	
			res = TLP_PacketDevide(&Packet, &APP_Packet, &G_PacketType);
			
			// A type input
			if((res == ERROR_NONE)&&(G_PacketType == TypeA)){
				
				InputCommandHandle(&APP_Packet);
				ShowRules(&RuleList);
				ShowCondition(&InZone_List);
				ShowCondition(&OutZone_List);
				ShowSpeedCondition(&TDSA_List);
			}
			
			// B type input
			if(G_PacketType == TypeB){
				ReportUpdata_Loop(0);
			}
			
			// D type input
			if(G_PacketType == TypeD){
 				ImageTransmit_loop(0);
			}
		}
	
		// check the fifo, if we got a new image, send it...	
		DrowsyImage_Check();
		DrowsyImage_Send();

		// if the image transmit is in working, the other update mesage is delay	
		if(Get_DT_State()==DT_Idle){		

			Interval_Locate_Check(&RuleList);									// position update process
			Interval_Locate_Updata(&GPS_Msg);

			ZoneInfo_Condition_Check(&InZone_List, &OutZone_List, &GPS_Msg);	// Zone information process
			ZoneInfo_Update(&GPS_Msg);

			Speed_Condition_Check(&TDSA_List,&GPS_Debug);
			SpeedReport_Update(&GPS_Debug);

			if( isTimeOut(_Task_Heartbeat_)==1 ){
				HeartBeat_Request(NULL);
				ClearTimeOut(_Task_Heartbeat_);	
			}

			if( isTimeOut(_Task_RE_Login_)==1 ){
			
				// reconfig the network
				NetWork_Connection_Config();
				Login_Process(gRxBuff);
				ClearTimeOut(_Task_RE_Login_);	
			}
		}

		// GPS information
		GPS_Read(&GPS_Msg);
		if( isTimeOut(_Task_GPS_Display_)==1 ){
			GPS_InfoPrintf(&GPS_Msg);
			ClearTimeOut(_Task_GPS_Display_);	
		}
		
		usleep(500000);
	}

	GSM_CloseConnection();

	for(i=0;i<100;i++){
		usleep(20000);
	}	

	GSM_Reset();	

	serial_close(&GsmDevice);
	
	return 0;
}