::=================================================================
::
:: Script	: incoming_sms.bat
:: 
:: Author	: BT (2009-09-29)
::
:: Function	: 
::
::
::
::================================================================

::echo %date% %time%: Phone: %1 String3G: %2>> d:\nvpopup\incoming.log

::nve nvarun 1 -i49989 -s4"%2" -s8"%1"

:: Initialize some globals
::set _NVT_DIR=\nvt


:: Do something with the string before starting the nve module
::===========================================================
:: example 1 of the string to pars= NV3GA:E77F6B9Ci84ABB8C12f1YC-0765814940
:: example 2 of string to pars=     NV3GA:E77F6B9C S1Ci84ABB8C12f1Ac-0765814940
::				    ::NV3GA:E77F6B9CS1Ci84ABB8C12f1Yt5AAAAAc-0765814940
				    ::NV3GA:E77F6B9C i84B1E6576f1Ac-0797777177
::  
::
:: PHONE
:: MAGICWORD
:: CRC
:: STATUS
:: JOBID
:: FLAG (TMS)
:: TMS
:: TEXT
:: ANSWER
:: ACTION
:: CLIENTID
:: ACTION_ACCEPTED

d:

cd nvt

@ECHO off

::DELETE ALL VARIABLE

SET PHONE=%~1
SET ACTION_ACCEPTED=1


for /f "tokens=1 delims=:" %%A IN (%2) do SET MAGICWORD=%%~A
for /f "tokens=2 delims=:" %%A IN (%2) do SET TOKEN=%%~A
for /f "tokens=2 delims=c-" %%A IN (%2) do SET CLIENTID=%%~A

ECHO MAGICWORD=%MAGICWORD%
ECHO TOKEN=%TOKEN%
SET TMPTOKEN=%TOKEN%

::GET TOKEN CRC
SET CRC=%TOKEN:~0,8%
ECHO CRC=%CRC%

REM pause




::GET TOKEN STATUS
::===================================

SET INDEX=8
CALL SET TMP=%%TOKEN:~%INDEX%,1%%%
SET STATUS_ON=0

IF "%TMP%" == "S" SET STATUS_ON=1 & goto GETSTATE

:GETSTATE
SET /A INDEX=%INDEX%+1
CALL SET LEN=%%TOKEN:~%INDEX%,1%%%
SET /A INDEX=%INDEX%+1
CALL SET STATUS=%%TOKEN:~%INDEX%,%LEN%%%
::ECHO %STATUS%
SET STATUS=%STATUS%
SET /A INDEX=%INDEX%+%LEN%
SET TMS="%STATUS%"


IF "%STATUS_ON%" == "0" SET INDEX=8
::IF "%STATUS_ON%" == "0" SET INDEX=9



ECHO STATUS=%STATUS%

::GET TOKEN JOBID
::===================================

::SET /A INDEX = %INDEX%+1
:GETJOBID
CALL SET JOBTOKEN=%%TOKEN:~%INDEX%,2%%


SET /A INDEX = %INDEX%+1
SET LEN=%JOBTOKEN:~1,1%
SET /A INDEX = %INDEX%+1
CALL SET JOBID=%%TOKEN:~%INDEX%,%LEN%%%
SET /A INDEX = %INDEX%+%LEN%
ECHO JOBID=%JOBID%

::GET TOKEN FLAG(TMS)
::===================================

CALL SET FLAGTOKEN=%%TOKEN:~%INDEX%,2%%
SET /A INDEX = %INDEX%+1
SET LEN=%FLAGTOKEN:~1,1%
SET /A INDEX = %INDEX%+1
CALL SET FLAG=%%TOKEN:~%INDEX%,%LEN%%%
ECHO FLAG=%FLAG%
SET /A INDEX = %INDEX%+%LEN%
IF "%FLAG%" == "A" SET ACTION_ACCEPTED=0
IF "%FLAG%" == "Y" SET ACTION="Yes"
IF "%FLAG%" == "N" SET ACTION="No"

::GET TOKEN TEXT
::===================================

CALL SET TEXTTOKEN=%%TOKEN:~%INDEX%,1%%


IF "%TEXTTOKEN%" == "t" goto GETTEXT
rem pause
:GETTEXT
SET /A INDEX=%INDEX%+1
CALL SET LEN=%%TOKEN:~%INDEX%,1%%%
IF "%LEN%" == "-" SET LEN=10
IF "%LEN%" == "A" SET LEN=11
IF "%LEN%" == "B" SET LEN=12
IF "%LEN%" == "C" SET LEN=13
IF "%LEN%" == "D" SET LEN=14
IF "%LEN%" == "E" SET LEN=15
IF "%LEN%" == "F" SET LEN=16
IF "%LEN%" == "G" SET LEN=17
IF "%LEN%" == "H" SET LEN=18
IF "%LEN%" == "J" SET LEN=19
IF "%LEN%" == "K" SET LEN=20
IF "%LEN%" == "L" SET LEN=21
IF "%LEN%" == "M" SET LEN=22
IF "%LEN%" == "N" SET LEN=23
IF "%LEN%" == "O" SET LEN=24
IF "%LEN%" == "P" SET LEN=25
IF "%LEN%" == "Q" SET LEN=26
IF "%LEN%" == "R" SET LEN=27
IF "%LEN%" == "S" SET LEN=28
IF "%LEN%" == "T" SET LEN=29
IF "%LEN%" == "U" SET LEN=30
IF "%LEN%" == "V" SET LEN=31
IF "%LEN%" == "W" SET LEN=32
IF "%LEN%" == "X" SET LEN=33
IF "%LEN%" == "Y" SET LEN=34
IF "%LEN%" == "Z" SET LEN=35
IF "%LEN%" == "a" SET LEN=36
IF "%LEN%" == "b" SET LEN=37
IF "%LEN%" == "c" SET LEN=38
IF "%LEN%" == "d" SET LEN=39
IF "%LEN%" == "e" SET LEN=40
IF "%LEN%" == "f" SET LEN=41
IF "%LEN%" == "g" SET LEN=42
IF "%LEN%" == "h" SET LEN=43
IF "%LEN%" == "j" SET LEN=44
IF "%LEN%" == "k" SET LEN=45
IF "%LEN%" == "l" SET LEN=46
IF "%LEN%" == "m" SET LEN=47
IF "%LEN%" == "n" SET LEN=48
IF "%LEN%" == "o" SET LEN=49
IF "%LEN%" == "p" SET LEN=50
SET /A INDEX=%INDEX%+1
CALL SET TEXT=%%TOKEN:~%INDEX%,%LEN%%%
SET /A INDEX = %INDEX%+%LEN%


IF NOT "%TEXTTOKEN%" == "t" SET TEXT=""
ECHO TEXT=%TEXT%


IF "%ACTION_ACCEPTED%" == "1" nve.exe nv3gwritejob 1 -s1%MAGICWORD% -s2%PHONE% -s4%JOBID% -s5%ACTION% -s6%TEXT% -s7%TMS% >> d:\nvt\LOG\incoming3GSMS.log

