Example #1
0
 //***NEW MODULE SETTINGS***
 $FileName = "{$ComFileDir}{$Imei}.tms";
 //Construct file name like: 123456789012345.tms
 if (@is_file($FileName) && !$pcGPS->RequireResponseActionMembersStall()) {
     //The file is expected to contain settings from the CGPSsettings
     //class or written to disk with the settings application.
     //If uploaded settings are received by the module, it will let the
     //result know via a transmission with Switch value
     //SV_SettingsAccepted or SV_SettingsRejected.
     //
     //Simply "$pcGPS->mSettings=file_get_contents($FileName);" would be
     //sufficient, but below we put the file contents in the CGPSsettings
     //class first to check if the file really contains settings data,
     //calculate the CRC of the settings and write the findings to the
     //log too.
     $pcGPSsettings = new CGPSsettings();
     //Create new instance object of the class
     if ($pcGPSsettings->SetSettingsData(@file_get_contents($FileName))) {
         //Class accepted the data, so it must be valid settings data
         $pcGPS->mSettings = $pcGPSsettings->GetSettingsData();
         //Put settings data in mSettings to upload it
         $CRC = $pcGPSsettings->GetSettingsCRC();
         //Calculate the CRC of the settings data
         LogError("INFO (not an error): Settings data from file '{$FileName}' with CRC value '{$CRC}' uploaded to module {$Imei}.");
     } else {
         LogError("Settings file '{$FileName}' error (file will be deleted): " . $pcGPSsettings->GetLastError());
     }
     @chmod($FileName, 0666);
     if (!@unlink($FileName)) {
         LogError("!!!SERIOUS PROBLEM!!! The file '{$FileName}' could not be deleted (will be retried later).");
     }
Example #2
0
 function SetTcpData($Imei, $TcpData)
 {
     $Len = strlen($TcpData);
     if ($Len > 15) {
         $db = ord($TcpData[0]);
         if ($db >= 0x80 && $db <= 0x85) {
             $b = true;
             $s = 0;
         } else {
             if ($db <= 0x63) {
                 $t = ord($TcpData[6]);
                 if ($t >= 0x80 && $t <= 0x85) {
                     $IMEI = sprintf('%02d%03d%03d%03d%03d', $db, ord($TcpData[1]) << 2 | ord($TcpData[2]) >> 6, (ord($TcpData[2]) & 0x3f) << 4 | ord($TcpData[3]) >> 4, (ord($TcpData[3]) & 0xf) << 6 | ord($TcpData[4]) >> 2, (ord($TcpData[4]) & 0x3) << 8 | ord($TcpData[5]));
                     $c = 0;
                     for ($i = 0; $i < 14; $i += 2) {
                         $d = $IMEI[$i + 1] << 1;
                         $c += $IMEI[$i] + (int) ($d / 10) + $d % 10;
                     }
                     $IMEI = sprintf('%s%d', $IMEI, (10 - $c % 10) % 10);
                     $b = true;
                     $s = 6;
                 }
             }
         }
         if (isset($b)) {
             if (!isset($IMEI)) {
                 if (!CheckImeiCrc($Imei)) {
                     $this->Clear();
                     $this->mLastError = "CGPS::SetTcpData() provided IMEI invalid while required for TcpData without one";
                     return 0;
                 }
             } else {
                 $Imei = $IMEI;
             }
             $this->maParts = array();
             for ($i = $s;; $i = $N) {
                 if ($i < $Len) {
                     switch ($t = ord($TcpData[$i])) {
                         case 0x80:
                         case 0x82:
                         case 0x84:
                             $N = ++$i + 33;
                             if ($Len < $N) {
                                 break;
                             }
                             $this->maParts[] = bin2hex(substr($TcpData, $i, 33));
                             if ($t == 0x80) {
                                 continue 2;
                             }
                             $this->mWantAck = $t == 0x84 ? false : true;
                             $this->mImei = $Imei;
                             $p = $N - 34;
                             $this->mCRC = CGPSsettings::CreateCRC($Imei . substr($TcpData, $s, $p - $s) . chr(0x80) . substr($TcpData, $p + 1, $N - $p - 1));
                             $this->SelectDataPart(0);
                             return $N;
                         case 0x81:
                         case 0x83:
                         case 0x85:
                             $N = ++$i + 15;
                             if ($Len < $N) {
                                 break;
                             }
                             $this->achanh(bin2hex(substr($TcpData, $i, 15)));
                             if ($t == 0x81) {
                                 continue 2;
                             }
                             $this->mWantAck = $t == 0x85 ? false : true;
                             $this->mImei = $Imei;
                             $p = $N - 16;
                             $this->mCRC = CGPSsettings::CreateCRC($Imei . substr($TcpData, $s, $p - $s) . chr(0x81) . substr($TcpData, $p + 1, $N - $p - 1));
                             $this->SelectDataPart(0);
                             return $N;
                         default:
                             if (!count($this->maParts)) {
                                 $this->Clear();
                             } else {
                                 $this->SelectDataPart(0);
                             }
                             $this->mImei = $Imei;
                             $this->mLastError = 'CGPS::SetTcpData() unsupported type for data part ' . count($this->maParts);
                             return 0;
                     }
                 }
                 $this->mImei = $Imei;
                 $this->SelectDataPart(0);
                 $this->mLastError = 'CGPS::SetTcpData() TcpData too short for data part ' . count($this->maParts);
                 return 0;
             }
         } else {
             $l = strpos($TcpData, "\n");
             $r = strpos($TcpData, "\r");
             if ($r !== false && $r < $l) {
                 $l = $r;
             }
             if ($l !== false) {
                 if ($db > 57 || $db < 48) {
                     $b = $this->SetHttpData($Imei . substr($TcpData, 0, $l));
                 } else {
                     $b = $this->SetHttpData(substr($TcpData, 0, $l));
                 }
                 if ($b) {
                     if ($TcpData[$l] == "\r") {
                         return -($l + 1);
                     }
                     return $l + 1;
                 }
                 $this->mLastError = 'CGPS::SetTcpData() forward ' . $this->mLastError;
                 return 0;
             }
         }
     }
     $this->Clear();
     $this->mLastError = "CGPS::SetTcpData() Invalid TcpData";
     return 0;
 }