- sms pdu mode, tmp commit, ignore
authorAlex Kalimulin <alex@netxms.org>
Sun, 20 Mar 2011 22:43:55 +0000 (22:43 +0000)
committerAlex Kalimulin <alex@netxms.org>
Sun, 20 Mar 2011 22:43:55 +0000 (22:43 +0000)
src/server/smsdrv/generic/generic.vcproj
src/server/smsdrv/generic/main.cpp

index 4b7c769..31200dc 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="windows-1251"?>\r
 <VisualStudioProject\r
        ProjectType="Visual C++"\r
-       Version="8.00"\r
+       Version="8,00"\r
        Name="generic"\r
        ProjectGUID="{41A5009F-4467-4D89-A171-5A919FEFE16E}"\r
        RootNamespace="generic"\r
                        />\r
                </Configuration>\r
                <Configuration\r
-                       Name="Debug|x64"\r
-                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
-                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
                        ConfigurationType="2"\r
                        CharacterSet="1"\r
+                       WholeProgramOptimization="1"\r
                        >\r
                        <Tool\r
                                Name="VCPreBuildEventTool"\r
                        />\r
                        <Tool\r
                                Name="VCMIDLTool"\r
-                               TargetEnvironment="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
-                               Optimization="0"\r
                                AdditionalIncludeDirectories="..\..\..\..\include;..\..\include"\r
-                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;GENERIC_EXPORTS"\r
-                               MinimalRebuild="true"\r
-                               BasicRuntimeChecks="3"\r
-                               RuntimeLibrary="3"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GENERIC_EXPORTS"\r
+                               RuntimeLibrary="2"\r
                                UsePrecompiledHeader="0"\r
                                WarningLevel="3"\r
-                               Detect64BitPortabilityProblems="true"\r
+                               Detect64BitPortabilityProblems="false"\r
                                DebugInformationFormat="3"\r
                        />\r
                        <Tool\r
                        <Tool\r
                                Name="VCLinkerTool"\r
                                OutputFile="$(OutDir)\$(ProjectName).sms"\r
-                               LinkIncremental="2"\r
+                               LinkIncremental="1"\r
                                GenerateDebugInformation="true"\r
                                SubSystem="2"\r
-                               TargetMachine="17"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
                        />\r
                </Configuration>\r
                <Configuration\r
-                       Name="Release|Win32"\r
-                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
-                       IntermediateDirectory="$(ConfigurationName)"\r
+                       Name="Debug|x64"\r
+                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
+                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"\r
                        ConfigurationType="2"\r
                        CharacterSet="1"\r
-                       WholeProgramOptimization="1"\r
                        >\r
                        <Tool\r
                                Name="VCPreBuildEventTool"\r
                        />\r
                        <Tool\r
                                Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
                                AdditionalIncludeDirectories="..\..\..\..\include;..\..\include"\r
-                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GENERIC_EXPORTS"\r
-                               RuntimeLibrary="2"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;GENERIC_EXPORTS"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
                                UsePrecompiledHeader="0"\r
                                WarningLevel="3"\r
-                               Detect64BitPortabilityProblems="false"\r
+                               Detect64BitPortabilityProblems="true"\r
                                DebugInformationFormat="3"\r
                        />\r
                        <Tool\r
                        <Tool\r
                                Name="VCLinkerTool"\r
                                OutputFile="$(OutDir)\$(ProjectName).sms"\r
-                               LinkIncremental="1"\r
+                               LinkIncremental="2"\r
                                GenerateDebugInformation="true"\r
                                SubSystem="2"\r
-                               OptimizeReferences="2"\r
-                               EnableCOMDATFolding="2"\r
-                               TargetMachine="1"\r
+                               TargetMachine="17"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
                                RelativePath=".\main.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\pdumode.cpp"\r
+                               >\r
+                       </File>\r
                </Filter>\r
                <Filter\r
                        Name="Header Files"\r
index b58cd16..7fdfeac 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "main.h"
 
+extern int SMSPack7BitChars(const char* input, char* output, int maxOutputLen);
+
 static Serial m_serial;
 
 // pszInitArgs format: portname,speed,databits,parity,stopbits
@@ -208,6 +210,52 @@ extern "C" BOOL EXPORT SMSDriverSend(const TCHAR *pszPhoneNumber, const TCHAR *p
        return true;
 }
 
+extern "C" BOOL EXPORT SMSDriverSendPDU(const TCHAR *pszPhoneNumber, const TCHAR *pszText)
+{
+       if (pszPhoneNumber != NULL && pszText != NULL)
+       {
+               char szTmp[512];
+
+               DbgPrintf(3, _T("SMS send: to {%s}: {%s}"), pszPhoneNumber, pszText);
+
+               m_serial.Write("ATZ\r\n", 5); // init modem && read user prefs
+               m_serial.Read(szTmp, 128); // read OK
+               DbgPrintf(4, _T("SMS send: ATZ sent, got {%hs}"), szTmp);
+               m_serial.Write("ATE0\r\n", 5); // disable echo
+               m_serial.Read(szTmp, 128); // read OK
+               DbgPrintf(4, _T("SMS send: ATE0 sent, got {%hs}"), szTmp);
+               m_serial.Write("AT+CMGF=0\r\n", 11); // =0 - send text in PDU mode
+               m_serial.Read(szTmp, 128); // read OK
+               DbgPrintf(4, _T("SMS send: AT+CMGF=0 sent, got {%hs}"), szTmp);
+
+               const int pduBufferSize = 512;
+               char pduBuffer[pduBufferSize];
+               char phoneNumberFormatted[32];
+               char payload[pduBufferSize];
+               int phoneLength = _tcslen(pszPhoneNumber);
+               strncpy(phoneNumberFormatted, (const char*)pszPhoneNumber, 32);
+               strcat(phoneNumberFormatted, "FF");
+               for (int i = 0; i <= phoneLength; i += 2)
+               {
+                       char tmp = phoneNumberFormatted[i+1];
+                       phoneNumberFormatted[i+1] = phoneNumberFormatted[i];
+                       phoneNumberFormatted[i] = tmp;
+               }
+               phoneNumberFormatted[phoneLength + 2 - phoneLength % 2] = '\0';
+               SMSPack7BitChars((const char*)pszText, payload, pduBufferSize);
+               snprintf(pduBuffer, pduBufferSize, "0001000%1X91%s0000%02X%s", strlen(phoneNumberFormatted), 
+                       phoneNumberFormatted, _tcslen(pszText), payload);
+               snprintf(szTmp, sizeof(szTmp), "AT+CMGS=%d\r\n", strlen(pduBuffer)/2);
+               m_serial.Write(szTmp, (int)strlen(szTmp)); 
+               snprintf(szTmp, sizeof(szTmp), "%s%c\r\n", pduBuffer, 0x1A);
+               m_serial.Write(szTmp, (int)strlen(szTmp)); // send text, end with ^Z
+               m_serial.Read(szTmp, 128); // read +CMGS:ref_num
+               DbgPrintf(4, _T("SMS send: AT+CMGS + message body sent, got {%hs}"), szTmp);
+       }
+
+       return true;
+}
+
 extern "C" void EXPORT SMSDriverUnload()
 {
        m_serial.Close();