Initial Commit
parent
ed27535aaa
commit
5395f11892
@ -0,0 +1,34 @@
|
||||
// aboutdlg.h : interface of the CAboutDlg class
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
class CAboutDlg : public CDialogImpl<CAboutDlg>
|
||||
{
|
||||
public:
|
||||
enum { IDD = IDD_ABOUTBOX };
|
||||
|
||||
BEGIN_MSG_MAP(CAboutDlg)
|
||||
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
|
||||
COMMAND_ID_HANDLER(IDOK, OnCloseCmd)
|
||||
COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd)
|
||||
END_MSG_MAP()
|
||||
|
||||
// Handler prototypes (uncomment arguments if needed):
|
||||
// LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
||||
// LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
||||
// LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)
|
||||
|
||||
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
||||
{
|
||||
CenterWindow(GetParent());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
||||
{
|
||||
EndDialog(wID);
|
||||
return 0;
|
||||
}
|
||||
};
|
@ -0,0 +1,213 @@
|
||||
#include "CacService.h"
|
||||
#include <json/json.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
#define KEEP_ALIVE 60
|
||||
|
||||
void CCacService::cac_message_callback(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message)
|
||||
{
|
||||
((CCacService*)userdata)->MessageCallback(mosq, message);
|
||||
}
|
||||
|
||||
void CCacService::cac_connect_callback(struct mosquitto *mosq, void *userdata, int result)
|
||||
{
|
||||
((CCacService*)userdata)->ConnectCallback(mosq, result);
|
||||
}
|
||||
|
||||
void CCacService::cac_subscribe_callback(struct mosquitto *mosq, void *userdata, int mid, int qos_count, const int *granted_qos)
|
||||
{
|
||||
((CCacService*)userdata)->SubscribeCallback(mosq, mid, qos_count, granted_qos);
|
||||
}
|
||||
|
||||
void CCacService::cac_log_callback(struct mosquitto *mosq, void *userdata, int level, const char *str)
|
||||
{
|
||||
((CCacService*)userdata)->LogCallback(mosq, level, str);
|
||||
}
|
||||
|
||||
CCacService::CCacService() : m_session(true), m_mosq(NULL), m_conn(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
CCacService::~CCacService()
|
||||
{
|
||||
if (m_mosq != NULL)
|
||||
{
|
||||
mosquitto_destroy(m_mosq);
|
||||
m_mosq = NULL;
|
||||
}
|
||||
if (m_conn != NULL)
|
||||
{
|
||||
delete m_conn;
|
||||
}
|
||||
}
|
||||
|
||||
void CCacService::MessageCallback(struct mosquitto *mosq, const struct mosquitto_message *message)
|
||||
{
|
||||
if (message->payloadlen) {
|
||||
printf("%s %s", message->topic, (char *)(message->payload));
|
||||
}
|
||||
else {
|
||||
printf("%s (null)\n", message->topic);
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void CCacService::ConnectCallback(struct mosquitto *mosq, int result)
|
||||
{
|
||||
int i;
|
||||
if (!result)
|
||||
{
|
||||
/* Subscribe to broker information topics on successful connect. */
|
||||
// mosquitto_subscribe(mosq, NULL, "GaiÒ¯:", 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Connect failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
void CCacService::SubscribeCallback(struct mosquitto *mosq, int mid, int qos_count, const int *granted_qos)
|
||||
{
|
||||
int i;
|
||||
printf("Subscribed (mid: %d): %d", mid, granted_qos[0]);
|
||||
for (i = 1; i < qos_count; i++)
|
||||
{
|
||||
printf(", %d", granted_qos[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void CCacService::LogCallback(struct mosquitto *mosq, int level, const char *str)
|
||||
{
|
||||
/* Pring all log messages regardless of level. */
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
||||
void CCacService::MosquittoLoop()
|
||||
{
|
||||
mosquitto_loop_forever(m_mosq, -1, 1);
|
||||
int aa = 0;
|
||||
}
|
||||
|
||||
void CCacService::ExportLoop(CMySQLAdo* conn)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
for (std::map<std::string, CSyncTable>::iterator it = m_syncTables.begin(); it != m_syncTables.end(); ++it)
|
||||
{
|
||||
Json::Value jonsObj = Json::objectValue;
|
||||
jonsObj["AssetList"] = Json::arrayValue;
|
||||
|
||||
m_conn->ProcessTable(it->second, jonsObj["AssetList"]);
|
||||
|
||||
int mid = 0;
|
||||
std::string data = CvtJSONToString(jonsObj);
|
||||
#ifdef _DEBUG
|
||||
std::cout << data << std::endl;
|
||||
writeFile("D://testJson.txt", (const unsigned char *)data.c_str(), data.size());
|
||||
#endif
|
||||
if (m_mosq != NULL)
|
||||
{
|
||||
int res = mosquitto_publish(m_mosq, &mid, "external/data", data.size(), (void *)(data.c_str()), SYNC_QOS_LEVEL_0, false);
|
||||
if (res == MOSQ_ERR_SUCCESS)
|
||||
{
|
||||
// Update time
|
||||
int aa = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (MOSQ_ERR_ERRNO == res)
|
||||
{
|
||||
int errorno = errno;
|
||||
char* errmsg = strerror(errorno);
|
||||
|
||||
int aa = 0;
|
||||
}
|
||||
int bbb = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CCacService::Start(const std::map<std::string, std::string>& arguments)
|
||||
{
|
||||
//create mosquitto client
|
||||
m_mosq = mosquitto_new(NULL, m_session, NULL);
|
||||
if (!m_mosq)
|
||||
{
|
||||
// printf("create client failed..\n");
|
||||
// mosquitto_lib_cleanup();
|
||||
return false;
|
||||
}
|
||||
// Callback
|
||||
mosquitto_user_data_set(m_mosq, (void *)this);
|
||||
// mosquitto_log_callback_set(mosq, cac_log_callback);
|
||||
mosquitto_connect_callback_set(m_mosq, cac_connect_callback);
|
||||
mosquitto_message_callback_set(m_mosq, cac_message_callback);
|
||||
// mosquitto_subscribe_callback_set(mosq, cac_subscribe_callback);
|
||||
// connect to server
|
||||
std::string mqttServer = FindArgument(arguments, ARG_KEY_MQTT_HOST);
|
||||
std::string mqttPort = FindArgument(arguments, ARG_KEY_MQTT_PORT);
|
||||
|
||||
std::string mqttUser = FindArgument(arguments, ARG_KEY_MQTT_USER);
|
||||
std::string mqttPwd = FindArgument(arguments, ARG_KEY_MQTT_PASSWORD);
|
||||
|
||||
mqttPwd = "AliOS%1688";
|
||||
|
||||
std::string dbServer = FindArgument(arguments, ARG_KEY_DB_HOST);
|
||||
unsigned short dbPort = 3306; // arguments["mqttport"];
|
||||
std::string dbName = FindArgument(arguments, ARG_KEY_DB_NAME);
|
||||
// std::string dbName = FindArgument(arguments, ARG_KEY_DB_NAME);
|
||||
std::string dbUser = FindArgument(arguments, ARG_KEY_DB_USER);
|
||||
std::string dbPwd = FindArgument(arguments, ARG_KEY_DB_PASSWORD);
|
||||
|
||||
mosquitto_username_pw_set(m_mosq, mqttUser.c_str(), mqttPwd.c_str());
|
||||
|
||||
if (mosquitto_connect(m_mosq, mqttServer.c_str(), atoi(mqttPort.c_str()), KEEP_ALIVE))
|
||||
{
|
||||
mosquitto_destroy(m_mosq);
|
||||
m_mosq = NULL;
|
||||
fprintf(stderr, "Unable to connect.\n");
|
||||
#ifndef _DEBUG
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
m_conn = new CMySQLAdo();
|
||||
if (!m_conn->Connect(dbServer, dbUser, dbPwd, dbName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_conn->loadSyncTables(SYNC_CLIENT_CAC_MQTT, m_syncTables);
|
||||
|
||||
//Ñ»·´¦ÀíÍøÂçÏûÏ¢
|
||||
// mosquitto_loop_forever(mosq, -1, 1);
|
||||
if (m_mosq != NULL)
|
||||
{
|
||||
std::thread th1(std::mem_fun(&CCacService::MosquittoLoop), this);
|
||||
m_mosqThread.swap(th1);
|
||||
}
|
||||
|
||||
std::thread th2(std::mem_fun(&CCacService::ExportLoop), this, m_conn);
|
||||
m_exportThread.swap(th2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCacService::Join()
|
||||
{
|
||||
if (m_mosqThread.joinable()) m_mosqThread.join();
|
||||
if (m_exportThread.joinable()) m_exportThread.join();
|
||||
}
|
||||
|
||||
// unsigned int CCacService::ProcessTable(const std::string& tableName, const CSyncRecord& syncRecord, const CSyncTableFields& syncTable)
|
||||
// {
|
||||
// return 0;
|
||||
// }
|
@ -0,0 +1,70 @@
|
||||
#ifndef __CAC_SERVICE__
|
||||
#define __CAC_SERVICE__
|
||||
|
||||
|
||||
#include <thread>
|
||||
#include <mosquitto.h>
|
||||
#include "MySQLAdo.h"
|
||||
|
||||
#define SYNC_CLIENT_CAC_MQTT 10
|
||||
#define SYNC_QOS_LEVEL_0 0
|
||||
|
||||
#define TOPIC_SENSOR "/xy/sensor/device/data/report"
|
||||
#define TOPIC_SENSOR "/xy/evaluation/transformer/results"
|
||||
|
||||
#define ARG_KEY_MQTT_HOST "mqtthost"
|
||||
#define ARG_KEY_MQTT_PORT "mqttport"
|
||||
#define ARG_KEY_MQTT_USER "mqttuser"
|
||||
#define ARG_KEY_MQTT_PASSWORD "mqttpwd"
|
||||
#define ARG_KEY_DB_HOST "dbhost"
|
||||
#define ARG_KEY_DB_PORT "dbport"
|
||||
#define ARG_KEY_DB_NAME "dbname"
|
||||
#define ARG_KEY_DB_USER "dbuser"
|
||||
#define ARG_KEY_DB_PASSWORD "dbpwd"
|
||||
|
||||
|
||||
class CCacService
|
||||
{
|
||||
public:
|
||||
CCacService();
|
||||
~CCacService();
|
||||
|
||||
bool Start(const std::map<std::string, std::string>& arguments);
|
||||
void Join();
|
||||
|
||||
protected:
|
||||
static void cac_message_callback(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message);
|
||||
static void cac_connect_callback(struct mosquitto *mosq, void *userdata, int result);
|
||||
static void cac_subscribe_callback(struct mosquitto *mosq, void *userdata, int mid, int qos_count, const int *granted_qos);
|
||||
static void cac_log_callback(struct mosquitto *mosq, void *userdata, int level, const char *str);
|
||||
|
||||
void MessageCallback(struct mosquitto *mosq, const struct mosquitto_message *message);
|
||||
void ConnectCallback(struct mosquitto *mosq, int result);
|
||||
void SubscribeCallback(struct mosquitto *mosq, int mid, int qos_count, const int *granted_qos);
|
||||
void LogCallback(struct mosquitto *mosq, int level, const char *str);
|
||||
|
||||
void MosquittoLoop();
|
||||
void ExportLoop(CMySQLAdo* conn);
|
||||
|
||||
// unsigned int ProcessTable(const std::string& tableName, const CSyncRecord& syncRecord, const CSyncTableFields& syncTable);
|
||||
|
||||
protected:
|
||||
std::string m_dbHost;
|
||||
std::string m_dbName;
|
||||
std::string m_dbUser;
|
||||
std::string m_dbPassword;
|
||||
|
||||
bool m_session;
|
||||
struct mosquitto* m_mosq;
|
||||
std::thread m_mosqThread;
|
||||
std::thread m_exportThread;
|
||||
|
||||
std::map<std::string, CSyncTable> m_syncTables;
|
||||
// std::vector<CSyncTable> m_syncRecords;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // __CAC_SERVICE__
|
||||
|
||||
|
@ -0,0 +1,56 @@
|
||||
// MQTTClient.cpp : main source file for MQTTClient.exe
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <atlframe.h>
|
||||
#include <atlctrls.h>
|
||||
#include <atldlgs.h>
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
#include "OptionDlg.h"
|
||||
#include "View.h"
|
||||
#include "aboutdlg.h"
|
||||
#include "MainFrm.h"
|
||||
|
||||
CAppModule _Module;
|
||||
|
||||
int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int nCmdShow = SW_SHOWDEFAULT)
|
||||
{
|
||||
CMessageLoop theLoop;
|
||||
_Module.AddMessageLoop(&theLoop);
|
||||
|
||||
CMainFrame wndMain;
|
||||
|
||||
if(wndMain.CreateEx() == NULL)
|
||||
{
|
||||
ATLTRACE(_T("Main window creation failed!\n"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
wndMain.ShowWindow(nCmdShow);
|
||||
|
||||
int nRet = theLoop.Run();
|
||||
|
||||
_Module.RemoveMessageLoop();
|
||||
return nRet;
|
||||
}
|
||||
|
||||
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
|
||||
{
|
||||
HRESULT hRes = ::CoInitialize(NULL);
|
||||
ATLASSERT(SUCCEEDED(hRes));
|
||||
|
||||
AtlInitCommonControls(ICC_BAR_CLASSES); // add flags to support other controls
|
||||
|
||||
hRes = _Module.Init(NULL, hInstance);
|
||||
ATLASSERT(SUCCEEDED(hRes));
|
||||
|
||||
int nRet = Run(lpstrCmdLine, nCmdShow);
|
||||
|
||||
_Module.Term();
|
||||
::CoUninitialize();
|
||||
|
||||
return nRet;
|
||||
}
|
@ -0,0 +1 @@
|
||||
// MQTTClient.h
|
@ -0,0 +1,342 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "atlres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Chinese (Simplified, PRC) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
|
||||
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
|
||||
#pragma code_page(936)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Menu
|
||||
//
|
||||
|
||||
IDR_MAINFRAME MENU
|
||||
BEGIN
|
||||
POPUP "&File"
|
||||
BEGIN
|
||||
MENUITEM "选项", ID_FILE_OPTIONS
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "E&xit", ID_APP_EXIT
|
||||
END
|
||||
POPUP "&Edit"
|
||||
BEGIN
|
||||
MENUITEM "&Undo\tCtrl+Z", ID_EDIT_UNDO
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Cu&t\tCtrl+X", ID_EDIT_CUT
|
||||
MENUITEM "&Copy\tCtrl+C", ID_EDIT_COPY
|
||||
MENUITEM "&Paste\tCtrl+V", ID_EDIT_PASTE
|
||||
END
|
||||
POPUP "&View"
|
||||
BEGIN
|
||||
MENUITEM "&Status Bar", ID_VIEW_STATUS_BAR
|
||||
END
|
||||
POPUP "&Help"
|
||||
BEGIN
|
||||
MENUITEM "&About MQTTClient", ID_APP_ABOUT
|
||||
END
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dialog
|
||||
//
|
||||
|
||||
IDD_ABOUTBOX DIALOG 0, 0, 187, 102
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "About"
|
||||
FONT 9, "Segoe UI"
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "OK",IDOK,130,81,50,14
|
||||
CTEXT "MQTTClient Application v1.0\n\n(c) Copyright 2024",IDC_STATIC,25,57,78,32
|
||||
ICON IDR_MAINFRAME,IDC_STATIC,55,26,18,20
|
||||
GROUPBOX "",IDC_STATIC,7,7,115,88
|
||||
END
|
||||
|
||||
IDD_MQTTCLIENT_FORM DIALOGEX 0, 0, 371, 158
|
||||
STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS
|
||||
EXSTYLE WS_EX_CLIENTEDGE
|
||||
FONT 9, "Segoe UI", 0, 0, 0x1
|
||||
BEGIN
|
||||
EDITTEXT IDC_TO_SEND,7,23,301,55,ES_MULTILINE | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL
|
||||
COMBOBOX IDC_TOPICES,7,7,292,30,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP
|
||||
PUSHBUTTON "发送",IDC_SEND,314,7,50,14
|
||||
EDITTEXT IDC_TO_RECV,7,83,357,68,ES_MULTILINE | ES_AUTOHSCROLL | WS_VSCROLL
|
||||
PUSHBUTTON "清空",IDC_CLEAR,314,65,50,14
|
||||
END
|
||||
|
||||
IDD_OPTIONS_DLG DIALOGEX 0, 0, 310, 177
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Dialog"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "OK",IDOK,199,156,50,14
|
||||
PUSHBUTTON "Cancel",IDCANCEL,253,156,50,14
|
||||
EDITTEXT IDC_USERNAME,46,7,124,14,ES_AUTOHSCROLL
|
||||
EDITTEXT IDC_PASSWORD,46,27,122,14,ES_AUTOHSCROLL
|
||||
LTEXT "用户名",IDC_STATIC,7,7,27,8
|
||||
LTEXT "密码",IDC_STATIC,9,29,18,8
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DESIGNINFO
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
GUIDELINES DESIGNINFO
|
||||
BEGIN
|
||||
IDD_ABOUTBOX, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 180
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 95
|
||||
END
|
||||
|
||||
IDD_MQTTCLIENT_FORM, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 364
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 151
|
||||
END
|
||||
|
||||
IDD_OPTIONS_DLG, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 303
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 170
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Accelerator
|
||||
//
|
||||
|
||||
IDR_MAINFRAME ACCELERATORS
|
||||
BEGIN
|
||||
"N", ID_FILE_NEW, VIRTKEY, CONTROL
|
||||
"O", ID_FILE_OPEN, VIRTKEY, CONTROL
|
||||
"S", ID_FILE_SAVE, VIRTKEY, CONTROL
|
||||
"P", ID_FILE_PRINT, VIRTKEY, CONTROL
|
||||
VK_F6, ID_NEXT_PANE, VIRTKEY
|
||||
VK_F6, ID_PREV_PANE, VIRTKEY, SHIFT
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,4
|
||||
PRODUCTVERSION 1,0,0,4
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "FileDescription", "MQTTClient Module"
|
||||
VALUE "FileVersion", "1.0.0.4"
|
||||
VALUE "InternalName", "MQTTClient"
|
||||
VALUE "LegalCopyright", "Copyright 2024"
|
||||
VALUE "OriginalFilename", "MQTTClient.exe"
|
||||
VALUE "ProductName", "MQTTClient Module"
|
||||
VALUE "ProductVersion", "1.0.0.4"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// AFX_DIALOG_LAYOUT
|
||||
//
|
||||
|
||||
IDD_MQTTCLIENT_FORM AFX_DIALOG_LAYOUT
|
||||
BEGIN
|
||||
0
|
||||
END
|
||||
|
||||
IDD_OPTIONS_DLG AFX_DIALOG_LAYOUT
|
||||
BEGIN
|
||||
0
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// String Table
|
||||
//
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDR_MAINFRAME "MQTTClient"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
ID_FILE_NEW "Create a new document\nNew"
|
||||
ID_FILE_OPEN "Open an existing document\nOpen"
|
||||
ID_FILE_CLOSE "Close the active document\nClose"
|
||||
ID_FILE_SAVE "Save the active document\nSave"
|
||||
ID_FILE_SAVE_AS "Save the active document with a new name\nSave As"
|
||||
ID_FILE_PAGE_SETUP "Change the printing options\nPage Setup"
|
||||
ID_FILE_PRINT_SETUP "Change the printer and printing options\nPrint Setup"
|
||||
ID_FILE_PRINT "Print the active document\nPrint"
|
||||
ID_FILE_PRINT_PREVIEW "Display full pages\nPrint Preview"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
ID_APP_ABOUT "Display program information, version number and copyright\nAbout"
|
||||
ID_APP_EXIT "Quit the application; prompts to save documents\nExit"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
ID_NEXT_PANE "Switch to the next window pane\nNext Pane"
|
||||
ID_PREV_PANE "Switch back to the previous window pane\nPrevious Pane"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
ID_WINDOW_NEW "Open another window for the active document\nNew Window"
|
||||
ID_WINDOW_ARRANGE "Arrange icons at the bottom of the window\nArrange Icons"
|
||||
ID_WINDOW_CASCADE "Arrange windows so they overlap\nCascade Windows"
|
||||
ID_WINDOW_TILE_HORZ "Arrange windows as non-overlapping tiles\nTile Windows"
|
||||
ID_WINDOW_TILE_VERT "Arrange windows as non-overlapping tiles\nTile Windows"
|
||||
ID_WINDOW_SPLIT "Split the active window into panes\nSplit"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
ID_EDIT_CLEAR "Erase the selection\nErase"
|
||||
ID_EDIT_CLEAR_ALL "Erase everything\nErase All"
|
||||
ID_EDIT_COPY "Copy the selection and put it on the Clipboard\nCopy"
|
||||
ID_EDIT_CUT "Cut the selection and put it on the Clipboard\nCut"
|
||||
ID_EDIT_FIND "Find the specified text\nFind"
|
||||
ID_EDIT_PASTE "Insert Clipboard contents\nPaste"
|
||||
ID_EDIT_REPEAT "Repeat the last action\nRepeat"
|
||||
ID_EDIT_REPLACE "Replace specific text with different text\nReplace"
|
||||
ID_EDIT_SELECT_ALL "Select the entire document\nSelect All"
|
||||
ID_EDIT_UNDO "Undo the last action\nUndo"
|
||||
ID_EDIT_REDO "Redo the previously undone action\nRedo"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
ID_VIEW_STATUS_BAR "Show or hide the status bar\nToggle StatusBar"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
ATL_IDS_SCSIZE "Change the window size"
|
||||
ATL_IDS_SCMOVE "Change the window position"
|
||||
ATL_IDS_SCMINIMIZE "Reduce the window to an icon"
|
||||
ATL_IDS_SCMAXIMIZE "Enlarge the window to full size"
|
||||
ATL_IDS_SCNEXTWINDOW "Switch to the next document window"
|
||||
ATL_IDS_SCPREVWINDOW "Switch to the previous document window"
|
||||
ATL_IDS_SCCLOSE "Close the active window and prompts to save the documents"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
ATL_IDS_SCRESTORE "Restore the window to normal size"
|
||||
ATL_IDS_SCTASKLIST "Activate Task List"
|
||||
ATL_IDS_MDICHILD "Activate this window"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
ATL_IDS_IDLEMESSAGE "Ready"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
ATL_IDS_MRU_FILE "Open this document"
|
||||
END
|
||||
|
||||
#endif // Chinese (Simplified, PRC) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (United States) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""atlres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Icon
|
||||
//
|
||||
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
IDR_MAINFRAME ICON "res\\MQTTClient.ico"
|
||||
|
||||
#endif // English (United States) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -0,0 +1,229 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{E4C7BDA2-EF45-4CAB-8542-DBF36D3624AB}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>D:\Workspace\deps\include;C:\Program Files\mosquitto\devel;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\wtl\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
|
||||
<LibraryPath>D:\Workspace\deps\x64\dbg;C:\Program Files\mosquitto\devel;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>D:\Workspace\deps\include;C:\Program Files\mosquitto\devel;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\wtl\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
|
||||
<LibraryPath>D:\Workspace\deps\x64\rel;C:\Program Files\mosquitto\devel;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_WINDOWS;STRICT;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0409</Culture>
|
||||
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ResourceCompile>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
<TargetEnvironment>Win32</TargetEnvironment>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<HeaderFileName>MQTTClient.h</HeaderFileName>
|
||||
<InterfaceIdentifierFileName>MQTTClient_i.c</InterfaceIdentifierFileName>
|
||||
<ProxyFileName>MQTTClient_p.c</ProxyFileName>
|
||||
<GenerateStublessProxies>true</GenerateStublessProxies>
|
||||
<TypeLibraryName>$(IntDir)/MQTTClient.tlb</TypeLibraryName>
|
||||
<DllDataFileName />
|
||||
</Midl>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_WINDOWS;STRICT;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0409</Culture>
|
||||
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ResourceCompile>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<HeaderFileName>MQTTClient.h</HeaderFileName>
|
||||
<InterfaceIdentifierFileName>MQTTClient_i.c</InterfaceIdentifierFileName>
|
||||
<ProxyFileName>MQTTClient_p.c</ProxyFileName>
|
||||
<GenerateStublessProxies>true</GenerateStublessProxies>
|
||||
<TypeLibraryName>$(IntDir)/MQTTClient.tlb</TypeLibraryName>
|
||||
<DllDataFileName />
|
||||
</Midl>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<ExceptionHandling />
|
||||
<DebugInformationFormat />
|
||||
<PreprocessorDefinitions>WIN32;_WINDOWS;STRICT;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
</Link>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0409</Culture>
|
||||
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ResourceCompile>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
<TargetEnvironment>Win32</TargetEnvironment>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<HeaderFileName>MQTTClient.h</HeaderFileName>
|
||||
<InterfaceIdentifierFileName>MQTTClient_i.c</InterfaceIdentifierFileName>
|
||||
<ProxyFileName>MQTTClient_p.c</ProxyFileName>
|
||||
<GenerateStublessProxies>true</GenerateStublessProxies>
|
||||
<TypeLibraryName>$(IntDir)/MQTTClient.tlb</TypeLibraryName>
|
||||
<DllDataFileName />
|
||||
</Midl>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<ExceptionHandling />
|
||||
<DebugInformationFormat />
|
||||
<PreprocessorDefinitions>_WINDOWS;STRICT;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
</Link>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0409</Culture>
|
||||
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ResourceCompile>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<HeaderFileName>MQTTClient.h</HeaderFileName>
|
||||
<InterfaceIdentifierFileName>MQTTClient_i.c</InterfaceIdentifierFileName>
|
||||
<ProxyFileName>MQTTClient_p.c</ProxyFileName>
|
||||
<GenerateStublessProxies>true</GenerateStublessProxies>
|
||||
<TypeLibraryName>$(IntDir)/MQTTClient.tlb</TypeLibraryName>
|
||||
<DllDataFileName />
|
||||
</Midl>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="MQTTClient.cpp" />
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="AboutDlg.h" />
|
||||
<ClInclude Include="MainFrm.h" />
|
||||
<ClInclude Include="OptionDlg.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
<ClInclude Include="View.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="MQTTClient.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="res\MQTTClient.ico" />
|
||||
<Image Include="res\toolbar.bmp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{6fa2c6ca-dbc4-427c-9442-85781df4716f}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{aca95d59-80cb-4025-a126-688751e88e02}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{3c2c911d-6a88-4ad3-9b1a-805d7a62a29d}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;jpg;jpeg;jpe;manifest</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MQTTClient.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MainFrm.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="View.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="AboutDlg.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="OptionDlg.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="MQTTClient.rc">
|
||||
<Filter>Resource Files</Filter>
|
||||
</ResourceCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="res\toolbar.bmp">
|
||||
<Filter>Resource Files</Filter>
|
||||
</Image>
|
||||
<Image Include="res\MQTTClient.ico">
|
||||
<Filter>Resource Files</Filter>
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -0,0 +1,108 @@
|
||||
// MainFrm.h : interface of the CMainFrame class
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
class CMainFrame :
|
||||
public CFrameWindowImpl<CMainFrame>,
|
||||
public CUpdateUI<CMainFrame>,
|
||||
public CMessageFilter, public CIdleHandler
|
||||
{
|
||||
public:
|
||||
DECLARE_FRAME_WND_CLASS(NULL, IDR_MAINFRAME)
|
||||
|
||||
CView m_view;
|
||||
|
||||
virtual BOOL PreTranslateMessage(MSG* pMsg)
|
||||
{
|
||||
if(CFrameWindowImpl<CMainFrame>::PreTranslateMessage(pMsg))
|
||||
return TRUE;
|
||||
|
||||
return m_view.PreTranslateMessage(pMsg);
|
||||
}
|
||||
|
||||
virtual BOOL OnIdle()
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BEGIN_UPDATE_UI_MAP(CMainFrame)
|
||||
UPDATE_ELEMENT(ID_VIEW_STATUS_BAR, UPDUI_MENUPOPUP)
|
||||
END_UPDATE_UI_MAP()
|
||||
|
||||
BEGIN_MSG_MAP(CMainFrame)
|
||||
MESSAGE_HANDLER(WM_CREATE, OnCreate)
|
||||
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
|
||||
COMMAND_ID_HANDLER(ID_APP_EXIT, OnFileExit)
|
||||
COMMAND_ID_HANDLER(ID_FILE_OPTIONS, OnFileOption)
|
||||
COMMAND_ID_HANDLER(ID_VIEW_STATUS_BAR, OnViewStatusBar)
|
||||
COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
|
||||
CHAIN_MSG_MAP(CUpdateUI<CMainFrame>)
|
||||
CHAIN_MSG_MAP(CFrameWindowImpl<CMainFrame>)
|
||||
END_MSG_MAP()
|
||||
|
||||
// Handler prototypes (uncomment arguments if needed):
|
||||
// LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
||||
// LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
||||
// LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)
|
||||
|
||||
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
||||
{
|
||||
|
||||
CreateSimpleStatusBar();
|
||||
|
||||
m_hWndClient = m_view.Create(m_hWnd);
|
||||
UISetCheck(ID_VIEW_STATUS_BAR, 1);
|
||||
|
||||
// register object for message filtering and idle updates
|
||||
CMessageLoop* pLoop = _Module.GetMessageLoop();
|
||||
ATLASSERT(pLoop != NULL);
|
||||
pLoop->AddMessageFilter(this);
|
||||
pLoop->AddIdleHandler(this);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
|
||||
{
|
||||
// unregister message filtering and idle updates
|
||||
CMessageLoop* pLoop = _Module.GetMessageLoop();
|
||||
ATLASSERT(pLoop != NULL);
|
||||
pLoop->RemoveMessageFilter(this);
|
||||
pLoop->RemoveIdleHandler(this);
|
||||
|
||||
bHandled = FALSE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
||||
{
|
||||
PostMessage(WM_CLOSE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LRESULT OnFileOption(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
||||
{
|
||||
COptionDlg dlg;
|
||||
dlg.DoModal();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
LRESULT OnViewStatusBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
||||
{
|
||||
BOOL bVisible = !::IsWindowVisible(m_hWndStatusBar);
|
||||
::ShowWindow(m_hWndStatusBar, bVisible ? SW_SHOWNOACTIVATE : SW_HIDE);
|
||||
UISetCheck(ID_VIEW_STATUS_BAR, bVisible);
|
||||
UpdateLayout();
|
||||
return 0;
|
||||
}
|
||||
|
||||
LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
||||
{
|
||||
CAboutDlg dlg;
|
||||
dlg.DoModal();
|
||||
return 0;
|
||||
}
|
||||
};
|
@ -0,0 +1,73 @@
|
||||
// aboutdlg.h : interface of the CAboutDlg class
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
class COptionDlg : public CDialogImpl<COptionDlg>
|
||||
{
|
||||
public:
|
||||
enum { IDD = IDD_OPTIONS_DLG };
|
||||
|
||||
BEGIN_MSG_MAP(COptionDlg)
|
||||
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
|
||||
COMMAND_ID_HANDLER(IDOK, OnCloseCmd)
|
||||
COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd)
|
||||
END_MSG_MAP()
|
||||
|
||||
// Handler prototypes (uncomment arguments if needed):
|
||||
// LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
||||
// LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
||||
// LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)
|
||||
|
||||
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
||||
{
|
||||
CenterWindow(GetParent());
|
||||
|
||||
SetDlgItemText(IDC_USERNAME, TEXT("test"));
|
||||
SetDlgItemText(IDC_PASSWORD, TEXT("123456"));
|
||||
CRegKey key;
|
||||
TCHAR buf[MAX_PATH] = { 0 };
|
||||
if (key.Open(HKEY_CURRENT_USER, TEXT("Software\\XYPower\\MQTTClient"), KEY_READ) == ERROR_SUCCESS)
|
||||
{
|
||||
ULONG bufLen = MAX_PATH;
|
||||
if (key.QueryStringValue(TEXT("UserName"), buf, &bufLen) == ERROR_SUCCESS)
|
||||
{
|
||||
SetDlgItemText(IDC_USERNAME, buf);
|
||||
}
|
||||
|
||||
bufLen = MAX_PATH;
|
||||
if (key.QueryStringValue(TEXT("Password"), buf, &bufLen) == ERROR_SUCCESS)
|
||||
{
|
||||
SetDlgItemText(IDC_PASSWORD, buf);
|
||||
}
|
||||
|
||||
key.Close();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
||||
{
|
||||
if (wID == IDOK)
|
||||
{
|
||||
CRegKey key;
|
||||
LSTATUS res = ERROR_SUCCESS;
|
||||
if ((res = key.Create(HKEY_CURRENT_USER, TEXT("Software\\XYPower\\MQTTClient"))) == ERROR_SUCCESS)
|
||||
{
|
||||
CString buf;
|
||||
GetDlgItemText(IDC_USERNAME, buf);
|
||||
key.SetStringValue(TEXT("UserName"), buf);
|
||||
|
||||
GetDlgItemText(IDC_PASSWORD, buf);
|
||||
key.SetStringValue(TEXT("Password"), buf);
|
||||
|
||||
key.Close();
|
||||
}
|
||||
}
|
||||
|
||||
EndDialog(wID);
|
||||
return 0;
|
||||
}
|
||||
};
|
@ -0,0 +1,431 @@
|
||||
// View.h : interface of the CView class
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#define SERVICES_COMMAND_TOPIC "/v1/devices/MSRDT-A/command"
|
||||
#define SERVICES_RESPONSE_TOPIC "/v1/devices/MSRDT-A/commandResponse"
|
||||
#define DEVICES_DATA_TOPIC "/v1/devices/MSRDT-A/datas"
|
||||
|
||||
#define MQTT_SERVER "61.169.135.146"
|
||||
#define MQTT_PORT 51001
|
||||
#define MQTT_USERNAME "test"
|
||||
#define MQTT_PASSWORD "123456"
|
||||
|
||||
|
||||
#define MQTT_KEEP_ALIVE 60
|
||||
#define SYNC_CLIENT_CAC_MQTT 10
|
||||
#define SYNC_QOS_LEVEL_0 0
|
||||
|
||||
#define WM_NEW_MSG (WM_USER + 2)
|
||||
|
||||
class CView : public CDialogImpl<CView>, public CDialogResize<CView>
|
||||
{
|
||||
public:
|
||||
enum { IDD = IDD_MQTTCLIENT_FORM };
|
||||
|
||||
struct mosquitto *m_mosq;
|
||||
bool m_session;
|
||||
|
||||
std::thread m_mqttThread;
|
||||
|
||||
CString m_userName;
|
||||
CString m_password;
|
||||
|
||||
BOOL PreTranslateMessage(MSG* pMsg)
|
||||
{
|
||||
return CWindow::IsDialogMessage(pMsg);
|
||||
}
|
||||
|
||||
BEGIN_DLGRESIZE_MAP(CView)
|
||||
DLGRESIZE_CONTROL(IDC_SEND, DLSZ_MOVE_X)
|
||||
DLGRESIZE_CONTROL(IDC_CLEAR, DLSZ_MOVE_X)
|
||||
DLGRESIZE_CONTROL(IDC_TOPICES, DLSZ_SIZE_X)
|
||||
DLGRESIZE_CONTROL(IDC_TO_SEND, DLSZ_SIZE_X)
|
||||
DLGRESIZE_CONTROL(IDC_TO_RECV, DLSZ_SIZE_X | DLSZ_SIZE_Y)
|
||||
END_DLGRESIZE_MAP()
|
||||
|
||||
|
||||
BEGIN_MSG_MAP(CView)
|
||||
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
|
||||
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
|
||||
MESSAGE_HANDLER(WM_NEW_MSG, OnNewMsgArrived)
|
||||
|
||||
COMMAND_HANDLER(IDC_SEND, BN_CLICKED, OnSendCmd)
|
||||
COMMAND_HANDLER(IDC_CLEAR, BN_CLICKED, OnClearCmd)
|
||||
CHAIN_MSG_MAP(CDialogResize<CView>)
|
||||
END_MSG_MAP()
|
||||
|
||||
// Handler prototypes (uncomment arguments if needed):
|
||||
// LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
||||
// LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
||||
// LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)
|
||||
|
||||
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
||||
{
|
||||
DlgResize_Init();
|
||||
|
||||
m_userName = TEXT(MQTT_USERNAME);
|
||||
m_password = TEXT(MQTT_PASSWORD);
|
||||
LoadUserAndPassword();
|
||||
|
||||
CEdit edt = GetDlgItem(IDC_TO_RECV);
|
||||
edt.SetLimitText(-1);
|
||||
|
||||
CComboBox cmb = GetDlgItem(IDC_TOPICES);
|
||||
cmb.AddString(TEXT(SERVICES_COMMAND_TOPIC));
|
||||
cmb.AddString(TEXT(SERVICES_RESPONSE_TOPIC));
|
||||
cmb.AddString(TEXT(DEVICES_DATA_TOPIC));
|
||||
|
||||
cmb.SetCurSel(0);
|
||||
|
||||
m_mosq = NULL;
|
||||
m_session = true;
|
||||
|
||||
mosquitto_lib_init();
|
||||
|
||||
//create mosquitto client
|
||||
const char * clientId = NULL;
|
||||
m_mosq = mosquitto_new(clientId, m_session, NULL);
|
||||
if (!m_mosq)
|
||||
{
|
||||
// printf("create client failed..\n");
|
||||
// mosquitto_lib_cleanup();
|
||||
return false;
|
||||
}
|
||||
// Callback
|
||||
mosquitto_user_data_set(m_mosq, (void *)this);
|
||||
// mosquitto_log_callback_set(mosq, cac_log_callback);
|
||||
mosquitto_connect_callback_set(m_mosq, cac_connect_callback);
|
||||
mosquitto_message_callback_set(m_mosq, cac_message_callback);
|
||||
mosquitto_subscribe_callback_set(m_mosq, cac_subscribe_callback);
|
||||
// connect to server
|
||||
|
||||
|
||||
CW2A userName(CT2W(m_userName), CP_UTF8);
|
||||
CW2A password(CT2W(m_password), CP_UTF8);
|
||||
|
||||
mosquitto_username_pw_set(m_mosq, (LPCSTR)userName, (LPCSTR)password);
|
||||
|
||||
if (mosquitto_connect(m_mosq, MQTT_SERVER, MQTT_PORT, MQTT_KEEP_ALIVE))
|
||||
{
|
||||
mosquitto_destroy(m_mosq);
|
||||
m_mosq = NULL;
|
||||
fprintf(stderr, "Unable to connect.\n");
|
||||
#ifndef _DEBUG
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* Subscribe to broker information topics on successful connect. */
|
||||
std::thread th = std::thread(MQTTThreadProc, this);
|
||||
m_mqttThread.swap(th);
|
||||
|
||||
int mid = 0;
|
||||
// mosquitto_subscribe(m_mosq, &mid, SERVICES_COMMAND_TOPIC, SYNC_QOS_LEVEL_0);
|
||||
// mosquitto_subscribe(m_mosq, &mid, SERVICES_RESPONSE_TOPIC, SYNC_QOS_LEVEL_0);
|
||||
// mosquitto_subscribe(m_mosq, &mid, DEVICES_DATA_TOPIC, SYNC_QOS_LEVEL_0);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
||||
{
|
||||
if (m_mosq != NULL)
|
||||
{
|
||||
int mid = 0;
|
||||
mosquitto_unsubscribe(m_mosq, &mid, SERVICES_COMMAND_TOPIC);
|
||||
mosquitto_unsubscribe(m_mosq, &mid, SERVICES_RESPONSE_TOPIC);
|
||||
mosquitto_unsubscribe(m_mosq, &mid, DEVICES_DATA_TOPIC);
|
||||
|
||||
mosquitto_disconnect(m_mosq);
|
||||
|
||||
mosquitto_loop_stop(m_mosq, false);
|
||||
if (m_mqttThread.joinable())
|
||||
{
|
||||
m_mqttThread.join();
|
||||
}
|
||||
mosquitto_destroy(m_mosq);
|
||||
m_mosq = NULL;
|
||||
}
|
||||
|
||||
mosquitto_lib_cleanup();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
LRESULT OnClearCmd(WORD /*wNotifyCode*/, WORD wID, HWND hWndCtl, BOOL& /*bHandled*/)
|
||||
{
|
||||
CEdit edt = GetDlgItem(IDC_TO_RECV);
|
||||
edt.SetWindowText(TEXT(""));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
LRESULT OnSendCmd(WORD /*wNotifyCode*/, WORD wID, HWND hWndCtl, BOOL& /*bHandled*/)
|
||||
{
|
||||
CString text;
|
||||
CEdit edt = GetDlgItem(IDC_TO_SEND);
|
||||
edt.GetWindowText(text);
|
||||
if (text.GetLength() == 0)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CString topic;
|
||||
CComboBox cmb = GetDlgItem(IDC_TOPICES);
|
||||
cmb.GetWindowText(topic);
|
||||
if (topic.GetLength() == 0)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CW2A utf8(CT2W(text), CP_UTF8);
|
||||
|
||||
CW2A utf8Topic(CT2W(topic), CP_UTF8);
|
||||
|
||||
int mid = 0;
|
||||
int res = mosquitto_publish(m_mosq, &mid, utf8Topic, strlen((LPCSTR)utf8), (void *)((LPCSTR)utf8), SYNC_QOS_LEVEL_0, false);
|
||||
if (res == MOSQ_ERR_SUCCESS)
|
||||
{
|
||||
// Update time
|
||||
int aa = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (MOSQ_ERR_ERRNO == res)
|
||||
{
|
||||
int errorno = errno;
|
||||
char* errmsg = strerror(errorno);
|
||||
|
||||
int aa = 0;
|
||||
}
|
||||
int bbb = 0;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
LRESULT OnNewMsgArrived(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
|
||||
{
|
||||
LPTSTR pszMsg = (LPTSTR)lParam;
|
||||
LPTSTR pszTopic = (LPTSTR)wParam;
|
||||
|
||||
CString text;
|
||||
CEdit edt = GetDlgItem(IDC_TO_RECV);
|
||||
edt.GetWindowText(text);
|
||||
|
||||
edt.AppendText(TEXT("\r\n"));
|
||||
|
||||
if (pszTopic != NULL)
|
||||
{
|
||||
edt.AppendText(TEXT("\r\n"));
|
||||
|
||||
edt.AppendText(FormatLocalTime());
|
||||
edt.AppendText(TEXT(" "));
|
||||
edt.AppendText(pszTopic);
|
||||
|
||||
delete[] pszTopic;
|
||||
}
|
||||
|
||||
if (pszMsg != NULL)
|
||||
{
|
||||
edt.AppendText(TEXT("\r\n"));
|
||||
edt.AppendText(pszMsg);
|
||||
|
||||
delete[] pszMsg;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int MQTTProc()
|
||||
{
|
||||
mosquitto_loop_forever(m_mosq, -1, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int MQTTThreadProc(CView *pThis);
|
||||
static void cac_message_callback(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message);
|
||||
static void cac_connect_callback(struct mosquitto *mosq, void *userdata, int result);
|
||||
static void cac_subscribe_callback(struct mosquitto *mosq, void *userdata, int mid, int qos_count, const int *granted_qos);
|
||||
static void cac_log_callback(struct mosquitto *mosq, void *userdata, int level, const char *str);
|
||||
|
||||
LPTSTR ConvertStr(const char* utf8)
|
||||
{
|
||||
CW2T str(CA2W(utf8, CP_UTF8));
|
||||
|
||||
size_t len = _tcslen((LPCTSTR)str);
|
||||
TCHAR *pszT = new TCHAR[len + 1];
|
||||
pszT[len] = 0;
|
||||
_tcscpy(pszT, (LPCTSTR)str);
|
||||
|
||||
return pszT;
|
||||
}
|
||||
|
||||
void MessageCallback(struct mosquitto *mosq, const struct mosquitto_message *message)
|
||||
{
|
||||
if (message->payloadlen) {
|
||||
|
||||
LPTSTR pszTopic = ConvertStr((char *)(message->topic));
|
||||
LPTSTR pszMsg = NULL;
|
||||
bool isJson = false;
|
||||
char* sz = (char *)message->payload;
|
||||
if (sz[0] == '{')
|
||||
{
|
||||
Json::Value jsonObj;
|
||||
Json::CharReaderBuilder builder;
|
||||
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
|
||||
|
||||
isJson = reader->parse(sz, sz + message->payloadlen, &jsonObj, NULL);
|
||||
if (isJson)
|
||||
{
|
||||
Json::StreamWriterBuilder writeBuilder;
|
||||
writeBuilder["indentation"] = " "; // assume default for comments is None
|
||||
writeBuilder["emitUTF8"] = true;
|
||||
std::string content = Json::writeString(writeBuilder, jsonObj);
|
||||
|
||||
size_t pos = 0;
|
||||
std::string replace = "\r\n";
|
||||
while ((pos = content.find('\n', pos)) != std::string::npos)
|
||||
{
|
||||
content.replace(pos, 1, replace);
|
||||
pos += replace.length();
|
||||
}
|
||||
|
||||
pszMsg = ConvertStr(content.c_str());
|
||||
}
|
||||
}
|
||||
if (pszMsg == NULL)
|
||||
{
|
||||
pszMsg = ConvertStr((char *)(message->payload));
|
||||
}
|
||||
|
||||
::PostMessage(m_hWnd, WM_NEW_MSG, (WPARAM)pszTopic, (LPARAM)pszMsg);
|
||||
|
||||
}
|
||||
else {
|
||||
// LPTSTR pszMsg = ConvertStr((char *)(message->payload));
|
||||
LPTSTR pszTopic = ConvertStr((char *)(message->topic));
|
||||
|
||||
::PostMessage(m_hWnd, WM_NEW_MSG, (WPARAM)pszTopic, 0);
|
||||
}
|
||||
// fflush(stdout);
|
||||
}
|
||||
|
||||
void ConnectCallback(struct mosquitto *mosq, int result)
|
||||
{
|
||||
int i;
|
||||
if (!result)
|
||||
{
|
||||
/* Subscribe to broker information topics on successful connect. */
|
||||
// std::thread th = std::thread(MQTTThreadProc, this);
|
||||
// m_mqttThread.swap(th);
|
||||
|
||||
int mid = 0;
|
||||
int res = 0;
|
||||
char* subs[] = { SERVICES_COMMAND_TOPIC, SERVICES_RESPONSE_TOPIC, DEVICES_DATA_TOPIC};
|
||||
|
||||
res = mosquitto_subscribe_multiple(m_mosq, &mid, sizeof(subs) / sizeof(char *), subs, SYNC_QOS_LEVEL_0, 0, NULL);
|
||||
if (res != MOSQ_ERR_SUCCESS)
|
||||
{
|
||||
int aa = 0;
|
||||
}
|
||||
|
||||
// res = mosquitto_subscribe(m_mosq, &mid, SERVICES_COMMAND_TOPIC, SYNC_QOS_LEVEL_0);
|
||||
// res = mosquitto_subscribe(m_mosq, &mid, SERVICES_RESPONSE_TOPIC, SYNC_QOS_LEVEL_0);
|
||||
// res = mosquitto_subscribe(m_mosq, &mid, DEVICES_DATA_TOPIC, SYNC_QOS_LEVEL_0);
|
||||
if (res != MOSQ_ERR_SUCCESS)
|
||||
{
|
||||
int aa = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Connect failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
void SubscribeCallback(struct mosquitto *mosq, int mid, int qos_count, const int *granted_qos)
|
||||
{
|
||||
int i;
|
||||
printf("Subscribed (mid: %d): %d", mid, granted_qos[0]);
|
||||
for (i = 1; i < qos_count; i++)
|
||||
{
|
||||
printf(", %d", granted_qos[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void LogCallback(struct mosquitto *mosq, int level, const char *str)
|
||||
{
|
||||
/* Pring all log messages regardless of level. */
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
||||
|
||||
CString FormatLocalTime(time_t t = 0)
|
||||
{
|
||||
if (t == 0)
|
||||
{
|
||||
time(&t);
|
||||
}
|
||||
|
||||
struct std::tm* tp = localtime(&t);
|
||||
CString str;
|
||||
str.Format(TEXT("%02d-%02d %02d:%02d:%02d"), tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec);
|
||||
return str;
|
||||
}
|
||||
|
||||
void LoadUserAndPassword()
|
||||
{
|
||||
TCHAR buf[MAX_PATH] = { 0 };
|
||||
CRegKey key;
|
||||
if (key.Open(HKEY_CURRENT_USER, TEXT("Software\\XYPower\\MQTTClient"), KEY_READ) == ERROR_SUCCESS)
|
||||
{
|
||||
ULONG bufLen = MAX_PATH;
|
||||
if (key.QueryStringValue(TEXT("UserName"), buf, &bufLen) == ERROR_SUCCESS)
|
||||
{
|
||||
m_userName = buf;
|
||||
}
|
||||
|
||||
bufLen = MAX_PATH;
|
||||
if (key.QueryStringValue(TEXT("Password"), buf, &bufLen) == ERROR_SUCCESS)
|
||||
{
|
||||
m_password = buf;
|
||||
}
|
||||
|
||||
|
||||
key.Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int CView::MQTTThreadProc(CView *pThis)
|
||||
{
|
||||
return pThis->MQTTProc();
|
||||
}
|
||||
|
||||
void CView::cac_message_callback(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message)
|
||||
{
|
||||
((CView*)userdata)->MessageCallback(mosq, message);
|
||||
}
|
||||
|
||||
void CView::cac_connect_callback(struct mosquitto *mosq, void *userdata, int result)
|
||||
{
|
||||
((CView*)userdata)->ConnectCallback(mosq, result);
|
||||
}
|
||||
|
||||
void CView::cac_subscribe_callback(struct mosquitto *mosq, void *userdata, int mid, int qos_count, const int *granted_qos)
|
||||
{
|
||||
((CView*)userdata)->SubscribeCallback(mosq, mid, qos_count, granted_qos);
|
||||
}
|
||||
|
||||
void CView::cac_log_callback(struct mosquitto *mosq, void *userdata, int level, const char *str)
|
||||
{
|
||||
((CView*)userdata)->LogCallback(mosq, level, str);
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
@ -0,0 +1,28 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by MQTTClient.rc
|
||||
//
|
||||
#define IDD_ABOUTBOX 100
|
||||
#define IDR_MAINFRAME 128
|
||||
#define IDD_MQTTCLIENT_FORM 129
|
||||
#define IDD_OPTIONS_DLG 202
|
||||
#define IDC_TO_SEND 1000
|
||||
#define IDC_TO_RECV 1001
|
||||
#define IDC_SEND 1002
|
||||
#define IDC_CLEAR 1003
|
||||
#define IDC_TOPICES 1004
|
||||
#define IDC_EDIT1 1005
|
||||
#define IDC_USERNAME 1005
|
||||
#define IDC_PASSWORD 1006
|
||||
#define ID_FILE_OPTIONS 32775
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 204
|
||||
#define _APS_NEXT_COMMAND_VALUE 32776
|
||||
#define _APS_NEXT_CONTROL_VALUE 1007
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
@ -0,0 +1,25 @@
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// MQTTClient.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
// #pragma comment(lib, "mariadbclient.lib")
|
||||
#pragma comment(lib, "mosquitto.lib")
|
||||
#pragma comment(lib, "jsoncpp.lib")
|
||||
// #pragma comment(lib, "mariadbclient.lib" )
|
||||
#pragma comment(lib, "Secur32.lib")
|
||||
#pragma comment(lib, "Ws2_32.lib")
|
||||
#pragma comment(lib, "Crypt32.lib")
|
||||
#pragma comment(lib, "Shlwapi.lib")
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "zlibd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "zlib.lib")
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,40 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
// Change these values to use different versions
|
||||
#define WINVER 0x0601
|
||||
#define _WIN32_WINNT 0x0601
|
||||
#define _WIN32_IE 0x0700
|
||||
#define _RICHEDIT_VER 0x0500
|
||||
|
||||
#include <atlbase.h>
|
||||
#include <atlapp.h>
|
||||
#include <atlcom.h>
|
||||
#include <atlhost.h>
|
||||
#include <atlctl.h>
|
||||
#include <atltypes.h>
|
||||
#include <atlstr.h>
|
||||
#include <atlcrypt.h>
|
||||
|
||||
#include <mosquitto.h>
|
||||
#include <json/json.h>
|
||||
|
||||
#include <thread>
|
||||
|
||||
extern CAppModule _Module;
|
||||
|
||||
#include <atlwin.h>
|
||||
|
||||
#if defined _M_IX86
|
||||
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
||||
#elif defined _M_IA64
|
||||
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
||||
#elif defined _M_X64
|
||||
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
||||
#else
|
||||
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
||||
#endif
|
Loading…
Reference in New Issue