Beispiel #1
0
void CInArchive::ReadHeaderReal(CItemEx &item)
{
  item.Flags = m_BlockHeader.Flags;
  item.PackSize = ReadUInt32();
  item.Size = ReadUInt32();
  item.HostOS = ReadByte();
  item.FileCRC = ReadUInt32();
  item.MTime.DosTime = ReadUInt32();
  item.UnPackVersion = ReadByte();
  item.Method = ReadByte();
  int nameSize = ReadUInt16();
  item.Attrib = ReadUInt32();

  item.MTime.LowSecond = 0;
  item.MTime.SubTime[0] =
      item.MTime.SubTime[1] =
      item.MTime.SubTime[2] = 0;

  if((item.Flags & NHeader::NFile::kSize64Bits) != 0)
  {
    item.PackSize |= ((UInt64)ReadUInt32() << 32);
    item.Size |= ((UInt64)ReadUInt32() << 32);
  }

  ReadName(item, nameSize);

  if (item.HasSalt())
    for (int i = 0; i < sizeof(item.Salt); i++)
      item.Salt[i] = ReadByte();

  // some rar archives have HasExtTime flag without field.
  if (m_CurPos < m_PosLimit && item.HasExtTime())
  {
    Byte accessMask = (Byte)(ReadByte() >> 4);
    Byte b = ReadByte();
    Byte modifMask = (Byte)(b >> 4);
    Byte createMask = (Byte)(b & 0xF);
    if ((modifMask & 8) != 0)
      ReadTime(modifMask, item.MTime);
    item.CTimeDefined = ((createMask & 8) != 0);
    if (item.CTimeDefined)
    {
      item.CTime.DosTime = ReadUInt32();
      ReadTime(createMask, item.CTime);
    }
    item.ATimeDefined = ((accessMask & 8) != 0);
    if (item.ATimeDefined)
    {
      item.ATime.DosTime = ReadUInt32();
      ReadTime(accessMask, item.ATime);
    }
  }
Beispiel #2
0
static bool
ParseLogbookContent(const char *_line, RecordedFlightInfo &info)
{
  NMEAInputLine line(_line);

  unsigned n;
  return line.Skip() &&
    line.ReadChecked(n) &&
    ReadFilename(line, info) > 0 &&
    ReadDate(line, info.date) &&
    ReadTime(line, info.start_time) &&
    ReadTime(line, info.end_time);
}
Beispiel #3
0
bool
NMEAParser::GLL(NMEAInputLine &line, NMEAInfo &info)
{
    /*
     * $--GLL,llll.ll,a,yyyyy.yy,a,hhmmss.ss,a,m,*hh
     *
     * Field Number:
     *  1) Latitude
     *  2) N or S (North or South)
     *  3) Longitude
     *  4) E or W (East or West)
     *  5) Universal Time Coordinated (UTC)
     *  6) Status A - Data Valid, V - Data Invalid
     *  7) FAA mode indicator (NMEA 2.3 and later)
     *  8) Checksum
     */

    GeoPoint location;
    bool valid_location = ReadGeoPoint(line, location);

    fixed this_time;
    if (!ReadTime(line, info.date_time_utc, this_time))
        return true;

    bool gps_valid = !NAVWarn(line.ReadFirstChar());

    if (!TimeHasAdvanced(this_time, info))
        return true;

    if (!gps_valid)
        info.location_available.Clear();
    else if (valid_location)
        info.location_available.Update(info.clock);

    if (valid_location)
        info.location = location;

    info.gps.real = real;
#if defined(ANDROID) || defined(__APPLE__)
    info.gps.nonexpiring_internal_gps = false;
#endif

    return true;
}
Beispiel #4
0
//------------------------------------
unsigned char dispMenu(msg_par par) 
{
//	menuItem* tempMenu;
//	tempMenu = (menuItem*)pgm_read_word(&selectedMenuItem);
//	//printf(" %c  ",SELECT+0x30);
	static unsigned char blink=100,blink_flag=0;
//	static unsigned char blink_mask=0xFF;
wdt_reset();	
	if(blink<2)
	{
		blink++;
	}	
	else
	{
		blink_flag=!blink_flag;
		blink=0;
	}

	switch(SELECT)
	{
		case MENU_TIME:
		{
		//	ReadTime(disp_buf);
			ReadTime(&clk,0);
			
			disp_buf[4]=clk.hour/10;
			disp_buf[3]=clk.hour%10;
			disp_buf[2]=0xA;
			disp_buf[1]=clk.minute/10;
			disp_buf[0]=clk.minute%10;
		//	SetPoint(3);
		//	LED_Out_Integer(clk.hour*100+clk.minute);
			LED_Out_Buf(disp_buf,5,0xFF);
		}
		break;
		
		case MENU_DATE:
		{
			ReadTime(&clk,1);

			disp_buf[4]=0xF;
			disp_buf[1]=clk.month/10;
			disp_buf[0]=(clk.month%10);
			disp_buf[3]=clk.day/10;
			disp_buf[2]=(clk.day%10)|0x80;

			LED_Out_Buf(disp_buf,5,0xFF);
		}
		break;

		case MENU_YEAR:
		{
			ReadTime(&clk,2);

			disp_buf[4]=0xF;
			disp_buf[3]=2;
			disp_buf[2]=0;
			disp_buf[1]=clk.year/10;
			disp_buf[0]=clk.year%10;

			LED_Out_Buf(disp_buf,5,0xFF);
		}
		break;

		case MENU_TUNE_BRIGHTNESS:
		{
			disp_buf[4]=0xF;
			disp_buf[3]=0xF;
			disp_buf[2]=0xF;
			if(brightness>9)
			{
				disp_buf[1]=brightness/10;
				disp_buf[0]=brightness%10;
			}
			else
			{
				disp_buf[1]=0xF;
				disp_buf[0]=brightness;
			}
			

			LED_Out_Buf(disp_buf,5,0xFF);
		}
		break;

		case MENU_TEMPERATURE_1:
		{
			static  int cap_temp,temperature;
			static unsigned char cap_temp_count=0;
				
			if(cap_temp_count<5)
			{
				cap_temp+=(int)(( long)((int)ReadADC(1)-(int)ReadADC(0))*VREF*100/1023);	
				cap_temp_count++;
			}
			else
			{
				temperature=cap_temp/5;
				cap_temp_count=0;
				cap_temp=0;
			}
			SetPoint(0);
			LED_Out_Integer(temperature);
		}
		break;

		case MENU_FREQUENCY:
		{
			unsigned char i;
			freq=0;
			for(i=0;i<MID_MAS_SIZE;i++)
			{
				freq+=mid_mas[i];
			}
			if(freq!=0)
			{
				freq=1875000*MID_MAS_SIZE/freq;
			}
			SetPoint(0);
			LED_Out_Integer((unsigned int)freq);
		}
		break;

		case MENU_VOLTAGE:
		{
			SetPoint(2);
			LED_Out_Integer((unsigned int)((unsigned long)ReadADC(2)*VREF*10*ATTEN/1023));
		}
		break;

		case MENU_TUNE_TIME:
		{
			disp_buf[4]=clk.hour/10;
			disp_buf[3]=clk.hour%10;
			disp_buf[2]=0xA;
			disp_buf[1]=clk.minute/10;
			disp_buf[0]=clk.minute%10;

			if(blink_flag)
			{
				if(time_tune_state)
				{
					LED_Out_Buf(disp_buf,5,0xFC);
				}
				else
				{
					LED_Out_Buf(disp_buf,5,0xE7);
				}
			}
			else
			{
				LED_Out_Buf(disp_buf,5,0xFF);
			}
		}
		break;

		case MENU_TUNE_DATE:
		{
			disp_buf[4]=0xF;
			disp_buf[1]=clk.month/10;
			disp_buf[0]=(clk.month%10);
			disp_buf[3]=clk.day/10;
			disp_buf[2]=(clk.day%10)|0x80;

			if(blink_flag)
			{
				if(date_tune_state)
				{
					LED_Out_Buf(disp_buf,5,0xE7);
				}
				else
				{
					LED_Out_Buf(disp_buf,5,0xF9);
				}
			}
			else
			{
				LED_Out_Buf(disp_buf,5,0xFF);
			}
		}
		break;

		case MENU_TUNE_YEAR:
		{
			disp_buf[4]=0xF;
			disp_buf[3]=2;
			disp_buf[2]=0;
			disp_buf[1]=clk.year/10;
			disp_buf[0]=clk.year%10;

			if(blink_flag)
			{
				LED_Out_Buf(disp_buf,5,0xE7);
			}
			else
			{
				LED_Out_Buf(disp_buf,5,0xFF);
			}
		}
		break;

		default:
		{
		}
		break;
	}

	setTimer(MSG_DISP_REFRESH, 0, 250);
	return (1);
}
Beispiel #5
0
bool
NMEAParser::GGA(NMEAInputLine &line, NMEAInfo &info)
{
    /*
     * $--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh
     *
     * Field Number:
     *  1) Universal Time Coordinated (UTC)
     *  2) Latitude
     *  3) N or S (North or South)
     *  4) Longitude
     *  5) E or W (East or West)
     *  6) GPS Quality Indicator,
     *     0 - fix not available,
     *     1 - GPS fix,
     *     2 - Differential GPS fix
     *     (values above 2 are 2.3 features)
     *     3 = PPS fix
     *     4 = Real Time Kinematic
     *     5 = Float RTK
     *     6 = estimated (dead reckoning)
     *     7 = Manual input mode
     *     8 = Simulation mode
     *  7) Number of satellites in view, 00 - 12
     *  8) Horizontal Dilution of precision (meters)
     *  9) Antenna Altitude above/below mean-sea-level (geoid) (in meters)
     * 10) Units of antenna altitude, meters
     * 11) Geoidal separation, the difference between the WGS-84 earth
     *     ellipsoid and mean-sea-level (geoid), "-" means mean-sea-level
     *     below ellipsoid
     * 12) Units of geoidal separation, meters
     * 13) Age of differential GPS data, time in seconds since last SC104
     *     type 1 or 9 update, null field when DGPS is not used
     * 14) Differential reference station ID, 0000-1023
     * 15) Checksum
     */

    GPSState &gps = info.gps;

    fixed this_time;
    if (!ReadTime(line, info.date_time_utc, this_time))
        return true;

    GeoPoint location;
    bool valid_location = ReadGeoPoint(line, location);

    unsigned fix_quality;
    if (line.ReadChecked(fix_quality)) {
        gps.fix_quality = (FixQuality)fix_quality;
        gps.fix_quality_available.Update(info.clock);
    }

    unsigned satellites_used;
    if (line.ReadChecked(satellites_used)) {
        info.gps.satellites_used = satellites_used;
        info.gps.satellites_used_available.Update(info.clock);
    }

    if (!TimeHasAdvanced(this_time, info))
        return true;

    (void)valid_location;
    /* JMW: note ignore location updates from GGA -- definitive frame is GPRMC sentence
    if (!gpsValid)
      info.LocationAvailable.Clear();
    else if (valid_location)
      info.LocationAvailable.Update(info.clock);

    if (valid_location)
      info.Location = location;
    */

    info.gps.real = real;
#if defined(ANDROID) || defined(__APPLE__)
    info.gps.nonexpiring_internal_gps = false;
#endif

    gps.hdop = line.Read(fixed(0));

    bool altitude_available = ReadAltitude(line, info.gps_altitude);
    if (altitude_available)
        info.gps_altitude_available.Update(info.clock);
    else
        info.gps_altitude_available.Clear();

    fixed geoid_separation;
    if (ReadAltitude(line, geoid_separation)) {
        // No real need to parse this value,
        // but we do assume that no correction is required in this case

        if (!altitude_available) {
            /* Some devices, such as the "LG Incite Cellphone" seem to be
               severely bugged, and report the GPS altitude in the Geoid
               column.  That sucks! */
            info.gps_altitude = geoid_separation;
            info.gps_altitude_available.Update(info.clock);
        }
    } else {
        // need to estimate Geoid Separation internally (optional)
        // FLARM uses MSL altitude
        //
        // Some others don't.
        //
        // If the separation doesn't appear in the sentence,
        // we can assume the GPS unit is giving ellipsoid height
        //
        if (use_geoid) {
            // JMW TODO really need to know the actual device..
            geoid_separation = EGM96::LookupSeparation(info.location);
            info.gps_altitude -= geoid_separation;
        }
    }

    return true;
}
Beispiel #6
0
bool
NMEAParser::RMC(NMEAInputLine &line, NMEAInfo &info)
{
    /*
     * $--RMC,hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,x.x,xxxx,x.x,a,m,*hh
     *
     * Field Number:
     *  1) UTC Time
     *  2) Status, V=Navigation receiver warning A=Valid
     *  3) Latitude
     *  4) N or S
     *  5) Longitude
     *  6) E or W
     *  7) Speed over ground, knots
     *  8) Track made good, degrees true
     *  9) Date, ddmmyy
     * 10) Magnetic Variation, degrees
     * 11) E or W
     * 12) FAA mode indicator (NMEA 2.3 and later)
     * 13) Checksum
     */

    fixed this_time;
    if (!ReadTime(line, info.date_time_utc, this_time))
        return true;

    bool gps_valid = !NAVWarn(line.ReadFirstChar());

    GeoPoint location;
    bool valid_location = ReadGeoPoint(line, location);

    fixed speed;
    bool ground_speed_available = line.ReadChecked(speed);

    Angle track;
    bool track_available = ReadBearing(line, track);

    // JMW get date info first so TimeModify is accurate
    ReadDate(line, info.date_time_utc);

    Angle variation;
    bool variation_available = ReadVariation(line, variation);

    if (!TimeHasAdvanced(this_time, info))
        return true;

    if (!gps_valid)
        info.location_available.Clear();
    else if (valid_location)
        info.location_available.Update(info.clock);

    if (valid_location)
        info.location = location;

    if (ground_speed_available) {
        info.ground_speed = Units::ToSysUnit(speed, Unit::KNOTS);
        info.ground_speed_available.Update(info.clock);
    }

    if (track_available && info.MovementDetected()) {
        // JMW don't update bearing unless we're moving
        info.track = track;
        info.track_available.Update(info.clock);
    }

    if (!variation_available)
        info.variation_available.Clear();
    else if (variation_available) {
        info.variation = variation;
        info.variation_available.Update(info.clock);
    }

    info.gps.real = real;
#if defined(ANDROID) || defined(__APPLE__)
    info.gps.nonexpiring_internal_gps = false;
#endif

    return true;
}
/* This is your main function! You should have an infinite loop in here that
 * does all the important stuff your node was designed for */
int main(void) {
    int initialGPSLock = 1;
	char nmea_buf_1[NMEA_BUFFER_SIZE];
	char nmea_buf_2[NMEA_BUFFER_SIZE];
	char *nmea_current_buf;
	struct UART_buffer_descriptor nmea_buf_desc_1, nmea_buf_desc_2;
	gps_point cur_point; 
	gps_speed cur_speed; 
	sc_time_t cur_point_stamp = 0; 
	sc_time_t last_timesync_time = 0; 
	uint32_t gga_parse_errors = 0;
	uint32_t next_baro_read=0;
	uint32_t next_rtc_time=0;

	/* We allow some time for the GPS to come up before we continue here */
	scandal_naive_delay(100000);
	setup();
	scandal_naive_delay(100000);

	scandal_init();
	scandal_delay(1000);

	/* Initialise the UART to the correct GPS baud rate */
#if defined(LOCOSYS)
	UART_Init(57600);
#else
#if defined(SANJOSE)
	UART_Init(38400);
#endif
#endif
	scandal_delay(1000); /* wait for the UART clocks to settle */

	sc_time_t one_sec_timer = sc_get_timer(); /* Initialise the timer variable */

	/* Set LEDs to known states */
	red_led(1);
	yellow_led(0);

	// Set up the barometer
	long b5, pres, temp, alt, up, ut;
	readCalibrationValues();		//read calibration values

	/* Some GPS config stuff that isn't really necessary */

	/* We can send a reset command if need be
	mtk_send_command("$PMTK103"); */

	/* Set which messages to send out
	 * This sets us to receive GPRMC and GPGGA on every position fix */
	mtk_send_command("$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0");

	/* put in 5Hz mode
	mtk_send_command("$PMTK220,200"); */

	/* Change the rate at which we fix the position. Presently every 1000ms */
	mtk_send_command("$PMTK300,1000,0,0,0,0*");

	/* We need a double buffer for reading the GPS messages while we parse them */
	UART_init_double_buffer(&nmea_buf_desc_1, nmea_buf_1, NMEA_BUFFER_SIZE,
								&nmea_buf_desc_2, nmea_buf_2, NMEA_BUFFER_SIZE);

	/* This is the main loop, go for ever! */
	while (1) {
		/* This checks whether there are pending requests from CAN, and sends a heartbeat message.
		 * The heartbeat message encodes some data in the first 4 bytes of the CAN message, such as
		 * the number of errors and the version of scandal */
		handle_scandal();

		if (sc_get_timer() > next_rtc_time){
		    ReadTime();
            UART_printf("Scandal Get Timer: %d\r\n", sc_get_timer_1());
		    next_rtc_time+=250;
		}

		/* Read a line from the UART into one of the buffers */
		nmea_current_buf = UART_readline_double_buffer(&nmea_buf_desc_1, &nmea_buf_desc_2);

		/* UART_readline_double_buffer will return a pointer to the current buffer. */
		if (nmea_current_buf != NULL) {

			/* If we didn't get a valid NMEA line */
			if(validate_nmea(nmea_current_buf) != 0)
				continue;

			/* check to see if we have a GGA message */ 
			if(strncmp(nmea_current_buf, "$GPGGA", 6) == 0){
				int res = parse_msg_gga(nmea_current_buf, &cur_point);
				if(res == 0){
                    if(initialGPSLock == 1) {
                        // Syncs GPS clock with RTC
                        SetTime(get_gga_time_array());
                        SetDate(get_rmc_date_array());
                        initialGPSLock = 0;
                    }
				   /*If the GPS is locked (res==0), send GPS data and set the RTC*/
					toggle_yellow_led();
                    
					cur_point_stamp = scandal_get_realtime32();
					scandal_send_channel_with_timestamp(CRITICAL_PRIORITY, GPSBAROMETER_FIX,
											1, cur_point_stamp);
					scandal_send_channel_with_timestamp(CRITICAL_PRIORITY, GPSBAROMETER_TIME,
											cur_point.time, cur_point_stamp);
					scandal_send_channel_with_timestamp(CRITICAL_PRIORITY, GPSBAROMETER_LATITUDE,
											cur_point.lat, cur_point_stamp);
					scandal_send_channel_with_timestamp(CRITICAL_PRIORITY, GPSBAROMETER_LONGITUDE,
											cur_point.lng, cur_point_stamp);
					scandal_send_channel_with_timestamp(CRITICAL_PRIORITY, GPSBAROMETER_ALTITUDE,
											cur_point.alt, cur_point_stamp);
					/* Only sets the RTC if the seconds value is under 58
					 * This is done to make sure nothing ticks over in the
					 * middle of a write process as strange values may result
					 */
                    
				/* an actual parse error */
				} else if (res == -1) {
					scandal_send_channel_with_timestamp(CRITICAL_PRIORITY, GPSBAROMETER_GGA_PARSE_ERROR_COUNT,
											gga_parse_errors++, cur_point_stamp);
				/* no fix yet */
				} else if (res == -2) {
					scandal_send_channel_with_timestamp(CRITICAL_PRIORITY, GPSBAROMETER_FIX,
											0, cur_point_stamp);
					//gps_lock=0;
				}
			}

			/* check to see if we have an RMC message */ 
			if(strncmp(nmea_current_buf, "$GPRMC", 6) == 0) {
				if(parse_msg_rmc(nmea_current_buf, &cur_speed) == 0) {
					toggle_red_led();

					/* Milliseconds since the epoch */
                    /* Converts date to milliseconds, adds time */
					uint64_t timestamp = days_since_epoch(getRTCDay(), getRTCMonth(), getRTCYear());
					timestamp *= 3600;
					timestamp *= 24;
					timestamp *= 1000;
                    timestamp += getRTCTimeSecond() * 1000;
                    timestamp += sc_get_timer_1();
                    
                    UART_printf("Day:%d Month:%d Year:%d\r\n", getRTCDay(), getRTCMonth(), getRTCYear());
                    
                    scandal_send_timesync(CRITICAL_PRIORITY, scandal_get_addr(), timestamp);
                    
                    scandal_set_realtime(timestamp);
                    
                    scandal_send_channel(CRITICAL_PRIORITY, GPSBAROMETER_SPEED, cur_speed.speed * 1000);
                    scandal_send_channel(CRITICAL_PRIORITY, GPSBAROMETER_MILLISECONDS_TODAY, cur_speed.time);
                    scandal_send_channel(CRITICAL_PRIORITY, GPSBAROMETER_DAYS_SINCE_EPOCH, cur_speed.date);
                    
					/* This is an evil hack to make sure that we get fairly consistent timestamps 
					Sometimes there seems to be a really long dela of ~0.3s on some timestamp
					messages. To get rid of this, we don't accept any time differences that are 
					more than 20ms later than we expect them to be. 
					This is pure evil, and the problem should really be fixed rather than 
					hacking around it like this */
					/*
                    if(last_timesync_time == 0)
						last_timesync_time = sc_get_timer();

					timediff = (sc_get_timer() - last_timesync_time) % 1000;
					if((timediff < 50) || (timediff > 600)) {
                        
						last_timesync_time = sc_get_timer();
						scandal_send_timesync(CRITICAL_PRIORITY, scandal_get_addr(), timestamp);
					}

					scandal_set_realtime(timestamp);

					scandal_send_channel(CRITICAL_PRIORITY, GPSBAROMETER_SPEED, cur_speed.speed * 1000);
					scandal_send_channel(CRITICAL_PRIORITY, GPSBAROMETER_MILLISECONDS_TODAY, cur_speed.time);
					scandal_send_channel(CRITICAL_PRIORITY, GPSBAROMETER_DAYS_SINCE_EPOCH, cur_speed.date);
                    */
					/*                    if(cur_point_stamp  != 0){
					scandal_send_channel_with_timestamp(CRITICAL_PRIORITY, GPSBAROMETER_TIME,
													cur_point.time, cur_point_stamp);
					scandal_send_channel_with_timestamp(CRITICAL_PRIORITY, GPSBAROMETER_LATITUDE,
													cur_point.lat, cur_point_stamp);
					scandal_send_channel_with_timestamp(CRITICAL_PRIORITY, GPSBAROMETER_LONGITUDE,
													cur_point.lng, cur_point_stamp);
					scandal_send_channel_with_timestamp(CRITICAL_PRIORITY, GPSBAROMETER_ALTITUDE,
													cur_point.alt, cur_point_stamp);
					cur_point_stamp = 0; 
					}
					*/

				}
			}
		}

#if 1
		if (sc_get_timer() > next_baro_read){

		    ut = bmp085ReadUT();					//read uncompensated temperature
		    scandal_delay(5);					//delay 4.5ms
		    up = bmp085ReadUP();					//read uncompensated pressure
		    scandal_delay(5);					//delay 4.5ms
		    b5 = bmp085Getb5(ut);				//calculate temperature constant
		    temp = bmp085GetTemperature(ut, b5);			//calculate true temperature
		    pres = bmp085GetPressure(up, b5);		//calculate true pressure
		    alt = bmp085GetAltitude(pres);				//estimate the altitude
		    next_baro_read=(sc_get_timer()+1000);
		}

#endif
		//UART_printf("B5: %d,Temp: %d:%d, Pres: %d:%d, Alt: %d\r\n", (int) b5,(int) ut, (int) temp, (int)up,(int) pres, (int) alt);
//		UART_printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n",(int) barometerCal -> AC1,(int) barometerCal -> AC2,(int) barometerCal -> AC3,(int) barometerCal -> AC4,(int) barometerCal -> AC5,(int) barometerCal -> AC6,(int) barometerCal -> B1,(int) barometerCal -> B2,(int) barometerCal -> MB,(int) barometerCal -> MC,(int) barometerCal -> MD);

		#if 0
		/* Flash an LED every second */
		if(sc_get_timer() >= one_sec_timer + 1000) {
			toggle_red_led();
			one_sec_timer = sc_get_timer();
		}
#endif
	}
}
Beispiel #8
0
//Publish using RTMP_SendPacket()  
int publish_using_packet(){  
	RTMP *rtmp=NULL;                             
	RTMPPacket *packet=NULL;  
	uint32_t start_time=0;  
	uint32_t now_time=0;  
	//the timestamp of the previous frame  
	long pre_frame_time=0;  
	long lasttime=0;  
	int bNextIsKey=1;  
	uint32_t preTagsize=0;  

	//packet attributes  
	uint32_t type=0;                          
	uint32_t datalength=0;             
	uint32_t timestamp=0;             
	uint32_t streamid=0;                          

	FILE*fp=NULL;  
	fp=fopen("../live.flv","rb");  
	if (!fp){  
		RTMP_LogPrintf("Open File Error.\n");  
	//	CleanupSockets();  
		return -1;  
	}  

	/* set log level */  
	//RTMP_LogLevel loglvl=RTMP_LOGDEBUG;  
	//RTMP_LogSetLevel(loglvl);  

//	if (!InitSockets()){  
//		RTMP_LogPrintf("Init Socket Err\n");  
//		return -1;  
//	}  

	rtmp=RTMP_Alloc();  
	RTMP_Init(rtmp);  
	//set connection timeout,default 30s  
	rtmp->Link.timeout=5;                        
	if(!RTMP_SetupURL(rtmp,"rtmp://101.251.251.93:1935/myapp/mystream"))  
	{  
		RTMP_Log(RTMP_LOGERROR,"SetupURL Err\n");  
		RTMP_Free(rtmp);  
	//	CleanupSockets();  
		return -1;  
	}  

	//if unable,the AMF command would be 'play' instead of 'publish'  
	RTMP_EnableWrite(rtmp);       

	if (!RTMP_Connect(rtmp,NULL)){  
		RTMP_Log(RTMP_LOGERROR,"Connect Err\n");  
		RTMP_Free(rtmp);  
	//	CleanupSockets();  
		return -1;  
	}  

	if (!RTMP_ConnectStream(rtmp,0)){  
		RTMP_Log(RTMP_LOGERROR,"ConnectStream Err\n");  
		RTMP_Close(rtmp);  
		RTMP_Free(rtmp);  
//		CleanupSockets();  
		return -1;  
	}  

	packet=(RTMPPacket*)malloc(sizeof(RTMPPacket));  
	RTMPPacket_Alloc(packet,1024*64);  
	RTMPPacket_Reset(packet);  

	packet->m_hasAbsTimestamp = 0;          
	packet->m_nChannel = 0x04;  
	packet->m_nInfoField2 = rtmp->m_stream_id;  

	RTMP_LogPrintf("Start to send data ...\n");  

	//jump over FLV Header  
	fseek(fp,9,SEEK_SET);       
	//jump over previousTagSizen  
	fseek(fp,4,SEEK_CUR);     
	start_time=RTMP_GetTime();  
	while(1)  
	{  
		if((((now_time=RTMP_GetTime())-start_time)  
					<(pre_frame_time)) && bNextIsKey){          
			//wait for 1 sec if the send process is too fast  
			//this mechanism is not very good,need some improvement  
			if(pre_frame_time>lasttime){  
				RTMP_LogPrintf("TimeStamp:%8lu ms\n",pre_frame_time);  
				lasttime=pre_frame_time;  
			}  
			sleep(1);  
			continue;  
		}  

		//not quite the same as FLV spec  
		if(!ReadU8(&type,fp))       
			break;  
		if(!ReadU24(&datalength,fp))  
			break;  
		if(!ReadTime(&timestamp,fp))  
			break;  
		if(!ReadU24(&streamid,fp))  
			break;  

		if (type!=0x08&&type!=0x09){  
			//jump over non_audio and non_video frame,  
			//jump over next previousTagSizen at the same time  
			fseek(fp,datalength+4,SEEK_CUR);  
			continue;  
		}  

		if(fread(packet->m_body,1,datalength,fp)!=datalength)  
			break;  

		packet->m_headerType = RTMP_PACKET_SIZE_LARGE;  
		packet->m_nTimeStamp = timestamp;  
		packet->m_packetType = type;  
		packet->m_nBodySize  = datalength;  
		pre_frame_time=timestamp;  

		if (!RTMP_IsConnected(rtmp)){  
			RTMP_Log(RTMP_LOGERROR,"rtmp is not connect\n");  
			break;  
		}  
		if (!RTMP_SendPacket(rtmp,packet,0)){  
			RTMP_Log(RTMP_LOGERROR,"Send Error\n");  
			break;  
		}  

		if(!ReadU32(&preTagsize,fp))  
			break;  

		if(!PeekU8(&type,fp))  
			break;  
		if(type==0x09){  
			if(fseek(fp,11,SEEK_CUR)!=0)  
				break;  
			if(!PeekU8(&type,fp)){  
				break;  
			}  
			if(type==0x17)  
				bNextIsKey=1;  
			else  
				bNextIsKey=0;  

			fseek(fp,-11,SEEK_CUR);  
		}  
	}                 

	RTMP_LogPrintf("\nSend Data Over\n");  

	if(fp)  
		fclose(fp);  

	if (rtmp!=NULL){  
		RTMP_Close(rtmp);          
		RTMP_Free(rtmp);   
		rtmp=NULL;  
	}  
	if (packet!=NULL){  
		RTMPPacket_Free(packet);      
		free(packet);  
		packet=NULL;  
	}  

//	CleanupSockets();  
	return 0;  
}  
Beispiel #9
0
//Publish using RTMP_Write()  
int publish_using_write(){  
	uint32_t start_time=0;  
	uint32_t now_time=0;  
	uint32_t pre_frame_time=0;  
	uint32_t lasttime=0;  
	int bNextIsKey=0;  
	char* pFileBuf=NULL;  

	//read from tag header  
	uint32_t type=0;  
	uint32_t datalength=0;  
	uint32_t timestamp=0;  

	RTMP *rtmp=NULL;                             

	FILE*fp=NULL;  
	fp=fopen("cuc_ieschool.flv","rb");  
	if (!fp){  
		RTMP_LogPrintf("Open File Error.\n");  
//		CleanupSockets();  
		return -1;  
	}  

	/* set log level */  
	//RTMP_LogLevel loglvl=RTMP_LOGDEBUG;  
	//RTMP_LogSetLevel(loglvl);  

//	if (!InitSockets()){  
//		RTMP_LogPrintf("Init Socket Err\n");  
//		return -1;  
//	}  

	rtmp=RTMP_Alloc();  
	RTMP_Init(rtmp);  
	//set connection timeout,default 30s  
	rtmp->Link.timeout=5;                        
	if(!RTMP_SetupURL(rtmp,"rtmp://localhost/publishlive/livestream"))  
	{  
		RTMP_Log(RTMP_LOGERROR,"SetupURL Err\n");  
		RTMP_Free(rtmp);  
	//	CleanupSockets();  
		return -1;  
	}  

	RTMP_EnableWrite(rtmp);  
	//1hour  
	RTMP_SetBufferMS(rtmp, 3600*1000);           
	if (!RTMP_Connect(rtmp,NULL)){  
		RTMP_Log(RTMP_LOGERROR,"Connect Err\n");  
		RTMP_Free(rtmp);  
//		CleanupSockets();  
		return -1;  
	}  

	if (!RTMP_ConnectStream(rtmp,0)){  
		RTMP_Log(RTMP_LOGERROR,"ConnectStream Err\n");  
		RTMP_Close(rtmp);  
		RTMP_Free(rtmp);  
		//CleanupSockets();  
		return -1;  
	}  

	printf("Start to send data ...\n");  

	//jump over FLV Header  
	fseek(fp,9,SEEK_SET);       
	//jump over previousTagSizen  
	fseek(fp,4,SEEK_CUR);     
	start_time=RTMP_GetTime();  
	while(1)  
	{  
		if((((now_time=RTMP_GetTime())-start_time)  
					<(pre_frame_time)) && bNextIsKey){          
			//wait for 1 sec if the send process is too fast  
			//this mechanism is not very good,need some improvement  
			if(pre_frame_time>lasttime){  
				RTMP_LogPrintf("TimeStamp:%8lu ms\n", pre_frame_time);  
				lasttime=pre_frame_time;  
			}  
			sleep(1);  
			continue;  
		}  

		//jump over type  
		fseek(fp,1,SEEK_CUR);     
		if(!ReadU24(&datalength,fp))  
			break;  
		if(!ReadTime(&timestamp,fp))  
			break;  
		//jump back  
		fseek(fp,-8,SEEK_CUR);    

		pFileBuf=(char*)malloc(11+datalength+4);  
		memset(pFileBuf,0,11+datalength+4);  
		if(fread(pFileBuf,1,11+datalength+4,fp)!=(11+datalength+4))  
			break;  

		pre_frame_time=timestamp;  

		if (!RTMP_IsConnected(rtmp)){  
			RTMP_Log(RTMP_LOGERROR,"rtmp is not connect\n");  
			break;  
		}  
		if (!RTMP_Write(rtmp,pFileBuf,11+datalength+4)){  
			RTMP_Log(RTMP_LOGERROR,"Rtmp Write Error\n");  
			break;  
		}  

		free(pFileBuf);  
		pFileBuf=NULL;  

		if(!PeekU8(&type,fp))  
			break;  
		if(type==0x09){  
			if(fseek(fp,11,SEEK_CUR)!=0)  
				break;  
			if(!PeekU8(&type,fp)){  
				break;  
			}  
			if(type==0x17)  
				bNextIsKey=1;  
			else  
				bNextIsKey=0;  
			fseek(fp,-11,SEEK_CUR);  
		}  
	}  

	RTMP_LogPrintf("\nSend Data Over\n");  

	if(fp)  
		fclose(fp);  

	if (rtmp!=NULL){  
		RTMP_Close(rtmp);          
		RTMP_Free(rtmp);  
		rtmp=NULL;  
	}  

	if(pFileBuf){  
		free(pFileBuf);  
		pFileBuf=NULL;  
	}  

	//CleanupSockets();  
	return 0;  
}  
Beispiel #10
0
////-------------------------------------------------------------------------------------------------
////函数名称:             uint8	ExpandCard(stcCardFlg	* sCardFlg)
////函数功能:             扩展卡
////入口参数:             无
////出口参数:             无
////--------------------------------------------------------------------------------------------------
uint8	ExpandCard(void)
{
	uint8	CardType;
	uint32	i;
	uint32	DisTime = 40;		//500ms
	uint32	Time 	= 0;		//500ms
	uint32	Times 	= 0;	
	
	stcTime		sTime;
	stcCardPara	sCardPara;

	if(!ReadCardPara((stcCardPara *)	&sCardPara))
	{	return 0;}


/*	
#ifdef	HARD_VER_090426	
	DisplaySet(150,1,"%u-%u-%u",sTime.Year,sTime.Month,sTime.Date);
	DisplaySet(60,1,"         ");	
	DisplaySet(350,1,"%u-%u-%u.",sTime.Hour,sTime.Min,sTime.Sec);	//等待时间补充
	DisplaySet(60,1,"         ");	
#endif
*/
	CardType = sCardPara.Reserve0;							//卡类型
	
	ReadTime((stcTime *)&sTime);
	i = sTime.Sec + sTime.Min * 60 +  sTime.Hour * 60 * 60;	

	while(1)
	{
		if(CardType == TIME_ADD_CARD)	
		{
			i++;
		}	
		else if(CardType == TIME_SUB_CARD)	
		{
			i--;	
		}
		else
		{
			//printfcom0("\r\n 不是时间卡");
			break;
		}
		
		i = i % (60*60*24);
		
		Times++;
		
		sTime.Sec  =   i % 60;
		sTime.Min  =  (i / 60 ) % 60;
		sTime.Hour =  ((i/60)/60) % 24;
		
		DisplaySet(1,1,"%02u-%02u-%02u.",sTime.Hour,sTime.Min,sTime.Sec);		//
		DelayX10ms(1);		

		Time = GetSysTime();
		while(GetSysTime() - Time < DisTime)
		{
		//SysHoldTast();;
		}
		
		if(DisTime > 4)
		{
			DisTime -= Times/10;		
		}
		
		if(GetPlugFlg() != PLUG_IN_CARD)
		{
			DelayX10ms(200);
			WriteTime(sTime);
			DelayX10ms(100);
			break;
		}
	}
	
	return	1;
}