Hallo,
eine andere Lösung finde ich über Google auch nicht. Im Gegensatz zu Windows scheint Linux dafür keine fertige Betriebssystemfunktion zu haben.
Druckbare Version
ping als Linux-Konsolen-Kommando funktioniert ja, z.B.
(== Google.de)Code:ping 216.58.209.99
- mehr bräuchte ich ja gar nicht!
Nur ob es klappt würde schon reichen, ohne weitere Details.
Ich brauche das eben nur auf C/C++ - Sourcecode-Ebene.
(@Peter-2: wie hattest du es denn vor in deinem 2. Post hier im Topic?
Oder war das nur eine vage Idee ohne genaue Kenntnis, wie man das macht?)
ps,
was ich brauche, ist kein ping Monster-Code, sondern notfalls eine Lib, die ich #includen kann, und dann eine dort implementierte Funktion nutze, in der Art
#include <tcptools.h>
//...
int i = ping("216.58.209.99"); // i<=0: error, i>0: success
printf("%d \n", i);
//...
Du kannst das Kommdozeilen ping auch aus deinem Programm aufrufen.
So wie hier im ersten Listing
http://ubuntuforums.org/showthread.php?t=1803980
super gut! :D
schon das erste Beispielprogramm funktioniert auf Anhieb!
Code:if (system("ping -c1 -s1 www.google.com"))
{
cout<<"There is no internet connection \n";
}
perfekt!
Tausend Dank!
- - - Aktualisiert - - -
so, isch 'abe fertig! :p
jetzt kann ich mit diesen Programmfunktionen die Internet-Verbindung überprüfen und die augenblickliche Systemzeit vorformatiert abfragen
und die ermittelten date/time Integerwerte dann verwenden, um ggf meine RTC nicht nur manuell, sondern auch automatisch per inet zu synchronisieren....Code:#include <iostream>
#include <stdio.h>
#include <time.h>
#include <string.h>
void getdatetime(int &year, int &mon, int &day, int &hour, int &min, int &sec, int &dow) {
time_t t = time(NULL);
struct tm tm = * localtime(&t);
year = (int)tm.tm_year+1900-2000,
mon = (int)tm.tm_mon+1;
day = (int)tm.tm_mday;
hour = (int)tm.tm_hour;
min = (int)tm.tm_min;
sec = (int)tm.tm_sec;
dow = (int)tm.tm_wday+1;
}
int main()
{
char sbuf[100];
int year, mon, day, hour, min, sec, dow;
if (system( "ping -c1 -s1 www.google.de") ) {
printf("internet connx failed \n");
}
else {
printf("internet connx OK ! :) \n");
}
getdatetime(year, mon, day, hour, min, sec, dow) ;
sprintf( sbuf, "%d %d %d %d %d %d %d", year, mon, day, hour, min, sec, dow );
printf(sbuf);
getchar();
return 0;
}
das war der Sinn des ganzen!Code:/*
*
* RTC DS3231
*
* test demo
* ver 0001
*
*/
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <wiringPi.h>
#include <wiringPiI2C.h>
#define byte uint8_t
// RTC DS3231
#define ADDR_RTCDS3231 0x68
int frtcds3231;
//=====================================================================================
// Convert normal decimal numbers to binary coded decimal
//=====================================================================================
byte decToBcd(byte val) { return( (val/10*16) + (val%10) ); }
//=====================================================================================
// Convert binary coded decimal to normal decimal numbers
//=====================================================================================
byte bcdToDec(byte val) { return( (val/16*10) + (val%16) ); }
//=====================================================================================
void setDS3231time( byte year, byte month, byte dayOfMonth, byte hour, byte
minute, byte second, byte dayOfWeek)
{
// sets time and date data to DS3231
wiringPiI2CWriteReg8(frtcds3231, 0, decToBcd(second)); // set seconds
wiringPiI2CWriteReg8(frtcds3231, 1, decToBcd(minute)); // set minutes
wiringPiI2CWriteReg8(frtcds3231, 2, decToBcd(hour)); // set hours
wiringPiI2CWriteReg8(frtcds3231, 3, decToBcd(dayOfWeek)); // ( 1=Sunday, 7=Saturday)
wiringPiI2CWriteReg8(frtcds3231, 4, decToBcd(dayOfMonth)); // set dayOfMonth (1 to 31)
wiringPiI2CWriteReg8(frtcds3231, 5, decToBcd(month)); // set month
wiringPiI2CWriteReg8(frtcds3231, 6, decToBcd(year)); // set year (0 to 99)
}
//=====================================================================================
int main() {
int year, month, dayOfMonth, hour, minute, second, dayOfWeek;
int i=0, check;
char sbuf[100];
frtcds3231 = wiringPiI2CSetupInterface( "/dev/i2c-0", ADDR_RTCDS3231 );
printf(" RTC DS3231 \n");
printf("Set new Date/Time: enter 1\n");
printf("else: display time\n\n");
i = getchar();
//debug
//printf("%d \n", i);
while (i=='1') {
// get string yy mm dd hh mm ss dw : gets() ?
printf("yy mm dd hh mm ss dw (DayOfWeek) \n");
check=scanf("%d %d %d %d %d %d %d", &year, &month, &dayOfMonth, &hour, &minute, &second, &dayOfWeek);
getchar();
printf("check=%d\n", check);
if(check==7) {
printf("%d \n", year);
printf("%d \n", month);
printf("%d \n", dayOfMonth);
printf("%d \n", hour);
printf("%d \n", minute);
printf("%d \n", second);
printf("%d \n", dayOfWeek);
setDS3231time( year, month, dayOfMonth, hour, minute, second, dayOfWeek );
}
printf(" RTC DS3231 \n");
printf("Set new Date/Time: enter 1\n");
printf("else: display time\n\n");
i=0;
i = getchar();
}
while(1) {
second = bcdToDec(wiringPiI2CReadReg8 (frtcds3231, 0) & 0x7f );
minute = bcdToDec(wiringPiI2CReadReg8 (frtcds3231, 1) );
hour = bcdToDec(wiringPiI2CReadReg8 (frtcds3231, 2) & 0x3f );
dayOfWeek = bcdToDec(wiringPiI2CReadReg8 (frtcds3231, 3) );
dayOfMonth = bcdToDec(wiringPiI2CReadReg8 (frtcds3231, 4) );
month = bcdToDec(wiringPiI2CReadReg8 (frtcds3231, 5) );
year = bcdToDec(wiringPiI2CReadReg8 (frtcds3231, 6) );
-
sprintf(sbuf, "20%02d/%02d/%02d %02d:%02d:%02d", year, month, dayOfMonth, hour, minute, second);
printf(sbuf);
printf(" Day of week %1d: ", dayOfWeek);
switch(dayOfWeek){
case 1:
printf("Sunday");
break;
case 2:
printf("Monday");
break;
case 3:
printf("Tuesday");
break;
case 4:
printf("Wednesday");
break;
case 5:
printf("Thursday");
break;
case 6:
printf("Friday");
break;
case 7:
printf("Saturday");
break;
}
printf("\n");
delay (1000);
}
return (0);
}
tausend Dank nochmal Mxt für deine Hilfe!
:cool: