Skip to content

Commit

Permalink
Fix compiler warnings/errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ZXGuesser committed Aug 10, 2020
1 parent 7619833 commit 3608a8e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
33 changes: 16 additions & 17 deletions packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,27 @@ void Packet::SetMRAG(uint8_t mag, uint8_t row)
*/
bool Packet::get_offset_time(char* str)
{
char strTime[6];
time_t rawtime;
struct tm tmGMT;
time( &rawtime );
char strTime[6];
time_t rawtime = time(nullptr);
struct tm *tmGMT;

// What is our offset in seconds?
int offset=((str[3]-'0')*10+str[4]-'0')*30*60; // @todo We really ought to validate this
// What is our offset in seconds?
int offset=((str[3]-'0')*10+str[4]-'0')*30*60; // @todo We really ought to validate this

// Is it negative (west of us?)
if (str[2]=='-')
offset=-offset;
else
if (str[2]!='+') return false; // Must be + or -
// Is it negative (west of us?)
if (str[2]=='-')
offset=-offset;
else
if (str[2]!='+') return false; // Must be + or -

// Add the offset to the time value
rawtime+=offset;
// Add the offset to the time value
rawtime+=offset;

gmtime_r(&rawtime, &tmGMT);
tmGMT = gmtime(&rawtime);

strftime(strTime, 21, "%H:%M", &tmGMT);
stringToBytes(str,strTime,5);
return true;
strftime(strTime, 21, "%H:%M", tmGMT);
stringToBytes(str,strTime,5);
return true;
}

/* Ideally we would set _packet[0] for other hardware, or _packet[3] for Alistair Buxton raspi-teletext/
Expand Down
27 changes: 13 additions & 14 deletions packet830.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ Packet830::~Packet830()

Packet* Packet830::GetPacket(Packet* p)
{
time_t timeRaw;
time_t timeRaw = time(nullptr);
time_t timeLocal;
struct tm tmLocal;
struct tm tmGMT;
struct tm *tmLocal;
struct tm *tmGMT;
int offsetHalfHours, year, month, day, hour, minute, second;
uint32_t modifiedJulianDay;

Expand Down Expand Up @@ -59,14 +59,13 @@ Packet* Packet830::GetPacket(Packet* p)
val[8] = _vbi_bit_reverse[nic & 0xFF];

/* calculate number of seconds local time is offset from UTC */
time(&timeRaw);
localtime_r(&timeRaw, &tmLocal);
tmLocal = localtime(&timeRaw);

/* convert tmLocal into a timestamp without correcting for timezones and summertime */
#ifdef WIN32
timeLocal = _mkgmtime(&tmLocal);
timeLocal = _mkgmtime(tmLocal);
#else
timeLocal = timegm(&tmLocal);
timeLocal = timegm(tmLocal);
#endif

offsetHalfHours = difftime(timeLocal, timeRaw) / 1800;
Expand All @@ -76,13 +75,13 @@ Packet* Packet830::GetPacket(Packet* p)
val[9] = ((offsetHalfHours < 0) ? 0xC1 : 0x81) | ((abs(offsetHalfHours) & 0x1F) << 1);

// get the time current UTC time into separate variables
gmtime_r(&timeRaw, &tmGMT);
year = tmGMT.tm_year + 1900;
month = tmGMT.tm_mon + 1;
day = tmGMT.tm_mday;
hour = tmGMT.tm_hour;
minute = tmGMT.tm_min;
second = tmGMT.tm_sec;
tmGMT = gmtime(&timeRaw);
year = tmGMT->tm_year + 1900;
month = tmGMT->tm_mon + 1;
day = tmGMT->tm_mday;
hour = tmGMT->tm_hour;
minute = tmGMT->tm_min;
second = tmGMT->tm_sec;

modifiedJulianDay = calculateMJD(year, month, day);
// generate five decimal digits of modified julian date decimal digits and increment each one.
Expand Down
4 changes: 2 additions & 2 deletions packetsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ enum Event
EVENT_P830_FORMAT_2_LABEL_3,
EVENT_SUBTITLE,
EVENT_DATABROADCAST,
EVENT_NUMBER_ITEMS,
EVENT_SPECIAL_PAGES,
EVENT_PACKET_29
EVENT_PACKET_29,
EVENT_NUMBER_ITEMS
} ;


Expand Down

0 comments on commit 3608a8e

Please sign in to comment.