|
@@ -0,0 +1,3161 @@
|
|
|
+//**************
|
|
|
+//* MeMod_GSM.c R. Russinger (C)opyright 2008,......
|
|
|
+//*
|
|
|
+//* Applikation für Modem UESL
|
|
|
+
|
|
|
+// wenn definiert dann wird die Spannung nicht überwacht, bzw keine Ladelogik angesteuert
|
|
|
+// sollte beim Bistro Display funktionieren
|
|
|
+
|
|
|
+#include <pthread.h>
|
|
|
+
|
|
|
+#include <stdio.h>
|
|
|
+#include <stdlib.h>
|
|
|
+#include <stdarg.h>
|
|
|
+#include <memory.h>
|
|
|
+#include <errno.h>
|
|
|
+#include <math.h>
|
|
|
+#include <ctype.h>
|
|
|
+#include <string.h>
|
|
|
+#include <time.h>
|
|
|
+
|
|
|
+#include <sys/time.h>
|
|
|
+#include <sys/types.h>
|
|
|
+#include <sys/stat.h>
|
|
|
+
|
|
|
+#include <signal.h>
|
|
|
+
|
|
|
+#include <fcntl.h>
|
|
|
+#include <sys/ioctl.h>
|
|
|
+#include <netdb.h>
|
|
|
+#include <sys/socket.h>
|
|
|
+
|
|
|
+#include <netinet/in.h>
|
|
|
+#include <netinet/ip.h>
|
|
|
+#include <linux/if_arp.h>
|
|
|
+#include <arpa/inet.h>
|
|
|
+#include <unistd.h>
|
|
|
+
|
|
|
+#include <sys/un.h>
|
|
|
+
|
|
|
+#include <sys/sysinfo.h>
|
|
|
+#include <linux/watchdog.h>
|
|
|
+
|
|
|
+//------
|
|
|
+#define SOCKET int
|
|
|
+#define FAR
|
|
|
+#define SOCKET_ERROR -1
|
|
|
+#define INVALID_SOCKET -1
|
|
|
+
|
|
|
+#define closesocket close
|
|
|
+//------
|
|
|
+#include "w32_base.h"
|
|
|
+
|
|
|
+#include "SerUX.h"
|
|
|
+#include "sms_serv.h"
|
|
|
+
|
|
|
+#define MAXSMS 20
|
|
|
+#define VERSION "$Revision: 2.103$"
|
|
|
+
|
|
|
+#ifndef MODEM_TTY
|
|
|
+#define MODEM_TTY "/dev/ttySC1"
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
+extern int GetPrivateProfileSectionNames( char * lpszReturnBuffer, int nSize, char * lpFileName);
|
|
|
+extern int GetPrivateProfileSection(char * lpAppName, char *lpReturnedString, int nSize, char *lpFileName);
|
|
|
+extern int WritePrivateProfileString(char *lpAppName, char *lpKeyName, char *pString, char *lpFileName);
|
|
|
+extern int WINAPI ComModemSMS_Read(unsigned char COM, // Schnittstelle
|
|
|
+ char *Cmd, // Steuersequenz zum Umschalten auf CommandMode
|
|
|
+ int WaitSec, // Warte Sekunden auf Beenden
|
|
|
+ int AnzMbxItems, // Anzahl der Mailboxitems
|
|
|
+ struct mbox_item *message
|
|
|
+ );
|
|
|
+extern void ComModemCleanIn(unsigned char COM);
|
|
|
+extern void SetConnectMessage(char *message);
|
|
|
+extern int CmdIPStart(int argc, char **argv, char **envp);
|
|
|
+extern void SetCmdIPPort(int Port);
|
|
|
+
|
|
|
+extern void Msq_UnLock(void);
|
|
|
+extern void Msq_Lock(void);
|
|
|
+extern void Msq_StartThread(void);
|
|
|
+
|
|
|
+extern void Snap7_UnLock(void);
|
|
|
+extern void Snap7_Lock(void);
|
|
|
+extern void Snap7_StartThread(char *SPSIpAdress, int SPSRack, int SPSSlot, int SPSDBnr);
|
|
|
+extern void Snap7_SetData(char *SPSIpAdress, int SPSRack, int SPSSlot, int SPSDBnr);
|
|
|
+extern int Snap7_InSMS(char *Date, char *Time, char *From, char *Text);
|
|
|
+extern int Snap7_Info(char *Provider, int Asu);
|
|
|
+
|
|
|
+#ifdef PSGDISPLAY
|
|
|
+static pthread_mutex_t TTY7Mutex = PTHREAD_MUTEX_INITIALIZER; // Mutex
|
|
|
+
|
|
|
+int print_moni_tty7(char *string, ...)
|
|
|
+{
|
|
|
+ static int first_call = 1;
|
|
|
+ va_list para;
|
|
|
+ char buf[512];
|
|
|
+ FILE *fp;
|
|
|
+
|
|
|
+ pthread_mutex_lock(&TTY7Mutex);
|
|
|
+//if((_VTGetActive() == 2) || (first_call))
|
|
|
+ {
|
|
|
+ first_call = 0;
|
|
|
+ fp = fopen("/dev/tty7", "a+");
|
|
|
+ va_start(para, string);
|
|
|
+
|
|
|
+ memset(buf,0,sizeof(buf));
|
|
|
+ vsnprintf(buf,sizeof(buf) - 1,string,para);
|
|
|
+
|
|
|
+ if(fp != NULL) {
|
|
|
+ fprintf(fp, "%s", buf);
|
|
|
+ fclose(fp);
|
|
|
+ }
|
|
|
+ va_end(para);
|
|
|
+ }
|
|
|
+ pthread_mutex_unlock(&TTY7Mutex);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+//#define printf print_moni_tty7
|
|
|
+
|
|
|
+#endif
|
|
|
+// Modem auflegen
|
|
|
+// ------------------------------------
|
|
|
+// Zeit seit Systemstart in sekunden
|
|
|
+long uptime(void)
|
|
|
+{
|
|
|
+ struct sysinfo info;
|
|
|
+
|
|
|
+ sysinfo(&info);
|
|
|
+
|
|
|
+ return info.uptime;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// GPRS Einstellungen
|
|
|
+#ifndef GPRS_TTY
|
|
|
+#define GPRS_TTY "/dev/ttySC0"
|
|
|
+#endif
|
|
|
+
|
|
|
+#define GPRS_BAUD 115200
|
|
|
+#define PPPD_CALL "pppd %s user \x22%s\x22 password \x22%s\x22 call gprs &"
|
|
|
+
|
|
|
+#ifndef SSHTUNNELDEFAULT
|
|
|
+#define SSHTUNNELDEFAULT "echo \x22SSHTUNNELDEFAULT undefined !!\x22"
|
|
|
+#endif
|
|
|
+
|
|
|
+#ifndef WWWTUNNELDEFAULT
|
|
|
+#define WWWTUNNELDEFAULT "echo \x22WWWTUNNELDEFAULT undefined !!\x22"
|
|
|
+#endif
|
|
|
+
|
|
|
+static int TimeToModule = 0; // wenn 1 erfolgreiches lesen der Zeit vom Internet >>= nach GSM Modul
|
|
|
+static int TimeFromModule = 0; // wenn 1 übertragen der Zeit vom GSM Modul nach System
|
|
|
+
|
|
|
+//------------------------------------------
|
|
|
+enum ModemType {DEFAULT, PH8_P, PLS8_E, ELS61_E};
|
|
|
+
|
|
|
+struct GSMData {
|
|
|
+ char IMEI[25];
|
|
|
+ char IMSI[25];
|
|
|
+ char SCID[25];
|
|
|
+ char NUM[25]; // SMS Nummer für Meldungen
|
|
|
+
|
|
|
+ char SMSINLOGFILENAME[200]; // Logfilename wenn da dann wird jede eingehende SMS in diese File eingetragen
|
|
|
+ char SMSOUTLOGFILENAME[200]; // Logfilename wenn da dann wird jede ausgehende SMS in diese File eingetragen
|
|
|
+
|
|
|
+ char SSHTUNNELCMD[200]; // Kommando für SSHTUNNEL
|
|
|
+ char WWWTUNNELCMD[200]; // KOMMANDO für WWWTUNNEL
|
|
|
+
|
|
|
+ char MEPWD[20];
|
|
|
+ char MEADR[20];
|
|
|
+
|
|
|
+ char GIP[40];
|
|
|
+ char GSERV[40];
|
|
|
+ char GNUN[25];
|
|
|
+ char GNPW[25];
|
|
|
+ int SENTSTART;
|
|
|
+ int GPORT;
|
|
|
+ int CMDPORT; // Portnummer für Kommandointerface
|
|
|
+ int PING;
|
|
|
+ time_t LastPING; // Zeitpunkt des letzten PING Aufrufes
|
|
|
+ int MBOOT; // Anzahl Minuten für Reboot
|
|
|
+ time_t LastMBOOT; // Zeitpunkt des Systemstartes oder Änderung der Bootzeit
|
|
|
+ int GPRSActive; // Flag ob GPRS noch AKtiv sein soll, damit auc nach einem Neustart Verbindung mit dem Server aufgenommen wird
|
|
|
+ int GPRSNAIL; // Flag ob immer eine GPRS Verbindung aufrecht erhalten wird, also automatisch an GPRS Anmelden > 0 überprüfungsintervall
|
|
|
+ time_t LastGPRSNAIL; // Zeitpunkt der Letzten überprüfung
|
|
|
+ int TSYNC; // Flag für Zeitsynchronisation wenn > 0 wir alle TSYNC minuten das TSYNCCMD ausgeführt
|
|
|
+ time_t LastTSYNC; // Zeitpunkt der Letzten überprüfung
|
|
|
+ char TSYNCCMD[200]; // Kommando für Tsync
|
|
|
+ char WATCHDOGDEVICE[200]; // Gerätename des Watchdogdevice wenn gesetzt wird watchdog im main rs232 zusätzlich aufgezogen
|
|
|
+ char SERDEVINIT[200]; // Kommando das bei "nicht Vorhandener" Schnittstelle aufgerufen wird
|
|
|
+ int SMSF;
|
|
|
+ enum ModemType MODEMTYPE;
|
|
|
+ int SIEMENS_IS_ACTIVE; // Konfiguration vorhanden
|
|
|
+ char SIEMENS_IP[200]; //IP Adresse oder DNS Name der Steuerung
|
|
|
+ int SIEMENS_SLOT; //Slot# der Verbindung
|
|
|
+ int SIEMENS_RACK; //Rack# der Verbindung
|
|
|
+ int SIEMENS_DBNR; //DB# für Datenaustausch
|
|
|
+};
|
|
|
+
|
|
|
+static struct GSMData GSMData, GSMDataWrk;
|
|
|
+
|
|
|
+
|
|
|
+int Snap7_is_active(void) {
|
|
|
+ return GSMData.SIEMENS_IS_ACTIVE;
|
|
|
+}
|
|
|
+
|
|
|
+//-------------------------------------------------------
|
|
|
+// Modem Auflegen falls noch was hängt !!!!
|
|
|
+// und Prozess fehlerhafterweise beendet wurde
|
|
|
+void GprsHangup(void)
|
|
|
+{
|
|
|
+ int ret;
|
|
|
+ int baud;
|
|
|
+
|
|
|
+ printf("GPRS Hangup Open %s : %d \n", GPRS_TTY, ret = ComInitUX(1, GPRS_TTY));
|
|
|
+ if(ret >= 0) {
|
|
|
+ baud = GPRS_BAUD;
|
|
|
+ ComSetState(1,baud,8,1,'N');
|
|
|
+ ComModemHangup(1, "+++", 3, "ATH");
|
|
|
+ sleep(1);
|
|
|
+ ComModemHangup(1, "+++", 3, "ATH");
|
|
|
+ ComReset(1);
|
|
|
+ // alles wieder freigegeben
|
|
|
+ } else {
|
|
|
+ printf("%s:: %s already in Use:: couldnt Init !!\n", __func__, GPRS_TTY);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void CreateGprsConnect(char *ApnName)
|
|
|
+{
|
|
|
+ // connect File erstellen
|
|
|
+ FILE *fp;
|
|
|
+
|
|
|
+ fp = fopen("/etc/ppp/gprs-connect", "w");
|
|
|
+ if(fp != NULL) {
|
|
|
+
|
|
|
+ if(GSMData.MODEMTYPE != ELS61_E) {
|
|
|
+ fprintf(fp, "TIMEOUT 10\nABORT \047BUSY\047\nABORT \047NO ANSWER\047\n"
|
|
|
+ "\042\042 \047\047\n"
|
|
|
+ "\042\042 \047AT\047"
|
|
|
+ "\nABORT \047ERROR\047\n"
|
|
|
+ "OK \047ATZ\047\n"
|
|
|
+ "OK \047ATE0\047\n"
|
|
|
+ "OK \047AT+CGDCONT=1,\042IP\042,\042%s\042\047\n"
|
|
|
+ "ABORT \047NO CARRIER\047\n"
|
|
|
+ "OK \047ATD*99***1#\047\nCONNECT \047\047\n",
|
|
|
+ ApnName);
|
|
|
+ } else {
|
|
|
+ fprintf(fp, "TIMEOUT 10\nABORT \047BUSY\047\nABORT \047NO ANSWER\047\n"
|
|
|
+ "\042\042 \047\047\n"
|
|
|
+ "\042\042 \047AT\047"
|
|
|
+ "\nABORT \047ERROR\047\n"
|
|
|
+ "OK \047ATZ\047\n"
|
|
|
+ "OK \047ATE0\047\n"
|
|
|
+ "OK \047AT+CGACT=0,1\047\n"
|
|
|
+ "OK \047AT+CGDCONT=1,\042IP\042,\042%s\042\047\n"
|
|
|
+ "OK \047AT+CGACT=1,1\047\n"
|
|
|
+ "ABORT \047NO CARRIER\047\n"
|
|
|
+ "OK \047ATD*99***1#\047\nCONNECT \047\047\n",
|
|
|
+ ApnName);
|
|
|
+ }
|
|
|
+ fclose(fp);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#ifndef INI_FILENAME
|
|
|
+#define INI_FILENAME "/var/Display_GSM.ini"
|
|
|
+#endif
|
|
|
+
|
|
|
+#ifndef VENDOR
|
|
|
+#define VENDOR "--VEND--"
|
|
|
+#endif
|
|
|
+
|
|
|
+//static pthread_mutex_t CMDMutex = PTHREAD_MUTEX_INITIALIZER; // Mutex für Kommandobehandlung
|
|
|
+static pthread_mutex_t INIMutex = PTHREAD_MUTEX_INITIALIZER; // Mutex für INIFILE Lesen
|
|
|
+
|
|
|
+pthread_t th_cmd, th_cmdip;
|
|
|
+
|
|
|
+int DoSendStart = 1; // Startinformation als SMS senden
|
|
|
+
|
|
|
+struct mbox_item SMSData[MAXSMS];
|
|
|
+
|
|
|
+struct DYNData {
|
|
|
+ char CMD[200]; // Dyndns Kommando
|
|
|
+ char USER[80]; // Dyndns Username
|
|
|
+ char PWD[80]; //Dyndns Password
|
|
|
+ char ALIAS[80]; //Dyndns aliasname
|
|
|
+} DYNData;
|
|
|
+
|
|
|
+
|
|
|
+char *String2NoControl(char *inbuf, int inSize, char **outbuf_in)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+ int outlen = 0;
|
|
|
+ char *outbuf;
|
|
|
+
|
|
|
+ if(*outbuf_in != NULL) {
|
|
|
+ free(*outbuf_in);
|
|
|
+ }
|
|
|
+
|
|
|
+ *outbuf_in = malloc((inSize + 1) * 2);
|
|
|
+ outbuf = *outbuf_in;
|
|
|
+
|
|
|
+ if(outbuf != NULL) {
|
|
|
+ memset(outbuf, 0, (inSize + 1) * 2);
|
|
|
+ for(i = 0; i < inSize; i++) {
|
|
|
+ switch(*(inbuf + i)) {
|
|
|
+ case 0:
|
|
|
+ *(outbuf + outlen) = '\\';
|
|
|
+ ++outlen;
|
|
|
+ *(outbuf + outlen) = '0';
|
|
|
+ ++outlen;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x27: // single quote
|
|
|
+ *(outbuf + outlen) = '\\';
|
|
|
+ ++outlen;
|
|
|
+ *(outbuf + outlen) = 0x27;
|
|
|
+ ++outlen;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x22: // double quote
|
|
|
+ *(outbuf + outlen) = '\\';
|
|
|
+ ++outlen;
|
|
|
+ *(outbuf + outlen) = 0x22;
|
|
|
+ ++outlen;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x08: // Backspace
|
|
|
+ *(outbuf + outlen) = '\\';
|
|
|
+ ++outlen;
|
|
|
+ *(outbuf + outlen) = 'b';
|
|
|
+ ++outlen;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x0a: // Newline
|
|
|
+ *(outbuf + outlen) = '\\';
|
|
|
+ ++outlen;
|
|
|
+ *(outbuf + outlen) = 'n';
|
|
|
+ ++outlen;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x0d: // carrige return
|
|
|
+ *(outbuf + outlen) = '\\';
|
|
|
+ ++outlen;
|
|
|
+ *(outbuf + outlen) = 'r';
|
|
|
+ ++outlen;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x09: // tabulator
|
|
|
+ *(outbuf + outlen) = '\\';
|
|
|
+ ++outlen;
|
|
|
+ *(outbuf + outlen) = 't';
|
|
|
+ ++outlen;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x1A: // Ctrl - Z
|
|
|
+ *(outbuf + outlen) = '\\';
|
|
|
+ ++outlen;
|
|
|
+ *(outbuf + outlen) = 'Z';
|
|
|
+ ++outlen;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case '\\':
|
|
|
+ *(outbuf + outlen) = '\\';
|
|
|
+ ++outlen;
|
|
|
+ *(outbuf + outlen) = '\\';
|
|
|
+ ++outlen;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ if(isprint(*(inbuf + i))) {
|
|
|
+ *(outbuf + outlen) = *(inbuf + i);
|
|
|
+ ++outlen;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return *outbuf_in;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+char *QuotedString2String(char *inbuf, int inSize, char *outbuf)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+ int outlen = 0;
|
|
|
+ unsigned char LastC = 0;
|
|
|
+
|
|
|
+ if(outbuf != NULL) {
|
|
|
+ memset(outbuf, 0, inSize);
|
|
|
+ for(i = 0; i < inSize; i++) {
|
|
|
+ if(LastC == '\\') {
|
|
|
+ switch (*(inbuf + i)) {
|
|
|
+ case '\\':
|
|
|
+ *(outbuf + outlen) = '\\';
|
|
|
+ ++outlen;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'n':
|
|
|
+ *(outbuf + outlen) = '\n';
|
|
|
+ ++outlen;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'r':
|
|
|
+ *(outbuf + outlen) = '\r';
|
|
|
+ ++outlen;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'b':
|
|
|
+ *(outbuf + outlen) = '\b';
|
|
|
+ ++outlen;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 't':
|
|
|
+ *(outbuf + outlen) = '\t';
|
|
|
+ ++outlen;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ LastC = 0;
|
|
|
+ } else {
|
|
|
+ LastC = *(inbuf + i);
|
|
|
+ if(*(inbuf + i) != '\\') {
|
|
|
+ *(outbuf + outlen) = *(inbuf + i);
|
|
|
+ ++outlen;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return outbuf;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// ------------ Tools später mal in eigene Bibliothek
|
|
|
+void StrTrimNOCRLF(char *cc,int len)
|
|
|
+{
|
|
|
+ // String zurechtstutzen und CR/LF am Ende entfernen
|
|
|
+// Vorlaufende und nachfolgende blans auch entfernen !!!! alles ANderer LAssen
|
|
|
+ int i;
|
|
|
+ int slen;
|
|
|
+
|
|
|
+ if((cc != NULL) && (len > 0)) {
|
|
|
+ // Tabs entfernen
|
|
|
+ for(i = 0; i < len; i++) *(cc+i) = (*(cc+i) == 0x09)?32:*(cc+i);
|
|
|
+
|
|
|
+ i = len - 1;
|
|
|
+ while((i >= 0) && ( (*(cc + i) == 0x0d) || (*(cc + i) == 0x0a) )) {
|
|
|
+ *(cc + i) = 0;
|
|
|
+ --len;
|
|
|
+ i = strlen(cc) - 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // nachfolgende blanks rausnehmen
|
|
|
+ for(i=len-1; i >= 0; i --) {
|
|
|
+ if(*(cc+i) == ' ') {
|
|
|
+ *(cc+i) = 0;
|
|
|
+ } else {
|
|
|
+ // abbrechen der schleife
|
|
|
+ i = -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ i=0;
|
|
|
+ while((i < (int)strlen(cc)) && ( *(cc + i) == ' ') ) ++i;
|
|
|
+
|
|
|
+ slen = strlen(cc + i);
|
|
|
+ memmove(cc,cc+i,slen);
|
|
|
+ memset(cc+slen,0,len-slen);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//--------------------------------------------------------------------
|
|
|
+//--- Aufteilen einer CSV Zeile in einzelne Felder und dann Auswerten
|
|
|
+//--------------------------------------------------------------------
|
|
|
+char *strdelim(char *cc, char *delim)
|
|
|
+{
|
|
|
+ // suchen der Position wo Irgendeiner der DELIM Zeichen Vorkommt, beim Ersten sofort abrechen
|
|
|
+ char *ret = NULL;
|
|
|
+ char **erg = NULL;
|
|
|
+ unsigned int i;
|
|
|
+
|
|
|
+//Anzahl der möglichen Zeiger allocieren
|
|
|
+// damit man sich einen rekursiven Aufruf sparen kann
|
|
|
+ erg = malloc(sizeof(char *) * strlen(delim));
|
|
|
+ if(erg != NULL) {
|
|
|
+ memset(erg, 0, sizeof(char *) * strlen(delim));
|
|
|
+ for( i= 0; i < strlen(delim); i++) {
|
|
|
+ erg[i] = strchr(cc, *(delim + i));
|
|
|
+ }
|
|
|
+ // kleinsten Zeiger Bestimmen
|
|
|
+ ret = NULL;
|
|
|
+ for( i= 0; i < strlen(delim); i++) {
|
|
|
+ if(erg[i] != NULL) {
|
|
|
+ if(ret == NULL) {
|
|
|
+ ret = erg[i];
|
|
|
+ } else {
|
|
|
+ if(erg[i] < ret) {
|
|
|
+ ret = erg[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ free(erg); // freigeben
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int CsvSplitLineEx(char *Fields, int MaxFields, int MaxFieldLength, char *Buff, char *DELIM)
|
|
|
+{
|
|
|
+ char DBuff[255];
|
|
|
+ int i;
|
|
|
+ int ret = -1;
|
|
|
+ char *cc, *ee;
|
|
|
+// Ausgabefeld löschen muss richtig dimensioniert sein !!!
|
|
|
+ memset(Fields, 0, MaxFields * MaxFieldLength);
|
|
|
+
|
|
|
+ cc = Buff;
|
|
|
+ i = 1;
|
|
|
+ while((cc = strdelim(cc,DELIM)) != NULL) {
|
|
|
+ memset(DBuff,0,255);
|
|
|
+ if(i == 1) cc = Buff; // beim Start nochmal zurücksetzen !!!
|
|
|
+ if((ee = strdelim(cc+1,DELIM))!=NULL) {
|
|
|
+ char Olddelim;
|
|
|
+
|
|
|
+ Olddelim = *ee;
|
|
|
+ *ee = 0;
|
|
|
+ memcpy(DBuff,(i == 1)? cc: cc+1,strlen((i == 1) ? cc : cc+1)>254?254:strlen((i == 1)?cc:cc+1));
|
|
|
+ *ee = Olddelim;
|
|
|
+ } else {
|
|
|
+ memcpy(DBuff,(i == 1)? cc: cc+1,strlen(cc+1)>254?254:strlen(cc+1)); // letzter Wert !!
|
|
|
+ }
|
|
|
+ ++cc;
|
|
|
+
|
|
|
+ StrTrimNOCRLF(DBuff,strlen(DBuff));
|
|
|
+
|
|
|
+ if(i < MaxFields) {
|
|
|
+ // In Übergabebuffer eintragen
|
|
|
+ memcpy(Fields + i * MaxFieldLength,DBuff,(int)strlen(DBuff) < (MaxFieldLength - 1)? strlen(DBuff):(MaxFieldLength - 1));
|
|
|
+ }
|
|
|
+ ++i;
|
|
|
+ ret = i;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------
|
|
|
+//-- logdate ausgeben
|
|
|
+int fnameprint_moni(char *fname, char *string, ...)
|
|
|
+{
|
|
|
+ va_list para;
|
|
|
+ char buf[512];
|
|
|
+ char tbuf[40];
|
|
|
+ FILE *fp;
|
|
|
+ time_t akttime;
|
|
|
+ struct tm zeit;
|
|
|
+
|
|
|
+ time(&akttime);
|
|
|
+ zeit = *localtime(&akttime);
|
|
|
+ memset(tbuf, 0, sizeof(tbuf));
|
|
|
+ strftime(tbuf, sizeof(tbuf), "%Y%m%d;%H:%M:%S", &zeit);
|
|
|
+
|
|
|
+ va_start(para, string);
|
|
|
+
|
|
|
+ memset(buf,0,sizeof(buf));
|
|
|
+ vsnprintf(buf,sizeof(buf) - 1,string,para);
|
|
|
+
|
|
|
+ if((fname != NULL) && (strlen(fname) > 0) ) {
|
|
|
+ printf("%s;%s\n", tbuf, buf); // Am Bildschirm nur ausgeben wenn Filename konfiguriert ist
|
|
|
+ fp = fopen(fname,"a+");
|
|
|
+
|
|
|
+ if(fp != NULL) {
|
|
|
+ fprintf(fp, "%s;%s\n", tbuf, buf);
|
|
|
+ fclose(fp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ va_end(para);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------
|
|
|
+//-- Daten in File
|
|
|
+int fnameprint_file(char *fname, int ToStdout, char *mode, char *string, ...)
|
|
|
+{
|
|
|
+ va_list para;
|
|
|
+ char buf[512];
|
|
|
+ char tbuf[40];
|
|
|
+ FILE *fp;
|
|
|
+ time_t akttime;
|
|
|
+ struct tm zeit;
|
|
|
+
|
|
|
+ time(&akttime);
|
|
|
+ zeit = *localtime(&akttime);
|
|
|
+ memset(tbuf, 0, sizeof(tbuf));
|
|
|
+ strftime(tbuf, sizeof(tbuf), "%Y%m%d;%H:%M:%S", &zeit);
|
|
|
+
|
|
|
+ va_start(para, string);
|
|
|
+
|
|
|
+ memset(buf,0,sizeof(buf));
|
|
|
+ vsnprintf(buf,sizeof(buf) - 1,string,para);
|
|
|
+
|
|
|
+ if((fname != NULL) && (strlen(fname) > 0) ) {
|
|
|
+ if(ToStdout) printf("%s;%s\n", tbuf, buf); // Am Bildschirm nur ausgeben wenn Filename konfiguriert ist
|
|
|
+ fp = fopen(fname, mode);
|
|
|
+
|
|
|
+ if(fp != NULL) {
|
|
|
+ int fh;
|
|
|
+ struct flock lock;
|
|
|
+
|
|
|
+ memset(&lock, 0, sizeof(lock));
|
|
|
+
|
|
|
+
|
|
|
+ fh = fileno(fp);
|
|
|
+
|
|
|
+ lock.l_type = F_WRLCK;
|
|
|
+ fcntl(fh, F_SETLKW, &lock);
|
|
|
+
|
|
|
+ fprintf(fp, "%s;%s\n", tbuf, buf);
|
|
|
+
|
|
|
+ lock.l_type = F_UNLCK;
|
|
|
+ fcntl(fh, F_SETLKW, &lock);
|
|
|
+
|
|
|
+ fclose(fp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ va_end(para);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int ping_watchdog(char *fname)
|
|
|
+{
|
|
|
+ int fh, ret;
|
|
|
+
|
|
|
+ if((fname != NULL) && (strlen(fname) > 0) ) {
|
|
|
+ fh = open(fname, O_RDWR);
|
|
|
+
|
|
|
+ if(fh >= 0) {
|
|
|
+ ret = ioctl(fh, WDIOC_KEEPALIVE, NULL);
|
|
|
+ if(ret != 0) printf("WDT_PING %d\n", ret);
|
|
|
+ close(fh);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+char *ComModemSMS_PDU_Log(unsigned char COM, // Schnittstelle
|
|
|
+ char *Number, // Nummer
|
|
|
+ char *Message, // SMS Message
|
|
|
+ int WaitSec // Warte Sekunden auf Beenden
|
|
|
+ )
|
|
|
+
|
|
|
+{
|
|
|
+#define SMS_MAXLEN 160
|
|
|
+
|
|
|
+ char *ret = NULL;
|
|
|
+ char *Htext = NULL;
|
|
|
+ char *SMessage = NULL;
|
|
|
+ int MessageLen = 0;
|
|
|
+ int MessageLenSent = 0;
|
|
|
+ int retry;
|
|
|
+ char Buf[1024]; //SMS Buffer
|
|
|
+
|
|
|
+ MessageLen = strlen(Message);
|
|
|
+
|
|
|
+ SMessage = malloc(MessageLen + 1);
|
|
|
+ if(SMessage != NULL) {
|
|
|
+ memset(SMessage, 0 , MessageLen + 1);
|
|
|
+
|
|
|
+ QuotedString2String(Message, MessageLen, SMessage);
|
|
|
+
|
|
|
+ /** Maximallänge von SMS_MAXLEN Zeichen beachten **/
|
|
|
+ MessageLen = strlen(SMessage);
|
|
|
+ MessageLenSent = 0;
|
|
|
+
|
|
|
+ do {
|
|
|
+ int ToCopy;
|
|
|
+ char MessageToSend[SMS_MAXLEN + 1];
|
|
|
+
|
|
|
+ if((MessageLen - MessageLenSent) > SMS_MAXLEN) {
|
|
|
+ ToCopy = SMS_MAXLEN;
|
|
|
+ } else {
|
|
|
+ ToCopy = MessageLen - MessageLenSent;
|
|
|
+ }
|
|
|
+
|
|
|
+ memset(MessageToSend, 0, sizeof(MessageToSend));
|
|
|
+ memcpy(MessageToSend, SMessage + MessageLenSent, ToCopy);
|
|
|
+
|
|
|
+ retry = 3;
|
|
|
+ do {
|
|
|
+ ret = ComModemSMS_PDU(COM, Number, MessageToSend, WaitSec, Buf, sizeof(Buf));
|
|
|
+ if(strstr(ret,"ERROR") != NULL) {
|
|
|
+ printf("SMS Send retry %d\n", retry--);
|
|
|
+ sleep(5);
|
|
|
+ } else {
|
|
|
+ retry = -1;
|
|
|
+ }
|
|
|
+ } while(retry >= 0);
|
|
|
+
|
|
|
+ MessageLenSent += ToCopy;
|
|
|
+ } while(MessageLenSent != MessageLen);
|
|
|
+
|
|
|
+ String2NoControl(SMessage, strlen(SMessage), &Htext);
|
|
|
+ if(Htext != NULL) {
|
|
|
+ fnameprint_moni(GSMData.SMSOUTLOGFILENAME, "%s;\x22%s\x22", Number, Htext);
|
|
|
+ printf(">>%s<<\n", ret);
|
|
|
+ if(strstr(ret,"ERROR") != NULL) {
|
|
|
+ String2NoControl(ret, strlen(ret), &Htext);
|
|
|
+ if(Htext != NULL)
|
|
|
+ fnameprint_moni(GSMData.SMSOUTLOGFILENAME, "%s;ERR::\x22%s\x22", Number, Htext);
|
|
|
+ }
|
|
|
+
|
|
|
+ free(Htext);
|
|
|
+ }
|
|
|
+
|
|
|
+ free(SMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+//-------------------------------------------------------
|
|
|
+//---------- Konfi Datei einlesen
|
|
|
+void ReadKonfiCommon(long len, char *SectName, char *Data)
|
|
|
+{
|
|
|
+ char *Such;
|
|
|
+
|
|
|
+ do {
|
|
|
+ //--- Hier die Section überprüfen
|
|
|
+ Such = "IMEI=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ char *Imei;
|
|
|
+ memset(GSMData.IMEI, 0, sizeof(GSMData.IMEI));
|
|
|
+ Imei = Data + strlen(Such);
|
|
|
+
|
|
|
+ if((strlen(Imei) < 16) && (*Imei != '0')) {
|
|
|
+ // vorlaufende Null einfügen
|
|
|
+ strncat(GSMData.IMEI, "0", sizeof(GSMData.IMEI));
|
|
|
+ }
|
|
|
+ strncat(GSMData.IMEI, Data + strlen(Such), sizeof(GSMData.IMEI));
|
|
|
+ }
|
|
|
+ Such = "IMSI=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.IMSI, 0, sizeof(GSMData.IMSI));
|
|
|
+ strncat(GSMData.IMSI, Data + strlen(Such), sizeof(GSMData.IMSI));
|
|
|
+ }
|
|
|
+ Such = "SCID=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.SCID, 0, sizeof(GSMData.SCID));
|
|
|
+ strncat(GSMData.SCID, Data + strlen(Such), sizeof(GSMData.SCID));
|
|
|
+ }
|
|
|
+ Such = "PING=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ GSMData.PING = atoi( Data + strlen(Such));
|
|
|
+ GSMData.LastPING = time(NULL); // Beim Setzen eines Neuen Wertes wird auch der Zähler aufgezogen
|
|
|
+ }
|
|
|
+ Such = "MBOOT=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ GSMData.MBOOT = atoi( Data + strlen(Such));
|
|
|
+ GSMData.LastMBOOT = uptime(); // Beim Setzen eines Neuen Wertes wird auch der Zähler aufgezogen
|
|
|
+ }
|
|
|
+ Such = "GPRSNAIL=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ GSMData.GPRSNAIL = atoi( Data + strlen(Such));
|
|
|
+ GSMData.LastGPRSNAIL = uptime() - GSMData.GPRSNAIL * 60; // sofort bei Änderung prüfen
|
|
|
+ }
|
|
|
+ Such = "TSYNC=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ if(GSMData.TSYNC != atoi( Data + strlen(Such))) {
|
|
|
+ // nur bei Änderung !
|
|
|
+ GSMData.TSYNC = atoi( Data + strlen(Such));
|
|
|
+ GSMData.LastTSYNC = uptime() - GSMData.TSYNC * 60; // sofort bei Änderung prüfen
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Such = "TSYNCCMD=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.TSYNCCMD, 0, sizeof(GSMData.TSYNCCMD));
|
|
|
+ strncat(GSMData.TSYNCCMD, Data + strlen(Such), sizeof(GSMData.TSYNCCMD) - 1);
|
|
|
+ }
|
|
|
+ Such = "SSHTUNNELCMD=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.SSHTUNNELCMD, 0, sizeof(GSMData.SSHTUNNELCMD));
|
|
|
+ strncat(GSMData.SSHTUNNELCMD, Data + strlen(Such), sizeof(GSMData.SSHTUNNELCMD) - 1);
|
|
|
+ }
|
|
|
+ Such = "WWWTUNNELCMD=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.WWWTUNNELCMD, 0, sizeof(GSMData.WWWTUNNELCMD));
|
|
|
+ strncat(GSMData.WWWTUNNELCMD, Data + strlen(Such), sizeof(GSMData.WWWTUNNELCMD) - 1);
|
|
|
+ }
|
|
|
+ Such = "WATCHDOGDEVICE=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.WATCHDOGDEVICE, 0, sizeof(GSMData.WATCHDOGDEVICE));
|
|
|
+ strncat(GSMData.WATCHDOGDEVICE, Data + strlen(Such), sizeof(GSMData.WATCHDOGDEVICE) - 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ Such = "SERDEVINIT=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.SERDEVINIT, 0, sizeof(GSMData.SERDEVINIT));
|
|
|
+ strncat(GSMData.SERDEVINIT, Data + strlen(Such), sizeof(GSMData.SERDEVINIT) - 1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Such = "SENTSTART=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ GSMData.SENTSTART = atoi( Data + strlen(Such));
|
|
|
+ }
|
|
|
+ Such = "NUM=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.NUM, 0, sizeof(GSMData.NUM));
|
|
|
+ strncat(GSMData.NUM, Data + strlen(Such), sizeof(GSMData.NUM));
|
|
|
+ }
|
|
|
+ Such = "SMSF=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ GSMData.SMSF = atoi( Data + strlen(Such));
|
|
|
+ }
|
|
|
+ Such = "GPRSACTIVE=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ GSMData.GPRSActive = atoi( Data + strlen(Such));
|
|
|
+ }
|
|
|
+ Such = "SMSINLOGFILENAME=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.SMSINLOGFILENAME, 0, sizeof(GSMData.SMSINLOGFILENAME));
|
|
|
+ strncat(GSMData.SMSINLOGFILENAME, Data + strlen(Such), sizeof(GSMData.SMSINLOGFILENAME) - 1);
|
|
|
+ }
|
|
|
+ Such = "SMSOUTLOGFILENAME=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.SMSOUTLOGFILENAME, 0, sizeof(GSMData.SMSOUTLOGFILENAME));
|
|
|
+ strncat(GSMData.SMSOUTLOGFILENAME, Data + strlen(Such), sizeof(GSMData.SMSOUTLOGFILENAME) - 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ Data += strlen(Data) + 1;
|
|
|
+ } while(strlen(Data));
|
|
|
+
|
|
|
+//-------------------------------
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void ReadKonfiGPRS(long len, char *SectName, char *Data)
|
|
|
+{
|
|
|
+ char *Such;
|
|
|
+
|
|
|
+ do {
|
|
|
+ //--- Hier die Section überprüfen
|
|
|
+ Such = "GIP=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.GIP, 0, sizeof(GSMData.GIP));
|
|
|
+ strncat(GSMData.GIP, Data + strlen(Such), sizeof(GSMData.GIP));
|
|
|
+ }
|
|
|
+
|
|
|
+ Such = "GSERV=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.GSERV, 0, sizeof(GSMData.GSERV));
|
|
|
+ strncat(GSMData.GSERV, Data + strlen(Such), sizeof(GSMData.GSERV));
|
|
|
+ }
|
|
|
+
|
|
|
+ Such = "GNUN=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.GNUN, 0, sizeof(GSMData.GNUN));
|
|
|
+ strncat(GSMData.GNUN, Data + strlen(Such), sizeof(GSMData.GNUN));
|
|
|
+ }
|
|
|
+
|
|
|
+ Such = "GNPW=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.GNPW, 0, sizeof(GSMData.GNPW));
|
|
|
+ strncat(GSMData.GNPW, Data + strlen(Such), sizeof(GSMData.GNPW));
|
|
|
+ }
|
|
|
+
|
|
|
+ Such = "GPORT=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ GSMData.GPORT = atoi( Data + strlen(Such));
|
|
|
+ }
|
|
|
+
|
|
|
+ Such = "CMDPORT=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ GSMData.CMDPORT = atoi( Data + strlen(Such));
|
|
|
+ }
|
|
|
+
|
|
|
+ Data += strlen(Data) + 1;
|
|
|
+ } while(strlen(Data));
|
|
|
+
|
|
|
+//-------------------------------
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+void ReadKonfiDYN(long len, char *SectName, char *Data)
|
|
|
+{
|
|
|
+ char *Such;
|
|
|
+
|
|
|
+ do {
|
|
|
+ //--- Hier die Section überprüfen
|
|
|
+ Such = "CMD=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(DYNData.CMD, 0, sizeof(DYNData.CMD));
|
|
|
+ strncat(DYNData.CMD, Data + strlen(Such), sizeof(DYNData.CMD));
|
|
|
+ }
|
|
|
+
|
|
|
+ Such = "USER=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(DYNData.USER, 0, sizeof(DYNData.USER));
|
|
|
+ strncat(DYNData.USER, Data + strlen(Such), sizeof(DYNData.USER));
|
|
|
+ }
|
|
|
+
|
|
|
+ Such = "PWD=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(DYNData.PWD, 0, sizeof(DYNData.PWD));
|
|
|
+ strncat(DYNData.PWD, Data + strlen(Such), sizeof(DYNData.PWD));
|
|
|
+ }
|
|
|
+
|
|
|
+ Such = "ALIAS=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(DYNData.ALIAS, 0, sizeof(DYNData.ALIAS));
|
|
|
+ strncat(DYNData.ALIAS, Data + strlen(Such), sizeof(DYNData.ALIAS));
|
|
|
+ }
|
|
|
+
|
|
|
+ Data += strlen(Data) + 1;
|
|
|
+ } while(strlen(Data));
|
|
|
+
|
|
|
+//-------------------------------
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+void ReadKonfiMeter(long len, char *SectName, char *Data)
|
|
|
+{
|
|
|
+ char *Such;
|
|
|
+
|
|
|
+ do {
|
|
|
+ //--- Hier die Section überprüfen
|
|
|
+ Such = "MEPWD=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.MEPWD, 0, sizeof(GSMData.MEPWD));
|
|
|
+ strncat(GSMData.MEPWD, Data + strlen(Such), sizeof(GSMData.MEPWD));
|
|
|
+ }
|
|
|
+ Such = "MEADR=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.MEADR, 0, sizeof(GSMData.MEADR));
|
|
|
+ strncat(GSMData.MEADR, Data + strlen(Such), sizeof(GSMData.MEADR));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Data += strlen(Data) + 1;
|
|
|
+ } while(strlen(Data));
|
|
|
+
|
|
|
+//-------------------------------
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+void ReadKonfiSIEMENS(long len, char *SectName, char *Data)
|
|
|
+{
|
|
|
+ char *Such;
|
|
|
+
|
|
|
+ do {
|
|
|
+ //--- Hier die Section überprüfen
|
|
|
+ Such = "SIEMENS_IP=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.SIEMENS_IP, 0, sizeof(GSMData.SIEMENS_IP));
|
|
|
+ strncat(GSMData.SIEMENS_IP, Data + strlen(Such), sizeof(GSMData.SIEMENS_IP));
|
|
|
+ GSMData.SIEMENS_IS_ACTIVE = 1;
|
|
|
+ }
|
|
|
+ Such = "SIEMENS_SLOT=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ GSMData.SIEMENS_SLOT = atoi( Data + strlen(Such));
|
|
|
+ }
|
|
|
+ Such = "SIEMENS_RACK=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ GSMData.SIEMENS_RACK = atoi( Data + strlen(Such));
|
|
|
+ }
|
|
|
+ Such = "SIEMENS_DBNR=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ GSMData.SIEMENS_DBNR = atoi( Data + strlen(Such));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Data += strlen(Data) + 1;
|
|
|
+ } while(strlen(Data));
|
|
|
+
|
|
|
+//-------------------------------
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int ReadKonfi(char *FName)
|
|
|
+{
|
|
|
+ enum SectNames {
|
|
|
+ UNDEF,
|
|
|
+ COMMON,
|
|
|
+ GPRS,
|
|
|
+ METER,
|
|
|
+ DYNDNS,
|
|
|
+ SIEMENS,
|
|
|
+ } SectNames;
|
|
|
+
|
|
|
+ int ret = -1;
|
|
|
+ struct stat IniStat;
|
|
|
+ time_t htime,mboottime,gprsnailtime,tsynctime,tsync;
|
|
|
+ enum ModemType mtype;
|
|
|
+ pthread_mutex_lock(&INIMutex);
|
|
|
+
|
|
|
+ htime = GSMData.LastPING; // Zeit Merken
|
|
|
+ mboottime = GSMData.LastMBOOT; // Zeit Merken
|
|
|
+ gprsnailtime = GSMData.LastGPRSNAIL; // Zeit Merken
|
|
|
+ tsynctime = GSMData.LastTSYNC; // Zeit Merken
|
|
|
+ tsync = GSMData.TSYNC;
|
|
|
+ mtype = GSMData.MODEMTYPE;
|
|
|
+ memset(&GSMData, 0, sizeof(struct GSMData));
|
|
|
+ GSMData.LastPING = htime; // Zeit wieder setzen
|
|
|
+ GSMData.LastMBOOT = mboottime; // Zeit wieder setzen
|
|
|
+ GSMData.LastGPRSNAIL = gprsnailtime; // Zeit wieder setzen
|
|
|
+ GSMData.LastTSYNC = tsynctime; // Zeit wieder setzen
|
|
|
+ GSMData.TSYNC = tsync; // Z
|
|
|
+ GSMData.MODEMTYPE = mtype;
|
|
|
+ GSMData.SIEMENS_IS_ACTIVE = 0; // nachsehen ob aktiviert
|
|
|
+ ret = stat(FName, &IniStat);
|
|
|
+//-----------------------------------------------------
|
|
|
+
|
|
|
+ if(ret == 0) {
|
|
|
+ //Ini File vorhanden weitermachen
|
|
|
+ char *Sections = NULL;
|
|
|
+
|
|
|
+ Sections = malloc(IniStat.st_size);
|
|
|
+ if(Sections != NULL) {
|
|
|
+ int i;
|
|
|
+ int len;
|
|
|
+ char *cc;
|
|
|
+
|
|
|
+ len = GetPrivateProfileSectionNames(Sections, IniStat.st_size, FName);
|
|
|
+
|
|
|
+ i = 0;
|
|
|
+ cc = Sections;
|
|
|
+
|
|
|
+ do {
|
|
|
+ char *Data;
|
|
|
+
|
|
|
+ // hier jede Section verfügbar
|
|
|
+ //-----------------------------
|
|
|
+ SectNames = UNDEF;
|
|
|
+ if(strnicmp(cc,"Common",6) == 0) {
|
|
|
+ SectNames = COMMON;
|
|
|
+ } else if(strnicmp(cc,"GPRS", 4) == 0) {
|
|
|
+ SectNames = GPRS;
|
|
|
+ } else if(strnicmp(cc,"METER", 4) == 0) {
|
|
|
+ SectNames = METER;
|
|
|
+ }
|
|
|
+ else if(strnicmp(cc,"DYNDNS", 4) == 0) {
|
|
|
+ SectNames = DYNDNS;
|
|
|
+ }
|
|
|
+ else if(strnicmp(cc,"SIEMENS", 7) == 0) {
|
|
|
+ SectNames = SIEMENS;
|
|
|
+ }
|
|
|
+
|
|
|
+ Data = malloc(IniStat.st_size);
|
|
|
+
|
|
|
+ if(Data != NULL) {
|
|
|
+ int i;
|
|
|
+ int len;
|
|
|
+ char *ss;
|
|
|
+
|
|
|
+ memset(Data, 0, IniStat.st_size);
|
|
|
+ len = GetPrivateProfileSection(cc, Data, IniStat.st_size, FName);
|
|
|
+
|
|
|
+ i = 0;
|
|
|
+ ss = Data;
|
|
|
+
|
|
|
+ switch(SectNames) {
|
|
|
+ case COMMON:
|
|
|
+ ReadKonfiCommon(len, cc, Data);
|
|
|
+ break;
|
|
|
+ case GPRS:
|
|
|
+ ReadKonfiGPRS(len, cc, Data);
|
|
|
+ break;
|
|
|
+ case METER:
|
|
|
+ ReadKonfiMeter(len, cc, Data);
|
|
|
+ break;
|
|
|
+ case DYNDNS:
|
|
|
+ ReadKonfiDYN(len, cc, Data);
|
|
|
+ break;
|
|
|
+ case SIEMENS:
|
|
|
+ ReadKonfiSIEMENS(len, cc, Data);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ free(Data);
|
|
|
+ }
|
|
|
+ //-----------------------------
|
|
|
+ cc += strlen(cc) + 1;
|
|
|
+ } while(strlen(cc));
|
|
|
+
|
|
|
+ free(Sections);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ pthread_mutex_unlock(&INIMutex);
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+// aus IMSI Zugangsdaten übernehmen
|
|
|
+// Eintragungen überschreiben Immer !! die anderen einstellungen
|
|
|
+// und werden in die Haupteinstellungen übernommen
|
|
|
+int ReadKonfiIMSI(char *FName, char *IMSI)
|
|
|
+{
|
|
|
+ int ret = 0;
|
|
|
+ char Hbuf[40];
|
|
|
+ char Info[1024];
|
|
|
+ char *Data;
|
|
|
+ char *Such;
|
|
|
+
|
|
|
+ memset(Hbuf, 0, sizeof(Hbuf));
|
|
|
+ sprintf(Hbuf, "IMSI=%5.5s", IMSI);
|
|
|
+
|
|
|
+ memset(Info, 0, sizeof(Info));
|
|
|
+
|
|
|
+ ret = GetPrivateProfileSection(Hbuf, Info, sizeof(Info), FName);
|
|
|
+ Data = Info;
|
|
|
+ do {
|
|
|
+ //--- Hier die Section überprüfen
|
|
|
+ printf("%s\n", Data);
|
|
|
+ Such = "GIP=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.GIP, 0, sizeof(GSMData.GIP));
|
|
|
+ strncat(GSMData.GIP, Data + strlen(Such), sizeof(GSMData.GIP));
|
|
|
+ WritePrivateProfileString("GPRS", "GIP", GSMData.GIP, FName);
|
|
|
+ }
|
|
|
+
|
|
|
+ Such = "GNUN=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.GNUN, 0, sizeof(GSMData.GNUN));
|
|
|
+ strncat(GSMData.GNUN, Data + strlen(Such), sizeof(GSMData.GNUN));
|
|
|
+ WritePrivateProfileString("GPRS", "GNUN", GSMData.GNUN, FName);
|
|
|
+ }
|
|
|
+
|
|
|
+ Such = "GNPW=";
|
|
|
+ if(!strnicmp(Such, Data, strlen(Such))) {
|
|
|
+ memset(GSMData.GNPW, 0, sizeof(GSMData.GNPW));
|
|
|
+ strncat(GSMData.GNPW, Data + strlen(Such), sizeof(GSMData.GNPW));
|
|
|
+ WritePrivateProfileString("GPRS", "GNPW", GSMData.GNPW, FName);
|
|
|
+ }
|
|
|
+
|
|
|
+ Data += strlen(Data) + 1;
|
|
|
+ } while(strlen(Data));
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+//------------------------------------------
|
|
|
+/*
|
|
|
+ Example code to obtain IP and MAC for all available interfaces on Linux.
|
|
|
+ by Adam Pierce <adam@doctort.org>
|
|
|
+ http://www.doctort.org/adam/
|
|
|
+*/
|
|
|
+int ifconfig(char *InfoTxt, int Len, char *Buf)
|
|
|
+{
|
|
|
+ extern char *inet_ntoa(struct in_addr in);
|
|
|
+ extern char *ether_ntoa(void *addr);
|
|
|
+
|
|
|
+ struct ifconf ifc;
|
|
|
+ struct ifreq ifr[64];
|
|
|
+ int sck;
|
|
|
+ int nInterfaces;
|
|
|
+ int i;
|
|
|
+
|
|
|
+ memset(Buf, 0, Len);
|
|
|
+ sprintf(Buf, "%s ", InfoTxt);
|
|
|
+
|
|
|
+ /* Get a socket handle. */
|
|
|
+ sck = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
+ if(sck < 0) {
|
|
|
+ perror("socket");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Query available interfaces. */
|
|
|
+ memset(ifr, 0, sizeof(ifr));
|
|
|
+ ifc.ifc_len = sizeof(ifr);
|
|
|
+ ifc.ifc_buf = (char *)ifr;
|
|
|
+ if(ioctl(sck, SIOCGIFCONF, &ifc) < 0) {
|
|
|
+ perror("ioctl(SIOCGIFCONF)");
|
|
|
+ close(sck);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Iterate through the list of interfaces. */
|
|
|
+ nInterfaces = ifc.ifc_len / sizeof(struct ifreq);
|
|
|
+ for(i = 0; i < nInterfaces; i++) {
|
|
|
+ struct ifreq *item = &ifr[i];
|
|
|
+
|
|
|
+ if(strstr(Buf, item->ifr_name) == NULL) {
|
|
|
+ /* Show the device name and IP address */
|
|
|
+ sprintf(Buf + strlen(Buf), "%s: IP %s",
|
|
|
+ item->ifr_name,
|
|
|
+ inet_ntoa(((struct sockaddr_in *)&item->ifr_addr)->sin_addr));
|
|
|
+
|
|
|
+ /* Get the MAC address */
|
|
|
+ if(ioctl(sck, SIOCGIFHWADDR, item) < 0) {
|
|
|
+ perror("ioctl(SIOCGIFHWADDR)");
|
|
|
+ close(sck);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ sprintf(Buf + strlen(Buf), ", MAC %s\n", ether_ntoa((void *)(item->ifr_hwaddr.sa_data)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ close(sck);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+//----------------------------------------------------------------
|
|
|
+// --- Auswertung der Kommandos
|
|
|
+// ---
|
|
|
+// Antwort auf Kommando in Zielstring einkopieren
|
|
|
+//
|
|
|
+int DoMeModCmdAnswer(int AnsLen, char *AnsText, char *Answer)
|
|
|
+{
|
|
|
+ int ret = 0;
|
|
|
+
|
|
|
+ if((AnsText != NULL) && (AnsLen > 0)) {
|
|
|
+ // nur wenn was getan werden kann/muss
|
|
|
+ memset(AnsText, 0, AnsLen);
|
|
|
+ memcpy(AnsText, Answer, (strlen(Answer) > (AnsLen - 1))?(AnsLen - 1):strlen(Answer));
|
|
|
+ ret = strlen(AnsText);
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+//--------------------
|
|
|
+// Typ ...
|
|
|
+// 0 .. Kommando über SMS
|
|
|
+// 1 .. Kommando über Serielle Leitung
|
|
|
+// 3 .. Kommando über GPRS
|
|
|
+// 4 .. Aufruf Intern
|
|
|
+// 5 .. Aufruf über CMD Server
|
|
|
+//
|
|
|
+// CmdText ... Text des Angegebenen Kommandos !
|
|
|
+// AnsLen ... Maximallänge im Antwortstring
|
|
|
+// IniFilename ... Dateiname des Ini Files
|
|
|
+//
|
|
|
+//
|
|
|
+
|
|
|
+#define ANZ_BYTES_CMDANSWER 4096
|
|
|
+
|
|
|
+char *strstrCMD(char *cc, char *such)
|
|
|
+{
|
|
|
+ // Kommando muss mit erstem Zeichen beginnen
|
|
|
+ char *ret;
|
|
|
+
|
|
|
+ ret = strstr(cc, such);
|
|
|
+
|
|
|
+ return ret == cc ? ret : NULL;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int DoMeModCmd(int Typ, char *CmdText, int AnsLen, char *AnsText, char *IniFilename)
|
|
|
+{
|
|
|
+ static pthread_mutex_t CMDMutex = PTHREAD_MUTEX_INITIALIZER; // Mutex für Kommandobehandlung
|
|
|
+ char *Hbuf, *cc;
|
|
|
+ int HbufLen;
|
|
|
+ int ret = -1;
|
|
|
+
|
|
|
+ pthread_mutex_lock(&CMDMutex);
|
|
|
+// Arbeitsbereich allocieren
|
|
|
+ if(AnsLen > ANZ_BYTES_CMDANSWER) {
|
|
|
+ // Wenn eine größere Antwort erwartet wird
|
|
|
+ Hbuf = malloc(AnsLen);
|
|
|
+ HbufLen = AnsLen;
|
|
|
+ } else {
|
|
|
+ Hbuf = malloc(ANZ_BYTES_CMDANSWER);
|
|
|
+ HbufLen = ANZ_BYTES_CMDANSWER;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(Hbuf != NULL) {
|
|
|
+ // nur wenn sich das ganze auch reservieren lässt !!
|
|
|
+ if(strstrCMD(CmdText, "*VER?") != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "VER Display_GSM %6.6s " VENDOR "; SCID %s; IMSI %s, IMEI %s; PING %d; PORT %d", VERSION + 10,
|
|
|
+ GSMData.SCID, GSMData.IMSI, GSMData.IMEI, GSMData.PING, GSMData.GPORT);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if (strstrCMD(CmdText, "*IFCONFIG?") != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+
|
|
|
+ ifconfig("IFCONFIG", HbufLen, Hbuf);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if (strstrCMD(CmdText, "*SYSINFO?") != NULL) {
|
|
|
+ struct sysinfo info;
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+
|
|
|
+ sysinfo(&info);
|
|
|
+
|
|
|
+ sprintf(Hbuf, "SYSINFO uptime %ld; TotRam %ld; FreeRam %ld; BufRam %ld; NumProcs %d", info.uptime, info.totalram, info.freeram, info.bufferram, info.procs);
|
|
|
+
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if (strstrCMD(CmdText, "*CMDR ") != NULL) {
|
|
|
+ // Kommando mit Ergebis zurück !
|
|
|
+ FILE *fp;
|
|
|
+ char CmdBuf[255];
|
|
|
+
|
|
|
+ memset(CmdBuf, 0, sizeof(CmdBuf));
|
|
|
+ sprintf(CmdBuf, "%s | tr -s \"[:space:]\" | tr \"\\n\\r\" \";\" > /tmp/cmds.out", CmdText + 6);
|
|
|
+ printf("*CMDR %s\n", CmdBuf);
|
|
|
+ system(CmdBuf);
|
|
|
+
|
|
|
+ fp = fopen("/tmp/cmds.out", "r");
|
|
|
+ if(fp != NULL) {
|
|
|
+ printf("CMDR Open OK!\n");
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ while(fread(Hbuf, 1, HbufLen - 1, fp) > 0) {
|
|
|
+ // gesamte ausgabe zurück !!
|
|
|
+ char *cc;
|
|
|
+
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ }
|
|
|
+ fclose(fp);
|
|
|
+ }
|
|
|
+ } else if (strstrCMD(CmdText, "*CMD ") != NULL) {
|
|
|
+ // Kommando ohne Ergebnis wird immer mit '&' gestartet damit nichts hängenbleibt
|
|
|
+ FILE *fp;
|
|
|
+ char CmdBuf[255];
|
|
|
+
|
|
|
+ memset(CmdBuf, 0, sizeof(CmdBuf));
|
|
|
+ sprintf(CmdBuf, "%s %c", CmdText + 6, strrchr(CmdText + 6, '&')?' ':'&' );
|
|
|
+ printf("*CMD %s\n", CmdBuf);
|
|
|
+ system(CmdBuf);
|
|
|
+
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, "CMD started");
|
|
|
+ }
|
|
|
+ else if ((cc = strstrCMD(CmdText, "*SMS=")) != NULL) {
|
|
|
+ // AT Kommando absetzen
|
|
|
+ char PhoneNumber[40];
|
|
|
+ char *TextStart;
|
|
|
+
|
|
|
+ memset(PhoneNumber, 0, sizeof(PhoneNumber));
|
|
|
+ if((TextStart = strchr(cc + 5, ' ')) == NULL)
|
|
|
+ TextStart = strchr(cc + 5, ';');
|
|
|
+
|
|
|
+ if(TextStart != NULL) {
|
|
|
+ *TextStart = 0;
|
|
|
+ strncat(PhoneNumber, cc + 5, sizeof(PhoneNumber) - 1);
|
|
|
+
|
|
|
+ ComModemSMS_PDU_Log(0, PhoneNumber, TextStart + 1, 50);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ snprintf(Hbuf, HbufLen - 1, "SentSMS=%s %s", PhoneNumber, TextStart + 1);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ }
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*SMSINLOGFILENAME?")) != NULL) {
|
|
|
+ // LOGFILENAME für eingehende SMS lesen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SMSINLOGFILENAME %s", GSMData.SMSINLOGFILENAME);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*SMSINLOGFILENAME ")) != NULL) {
|
|
|
+ // LOGFILENAME für eingehende SMS setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 18);
|
|
|
+
|
|
|
+ WritePrivateProfileString("Common", "SMSINLOGFILENAME", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SMSINLOGFILENAME %s", GSMData.SMSINLOGFILENAME);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*SMSOUTLOGFILENAME?")) != NULL) {
|
|
|
+ // LOGFILENAME für ausgehende SMS lesen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SMSOUTLOGFILENAME %s", GSMData.SMSOUTLOGFILENAME);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*SMSOUTLOGFILENAME ")) != NULL) {
|
|
|
+ // LOGFILENAME für ausgehende SMS setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 19);
|
|
|
+
|
|
|
+ WritePrivateProfileString("Common", "SMSOUTLOGFILENAME", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SMSOUTLOGFILENAME %s", GSMData.SMSOUTLOGFILENAME);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*AT")) != NULL) {
|
|
|
+ // AT Kommando absetzen
|
|
|
+ char *Answer;
|
|
|
+ char *sd;
|
|
|
+
|
|
|
+ set_CmdAt_ExitOnError(0, 0);
|
|
|
+ sd = ComModemAT(0, cc + 1, 30); // hier 30 Sekunden Wartezeit !! da es längerwierige Kommandos gibt
|
|
|
+ set_CmdAt_ExitOnError(0, 1);
|
|
|
+
|
|
|
+ Answer = malloc(strlen(sd) + 1);
|
|
|
+ if(Answer != NULL) {
|
|
|
+ // Kopieren da das ganze beim nächsten Kommando überschrieben wird !
|
|
|
+ // z.B beim SMS Senden
|
|
|
+ memset(Answer, 0, strlen(sd) + 1);
|
|
|
+ memcpy(Answer, sd, strlen(sd));
|
|
|
+
|
|
|
+ sd = Answer;
|
|
|
+ while(strlen(sd) ) {
|
|
|
+ int len;
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ len = (strlen(sd) > (HbufLen - 1)) ? (HbufLen - 1) : strlen(sd);
|
|
|
+ memcpy(Hbuf, sd, len);
|
|
|
+ printf("\n<%d[[%s]]\n", len, Hbuf);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ sd += len;
|
|
|
+ }
|
|
|
+ free(Answer);
|
|
|
+ }
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*MSTATUS?")) != NULL) {
|
|
|
+ // Modemstatus Abfragen
|
|
|
+ char *Answer;
|
|
|
+ char *sd;
|
|
|
+
|
|
|
+ sd = ComModemAT(0, "AT^SIND?", 30); // hier 30 Sekunden Wartezeit !! da es längerwierige Kommandos gibt
|
|
|
+
|
|
|
+ Answer = malloc(strlen(sd) + 1);
|
|
|
+ if(Answer != NULL) {
|
|
|
+ // Kopieren da das ganze beim nächsten Kommando überschrieben wird !
|
|
|
+ // z.B beim SMS Senden
|
|
|
+ memset(Answer, 0, strlen(sd) + 1);
|
|
|
+ memcpy(Answer, sd, strlen(sd));
|
|
|
+
|
|
|
+ sd = Answer;
|
|
|
+ if(strlen(sd) ) {
|
|
|
+
|
|
|
+ char *ConnMode[]= {
|
|
|
+ "GPRS-EGPRS not avail",
|
|
|
+ "GPRS available",
|
|
|
+ "GPRS attached",
|
|
|
+ "EGPRS available",
|
|
|
+ "EGPRS attached",
|
|
|
+ "WCDMA available",
|
|
|
+ "WCDMA attached",
|
|
|
+ "HSDPA available",
|
|
|
+ "HSDPA attached",
|
|
|
+ "HSDPA-HSUPA available",
|
|
|
+ "HSDPA-HSUPA attached",
|
|
|
+ "--11--",
|
|
|
+ "--12--",
|
|
|
+ "--13--",
|
|
|
+ "--14--",
|
|
|
+ "--15--",
|
|
|
+ "4G available",
|
|
|
+ "4G attached",
|
|
|
+ };
|
|
|
+
|
|
|
+ char Provider[80];
|
|
|
+ char Psinfo[80];
|
|
|
+ char *cc;
|
|
|
+ int len;
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ len = (strlen(sd) > (HbufLen - 1)) ? (HbufLen - 1) : strlen(sd);
|
|
|
+ memcpy(Hbuf, sd, len);
|
|
|
+ printf("\n<%d[[%s]]\n", len, Hbuf);
|
|
|
+ memset(Provider, 0, sizeof(Provider));
|
|
|
+ memset(Psinfo, 0, sizeof(Psinfo));
|
|
|
+
|
|
|
+ sprintf(Provider, "--\?\?--");
|
|
|
+ sprintf(Psinfo, "--\?\?--");
|
|
|
+ /** Antwort in Hbuf **/
|
|
|
+ if((cc = strstr(Hbuf,"eons,")) != NULL) {
|
|
|
+ char *dd;
|
|
|
+ if((dd = strchr(cc+5,'\042')) != NULL) {
|
|
|
+ char *ee;
|
|
|
+ if((ee = strchr(dd + 1, '\042')) != NULL) {
|
|
|
+ *ee = 0;
|
|
|
+ sprintf(Provider, "%s", dd + 1);
|
|
|
+ *ee = '\42';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if((cc = strstr(Hbuf," psinfo,")) != NULL) {
|
|
|
+ char *dd;
|
|
|
+ if((dd = strchr(cc + 8,',')) != NULL) {
|
|
|
+ int psi;
|
|
|
+ psi = atoi(dd + 1);
|
|
|
+ sprintf(Psinfo, "%s", ((psi >= 0) && (psi <= 17))?ConnMode[psi]:"???");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "MSTATUS=Provider(%s),ConnType(%s)", Provider, Psinfo);
|
|
|
+
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ }
|
|
|
+ free(Answer);
|
|
|
+ }
|
|
|
+ } else if (strstrCMD(CmdText, "*SSHTUNNEL_ON") != NULL) {
|
|
|
+ // nur wenn keine Verbindung da ist neue Verbindung aufbauen
|
|
|
+ FILE *fp;
|
|
|
+ int loop;
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ ifconfig("IFCONFIG", HbufLen, Hbuf);
|
|
|
+ if (strstr(Hbuf, "ppp0: IP") == NULL) {
|
|
|
+ CreateGprsConnect(GSMData.GIP);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, PPPD_CALL, GPRS_TTY, GSMData.GNUN, GSMData.GNPW );
|
|
|
+ printf("APN: %s :: system %s\n", GSMData.GIP, Hbuf);
|
|
|
+ GprsHangup();
|
|
|
+ system(Hbuf);
|
|
|
+
|
|
|
+ loop = 0;
|
|
|
+ do {
|
|
|
+ sleep(10);
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ ifconfig("IFCONFIG", HbufLen, Hbuf);
|
|
|
+ ++loop;
|
|
|
+ } while((loop < 4) && (strstr(Hbuf, "ppp0: IP") == NULL));
|
|
|
+ }
|
|
|
+ // ---- Inetd einschalten
|
|
|
+ system("inetd &");
|
|
|
+ sleep(2);
|
|
|
+ // Tunnel Aktivieren
|
|
|
+ system(strlen(GSMData.SSHTUNNELCMD)?GSMData.SSHTUNNELCMD:SSHTUNNELDEFAULT);
|
|
|
+
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, "SSHTUNNEL started"); // Keine Antwort !!!
|
|
|
+ } else if (strstrCMD(CmdText, "*SSHTUNNEL_OFF") != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ ifconfig("IFCONFIG", HbufLen, Hbuf);
|
|
|
+ if (strstr(Hbuf, "ppp0: IP") != NULL) {
|
|
|
+ // nur wenn verbindung da ist abbrechen
|
|
|
+ system("killall ssh");
|
|
|
+ sleep(5);
|
|
|
+ system("killall inetd");
|
|
|
+ sleep(5);
|
|
|
+ system("killall pppd");
|
|
|
+ sleep(5);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ ifconfig("IFCONFIG", HbufLen, Hbuf);
|
|
|
+ }
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, "SSHTUNNEL stopped"); // Auch Keine Antwort
|
|
|
+ } else if (strstrCMD(CmdText, "*WWWTUNNEL_ON") != NULL) {
|
|
|
+ // nur wenn keine Verbindung da ist neue Verbindung aufbauen
|
|
|
+ FILE *fp;
|
|
|
+ int loop;
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ ifconfig("WWTUNNEL", HbufLen, Hbuf);
|
|
|
+ if (strstr(Hbuf, "ppp0: IP") == NULL) {
|
|
|
+ CreateGprsConnect(GSMData.GIP);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, PPPD_CALL, GPRS_TTY, GSMData.GNUN, GSMData.GNPW );
|
|
|
+ printf("APN: %s :: system %s\n", GSMData.GIP, Hbuf);
|
|
|
+ GprsHangup();
|
|
|
+ system(Hbuf);
|
|
|
+
|
|
|
+ loop = 0;
|
|
|
+ do {
|
|
|
+ sleep(10);
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ ifconfig("WWWTUNNEL", HbufLen, Hbuf);
|
|
|
+ ++loop;
|
|
|
+ } while((loop < 4) && (strstr(Hbuf, "ppp0: IP") == NULL));
|
|
|
+ }
|
|
|
+ // Tunnel Aktivieren
|
|
|
+ system(strlen(GSMData.WWWTUNNELCMD)?GSMData.WWWTUNNELCMD:WWWTUNNELDEFAULT);
|
|
|
+
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf); // IFCONFIG Senden
|
|
|
+ } else if (strstrCMD(CmdText, "*WWWTUNNEL_OFF") != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ ifconfig("IFCONFIG", HbufLen, Hbuf);
|
|
|
+ if (strstr(Hbuf, "ppp0: IP") != NULL) {
|
|
|
+ // nur wenn verbindung da ist abbrechen
|
|
|
+ system("killall ssh");
|
|
|
+ sleep(2);
|
|
|
+ system("killall pppd");
|
|
|
+ sleep(5);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ ifconfig("IFCONFIG", HbufLen, Hbuf);
|
|
|
+ }
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, ""); // Auch Keine Antwort
|
|
|
+ } else if (strstrCMD(CmdText, "*PPPD_ON") != NULL) {
|
|
|
+ // nur wenn keine Verbindung da ist neue Verbindung aufbauen
|
|
|
+ FILE *fp;
|
|
|
+ int loop;
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ ifconfig("PPPD_ON", HbufLen, Hbuf);
|
|
|
+ if (strstr(Hbuf, "ppp0: IP") == NULL) {
|
|
|
+ // auf alle Fälle prozess abschießen falls vorhanden
|
|
|
+ if(strlen(DYNData.CMD) > 0) {
|
|
|
+ // Dyndns starten
|
|
|
+ system("kill `screen -list | grep inadyn | awk -F'.' '{print $1}'`");
|
|
|
+ system("killall inadyn");
|
|
|
+ }
|
|
|
+ system("killall pppd");
|
|
|
+ sleep(5);
|
|
|
+
|
|
|
+ CreateGprsConnect(GSMData.GIP);
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, PPPD_CALL, GPRS_TTY, GSMData.GNUN, GSMData.GNPW );
|
|
|
+ printf("APN: %s :: system %s\n", GSMData.GIP, Hbuf);
|
|
|
+ GprsHangup();
|
|
|
+ system(Hbuf);
|
|
|
+
|
|
|
+ loop = 0;
|
|
|
+ do {
|
|
|
+ sleep(10);
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ ifconfig("PPPD_ON", HbufLen, Hbuf);
|
|
|
+ ++loop;
|
|
|
+ } while((loop < 4) && (strstr(Hbuf, "ppp0: IP") == NULL));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(strlen(DYNData.CMD) > 0) {
|
|
|
+ // Dyndns starten
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ //sprintf(Hbuf, "%s --background --system dyndns@dyndns.org -u %s -p %s -a %s", DYNData.CMD, DYNData.USER, DYNData.PWD, DYNData.ALIAS);
|
|
|
+ sprintf(Hbuf, "/usr/bin/screen -dmS inadyn sh -c \x22. /etc/profile; while true; do %s -V 5 --system dyndns@dyndns.org -u %s -p %s -a %s; sleep 2; echo 'INADYNEXITCODE : $?';done\x22", DYNData.CMD, DYNData.USER, DYNData.PWD, DYNData.ALIAS);
|
|
|
+ system(Hbuf);
|
|
|
+ printf("DYNDNS %s\n", Hbuf);
|
|
|
+ }
|
|
|
+ ifconfig("PPPD_ON", HbufLen, Hbuf);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if (strstrCMD(CmdText, "*PPPD_OFF") != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ ifconfig("IFCONFIG", HbufLen, Hbuf);
|
|
|
+ //if (strstr(Hbuf, "ppp0: IP") != NULL)
|
|
|
+ {
|
|
|
+ // nur wenn verbindung da ist abbrechen
|
|
|
+ if(strlen(DYNData.CMD) > 0) {
|
|
|
+ // Dyndns starten
|
|
|
+ system("killall inadyn");
|
|
|
+ }
|
|
|
+ system("killall pppd");
|
|
|
+ sleep(5);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ ifconfig("IFCONFIG", HbufLen, Hbuf);
|
|
|
+ }
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if (strstrCMD(CmdText, "*REBOOT") != NULL) {
|
|
|
+ system("reboot");
|
|
|
+ } else if (strstrCMD(CmdText, "*HALT") != NULL) {
|
|
|
+ // Prozess Hart beenden
|
|
|
+ system("killall pppd");
|
|
|
+ exit(-90);
|
|
|
+ }
|
|
|
+ else if (strstrCMD(CmdText, "*BESTAND?") != NULL) {
|
|
|
+ system("telnet localhost 11115 <<EOF\n*BESTAND?\nEOF\n");
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, "");
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*DYNCMD ")) != NULL) {
|
|
|
+ // Kommandoname für Dyndns
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 8);
|
|
|
+
|
|
|
+ WritePrivateProfileString("DYNDNS", "CMD", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "DYNCMD %s", DYNData.CMD);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*DYNCMD?")) != NULL) {
|
|
|
+ // Kommandoname für Dyndns
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "DYNCMD %s", DYNData.CMD);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*DYNUSER ")) != NULL) {
|
|
|
+ // Kommandoname für Dyndns
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 9);
|
|
|
+
|
|
|
+ WritePrivateProfileString("DYNDNS", "USER", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "DYNUSER %s", DYNData.USER);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*DYNUSER?")) != NULL) {
|
|
|
+ // Kommandoname für Dyndns
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "DYNUSER %s", DYNData.USER);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*DYNPWD ")) != NULL) {
|
|
|
+ // Kommandoname für Dyndns
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 8);
|
|
|
+
|
|
|
+ WritePrivateProfileString("DYNDNS", "PWD", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "DYNPWD %s", DYNData.PWD);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*DYNPWD?")) != NULL) {
|
|
|
+ // Kommandoname für Dyndns
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "DYNPWD %s", DYNData.PWD);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*DYNALIAS ")) != NULL) {
|
|
|
+ // Kommandoname für Dyndns
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 10);
|
|
|
+
|
|
|
+ WritePrivateProfileString("DYNDNS", "ALIAS", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "DYNALIAS %s", DYNData.ALIAS);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*DYNALIAS?")) != NULL) {
|
|
|
+ // Kommandoname für Dyndns
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "DYNALIAS %s", DYNData.ALIAS);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if (strstrCMD(CmdText, "*INETD_ON") != NULL) {
|
|
|
+ system("inetd &");
|
|
|
+ sleep(2);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "INETD_ON");
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if (strstrCMD(CmdText, "*INETD_OFF") != NULL) {
|
|
|
+ system("killall inetd ");
|
|
|
+ sleep(2);
|
|
|
+ system("killall inetd ");
|
|
|
+ sleep(2);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "INETD OFF");
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*IMEI?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "IMEI %s", GSMData.IMEI);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*IMSI?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "IMSI %s", GSMData.IMSI);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*SCID?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SCID %s", GSMData.SCID);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*PING ")) != NULL) {
|
|
|
+ // hier wert setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ GSMData.PING = atoi(cc+6);
|
|
|
+ sprintf(Hbuf, "%d", GSMData.PING);
|
|
|
+
|
|
|
+ WritePrivateProfileString("Common", "PING", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "PING %d minutes", GSMData.PING);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*PING?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ if(GSMData.PING > 0) {
|
|
|
+ // Mit Rest ausgeben
|
|
|
+ sprintf(Hbuf, "PING %d minutes %d minutes left", GSMData.PING, ((GSMData.LastPING + GSMData.PING * 60) - time(NULL)) / 60);
|
|
|
+ } else {
|
|
|
+ sprintf(Hbuf, "PING %d minutes", GSMData.PING);
|
|
|
+ }
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*MBOOT ")) != NULL) {
|
|
|
+ // hier wert setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ GSMData.MBOOT = atoi(cc+7);
|
|
|
+ sprintf(Hbuf, "%d", GSMData.MBOOT);
|
|
|
+
|
|
|
+ WritePrivateProfileString("Common", "MBOOT", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "MBOOT %d minutes", GSMData.MBOOT);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*MBOOT?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ if(GSMData.MBOOT > 0) {
|
|
|
+ // Mit Rest ausgeben
|
|
|
+ sprintf(Hbuf, "MBOOT %d minutes %d minutes left", GSMData.MBOOT, ((GSMData.LastMBOOT + GSMData.MBOOT * 60) - uptime()) / 60);
|
|
|
+ } else {
|
|
|
+ sprintf(Hbuf, "MBOOT %d minutes", GSMData.MBOOT);
|
|
|
+ }
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*GPRSNAIL ")) != NULL) {
|
|
|
+ // hier wert setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ GSMData.GPRSNAIL = atoi(cc+10);
|
|
|
+ sprintf(Hbuf, "%d", GSMData.GPRSNAIL);
|
|
|
+
|
|
|
+ WritePrivateProfileString("Common", "GPRSNAIL", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "GPRSNAIL %d ", GSMData.GPRSNAIL);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*GPRSNAIL?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "GPRSNAIL %d", GSMData.GPRSNAIL);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*TSYNC ")) != NULL) {
|
|
|
+ // hier wert setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "%d", atoi(cc+7));
|
|
|
+
|
|
|
+ WritePrivateProfileString("Common", "TSYNC", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "TSYNC %d ", GSMData.TSYNC);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*TSYNC?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "TSYNC %d", GSMData.TSYNC);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*TSYNCCMD?")) != NULL) {
|
|
|
+ // TSYNCCMD lesen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "TSYNCCMD %s", GSMData.TSYNCCMD);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*TSYNCCMD ")) != NULL) {
|
|
|
+ // TSYNCCMD setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 10);
|
|
|
+
|
|
|
+ WritePrivateProfileString("Common", "TSYNCCMD", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "TSYNCCMD %s", GSMData.TSYNCCMD);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*SSHTUNNELCMD?")) != NULL) {
|
|
|
+ // SSHTUNNELCMD lesen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ if(strlen(GSMData.SSHTUNNELCMD)) {
|
|
|
+ sprintf(Hbuf, "SSHTUNNELCMD %s", GSMData.SSHTUNNELCMD);
|
|
|
+ } else {
|
|
|
+ sprintf(Hbuf, "SSHTUNNELCMD DEF %s", SSHTUNNELDEFAULT);
|
|
|
+ }
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*SSHTUNNELCMD ")) != NULL) {
|
|
|
+ // SSHTUNNELCMD setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 14);
|
|
|
+
|
|
|
+ WritePrivateProfileString("Common", "SSHTUNNELCMD", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ if(strlen(GSMData.SSHTUNNELCMD)) {
|
|
|
+ sprintf(Hbuf, "SSHTUNNELCMD %s", GSMData.SSHTUNNELCMD);
|
|
|
+ } else {
|
|
|
+ sprintf(Hbuf, "SSHTUNNELCMD DEF %s", SSHTUNNELDEFAULT);
|
|
|
+ }
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*WWWTUNNELCMD?")) != NULL) {
|
|
|
+ // WWWTUNNELCMD lesen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ if(strlen(GSMData.WWWTUNNELCMD)) {
|
|
|
+ sprintf(Hbuf, "WWWTUNNELCMD %s", GSMData.WWWTUNNELCMD);
|
|
|
+ } else {
|
|
|
+ sprintf(Hbuf, "WWWTUNNELCMD DEF %s", WWWTUNNELDEFAULT);
|
|
|
+ }
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*WWWTUNNELCMD ")) != NULL) {
|
|
|
+ // WWWTUNNELCMD setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 14);
|
|
|
+
|
|
|
+ WritePrivateProfileString("Common", "WWWTUNNELCMD", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ if(strlen(GSMData.WWWTUNNELCMD)) {
|
|
|
+ sprintf(Hbuf, "WWWTUNNELCMD %s", GSMData.WWWTUNNELCMD);
|
|
|
+ } else {
|
|
|
+ sprintf(Hbuf, "WWWTUNNELCMD DEF %s", WWWTUNNELDEFAULT);
|
|
|
+ }
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ }
|
|
|
+
|
|
|
+ else if ((cc = strstrCMD(CmdText, "*WATCHDOGDEVICE?")) != NULL) {
|
|
|
+ // WATCHDOGDEVICE lesen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "WATCHDOGDEVICE %s", GSMData.WATCHDOGDEVICE);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*WATCHDOGDEVICE ")) != NULL) {
|
|
|
+ // WATCHDOGDEVICE setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 16);
|
|
|
+
|
|
|
+ WritePrivateProfileString("Common", "WATCHDOGDEVICE", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "WATCHDOGDEVICE %s", GSMData.WATCHDOGDEVICE);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*SERDEVINIT?")) != NULL) {
|
|
|
+ // SERDEVINIT lesen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SERDEVINIT %s", GSMData.SERDEVINIT);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ((cc = strstrCMD(CmdText, "*SERDEVINIT ")) != NULL) {
|
|
|
+ // SERDEVINIT setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 12);
|
|
|
+
|
|
|
+ WritePrivateProfileString("Common", "SERDEVINIT", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SERDEVINIT %s", GSMData.SERDEVINIT);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*MEPWD ")) != NULL) {
|
|
|
+ //Zählerpasswort setzen
|
|
|
+ // hier wert setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 7);
|
|
|
+
|
|
|
+ WritePrivateProfileString("METER", "MEPWD", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "MEPWD %s", GSMData.MEPWD);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*MEADR ")) != NULL) {
|
|
|
+ //Zähleradresse setzen
|
|
|
+ // hier wert setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 7);
|
|
|
+
|
|
|
+ WritePrivateProfileString("METER", "MEADR", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "MEADR %s", GSMData.MEADR);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*GPORT ")) != NULL) {
|
|
|
+ // hier wert setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ GSMData.GPORT = atoi(cc+7);
|
|
|
+ sprintf(Hbuf, "%d", GSMData.GPORT);
|
|
|
+
|
|
|
+ WritePrivateProfileString("GPRS", "GPORT", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "GPORT %d", GSMData.GPORT);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*GPORT?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "GPORT %d", GSMData.GPORT);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*CMDPORT ")) != NULL) {
|
|
|
+ // hier wert setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ GSMData.CMDPORT = atoi(cc+9);
|
|
|
+ sprintf(Hbuf, "%d", GSMData.CMDPORT);
|
|
|
+
|
|
|
+ WritePrivateProfileString("GPRS", "CMDPORT", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "CMDPORT %d", GSMData.CMDPORT);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*CMDPORT?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "CMDPORT %d", GSMData.CMDPORT);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*GSERV ")) != NULL) {
|
|
|
+ // hier wert setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 7);
|
|
|
+
|
|
|
+ WritePrivateProfileString("GPRS", "GSERV", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "GSERV %s", GSMData.GSERV);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*GSERV?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "GSERV %s", GSMData.GSERV);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*GIP ")) != NULL) {
|
|
|
+ // hier wert setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 5);
|
|
|
+
|
|
|
+ WritePrivateProfileString("GPRS", "GIP", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ {
|
|
|
+ // Zugehörigen IMSI Eintrag setzen
|
|
|
+ char ImsiBuf[40];
|
|
|
+
|
|
|
+ memset(ImsiBuf, 0, sizeof(ImsiBuf));
|
|
|
+ sprintf(ImsiBuf, "IMSI=%5.5s", GSMData.IMSI);
|
|
|
+ WritePrivateProfileString(ImsiBuf, "GIP", Hbuf, IniFilename);
|
|
|
+ }
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "GIP %s", GSMData.GIP);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*GIP?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "GIP %s", GSMData.GIP);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*NUM ")) != NULL) {
|
|
|
+ // hier wert setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 5);
|
|
|
+
|
|
|
+ WritePrivateProfileString("Common", "NUM", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "NUM %s", GSMData.NUM);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*NUM?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "NUM %s", GSMData.NUM);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*PON ")) != NULL) {
|
|
|
+ // hier wert setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 5);
|
|
|
+
|
|
|
+ GSMData.SENTSTART = atoi(Hbuf);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf,"%d", (GSMData.SENTSTART != 0)?0:1);
|
|
|
+
|
|
|
+ WritePrivateProfileString("Common", "SENTSTART", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ if(GSMData.SENTSTART != 0) {
|
|
|
+ sprintf(Hbuf, "PON POWER ON SMS SIGNAL DISABLED");
|
|
|
+ } else {
|
|
|
+ sprintf(Hbuf, "PON POWER ON SMS SIGNAL ENABLED");
|
|
|
+ }
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ DoSendStart = 0; // Damit die Meldung wirklich erst beim nächste neustart gesendet wird
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*PON?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ if(GSMData.SENTSTART != 0) {
|
|
|
+ sprintf(Hbuf, "PON POWER ON SMS SIGNAL DISABLED");
|
|
|
+ } else {
|
|
|
+ sprintf(Hbuf, "PON POWER ON SMS SIGNAL ENABLED");
|
|
|
+ }
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*SMSF ")) != NULL) {
|
|
|
+ // hier wert setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 6);
|
|
|
+
|
|
|
+ GSMData.SMSF = atoi(Hbuf);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf,"%d", GSMData.SMSF);
|
|
|
+
|
|
|
+ WritePrivateProfileString("Common", "SMSF", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SMSF 0x%2.2X %d", GSMData.SMSF, GSMData.SMSF);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*SMSF?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SMSF 0x%2.2X %d", GSMData.SMSF, GSMData.SMSF);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*GPRSCONF ")) != NULL) {
|
|
|
+#define MAXFIELDS 10
|
|
|
+#define MAXFIELDLENGTH 30
|
|
|
+
|
|
|
+ char Fields[MAXFIELDS * MAXFIELDLENGTH];
|
|
|
+ int AnzFields;
|
|
|
+
|
|
|
+ // String auseinanderbauen !!!!
|
|
|
+ AnzFields = CsvSplitLineEx(Fields, MAXFIELDS, MAXFIELDLENGTH, cc + 10, " ,;");
|
|
|
+
|
|
|
+ if(AnzFields > 1) {
|
|
|
+ char Hbuf[40];
|
|
|
+
|
|
|
+ WritePrivateProfileString("GPRS", "GIP", Fields + 1 * MAXFIELDLENGTH, IniFilename);
|
|
|
+ WritePrivateProfileString("GPRS", "GSERV", Fields + 2 * MAXFIELDLENGTH, IniFilename);
|
|
|
+ WritePrivateProfileString("GPRS", "GPORT", Fields + 3 * MAXFIELDLENGTH, IniFilename);
|
|
|
+ WritePrivateProfileString("GPRS", "GNUN", Fields + 4 * MAXFIELDLENGTH, IniFilename);
|
|
|
+ WritePrivateProfileString("GPRS", "GNPW", Fields + 5 * MAXFIELDLENGTH, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ // Zugehörigen IMSI Eintrag setzen
|
|
|
+ memset(Hbuf, 0, sizeof(Hbuf));
|
|
|
+ sprintf(Hbuf, "IMSI=%5.5s", GSMData.IMSI);
|
|
|
+ WritePrivateProfileString(Hbuf, "GIP", Fields + 1 * MAXFIELDLENGTH, IniFilename);
|
|
|
+ WritePrivateProfileString(Hbuf, "GNUN", Fields + 4 * MAXFIELDLENGTH, IniFilename);
|
|
|
+ WritePrivateProfileString(Hbuf, "GNPW", Fields + 5 * MAXFIELDLENGTH, IniFilename);
|
|
|
+ }
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "GPRSCONF %s %s %d %s %s",GSMData.GIP, GSMData.GSERV, GSMData.GPORT, GSMData.GNUN, GSMData.GNPW);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+#undef MAXFIELDS
|
|
|
+#undef MAXFIELDLENGTH
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*GPRSCONF?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "GPRSCONF %s %s %d %s %s",GSMData.GIP, GSMData.GSERV, GSMData.GPORT, GSMData.GNUN, GSMData.GNPW);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*GNUN ")) != NULL) {
|
|
|
+ // hier wert setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 6);
|
|
|
+
|
|
|
+ WritePrivateProfileString("GPRS", "GNUN", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ {
|
|
|
+ // Zugehörigen IMSI Eintrag setzen
|
|
|
+ char ImsiBuf[40];
|
|
|
+
|
|
|
+ memset(ImsiBuf, 0, sizeof(ImsiBuf));
|
|
|
+ sprintf(ImsiBuf, "IMSI=%5.5s", GSMData.IMSI);
|
|
|
+ WritePrivateProfileString(ImsiBuf, "GNUN", Hbuf, IniFilename);
|
|
|
+ }
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "GNUN %s", GSMData.GNUN);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*GNUN?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "GNUN %s", GSMData.GNUN);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*GNPW ")) != NULL) {
|
|
|
+ // hier wert setzen
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 6);
|
|
|
+
|
|
|
+ WritePrivateProfileString("GPRS", "GNPW", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ {
|
|
|
+ // Zugehörigen IMSI Eintrag setzen
|
|
|
+ char ImsiBuf[40];
|
|
|
+
|
|
|
+ memset(ImsiBuf, 0, sizeof(ImsiBuf));
|
|
|
+ sprintf(ImsiBuf, "IMSI=%5.5s", GSMData.IMSI);
|
|
|
+ WritePrivateProfileString(ImsiBuf, "GNPW", Hbuf, IniFilename);
|
|
|
+ }
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "GNPW %s", GSMData.GNPW);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*GNPW?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "GNPW %s", GSMData.GNPW);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*RETRY")) != NULL) {
|
|
|
+ unsigned char MeModChkSum(unsigned char *Data, int len);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "\r%s,%2.2X", GSMData.IMEI, MeModChkSum(GSMData.IMEI, strlen(GSMData.IMEI)));
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*GPRSDONE")) != NULL) {
|
|
|
+ unsigned char MeModChkSum(unsigned char *Data, int len);
|
|
|
+
|
|
|
+ // Stop der GPRS Verbindung vermerken !!!
|
|
|
+ WritePrivateProfileString("Common", "GPRSACTIVE", "0", IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "GPRS RESET");
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*SIEMENS_IP ")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, cc + 12);
|
|
|
+
|
|
|
+ WritePrivateProfileString("SIEMENS", "SIEMENS_IP", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SIEMENS_IP %s", GSMData.SIEMENS_IP);
|
|
|
+ Snap7_SetData(GSMData.SIEMENS_IP, GSMData.SIEMENS_RACK, GSMData.SIEMENS_SLOT, GSMData.SIEMENS_DBNR);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*SIEMENS_IP?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SIEMENS_IP %s", GSMData.SIEMENS_IP);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*SIEMENS_SLOT ")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ GSMData.SIEMENS_SLOT = atoi(cc+14);
|
|
|
+ sprintf(Hbuf, "%d", GSMData.SIEMENS_SLOT);
|
|
|
+
|
|
|
+ WritePrivateProfileString("SIEMENS", "SIEMENS_SLOT", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SIEMENS_SLOT %d", GSMData.SIEMENS_SLOT);
|
|
|
+ Snap7_SetData(GSMData.SIEMENS_IP, GSMData.SIEMENS_RACK, GSMData.SIEMENS_SLOT, GSMData.SIEMENS_DBNR);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*SIEMENS_SLOT?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SIEMENS_SLOT %d", GSMData.SIEMENS_SLOT);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*SIEMENS_RACK ")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ GSMData.SIEMENS_RACK = atoi(cc+14);
|
|
|
+ sprintf(Hbuf, "%d", GSMData.SIEMENS_RACK);
|
|
|
+
|
|
|
+ WritePrivateProfileString("SIEMENS", "SIEMENS_RACK", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SIEMENS_RACK %d", GSMData.SIEMENS_RACK);
|
|
|
+ Snap7_SetData(GSMData.SIEMENS_IP, GSMData.SIEMENS_RACK, GSMData.SIEMENS_SLOT, GSMData.SIEMENS_DBNR);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*SIEMENS_RACK?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SIEMENS_RACK %d", GSMData.SIEMENS_RACK);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*SIEMENS_DBNR ")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ GSMData.SIEMENS_DBNR = atoi(cc+14);
|
|
|
+ sprintf(Hbuf, "%d", GSMData.SIEMENS_DBNR);
|
|
|
+
|
|
|
+ WritePrivateProfileString("SIEMENS", "SIEMENS_DBNR", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SIEMENS_DBNR %d", GSMData.SIEMENS_DBNR);
|
|
|
+ Snap7_SetData(GSMData.SIEMENS_IP, GSMData.SIEMENS_RACK, GSMData.SIEMENS_SLOT, GSMData.SIEMENS_DBNR);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ } else if ( (cc = strstrCMD(CmdText, "*SIEMENS_DBNR?")) != NULL) {
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ sprintf(Hbuf, "SIEMENS_DBNR %d", GSMData.SIEMENS_DBNR);
|
|
|
+ ret = DoMeModCmdAnswer(AnsLen, AnsText, Hbuf);
|
|
|
+ }
|
|
|
+ free(Hbuf);
|
|
|
+ Hbuf = NULL;
|
|
|
+ } // ... if(Hbuf !=
|
|
|
+
|
|
|
+ pthread_mutex_unlock(&CMDMutex);
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------
|
|
|
+// Socketsachen und so weiter
|
|
|
+// Port ... Zielportnummer
|
|
|
+// *socketID ... Referenz auf Socket Identifier
|
|
|
+// HostName ... Name des Hosts z.B.: "www.russinger.at" oder "194.25.153.12", es wird versucht den NAmen aufzulösen !!!
|
|
|
+//
|
|
|
+// returns Connect Status rc == SOCKET_ERROR dann ist ein Fehler passiert !!!
|
|
|
+
|
|
|
+int MeModConnectIP(int Port, int *socketID, char *HostName)
|
|
|
+{
|
|
|
+ unsigned long taddr_n;
|
|
|
+ short tport_n;
|
|
|
+ short tport_h;
|
|
|
+
|
|
|
+ unsigned long ip_address;
|
|
|
+ int rc = SOCKET_ERROR;
|
|
|
+ struct sockaddr_in sa_in;
|
|
|
+ struct hostent *host_str;
|
|
|
+
|
|
|
+// Verbindungsaufbau !!!
|
|
|
+// Socketverbindung aufmachen Client Open !!!!
|
|
|
+ if(*socketID != INVALID_SOCKET) {
|
|
|
+ // falls was da ist mal zumachen
|
|
|
+ closesocket(*socketID);
|
|
|
+ }
|
|
|
+
|
|
|
+ *socketID = socket(PF_INET, SOCK_STREAM, 6);
|
|
|
+
|
|
|
+ ip_address = INADDR_NONE;
|
|
|
+ host_str = NULL;
|
|
|
+
|
|
|
+ ip_address = inet_addr(HostName);
|
|
|
+ if(ip_address == INADDR_NONE) {
|
|
|
+ // keine adresse sonder HOSTName auflösen versuchen
|
|
|
+ host_str = gethostbyname(HostName);
|
|
|
+ usleep(50000); // Kontextwechsel erzwingen !!
|
|
|
+ }
|
|
|
+
|
|
|
+ if( (host_str != NULL) || (ip_address != INADDR_NONE)) {
|
|
|
+ // Hostname konnte aufgelöst werden !!!
|
|
|
+ if(host_str != NULL) {
|
|
|
+ // Hostname angegeben
|
|
|
+ memcpy((char *) &(taddr_n),host_str->h_addr,host_str->h_length);
|
|
|
+ } else {
|
|
|
+ // IP Addresse angegeben
|
|
|
+ taddr_n = ip_address;
|
|
|
+ }
|
|
|
+ // Portnummer einstellen
|
|
|
+ tport_h = Port;
|
|
|
+ tport_n = htons(tport_h);
|
|
|
+
|
|
|
+ // Address Name in sa eintragen
|
|
|
+ sa_in.sin_family = PF_INET;
|
|
|
+ sa_in.sin_port = tport_n;
|
|
|
+ sa_in.sin_addr.s_addr = taddr_n;
|
|
|
+
|
|
|
+ rc = connect(*socketID, (struct sockaddr *)&(sa_in), sizeof(sa_in));
|
|
|
+ }
|
|
|
+
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------
|
|
|
+//-- Starten und Abarbeiten einer GPRS Verbindung
|
|
|
+unsigned char MeModChkSum(unsigned char *Data, int len)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+ unsigned char ret = 0;
|
|
|
+
|
|
|
+ for(i = 0; i< len; i++) ret += *(Data + i);
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+//--------------------------------------------------------
|
|
|
+//--
|
|
|
+int readComChar(int Hand, char *rbuf, int len, int TimeOutmSec)
|
|
|
+{
|
|
|
+ fd_set rmask;
|
|
|
+ struct timeval timeout;
|
|
|
+ int maxfd;
|
|
|
+ int ret = 0;
|
|
|
+
|
|
|
+ timeout.tv_sec = TimeOutmSec / 1000;
|
|
|
+ timeout.tv_usec = (TimeOutmSec % 1000) * 1000;
|
|
|
+
|
|
|
+ maxfd = Hand;
|
|
|
+ maxfd ++;
|
|
|
+
|
|
|
+ FD_ZERO(&rmask);
|
|
|
+ FD_SET(Hand, &rmask);
|
|
|
+
|
|
|
+ ret = select(maxfd, &rmask, NULL, NULL, &timeout);
|
|
|
+ switch(ret) {
|
|
|
+ case -1: // fehler
|
|
|
+ //printf("e");
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0: // Timeout
|
|
|
+ //printf("t");
|
|
|
+ break;
|
|
|
+
|
|
|
+ default: //was da
|
|
|
+ ret = read(Hand, rbuf, len);
|
|
|
+ //printf("c:%s\n", rbuf);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+void DoCommand(char *Cmd)
|
|
|
+{
|
|
|
+ DoMeModCmd(4, Cmd, 0, NULL, INI_FILENAME); // Kommandos ausführen !!!!!
|
|
|
+}
|
|
|
+
|
|
|
+//--------------- Hauptprogramm zum Modembearbeiten
|
|
|
+void main_Modem(int argc, char **argv, char **envp)
|
|
|
+{
|
|
|
+ char *cc, *cc1;
|
|
|
+ int rval;
|
|
|
+ char ModemBuf[200];
|
|
|
+ char *ModemName = "???";
|
|
|
+ unsigned char RCh;
|
|
|
+ int BufCnt;
|
|
|
+ int AnsWait;
|
|
|
+ int AnzSMS;
|
|
|
+ int i;
|
|
|
+ int loopcnt = 0;
|
|
|
+
|
|
|
+
|
|
|
+ int baud;
|
|
|
+ int ret;
|
|
|
+ char *IniFilename = INI_FILENAME;
|
|
|
+
|
|
|
+ struct stat IniStat;
|
|
|
+
|
|
|
+ printf("Open %s %d : %d \n", GPRS_TTY, 1, ret = ComInitUX(1, GPRS_TTY));
|
|
|
+ if(ret >= 0) {
|
|
|
+ // Nur einmal Testweise aktivieren geschw. einstellen
|
|
|
+ // damit dann das entspr connect script auch vernünftig startet !!
|
|
|
+ char *cc = NULL;
|
|
|
+
|
|
|
+ baud = GPRS_BAUD;
|
|
|
+ ComSetState(1,baud,8,1,'N');
|
|
|
+ ComModemAT(1, "AT", 2);
|
|
|
+ sleep(1);
|
|
|
+ ComModemAT(1, "AT", 2);
|
|
|
+ sleep(1);
|
|
|
+ ComModemAT(1, "AT", 2);
|
|
|
+ sleep(1);
|
|
|
+ ComModemAT(1, "ATZ", 2);
|
|
|
+ sleep(1);
|
|
|
+
|
|
|
+ // Modemtyp feststellen
|
|
|
+ {
|
|
|
+#define MAXFIELDS 30
|
|
|
+#define MAXFIELDLENGTH 60
|
|
|
+ int i;
|
|
|
+ char Fields[MAXFIELDS * MAXFIELDLENGTH];
|
|
|
+ char ATIBuf[250];
|
|
|
+ int AnzFields;
|
|
|
+
|
|
|
+ GSMData.MODEMTYPE = DEFAULT;
|
|
|
+ cc = ComModemAT_r(1,"ATI", 50, ATIBuf, sizeof(ATIBuf));
|
|
|
+ printf(">>>>>>\n%S\n<<<<<<\n", cc);
|
|
|
+ // String auseinanderbauen !!!!
|
|
|
+ AnzFields = CsvSplitLineEx(Fields, MAXFIELDS, MAXFIELDLENGTH, cc, "\n");
|
|
|
+ for(i = 0; i < AnzFields; i++) {
|
|
|
+ //printf("%d :: %s\n", i, Fields + i * MAXFIELDLENGTH);
|
|
|
+ if(strcmp(Fields + i * MAXFIELDLENGTH, "PH8-P") == 0)
|
|
|
+ GSMData.MODEMTYPE = PH8_P;
|
|
|
+ if(strcmp(Fields + i * MAXFIELDLENGTH, "PLS8-E") == 0)
|
|
|
+ GSMData.MODEMTYPE = PLS8_E;
|
|
|
+ if(strcmp(Fields + i * MAXFIELDLENGTH, "ELS61-E") == 0)
|
|
|
+ GSMData.MODEMTYPE = ELS61_E;
|
|
|
+ }
|
|
|
+
|
|
|
+ switch(GSMData.MODEMTYPE) {
|
|
|
+ case DEFAULT:
|
|
|
+ ModemName = "DEFAULT";
|
|
|
+ break;
|
|
|
+
|
|
|
+ case PH8_P:
|
|
|
+ ModemName = "PH8-P";
|
|
|
+ break;
|
|
|
+
|
|
|
+ case PLS8_E:
|
|
|
+ ModemName = "PLS8-E";
|
|
|
+ break;
|
|
|
+
|
|
|
+ case ELS61_E:
|
|
|
+ ModemName = "ELS61-E";
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ ModemName = "????";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ printf("MODEM:: %s\n", ModemName);
|
|
|
+
|
|
|
+#undef MAXFIELDS
|
|
|
+#undef MAXFIELDLENGTH
|
|
|
+ }
|
|
|
+ cc = ComModemAT(1, "AT+CCLK?", 2);
|
|
|
+ if(cc != NULL) {
|
|
|
+ char *xx;
|
|
|
+
|
|
|
+ if((xx = strrchr(cc, 0x22)) != NULL) {
|
|
|
+ *xx = 0;
|
|
|
+ }
|
|
|
+ if((xx = strrchr(cc, 0x22)) != NULL) {
|
|
|
+ ++xx;
|
|
|
+ } else {
|
|
|
+ xx = cc;
|
|
|
+ }
|
|
|
+ printf(">>>TIME<<<: %s\n", xx);
|
|
|
+ }
|
|
|
+ ComReset(1);
|
|
|
+ // alles wieder freigegeben
|
|
|
+ } else {
|
|
|
+ printf("%s:: %s already in Use:: couldnt Init !!\n", __func__, GPRS_TTY);
|
|
|
+ }
|
|
|
+
|
|
|
+ printf("Open %s %d : %d \n", MODEM_TTY, 0, ComInitUX(0, MODEM_TTY));
|
|
|
+ baud = GPRS_BAUD;
|
|
|
+
|
|
|
+ ComSetState(0,baud,8,1,'N');
|
|
|
+
|
|
|
+ ComModemAT(0, "AT", 2);
|
|
|
+ sleep(1);
|
|
|
+ ComModemAT(0, "AT", 2);
|
|
|
+ sleep(1);
|
|
|
+ ComModemAT(0, "AT", 2);
|
|
|
+ sleep(1);
|
|
|
+ ComModemAT(0, "ATZ", 2);
|
|
|
+ sleep(1);
|
|
|
+
|
|
|
+ ret = ComModemCmd(0, "ATE1", 2);
|
|
|
+ ret = 0;
|
|
|
+
|
|
|
+ if(!ret) {
|
|
|
+ printf("--- 8 Bit eingestellt !!!---\n");
|
|
|
+ ComSetState(0,baud,8,1,'N');
|
|
|
+ ret = ComModemCmd(0, "AT", 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ret) {
|
|
|
+ if(GSMData.MODEMTYPE != ELS61_E) {
|
|
|
+ ret = ComModemCmd(0, "AT+CRC=1", 20); // Erweiterte Rückmeldungen
|
|
|
+ }
|
|
|
+ if(GSMData.MODEMTYPE != PLS8_E) {
|
|
|
+ ret = ComModemCmd(0, "AT+CSNS=4", 20); // Akzeptiere alle Anrufe
|
|
|
+ }
|
|
|
+ if(GSMData.MODEMTYPE != ELS61_E) {
|
|
|
+ ret = ComModemCmd(0, "AT+CPMS=\x22MT\x22,\x22MT\x22,\x22MT\x22", 20); // Gerätespeicher
|
|
|
+ } else {
|
|
|
+ ret = ComModemCmd(0, "AT+CPMS=\x22ME\x22,\x22ME\x22,\x22ME\x22", 20); // Gerätespeicher
|
|
|
+ }
|
|
|
+ ret = ComModemCmd(0, "AT+CMEE=2", 20); // Fehlermeldung mit Text
|
|
|
+ ret = ComModemCmd(0, "AT+CSCS=\x22GSM\x22", 20); // Zeichensatz
|
|
|
+ ComSetState(0,baud,8,1,'N'); // Schnittstelle verbiegen
|
|
|
+ if(GSMData.MODEMTYPE != ELS61_E) {
|
|
|
+ ret = ComModemCmd(0, "AT+CRC=1", 20); // Erweiterte Rückmeldungen
|
|
|
+ }
|
|
|
+ ret = ComModemCmd(0, "AT+CSNS=4", 20); // Akzeptiere alle Anrufe
|
|
|
+ if(GSMData.MODEMTYPE != ELS61_E) {
|
|
|
+ ret = ComModemCmd(0, "AT+CLIP=1", 20); // Anruferinfo Anzeigen
|
|
|
+ }
|
|
|
+ // Aktuelle IMEI immer eintragen
|
|
|
+ cc=ComModemAT(0, "AT+CGSN", 50);
|
|
|
+ cc1 = strstr(cc, "\r\n");
|
|
|
+
|
|
|
+ if(cc1!= NULL) {
|
|
|
+ char *chlp;
|
|
|
+ if((chlp = strstr(cc1+2, "\r\n")) != NULL) {
|
|
|
+ *chlp = 0;
|
|
|
+ printf("IMEI =[[%s]]\n", cc1+2);
|
|
|
+ WritePrivateProfileString("Common", "IMEI", cc1 + 2, IniFilename);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+
|
|
|
+ // Aktuelle IMSI immer eintragen
|
|
|
+ cc=ComModemAT(0, "AT+CIMI", 50);
|
|
|
+ cc1 = strstr(cc, "\r\n");
|
|
|
+
|
|
|
+ if(cc1!= NULL) {
|
|
|
+ char *chlp;
|
|
|
+ if((chlp = strstr(cc1+2, "\r\n")) != NULL) {
|
|
|
+ *chlp = 0;
|
|
|
+ printf("IMSI =[[%s]]\n", cc1+2);
|
|
|
+ WritePrivateProfileString("Common", "IMSI", cc1 + 2, IniFilename);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Aktuelle SCID (SimCardID) immer eintragen
|
|
|
+ if(GSMData.MODEMTYPE != ELS61_E) {
|
|
|
+ cc=ComModemAT(0, "AT^SCID", 50);
|
|
|
+ } else {
|
|
|
+ cc=ComModemAT(0, "AT+CCID", 50);
|
|
|
+ }
|
|
|
+ if(strstr(cc, "\r\nOK") != NULL) {
|
|
|
+ cc1 = strrchr(cc, 0x0d);
|
|
|
+ if(cc1 != NULL) *cc1 = 0;
|
|
|
+
|
|
|
+ cc1 = strrchr(cc, ':');
|
|
|
+ if(cc1 != NULL) cc= cc1+2;
|
|
|
+
|
|
|
+ cc1 = strchr(cc, 0x0d);
|
|
|
+ if(cc1 != NULL) *cc1 = 0; // leerzeichen vor OK ruasnehmen
|
|
|
+ WritePrivateProfileString("Common", "SCID", cc, IniFilename);
|
|
|
+ } else {
|
|
|
+ WritePrivateProfileString("Common", "SCID", "--N/A--", IniFilename);
|
|
|
+ }
|
|
|
+
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+ ReadKonfiIMSI(IniFilename, GSMData.IMSI);
|
|
|
+ // ab Hier breits gelesene SMS entfernen
|
|
|
+ // alle Meldungen übernehmen und nach Auswertung löschen
|
|
|
+ cc = ComModemAT(0, "ATE1", 2);
|
|
|
+ AnzSMS = ComModemSMS_Read(0, "AT+CMGL=1", 50, MAXSMS, SMSData);
|
|
|
+ while(AnzSMS > 0) {
|
|
|
+ for(i = 0; i < AnzSMS; i++) {
|
|
|
+ char Hbuf[160];
|
|
|
+ char *Htext = NULL;
|
|
|
+
|
|
|
+ printf ("Message ID: [%d]\n", (SMSData + i)->msgid);
|
|
|
+ printf ("Message Status: [%d]\n", (SMSData + i)->msgstatus);
|
|
|
+ printf ("Sender addr.: [%s] (%d char.)\n", (SMSData + i)->fromgsm, strlen ((SMSData + i)->fromgsm));
|
|
|
+ printf ("Message date: [%s] (%d char.)\n", (SMSData + i)->date, strlen ((SMSData + i)->date));
|
|
|
+ printf ("Message time: [%s] (%d char.)\n", (SMSData + i)->time, strlen ((SMSData + i)->time));
|
|
|
+ printf ("Message: [%s] (%d char.)\n", (SMSData + i)->text, strlen ((SMSData + i)->text));
|
|
|
+
|
|
|
+ String2NoControl((SMSData + i)->text, strlen((SMSData + i)->text), &Htext);
|
|
|
+ if(Htext != NULL) {
|
|
|
+ fnameprint_moni(GSMData.SMSINLOGFILENAME, "%s;%s;%s;\x22%s\x22",
|
|
|
+ (SMSData + i)->fromgsm, (SMSData + i)->date, (SMSData + i)->time, Htext);
|
|
|
+ free(Htext);
|
|
|
+ }
|
|
|
+ memset(Hbuf, 0, sizeof(Hbuf));
|
|
|
+ sprintf(Hbuf, "AT+CMGD=%d", (SMSData + i)->msgid);
|
|
|
+ ComModemAT(0, Hbuf, 80);
|
|
|
+ }
|
|
|
+ // um alle SMS wegzulesen
|
|
|
+ AnzSMS = ComModemSMS_Read(0, "AT+CMGL=1", 50, MAXSMS, SMSData);
|
|
|
+ }
|
|
|
+ AnsWait = 1; // Endlos warten bis CRING kommt !
|
|
|
+ } else {
|
|
|
+ // keine Simkarte da !!!!
|
|
|
+ WritePrivateProfileString("Common", "IMSI", "", IniFilename);
|
|
|
+ WritePrivateProfileString("Common", "SCID", "", IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+ printf("SIM Card missing !\n");
|
|
|
+ AnsWait = 0; // gar nicht in die while Schleife ren sondern sofort wieder raus
|
|
|
+ }
|
|
|
+
|
|
|
+ // ---------------------------------------
|
|
|
+ memset(ModemBuf, 0, sizeof(ModemBuf));
|
|
|
+ BufCnt = 0;
|
|
|
+ loopcnt = 0;
|
|
|
+ printf("\n--- START MODEM MAINLOOP ---\n");
|
|
|
+ Msq_UnLock();
|
|
|
+ Snap7_UnLock();
|
|
|
+ while (AnsWait > 0) {
|
|
|
+ struct stat ttyStat;
|
|
|
+ // Wartezeit abwarten Alle Sekunden mal Probieren
|
|
|
+ // --- Harwarechecks durchführen
|
|
|
+ if(stat(GPRS_TTY, &ttyStat)) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(stat(MODEM_TTY, &ttyStat)) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+#ifdef CHECK_MUX
|
|
|
+ if(system("pidof gsmMuxd_Ser > /dev/null") != 0) {
|
|
|
+ printf("gsmMuxd_Ser not running !!");
|
|
|
+ fnameprint_moni("/etc/PPPDTIME", "gsmMuxd_Ser not running !");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ // Watchdog
|
|
|
+ if(loopcnt == 0) {
|
|
|
+ ping_watchdog(GSMData.WATCHDOGDEVICE);
|
|
|
+ }
|
|
|
+
|
|
|
+ pthread_mutex_lock(&INIMutex);
|
|
|
+ memcpy(&GSMDataWrk, &GSMData, sizeof(GSMData));
|
|
|
+ pthread_mutex_unlock(&INIMutex);
|
|
|
+
|
|
|
+ // MBOOTZEITPUNKT Abfragen
|
|
|
+ if( (GSMDataWrk.MBOOT > 0) && ((GSMDataWrk.LastMBOOT + GSMDataWrk.MBOOT * 60) < uptime())) {
|
|
|
+ // Its Time to REBOOT
|
|
|
+ if(GSMDataWrk.GPRSActive == 0) {
|
|
|
+ // kein aktiver GPRS Auftrag starten
|
|
|
+ printf("MBOOOT time \n Process will be restarted\n");
|
|
|
+ sleep(1);
|
|
|
+ system("killall pppd");
|
|
|
+ sleep(1);
|
|
|
+ exit(-91);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // GPRSNAILZEITPUNKT Abfragen
|
|
|
+ if( (GSMDataWrk.GPRSNAIL > 0) && ((GSMDataWrk.LastGPRSNAIL + GSMDataWrk.GPRSNAIL * 60) < uptime())) {
|
|
|
+ // Its Time to CHECK
|
|
|
+ char Hbuf[512];
|
|
|
+ int HbufLen;
|
|
|
+
|
|
|
+ GSMDataWrk.LastGPRSNAIL = uptime(); // Testzeit sezen
|
|
|
+
|
|
|
+ HbufLen = sizeof(Hbuf);
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ ifconfig("PPPD_NAIL", HbufLen, Hbuf);
|
|
|
+ if (strstr(Hbuf, "ppp0: IP") == NULL) {
|
|
|
+ printf("GPRSNAIL time \n check pppd NOT active !! TRY TO (RE-)CONNECT\n");
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ DoMeModCmd(4, "*PPPD_ON", HbufLen, Hbuf, INI_FILENAME); // Kommandos ausführen !!!!!
|
|
|
+ printf("\n---NAIL---\n%s\n", Hbuf);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // TSYNCZEITPUNKT Abfragen aber nur wenn auch GPRSNAIL aktiv ist sonst machts nicht wirklich Sinn
|
|
|
+ if( (GSMDataWrk.TSYNC > 0) && (GSMDataWrk.GPRSNAIL > 0) && (strlen(GSMDataWrk.TSYNCCMD)) && ((GSMDataWrk.LastTSYNC + GSMDataWrk.TSYNC * 60) < uptime())) {
|
|
|
+ // Its Time to CHECK
|
|
|
+ char Hbuf[512];
|
|
|
+ int HbufLen;
|
|
|
+
|
|
|
+ HbufLen = sizeof(Hbuf);
|
|
|
+ memset(Hbuf, 0, HbufLen);
|
|
|
+ ifconfig("PPPD_TSYNC", HbufLen, Hbuf);
|
|
|
+ if (strstr(Hbuf, "ppp0: IP") != NULL) {
|
|
|
+ // nur wenn PPP Verbindung aktiv !!!
|
|
|
+ int ret;
|
|
|
+
|
|
|
+ GSMDataWrk.LastTSYNC = uptime(); // Testzeit sezen
|
|
|
+
|
|
|
+ printf("TSYNC time call:: <<%s>> \n", GSMDataWrk.TSYNCCMD);
|
|
|
+ ret = system(GSMDataWrk.TSYNCCMD); // Konfiguriertes Kommando aufrufen
|
|
|
+ printf("TSYNC ret = %d\n", ret);
|
|
|
+ if(ret == 0) {
|
|
|
+ TimeToModule = 1;
|
|
|
+ } else {
|
|
|
+ TimeFromModule = 1; // wenns nicht gutgegangen ist, dann Zeit aus Modul übernehmen
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ TimeFromModule = 1; // bei fehlender PPP Verbindung Zeit aus Modul
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ pthread_mutex_lock(&INIMutex);
|
|
|
+ GSMData.LastPING = GSMDataWrk.LastPING; // Zeit wieder setzen
|
|
|
+ GSMData.LastMBOOT = GSMDataWrk.LastMBOOT; // Zeit wieder setzen
|
|
|
+ GSMData.LastGPRSNAIL = GSMDataWrk.LastGPRSNAIL; // Zeit wieder setzen
|
|
|
+ GSMData.LastTSYNC = GSMDataWrk.LastTSYNC; // Zeit wieder setzen
|
|
|
+ pthread_mutex_unlock(&INIMutex);
|
|
|
+
|
|
|
+ ComModemCleanIn(0); /**< eventuelle schmierzeichen weglesen */
|
|
|
+
|
|
|
+ ++loopcnt;
|
|
|
+ usleep(1000000); // eine Sekunde warten
|
|
|
+ //-----------------------------------------------------
|
|
|
+ if(loopcnt > 5) {
|
|
|
+ // Aktuelle IMSI immer eintragen
|
|
|
+ //printf("--- IMSI, SMS, .... ---\n");
|
|
|
+ cc = ComModemAT(0, "ATE1", 2);
|
|
|
+ // Aktuelle IMSI immer eintragen
|
|
|
+ cc=ComModemAT(0, "AT+CIMI", 50);
|
|
|
+ cc1 = strstr(cc, "\r\n");
|
|
|
+
|
|
|
+ if(cc1!= NULL) {
|
|
|
+ char *chlp;
|
|
|
+ if((chlp = strstr(cc1+2, "\r\n")) != NULL) {
|
|
|
+ *chlp = 0;
|
|
|
+ if(strcmp(cc1 + 2, GSMData.IMSI) != 0) {
|
|
|
+ // irgendwie eine andere SIM karte untergejubelt !
|
|
|
+ printf("IMSI unterschied !![[%s]]<<%s>> \n", cc1 + 2, GSMData.IMSI);
|
|
|
+ //break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ { /*** ConnStatus ausgeben ***/
|
|
|
+ char *cc;
|
|
|
+ char HHbuf[2048];
|
|
|
+ char IIbuf[2048];
|
|
|
+ char ATBuf[1024];
|
|
|
+
|
|
|
+ char *ConnMode[]= {
|
|
|
+ "GPRS-EGPRS not avail",
|
|
|
+ "GPRS available",
|
|
|
+ "GPRS attached",
|
|
|
+ "EGPRS available",
|
|
|
+ "EGPRS attached",
|
|
|
+ "WCDMA available",
|
|
|
+ "WCDMA attached",
|
|
|
+ "HSDPA available",
|
|
|
+ "HSDPA attached",
|
|
|
+ "HSDPA-HSUPA available",
|
|
|
+ "HSDPA-HSUPA attached",
|
|
|
+ "--11--",
|
|
|
+ "--12--",
|
|
|
+ "--13--",
|
|
|
+ "--14--",
|
|
|
+ "--15--",
|
|
|
+ "4G available",
|
|
|
+ "4G attached",
|
|
|
+ };
|
|
|
+
|
|
|
+ char QualString[10];
|
|
|
+ char Provider[80];
|
|
|
+ char Psinfo[80];
|
|
|
+
|
|
|
+ memset(HHbuf, 0, sizeof(HHbuf));
|
|
|
+
|
|
|
+ cc = ComModemAT_r(0,"AT^SIND?", 2, ATBuf, sizeof(ATBuf));
|
|
|
+ if(strlen(cc)) {
|
|
|
+ strcat(HHbuf, cc);
|
|
|
+ }
|
|
|
+ cc = ComModemAT_r(0,"AT+csq", 2, ATBuf, sizeof(ATBuf));
|
|
|
+ if(strlen(cc)) {
|
|
|
+ strcat(HHbuf, cc);
|
|
|
+ }
|
|
|
+
|
|
|
+ if((GSMData.MODEMTYPE == PLS8_E) || (GSMData.MODEMTYPE == ELS61_E) || (GSMData.MODEMTYPE == PH8_P)) {
|
|
|
+ cc = ComModemAT_r(0,"AT^SMONI", 2, ATBuf, sizeof(ATBuf));
|
|
|
+ if(strlen(cc)) {
|
|
|
+ strcat(HHbuf, cc);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fnameprint_file("/var/tmp/Display_GSM.info_raw", 0, "w+", "%s", HHbuf);
|
|
|
+
|
|
|
+ memset(IIbuf, 0, sizeof(IIbuf));
|
|
|
+ memset(Psinfo, 0, sizeof(Psinfo));
|
|
|
+ memset(QualString, 0, sizeof(QualString));
|
|
|
+ memset(Provider, 0, sizeof(Provider));
|
|
|
+
|
|
|
+ if((cc = strstr(HHbuf,"+CSQ:")) != NULL) {
|
|
|
+
|
|
|
+ int db_qual;
|
|
|
+
|
|
|
+ int qual;
|
|
|
+ qual = atoi(cc + 5);
|
|
|
+
|
|
|
+ if(qual == 0) db_qual = -113;
|
|
|
+ else if (qual == 1) db_qual = -111;
|
|
|
+ else if ((qual > 1) && (qual <= 30)) db_qual = -109 + (qual - 2) * 2;
|
|
|
+ else if (qual == 31) db_qual = -51;
|
|
|
+ else db_qual = 0;
|
|
|
+
|
|
|
+ sprintf(QualString, "%d (%d dBm)", qual, db_qual);
|
|
|
+ } else {
|
|
|
+ sprintf(QualString, "???");
|
|
|
+ }
|
|
|
+
|
|
|
+ if((cc = strstr(HHbuf,"eons,")) != NULL) {
|
|
|
+ char *dd;
|
|
|
+ if((dd = strchr(cc+5,'\042')) != NULL) {
|
|
|
+ char *ee;
|
|
|
+ if((ee = strchr(dd + 1, '\042')) != NULL) {
|
|
|
+ *ee = 0;
|
|
|
+ sprintf(Provider, "%s", dd + 1);
|
|
|
+ *ee = '\42';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if((cc = strstr(HHbuf," psinfo,")) != NULL) {
|
|
|
+ char *dd;
|
|
|
+ if((dd = strchr(cc + 8,',')) != NULL) {
|
|
|
+ int psi;
|
|
|
+ psi = atoi(dd + 1);
|
|
|
+ sprintf(Psinfo, "%s", ((psi >= 0) && (psi <= 17))?ConnMode[psi]:"???" );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ memset(IIbuf, 0, sizeof(IIbuf));
|
|
|
+ sprintf(IIbuf, "\nQUAL : %s\n"
|
|
|
+ "PS : %s\n"
|
|
|
+ "PROV : %s\n", QualString, Psinfo, Provider);
|
|
|
+
|
|
|
+ if((cc = strstr(HHbuf, "^SMONI: ")) != NULL) {
|
|
|
+ #define MAXFIELDS 30
|
|
|
+ #define MAXFIELDLENGTH 30
|
|
|
+ int Stricherl = 0;
|
|
|
+ int rc;
|
|
|
+ int dBm;
|
|
|
+ int rss_fieldno;
|
|
|
+ char *mode;
|
|
|
+ char Fields[MAXFIELDS * MAXFIELDLENGTH];
|
|
|
+ int AnzFields;
|
|
|
+
|
|
|
+ // String auseinanderbauen !!!!
|
|
|
+ AnzFields = CsvSplitLineEx(Fields, MAXFIELDS, MAXFIELDLENGTH, cc + 8, " ,;");
|
|
|
+
|
|
|
+ if(AnzFields > 1) {
|
|
|
+ mode = Fields + 1 * MAXFIELDLENGTH;
|
|
|
+ rss_fieldno = strcmp(mode, "2G") == 0?3:strcmp(mode, "3G") == 0?5:13;
|
|
|
+ dBm = strcmp(mode, "2G") == 0?-113:strcmp(mode, "3G") == 0?-113:-140;
|
|
|
+
|
|
|
+ rc = sscanf(Fields + rss_fieldno * MAXFIELDLENGTH,"%d",&dBm);
|
|
|
+ if( rc == 1) {
|
|
|
+ if(strcmp(mode, "4G") == 0) {
|
|
|
+ if(dBm >= -140) Stricherl = 1;
|
|
|
+ if(dBm >= -129) Stricherl = 2;
|
|
|
+ if(dBm >= -119) Stricherl = 3;
|
|
|
+ if(dBm >= -109) Stricherl = 4;
|
|
|
+ if(dBm >= -99) Stricherl = 5;
|
|
|
+ }
|
|
|
+ else if(strcmp(mode, "3G") == 0) {
|
|
|
+ if(dBm >= -113) Stricherl = 1;
|
|
|
+ if(dBm >= -107) Stricherl = 2;
|
|
|
+ if(dBm >= -104) Stricherl = 3;
|
|
|
+ if(dBm >= -97) Stricherl = 4;
|
|
|
+ if(dBm >= -90) Stricherl = 5;
|
|
|
+ }
|
|
|
+ else if(strcmp(mode, "2G") == 0) {
|
|
|
+ if(dBm >= -113) Stricherl = 1;
|
|
|
+ if(dBm >= -107) Stricherl = 2;
|
|
|
+ if(dBm >= -104) Stricherl = 3;
|
|
|
+ if(dBm >= -97) Stricherl = 4;
|
|
|
+ if(dBm >= -90) Stricherl = 5;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sprintf(IIbuf + strlen(IIbuf), "ASU : %d (%d dBm) [%s]\nSIM : %s\nMODEM : %s\nVERS : %s",
|
|
|
+ Stricherl, dBm, mode, GSMData.SCID, ModemName, VERSION + 10);
|
|
|
+ fnameprint_file("/var/tmp/Display_GSM.info", 0, "w+", "%s", IIbuf);
|
|
|
+ #undef MAXFIELDS
|
|
|
+ #undef MAXFIELDLENGTH
|
|
|
+ {
|
|
|
+ char Prov[100];
|
|
|
+
|
|
|
+ sprintf(Prov, "%s [%s]", Provider, mode);
|
|
|
+ Snap7_Info(Prov, Stricherl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //printf("\n chkSMS\n");
|
|
|
+ if((GSMData.SENTSTART == 0) && (strlen(GSMData.NUM) > 0) && (DoSendStart == 1) ) {
|
|
|
+ // nur wenn noch nicht gemacht
|
|
|
+ char Hbuf[160];
|
|
|
+
|
|
|
+ memset(Hbuf, 0, sizeof(Hbuf));
|
|
|
+ sprintf(Hbuf, "Display first Power on ! VER Display_GSM %6.6s " VENDOR "; SCID %s; IMSI %s, IMEI %s; PING %d; PORT %d", VERSION + 10,
|
|
|
+ GSMData.SCID, GSMData.IMSI, GSMData.IMEI, GSMData.PING, GSMData.GPORT);
|
|
|
+ ComModemSMS_PDU_Log(0, GSMData.NUM, Hbuf, 50);
|
|
|
+
|
|
|
+ GSMData.SENTSTART = 1;// Daten übertragen
|
|
|
+ memset(Hbuf, 0, sizeof(Hbuf));
|
|
|
+ sprintf(Hbuf, "%d", GSMData.SENTSTART);
|
|
|
+ WritePrivateProfileString("Common", "SENTSTART", Hbuf, IniFilename);
|
|
|
+ ReadKonfi(IniFilename);
|
|
|
+ DoSendStart = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // alle Neuen Meldungen übernehmen und nach Auswertung löschen
|
|
|
+ AnzSMS = ComModemSMS_Read(0, "AT+CMGL=0", 50, MAXSMS, SMSData);
|
|
|
+
|
|
|
+ for(i = 0; i < AnzSMS; i++) {
|
|
|
+ char Hbuf[160];
|
|
|
+ char *Htext = NULL;
|
|
|
+
|
|
|
+ printf ("Message ID: [%d]\n", (SMSData + i)->msgid);
|
|
|
+ printf ("Message Status: [%d]\n", (SMSData + i)->msgstatus);
|
|
|
+ printf ("Sender addr.: [%s] (%d char.)\n", (SMSData + i)->fromgsm, strlen ((SMSData + i)->fromgsm));
|
|
|
+ printf ("Message date: [%s] (%d char.)\n", (SMSData + i)->date, strlen ((SMSData + i)->date));
|
|
|
+ printf ("Message time: [%s] (%d char.)\n", (SMSData + i)->time, strlen ((SMSData + i)->time));
|
|
|
+ printf ("Message: [%s] (%d char.)\n", (SMSData + i)->text, strlen ((SMSData + i)->text));
|
|
|
+
|
|
|
+ String2NoControl((SMSData + i)->text, strlen((SMSData + i)->text), &Htext);
|
|
|
+ if(Htext != NULL) {
|
|
|
+ fnameprint_moni(GSMData.SMSINLOGFILENAME, "%s;%s;%s;\x22%s\x22",
|
|
|
+ (SMSData + i)->fromgsm, (SMSData + i)->date, (SMSData + i)->time, Htext);
|
|
|
+ free(Htext);
|
|
|
+ }
|
|
|
+ memset(Hbuf, 0, sizeof(Hbuf));
|
|
|
+ sprintf(Hbuf, "AT+CMGD=%d", (SMSData + i)->msgid);
|
|
|
+ ComModemAT(0, Hbuf, 80); // Meldung köschen
|
|
|
+
|
|
|
+ // ---- hier auswerten !!!
|
|
|
+ {
|
|
|
+ int AnzChar;
|
|
|
+ int AnsLen;
|
|
|
+ char *AnsBuf = NULL;
|
|
|
+
|
|
|
+ AnsBuf = malloc(4096);
|
|
|
+ AnsLen = 4096;
|
|
|
+
|
|
|
+ if(AnsBuf != NULL) {
|
|
|
+ AnzChar = DoMeModCmd(0, (SMSData + i)->text, AnsLen, AnsBuf, IniFilename); // Kommandos ausführen !!!!!
|
|
|
+ if(AnzChar > 0){
|
|
|
+ ComModemSMS_PDU_Log(0, (SMSData + i)->fromgsm, AnsBuf, 50);
|
|
|
+ }
|
|
|
+
|
|
|
+ free(AnsBuf);
|
|
|
+ }
|
|
|
+
|
|
|
+ Snap7_InSMS((SMSData + i)->date, (SMSData + i)->time, (SMSData + i)->fromgsm, (SMSData + i)->text);
|
|
|
+ }
|
|
|
+ // ---------------------------
|
|
|
+ }
|
|
|
+ loopcnt = 0;
|
|
|
+ }
|
|
|
+ } // while (AnsWait ....
|
|
|
+ Msq_Lock();
|
|
|
+ printf("\n------------------ END MODEM MAINLOOP ---------------\n");
|
|
|
+ //--------
|
|
|
+ } else {
|
|
|
+ printf("CANT INIT MODEM\n");
|
|
|
+ // auf alle Fälle auch Batterie prüfen !!!
|
|
|
+
|
|
|
+ // Vergleichsstring zurücksetzen
|
|
|
+ memset(ModemBuf, 0, sizeof(ModemBuf));
|
|
|
+ BufCnt = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ ComReset(0);
|
|
|
+}
|
|
|
+
|
|
|
+// Einlesen eine Strings vom IP Port
|
|
|
+static int readIPCMD(int Hand, char *Answer, int Anslen , int TimeOutmSec)
|
|
|
+{
|
|
|
+ fd_set rmask;
|
|
|
+ struct timeval timeout;
|
|
|
+ int maxfd;
|
|
|
+ int ret = 0;
|
|
|
+ char Rch;
|
|
|
+ int DoIt;
|
|
|
+ int AnzChar;
|
|
|
+ int TCPTimeoutmSec = 0;
|
|
|
+
|
|
|
+ maxfd = Hand;
|
|
|
+ maxfd ++;
|
|
|
+
|
|
|
+ AnzChar = 0;
|
|
|
+ DoIt = 1;
|
|
|
+ do {
|
|
|
+ FD_ZERO(&rmask);
|
|
|
+ FD_SET(Hand, &rmask);
|
|
|
+
|
|
|
+ timeout.tv_sec = TimeOutmSec/1000;
|
|
|
+ timeout.tv_usec = (TimeOutmSec % 1000) * 1000;
|
|
|
+
|
|
|
+ ret = select(maxfd, &rmask, NULL, NULL, &timeout);
|
|
|
+ switch(ret) {
|
|
|
+ case -1: // fehler
|
|
|
+ //printf("e");
|
|
|
+ DoIt = -1; // Bei Fehler beenden
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0: // Timeout
|
|
|
+ //printf("..t..");
|
|
|
+ TCPTimeoutmSec += TimeOutmSec; // Timeoutzähler hochsetzen
|
|
|
+ if(TCPTimeoutmSec > 60000) { // --- maximal eine minute Timeout
|
|
|
+ // Abbruch angefordert !!!
|
|
|
+ printf("TCP CMD Timeout --> abbrechen !\n");
|
|
|
+ DoIt = -2;
|
|
|
+ AnzChar = 0; //macht alles keinen Sinn
|
|
|
+ }
|
|
|
+ //printf("[IP]%d..", TCPTimeoutmSec);
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ default: //was da
|
|
|
+ //read(Hand, &Rch, 1); // geht sicher immer gut da fehler und timeout woanders abgefangen werden
|
|
|
+ if(recv(Hand, &Rch, 1, 0) > 0) { // geht sicher immer gut da fehler und timeout woanders abgefangen werden
|
|
|
+ TCPTimeoutmSec = 0; // Timeout zurücksetzen !!!
|
|
|
+ *(Answer + AnzChar) = Rch;
|
|
|
+
|
|
|
+ ++AnzChar;
|
|
|
+ if(AnzChar >= Anslen) {
|
|
|
+ // Buffer voll, um ein Zeichen nach Links damit alles soweit angehängt werden kann
|
|
|
+ --AnzChar;
|
|
|
+ memmove(Answer, Answer + 1, AnzChar);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ printf("ERROR IPCMD recv\n");
|
|
|
+ DoIt = -3;
|
|
|
+ AnzChar = 0; // nichts vernünftiges da !!!
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } while((Rch != '\r') && (DoIt == 1));
|
|
|
+
|
|
|
+ return AnzChar;
|
|
|
+}
|
|
|
+
|
|
|
+void *CmdIPThread(void *arg)
|
|
|
+{
|
|
|
+ char *msg;
|
|
|
+ char *argv = NULL, *envp = NULL;
|
|
|
+
|
|
|
+ msg = malloc(512);
|
|
|
+ if(msg != NULL) {
|
|
|
+ memset(msg, 0, 512);
|
|
|
+ sprintf(msg, "VER Display_GSM %6.6s " VENDOR ";\r\n SCID %s; IMSI %s, IMEI %s; PING %d; PORT %d\r\n quit ... End Connection\r\n\x04", VERSION + 10,
|
|
|
+ GSMData.SCID, GSMData.IMSI, GSMData.IMEI, GSMData.PING, GSMData.GPORT);
|
|
|
+ SetConnectMessage(msg);
|
|
|
+ free(msg);
|
|
|
+ }
|
|
|
+ CmdIPStart(0, &argv, &envp);
|
|
|
+}
|
|
|
+
|
|
|
+//---------------------------------------
|
|
|
+// wird vom Kommandohandler aufgerufen
|
|
|
+//---------------------------------------
|
|
|
+int DoIPCmd(char *message, char *SocketData, int SocketDataLen)
|
|
|
+{
|
|
|
+ int ret = 0;
|
|
|
+
|
|
|
+// Ende Kommando auswerten
|
|
|
+ if(strnicmp(message, "quit", 4) == 0) {
|
|
|
+ ret = 0;
|
|
|
+ } else {
|
|
|
+ if((SocketData != NULL) && (SocketDataLen > 0)) {
|
|
|
+ char *AnsBuf;
|
|
|
+ int AnsLen;
|
|
|
+ int AnzChar;
|
|
|
+
|
|
|
+ memset(SocketData, 0, SocketDataLen);
|
|
|
+
|
|
|
+ AnsLen = 1024;
|
|
|
+ AnsBuf = malloc(AnsLen);
|
|
|
+
|
|
|
+ if(AnsBuf != NULL) {
|
|
|
+
|
|
|
+ memset(AnsBuf, 0, AnsLen);
|
|
|
+ AnzChar = DoMeModCmd(5, message, AnsLen, AnsBuf, INI_FILENAME); // Kommandos ausführen !!!!!
|
|
|
+
|
|
|
+ if(AnzChar > 0) {
|
|
|
+ //snprintf(SocketData, SocketDataLen, "\r\n%d\r\n%*.*s\r\n",AnzChar, AnzChar, AnzChar, AnsBuf);
|
|
|
+ snprintf(SocketData, SocketDataLen, "\r\n%*.*s\r\n\x04", AnzChar, AnzChar, AnsBuf);
|
|
|
+ } else {
|
|
|
+ snprintf(SocketData, SocketDataLen, "\r\n\x04");
|
|
|
+ }
|
|
|
+ ret = strlen(SocketData);
|
|
|
+
|
|
|
+ free(AnsBuf);
|
|
|
+ } else {
|
|
|
+ printf("!!!!ANSBUF!!!\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+char *GetIniFileName(void)
|
|
|
+{
|
|
|
+ return INI_FILENAME;
|
|
|
+}
|
|
|
+
|
|
|
+int main(int argc, char **argv, char **envp)
|
|
|
+{
|
|
|
+ int retcode;
|
|
|
+
|
|
|
+ int Err = 0;
|
|
|
+ int WatchLoops = 0;
|
|
|
+//-------------------------------------------------------------------------------------------------------------------------------
|
|
|
+ GSMData.LastPING = time(NULL); // Zeit beim Programmstart setzen
|
|
|
+//------------------
|
|
|
+ ReadKonfi(INI_FILENAME);
|
|
|
+ if(GSMData.CMDPORT > 0) {
|
|
|
+ // nur wenn Port gesetzt ist
|
|
|
+ SetCmdIPPort(GSMData.CMDPORT);
|
|
|
+ retcode = pthread_create(&th_cmdip, NULL, CmdIPThread, NULL);
|
|
|
+ if(retcode == 0) {
|
|
|
+ pthread_detach(th_cmdip);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Msq_StartThread();
|
|
|
+
|
|
|
+ Snap7_Lock();
|
|
|
+ Snap7_StartThread(GSMData.SIEMENS_IP, GSMData.SIEMENS_RACK, GSMData.SIEMENS_SLOT, GSMData.SIEMENS_DBNR);
|
|
|
+
|
|
|
+fnameprint_file("/var/tmp/Display_GSM.info", 0, "w+", "\n"
|
|
|
+ "QUAL : --\n"
|
|
|
+ "PS : --\n"
|
|
|
+ "PROV : --\n"
|
|
|
+ "ASU : --\n"
|
|
|
+ "SIM : --\n"
|
|
|
+ "MODEM : --\n"
|
|
|
+ "VER : --\n"
|
|
|
+ );
|
|
|
+
|
|
|
+ while(1) {
|
|
|
+ Err = 0;
|
|
|
+
|
|
|
+ //prüfen ob schnittstelle überhaupt vorhanden
|
|
|
+ {
|
|
|
+ struct stat ttyStat;
|
|
|
+ /*while (stat(GPRS_TTY, &ttyStat))*/ {
|
|
|
+ printf("Schnittstelle: %s initialisieren !!\n", GPRS_TTY);
|
|
|
+ if(strlen(GSMData.SERDEVINIT)) {
|
|
|
+ printf("\t system(%s);\n", GSMData.SERDEVINIT);
|
|
|
+ system(GSMData.SERDEVINIT);
|
|
|
+ }
|
|
|
+ sleep(5);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!Err)
|
|
|
+ {
|
|
|
+ // Starten des COMMANDO Threads
|
|
|
+ main_Modem(argc, argv, envp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|