OTA.cpp 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195
  1. #include "pch.h"
  2. #include "OTA.h"
  3. #include "CharEncoding.h"
  4. #include "TCL Copy ToolDlg.h"
  5. std::vector<_SIACP_> g_vtSiacp = {
  6. {"EnterFactory", "AA", "10", "01", false, 100},
  7. {"LeaveFactory", "AA", "10", "00", false, 100},
  8. {"WBInit", "AA", "16", "02", false, 100},//白平衡数据初始化(适用于所有信源)
  9. {"GetProjectID", "AA", "84", "00", false, 100},
  10. {"GetSoftVersion", "AA", "57", "00", false, 100},
  11. {"GetDeviceId", "AA", "BE", "01", true, 100},
  12. {"GetClientType", "AA", "8C", "00", false, 100},
  13. {"GetMAC", "AA", "BE", "00", true, 100},
  14. {"GetHDCPKey", "AA", "EE", "00", false, 100},
  15. {"GetHDCPKey22", "AA", "E7", "00", false, 100},
  16. {"GetWidi", "AA", "E7", "00", false, 100},
  17. {"GetNetflixESN", "AA", "BE", "06", true, 100},
  18. {"GetWidevine", "AA", "EC", "00", true, 100},
  19. {"GetCiKey", "AA", "EC", "01", true, 100},
  20. {"GetOSDLanguage", "AA", "97", "00", true, 100},
  21. {"GetShopLanguage", "AA", "97", "01", true, 100},
  22. {"GetChannel", "AA", "97", "13", true, 100},
  23. // 设置;
  24. {"SetProjectId", "AA", "70", "", false, 100},
  25. {"SetDeviceID", "AA", "B2", "", false, 100},
  26. {"SetMAC", "AA", "B3", "", false, 100},
  27. {"SetHDCPKey", "AA FE", "86", "", false, 100},
  28. {"SetHDCPKey22", "AA FE", "E4", "", false, 100},
  29. {"SetNetflixESN", "AA", "99 00", "", false, 100},
  30. {"SetWidi", "AA FE", "E4", "", false, 100}, //与hdcp22相同指令
  31. {"SetWidevine", "AA FE", "E9 00", "", false, 100},
  32. {"SetCiKey", "AA FE", "E9 01", "", false, 100},
  33. {"SetOSDLanguage", "AA", "96 00", "", true, 100},
  34. {"SetShopLanguage", "AA", "96 01", "", true, 100},
  35. // 设置;
  36. {"SetChannel", "AA", "15", "", false, 100},
  37. {"SetWBNormal", "AA", "4D 04 01 01", "", false, 100},
  38. {"SetWBCool", "AA", "4D 04 02 01", "", false, 100},
  39. {"SetWBWarm", "AA", "4D 04 03 01", "", false, 100},
  40. // 检测;
  41. {"CheckMAC", "AA", "B4", "00", false, 100},
  42. {"CheckDeviceId", "AA", "B4", "00", false, 100},
  43. {"CheckHDCP", "AA", "87", "00", false, 100},
  44. {"CheckNetflixESN", "AA", "9A", "00", true, 100},
  45. {"CheckWidi", "AA", "E5", "00", false, 100},
  46. {"CheckWidevine", "AA", "EA", "00", true, 100},
  47. {"CheckCikey", "AA", "EA", "01", true, 100},
  48. {"CheckHDCP22", "AA", "E5", "00", false, 100},
  49. {"StarWarmUpMode", "AA", "13", "01", false, 100},
  50. {"StopWarmUpMode", "AA", "13", "00", false, 100}
  51. };
  52. const unsigned short CRC16_TABLE[16] = {
  53. 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
  54. 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF};
  55. unsigned short CRC16Calculate(byte *pBuffer, unsigned int wordLength)
  56. {
  57. unsigned short wordCRC;
  58. byte byteTemp;
  59. wordCRC = 0xFFFF;
  60. while (wordLength--)
  61. {
  62. byteTemp = (byte)(wordCRC >> 0x0C);
  63. wordCRC <<= 4;
  64. wordCRC ^= CRC16_TABLE[byteTemp ^ ((*pBuffer) >> 0x04)];
  65. byteTemp = (byte)(wordCRC >> 0x0C);
  66. wordCRC <<= 4;
  67. wordCRC ^= CRC16_TABLE[byteTemp ^ ((*pBuffer) & 0x0F)];
  68. pBuffer++;
  69. }
  70. return wordCRC;
  71. }
  72. unsigned char TwoHexChar2Char(char ch1, char ch2)
  73. {
  74. char Numb1;
  75. char Numb2;
  76. if (ch1 >= 'A')
  77. Numb1 = (toupper(ch1) - '0' - 7) * 16;
  78. else
  79. Numb1 = (ch1 - '0') * 16;
  80. if (ch2 >= 'A')
  81. Numb2 = (toupper(ch2) - '0' - 7);
  82. else
  83. Numb2 = (ch2 - '0');
  84. return (Numb1 + Numb2);
  85. }
  86. std::string HexString2Bytes(std::string strHex, const int &len /* = 3 */)
  87. {
  88. byte value = 0;
  89. std::string strBytes;
  90. int nSize = strHex.size();
  91. for (int i = 0; i < nSize; i += len)
  92. {
  93. strBytes.push_back(TwoHexChar2Char(strHex[i], strHex[i + 1]));
  94. }
  95. return strBytes;
  96. }
  97. std::string Bytes2HexString(const unsigned char *pbuffer, int nLen, char chSpace)
  98. {
  99. std::string hex;
  100. char szhex[5] = {0};
  101. for (int i = 0; i < nLen; i++)
  102. {
  103. memset(szhex, 0, 5);
  104. _stprintf_s(szhex, "%02X%c", pbuffer[i], chSpace);
  105. hex.append(szhex);
  106. }
  107. return hex.substr(0, hex.size() - 1);
  108. }
  109. std::string Bytes2HexString(const unsigned char *pbuffer, int nLen)
  110. {
  111. std::string hex;
  112. char szhex[5] = {0};
  113. for (int i = 0; i < nLen; i++)
  114. {
  115. memset(szhex, 0, 5);
  116. _stprintf_s(szhex, "%02X", pbuffer[i]);
  117. hex.append(szhex);
  118. }
  119. return hex;
  120. }
  121. BOOL IsValidString(LPCTSTR lpszString)
  122. {
  123. if (lpszString == NULL)
  124. return FALSE;
  125. do
  126. {
  127. // ASCII可显示的字符;
  128. if (*lpszString < 32 || *lpszString > 126)
  129. {
  130. return FALSE;
  131. }
  132. } while (*++lpszString);
  133. return TRUE;
  134. }
  135. // 去除空格;
  136. std::string &trim(std::string &str)
  137. {
  138. int nIndex = 0;
  139. while ((nIndex = str.find_first_of(' ')) != std::string::npos)
  140. str.erase(nIndex, 1);
  141. return str;
  142. }
  143. CSIACP::CSIACP(void) //:m_vtcommand(g_siacp, g_siacp+sizeof(g_siacp)/sizeof(_SIACP_))
  144. {
  145. m_pMainDlg = nullptr;
  146. m_pSerial = NULL;
  147. LoadCommand();
  148. }
  149. CSIACP::~CSIACP(void)
  150. {
  151. CloseComm();
  152. }
  153. void CSIACP::SetMainDlg(CDialogEx* p)
  154. {
  155. m_pMainDlg = p;
  156. }
  157. void CSIACP::ShowMessage(LPCTSTR lpMsg, LOG_ENUM logtype)
  158. {
  159. if (m_pMainDlg && lpMsg)
  160. {
  161. CTCLCopyToolDlg* pMainDlg = (CTCLCopyToolDlg*)m_pMainDlg;
  162. pMainDlg->SetOptionLog(std::string(lpMsg), logtype);
  163. }
  164. }
  165. void CSIACP::LoadCommand()
  166. {
  167. // 解析xml;
  168. tinyxml2::XMLDocument doc;
  169. if (tinyxml2::XML_SUCCESS != doc.LoadFile(_T("Siacp.xml")))
  170. {
  171. SaveCommand(g_vtSiacp, _T("Siacp.xml"));
  172. return;
  173. }
  174. std::string ver;
  175. std::string desc;
  176. g_vtSiacp.clear();
  177. tinyxml2::XMLElement *pXmlRoot = NULL;
  178. if ((pXmlRoot = doc.RootElement()) != NULL)
  179. {
  180. if (_tcsicmp(pXmlRoot->Value(), "CommandList") == 0)
  181. {
  182. // 属性;
  183. const tinyxml2::XMLAttribute *pAttr = pXmlRoot->FirstAttribute();
  184. while (pAttr)
  185. {
  186. if (_tcsicmp(pAttr->Name(), "ver") == 0)
  187. {
  188. ver = pAttr->Value();
  189. }
  190. if (_tcsicmp(pAttr->Name(), "desc") == 0)
  191. {
  192. desc = pAttr->Value();
  193. }
  194. pAttr = pAttr->Next();
  195. }
  196. // 子项;
  197. tinyxml2::XMLElement *pXmlElent = pXmlRoot->FirstChildElement();
  198. while (pXmlElent)
  199. {
  200. _SIACP_ siacp;
  201. if (_tcsicmp(pXmlElent->Value(), _T("Item")) == 0)
  202. {
  203. tinyxml2::XMLElement *pItem = pXmlElent->FirstChildElement();
  204. while (pItem)
  205. {
  206. if (_tcsicmp(pItem->Value(), _T("Name")) == 0)
  207. {
  208. siacp.name = pItem->GetText();
  209. }
  210. else if (_tcsicmp(pItem->Value(), _T("HeadCode")) == 0)
  211. {
  212. siacp.head = pItem->GetText();
  213. }
  214. else if (_tcsicmp(pItem->Value(), _T("ucCommand")) == 0)
  215. {
  216. siacp.code = pItem->GetText();
  217. }
  218. else if (_tcsicmp(pItem->Value(), _T("Mark")) == 0)
  219. {
  220. siacp.mark = pItem->GetText();
  221. }
  222. else if (_tcsicmp(pItem->Value(), _T("MultiParams")) == 0)
  223. {
  224. siacp.bMulticode = pItem->BoolText();
  225. }
  226. else if (_tcsicmp(pItem->Value(), _T("ReadWaitTime")) == 0)
  227. {
  228. siacp.read_wait_time = pItem->IntText();
  229. }
  230. else if (_tcsicmp(pItem->Value(), _T("CmdWaitTime")) == 0)
  231. {
  232. siacp.cmd_wait_time = pItem->IntText();
  233. }
  234. pItem = pItem->NextSiblingElement();
  235. }
  236. }
  237. g_vtSiacp.push_back(siacp);
  238. pXmlElent = pXmlElent->NextSiblingElement();
  239. }
  240. }
  241. }
  242. }
  243. void CSIACP::SaveCommand(std::vector<_SIACP_> &vtSiacp, std::string path)
  244. {
  245. tinyxml2::XMLDocument doc;
  246. //添加申明可以使用如下两行
  247. tinyxml2::XMLDeclaration *declaration = doc.NewDeclaration();
  248. doc.InsertFirstChild(declaration);
  249. tinyxml2::XMLElement *root = doc.NewElement("CommandList");
  250. root->SetAttribute("ver", "9.5");
  251. root->SetAttribute("desc", "command info");
  252. doc.InsertEndChild(root);
  253. std::vector<_SIACP_>::iterator it = vtSiacp.begin();
  254. for (; it != vtSiacp.end(); it++)
  255. {
  256. tinyxml2::XMLElement *pItem = doc.NewElement("Item");
  257. tinyxml2::XMLElement *pName = doc.NewElement("Name");
  258. pName->SetText(it->name.c_str());
  259. pItem->InsertEndChild(pName);
  260. tinyxml2::XMLElement *pHeadCode = doc.NewElement("HeadCode");
  261. pHeadCode->SetText(it->head.c_str());
  262. pItem->InsertEndChild(pHeadCode);
  263. tinyxml2::XMLElement *pucCommand = doc.NewElement("ucCommand");
  264. pucCommand->SetText(it->code.c_str());
  265. pItem->InsertEndChild(pucCommand);
  266. tinyxml2::XMLElement *pMark = doc.NewElement("Mark");
  267. pMark->SetText(it->mark.c_str());
  268. pItem->InsertEndChild(pMark);
  269. tinyxml2::XMLElement *pMultiParams = doc.NewElement("MultiParams");
  270. pMultiParams->SetText(it->bMulticode);
  271. pItem->InsertEndChild(pMultiParams);
  272. tinyxml2::XMLElement *pReadWaitTime = doc.NewElement("ReadWaitTime");
  273. pReadWaitTime->SetText(it->read_wait_time);
  274. pItem->InsertEndChild(pReadWaitTime);
  275. tinyxml2::XMLElement* pCmdWaitTime = doc.NewElement("CmdWaitTime");
  276. pCmdWaitTime->SetText(it->cmd_wait_time);
  277. pItem->InsertEndChild(pCmdWaitTime);
  278. root->InsertEndChild(pItem);
  279. }
  280. doc.SaveFile(path.c_str());
  281. }
  282. BOOL CSIACP::OpenComm(LPCTSTR lpszCom, DWORD dwBaudrate)
  283. {
  284. if (lpszCom == NULL || lpszCom[0] == '\0')
  285. {
  286. Global::WriteReportLog(1, "Parameter error", "(lpszCom) Invalid parameter!");
  287. return FALSE;
  288. }
  289. // 释放打开的;
  290. if (m_pSerial)
  291. delete m_pSerial;
  292. m_pSerial = NULL;
  293. m_pSerial = new CSerialPort();
  294. if (m_pSerial == NULL)
  295. {
  296. Global::WriteReportLog(1, "Memory error", "(m_pSerial) Fail to create object!");
  297. return FALSE;
  298. }
  299. m_pSerial->Open(lpszCom, dwBaudrate);
  300. if (m_pSerial->IsOpen() == FALSE)
  301. {
  302. delete m_pSerial;
  303. m_pSerial = NULL;
  304. Global::WriteReportLog(1, "Serial port error", "Open Serial Port Fail !");
  305. return FALSE;
  306. }
  307. // 超时值设置;
  308. COMMTIMEOUTS comTimeOut;
  309. comTimeOut.ReadIntervalTimeout = 50;
  310. comTimeOut.ReadTotalTimeoutConstant = 8000; // 读取所有字节总超时值;
  311. comTimeOut.ReadTotalTimeoutMultiplier = 100; // 读取1个字节超时值;
  312. comTimeOut.WriteTotalTimeoutConstant = 5000; // 写所有字节的总超时值;
  313. comTimeOut.WriteTotalTimeoutMultiplier = 100; // 写1个字节的超时值;
  314. m_pSerial->SetTimeouts(comTimeOut);
  315. return TRUE;
  316. }
  317. void CSIACP::CloseComm()
  318. {
  319. if (m_pSerial)
  320. delete m_pSerial;
  321. m_pSerial = NULL;
  322. }
  323. BOOL CSIACP::ExecSerialCommand(const _SIACP_ &siacp, std::string command)
  324. {
  325. if (m_pSerial == NULL || !m_pSerial->IsOpen())
  326. {
  327. Global::WriteReportLog(1, "Serial port error", "Serial Port un't Open!");
  328. return FALSE;
  329. }
  330. byte szRecive[BUFFER_LEN] = {0};
  331. DWORD dwWritten = m_pSerial->Write(command.c_str(), command.size());
  332. Global::WriteTextLog(_T("COM Write:%s"), Bytes2HexString((const byte *)command.c_str(), command.size(), ' ').c_str());
  333. if (dwWritten != command.size())
  334. {
  335. Global::WriteTextLog("COM Written Error");
  336. Global::WriteReportLog(1, "Serial Writing Error", "COM Written Error, Buffer=%s", Bytes2HexString((const byte*)command.c_str(), command.size(), ' ').c_str());
  337. return FALSE;
  338. }
  339. // 暂停时间;// 等待设备响应完成;
  340. Sleep(siacp.read_wait_time);
  341. DWORD dwBytesRead = m_pSerial->Read(szRecive, BUFFER_LEN);
  342. if (dwBytesRead == 0)
  343. {
  344. Global::WriteTextLog("COM Read Error");
  345. Global::WriteReportLog(1, "Serial Reading Error","COM Read Error(No Data Return), Write=%s!", Bytes2HexString((const byte*)command.c_str(), command.size(), ' ').c_str());
  346. return FALSE;
  347. }
  348. Global::WriteTextLog(_T("COM Read:%s\r"), Bytes2HexString(szRecive, dwBytesRead, ' ').c_str());
  349. // 下一条命令等待时间;
  350. Sleep(siacp.cmd_wait_time);
  351. // 解析数据;
  352. return ParserSerialData(m_vtdata, siacp, szRecive, dwBytesRead);
  353. }
  354. BOOL CSIACP::ParserSerialData(std::vector<RTN> &vtdata, const _SIACP_ &siacp, byte *pbuffer, DWORD dwlen)
  355. {
  356. vtdata.clear();
  357. if (pbuffer == NULL || dwlen < 5)
  358. {
  359. Global::WriteReportLog(1, "Serial Parsing error", "cmd=%s,Return length less than 5! Buffer = %s", siacp.name.c_str(), Bytes2HexString(pbuffer, dwlen, ' ').c_str());
  360. return FALSE;
  361. }
  362. // 返回码;
  363. byte byReturn = TV_Return;
  364. byte byHead = (byte)HexString2Bytes(siacp.head)[0];
  365. byte byCode = (byte)HexString2Bytes(siacp.code)[0];
  366. if (byHead == TV_Debug)
  367. {
  368. byReturn = TV_Return;
  369. }
  370. else if (byHead == TV_Panel_Debug)
  371. {
  372. byReturn = TV_Panel_Return;
  373. }
  374. else if (byHead == TV_Debug_Other)
  375. {
  376. byReturn = TV_Other_Return;
  377. }
  378. else
  379. {
  380. Global::WriteTextLog("COM Read Parser: Invalid return code!");
  381. Global::WriteReportLog(1, "Serial Parsing error", "cmd=%s,Invalid return code! Buffer=%s", siacp.name.c_str(), Bytes2HexString(pbuffer, dwlen, ' ').c_str());
  382. return FALSE;
  383. }
  384. std::string data;
  385. data.append((const char *)pbuffer, dwlen);
  386. int nABFE = 0;
  387. std::string package;
  388. int package_len = 0;
  389. // 已取出的长度;
  390. int nTookenLen = 0;
  391. unsigned short usCRCValue;
  392. while (true)
  393. {
  394. // 是否已取完所有数据;
  395. if (nTookenLen >= dwlen)
  396. break;
  397. // 取出长度;
  398. if ((byte)data.at(nTookenLen + 1) == 0xFE)
  399. {
  400. nABFE = 2; //FE占1字节,长度多占1字节;共多占2字节;
  401. package_len = ((unsigned int)data[nTookenLen + 2] << 8) | (byte)data[nTookenLen + 3];
  402. }
  403. else
  404. {
  405. nABFE = 0;
  406. package_len = data[nTookenLen + 1];
  407. }
  408. // 包长度是否在有效长度内;
  409. if (package_len > (dwlen - nTookenLen))
  410. {
  411. Global::WriteTextLog("COM Read Parser: Incorrect length of returned data!");
  412. Global::WriteReportLog(1, "Serial Parsing error", "cmd=%s,Incorrect length of returned data! Buffer=%s", siacp.name.c_str(), Bytes2HexString(pbuffer, dwlen, ' ').c_str());
  413. return FALSE;
  414. }
  415. // 取出数据包;
  416. package = data.substr(nTookenLen, nTookenLen + package_len);
  417. // 校验包头是否正确;
  418. if (byte(package[0]) != byReturn)
  419. {
  420. Global::WriteTextLog("COM Read Parser: Data Header Check Error!");
  421. Global::WriteReportLog(1, "Serial Parsing error", "cmd=%s,Data Header Check Error! Buffer=%s", siacp.name.c_str(), Bytes2HexString(pbuffer, dwlen, ' ').c_str());
  422. return FALSE;
  423. }
  424. // 校验crc;
  425. usCRCValue = CRC16Calculate((unsigned char *)package.data(), package_len - 2);
  426. if (((usCRCValue >> 8) & 0xFF) != (unsigned char)package[package_len - 2] || (usCRCValue & 0xFF) != (unsigned char)package[package_len - 1])
  427. {
  428. Global::WriteTextLog("COM Read Parser: Data CRC validation failure!");
  429. Global::WriteReportLog(1, "Serial Parsing error", "cmd=%s,Data CRC validation failure! Buffer=%s", siacp.name.c_str(), Bytes2HexString(pbuffer, dwlen, ' ').c_str());
  430. return FALSE;
  431. }
  432. // 第一组返回,检测结果码
  433. if (nTookenLen == 0)
  434. {
  435. if (package[2] != RC_OK)
  436. {
  437. Global::WriteTextLog("COM Read Parser: The return code of the response data is invalid!");
  438. Global::WriteReportLog(1, "Serial Parsing error", "cmd=%s,The return code of the response data is invalid! Buffer=%s", siacp.name.c_str(), Bytes2HexString(pbuffer, dwlen, ' ').c_str());
  439. return FALSE;
  440. }
  441. }
  442. else
  443. {
  444. // 响应数据的命令码 = 发送数据的命令码 - 1;
  445. if (byte(package[2 + nABFE] - 1) != byCode)
  446. {
  447. Global::WriteTextLog("COM Read Parser: The command code of response data does not match the command code of sending data!");
  448. Global::WriteReportLog(1, "Serial Parsing error", "cmd=%s,The command code of response data does not match the command code of sending data! Buffer=%s", siacp.name.c_str(), Bytes2HexString(pbuffer, dwlen, ' ').c_str());
  449. return FALSE;
  450. }
  451. RTN rtn;
  452. // 获取结果值;
  453. if (siacp.bMulticode)
  454. {
  455. rtn.len = package_len - 6 - nABFE;
  456. rtn.data = package.substr(4 + nABFE, package_len - 6 - nABFE);
  457. }
  458. else
  459. {
  460. rtn.len = package_len - 5 - nABFE;
  461. rtn.data = package.substr(3 + nABFE, package_len - 5 - nABFE);
  462. }
  463. vtdata.push_back(rtn);
  464. }
  465. nTookenLen += package_len;
  466. }
  467. return TRUE;
  468. }
  469. const _SIACP_ *CSIACP::GetSiacp(std::string name)
  470. {
  471. std::vector<_SIACP_>::iterator it = g_vtSiacp.begin();
  472. for (; it != g_vtSiacp.end(); it++)
  473. {
  474. if (_tcsicmp(it->name.c_str(), name.c_str()) == 0)
  475. {
  476. return &*it;
  477. }
  478. }
  479. return NULL;
  480. }
  481. std::string CSIACP::GetSiacpCommand(const _SIACP_ &siacp, std::string others, int othersLen)
  482. {
  483. std::string command;
  484. command.append(HexString2Bytes(siacp.head).c_str(), (siacp.head.size() + 1) / 3);
  485. command.append(HexString2Bytes(siacp.code).c_str(), (siacp.code.size() + 1) / 3);
  486. command.append(HexString2Bytes(siacp.mark).c_str(), (siacp.mark.size() + 1) / 3);
  487. command.append(others.c_str(), othersLen);
  488. // 长度;
  489. byte szlen[2] = {0};
  490. int len = command.size() + 3; // 3=长度本身占1位+2位crc;
  491. if ((byte)command[1] == 0xFE)
  492. {
  493. szlen[0] = ((len + 1) >> 8) & 0xFF;
  494. szlen[1] = (len + 1) & 0xFF;
  495. command.insert(2, (char *)szlen, 2);
  496. }
  497. else
  498. {
  499. szlen[0] = len & 0xFF;
  500. command.insert(1, (char *)szlen, 1);
  501. }
  502. // crc校验;
  503. byte szcrc[2] = {0};
  504. WORD usCRCValue = CRC16Calculate((byte *)command.c_str(), command.size());
  505. szcrc[0] = (usCRCValue >> 8) & 0xFF;
  506. szcrc[1] = usCRCValue & 0xFF;
  507. command.append((char *)szcrc, 2);
  508. return command;
  509. }
  510. std::string CSIACP::GetSiacpCommand(std::string name, std::string others, int othersLen)
  511. {
  512. std::string command;
  513. std::vector<_SIACP_>::iterator it = g_vtSiacp.begin();
  514. for (; it != g_vtSiacp.end(); it++)
  515. {
  516. if (_tcsicmp(name.c_str(), it->name.c_str()) == 0)
  517. {
  518. command.append(HexString2Bytes(it->head).c_str(), (it->head.size() + 1) / 3);
  519. command.append(HexString2Bytes(it->code).c_str(), (it->code.size() + 1) / 3);
  520. command.append(HexString2Bytes(it->mark).c_str(), (it->mark.size() + 1) / 3);
  521. command.append(others.c_str(), othersLen);
  522. // 长度;
  523. byte szlen[2] = {0};
  524. int len = command.size() + 3; // 长度本身占1位;
  525. if ((byte)command[1] == 0xFE)
  526. {
  527. szlen[0] = ((len + 1) >> 8) & 0xFF;
  528. szlen[1] = (len + 1) & 0xFF;
  529. command.insert(2, (char *)szlen, 2);
  530. }
  531. else
  532. {
  533. szlen[0] = len & 0xFF;
  534. command.insert(1, (char *)szlen, 1);
  535. }
  536. // crc校验;
  537. byte szcrc[2] = {0};
  538. int usCRCValue = CRC16Calculate((byte *)command.c_str(), command.size());
  539. szcrc[0] = (usCRCValue >> 8) & 0xFF;
  540. szcrc[1] = usCRCValue & 0xFF;
  541. command.append((char *)szcrc, 2);
  542. break;
  543. }
  544. }
  545. return command;
  546. }
  547. BOOL CSIACP::SendCommand(std::string cmd_name, const byte *pszOthers, DWORD dwOthersLen)
  548. {
  549. std::string others;
  550. if (pszOthers && dwOthersLen > 0)
  551. {
  552. others.append((char *)pszOthers, dwOthersLen);
  553. }
  554. // 获取命令协议;
  555. const _SIACP_ *pSiacp = GetSiacp(cmd_name);
  556. if (pSiacp == NULL)
  557. {
  558. Global::WriteTextLog("This command is not supported!");
  559. Global::WriteReportLog(1, "Invalid command", "This command(%s) is not supported!", cmd_name.c_str());
  560. return FALSE;
  561. }
  562. std::string command = GetSiacpCommand(*pSiacp, others, dwOthersLen);
  563. if (command.size() == 0)
  564. {
  565. Global::WriteTextLog("Generation command failed!");
  566. Global::WriteReportLog(1, "Generation command failed", "command=%s", cmd_name.c_str());
  567. return FALSE;
  568. }
  569. return ExecSerialCommand(*pSiacp, command);
  570. }
  571. BOOL CSIACP::SendCommand2(std::string cmd_name, std::string data /* = "" */, size_t nlen /* = 0 */)
  572. {
  573. // 获取命令协议;
  574. const _SIACP_ *pSiacp = GetSiacp(cmd_name);
  575. if (pSiacp == NULL)
  576. {
  577. Global::WriteTextLog("This command is not supported!");
  578. Global::WriteReportLog(1, "Invalid command", "This command(%s) is not supported!", cmd_name.c_str());
  579. return FALSE;
  580. }
  581. std::string command = GetSiacpCommand(*pSiacp, data, nlen);
  582. if (command.size() == 0)
  583. {
  584. Global::WriteTextLog("Generation command failed!");
  585. Global::WriteReportLog(1, "Generation command failed", "command=%s", cmd_name.c_str());
  586. return FALSE;
  587. }
  588. return ExecSerialCommand(*pSiacp, command);
  589. }
  590. BOOL CSIACP::SCBC_WaitTVBoot()
  591. {
  592. byte szRecive[BUFFER_LEN] = { 0 };
  593. DWORD dwBytesRead = 0;
  594. // 根据配置文件,是否需要读等待;
  595. if ( Global::g_tConfig.bootread )
  596. dwBytesRead = m_pSerial->Read(szRecive, BUFFER_LEN);
  597. if (dwBytesRead == 0)
  598. {
  599. if ( SCBC_EnterFactory() )
  600. {
  601. SCBC_LeaveFactory();
  602. return TRUE;
  603. }
  604. }
  605. return FALSE;
  606. }
  607. BOOL CSIACP::SCBC_MTKInit()
  608. {
  609. if (m_pSerial == NULL)
  610. {
  611. Global::WriteTextLog("串口对象未初始化");
  612. Global::WriteReportLog(1, "MTKInit Error", "Serial port object uninitialized!");
  613. return FALSE;
  614. }
  615. if (!m_pSerial->IsOpen())
  616. {
  617. Global::WriteTextLog("未打开串口");
  618. Global::WriteReportLog(1, "MTKInit Error", "Unopened Serial Port!");
  619. return FALSE;
  620. }
  621. unsigned char ucBufInitMTK8223[16] = {0x54, 0x8A, 0x51, 0x37, 0x56, 0x92, 0x1C, 0xB2, 0x50, 0x80, 0x50, 0x02, 0x50, 0x01, 0x50, 0xE2};
  622. m_pSerial->Write(ucBufInitMTK8223, 16);
  623. Sleep(50);
  624. return TRUE;
  625. }
  626. // 对外接口;
  627. BOOL CSIACP::SCBC_EnterFactory()
  628. {
  629. return SendCommand("EnterFactory");
  630. }
  631. BOOL CSIACP::SCBC_LeaveFactory()
  632. {
  633. return SendCommand("LeaveFactory");
  634. }
  635. BOOL CSIACP::SCBC_WBInit()
  636. {
  637. return SendCommand("WBInit");
  638. }
  639. BOOL CSIACP::SCBC_GetProjectId(int &pid)
  640. {
  641. BOOL bRet = SendCommand("GetProjectId");
  642. if (bRet)
  643. {
  644. if (m_vtdata.size() == 0)
  645. {
  646. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  647. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  648. return FALSE;
  649. }
  650. RTN rtn = m_vtdata.at(0);
  651. if (rtn.len == 2)
  652. {
  653. pid = (byte)rtn.data[0] << 8;
  654. pid += (byte)rtn.data[1];
  655. }
  656. else
  657. {
  658. pid = (byte)rtn.data[0];
  659. }
  660. }
  661. return bRet;
  662. }
  663. BOOL CSIACP::SCBC_GetSoftVersion(std::string &strVer)
  664. {
  665. BOOL bRet = SendCommand("GetSoftVersion");
  666. if (bRet)
  667. {
  668. if (m_vtdata.size() == 0)
  669. {
  670. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  671. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  672. return FALSE;
  673. }
  674. RTN rtn = m_vtdata.at(0);
  675. if (!IsValidString(rtn.data.c_str()))
  676. {
  677. Global::WriteTextLog("%s:%s%s!", __FUNCTION__, "tv version string is invalid=", rtn.data.c_str());
  678. Global::WriteReportLog(1, "Copy Key", "%s:%s%s!", __FUNCTION__, "tv version string is invalid=", rtn.data.c_str());
  679. return FALSE;
  680. }
  681. strVer.append(rtn.data.c_str(), rtn.len);
  682. }
  683. return bRet;
  684. }
  685. BOOL CSIACP::SCBC_GetDeviceId(std::string &strDid)
  686. {
  687. BOOL bRet = SendCommand("GetDeviceId");
  688. if (bRet)
  689. {
  690. if (m_vtdata.size() == 0)
  691. {
  692. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  693. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  694. return FALSE;
  695. }
  696. RTN rtn = m_vtdata.at(0);
  697. strDid.append(rtn.data.c_str(), rtn.len);
  698. }
  699. return bRet;
  700. }
  701. BOOL CSIACP::SCBC_GetClientType(std::string &strClt)
  702. {
  703. BOOL bRet = SendCommand("GetClientType");
  704. if (bRet)
  705. {
  706. if (m_vtdata.size() == 0)
  707. {
  708. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  709. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  710. return FALSE;
  711. }
  712. RTN rtn = m_vtdata.at(0);
  713. if (!IsValidString(rtn.data.c_str()))
  714. {
  715. Global::WriteTextLog("%s:%s%s!", __FUNCTION__, "tv client string is invalid=", rtn.data.c_str());
  716. Global::WriteReportLog(1, "Copy Key", "%s:%s%s!", __FUNCTION__, "tv client string is invalid=", rtn.data.c_str());
  717. return FALSE;
  718. }
  719. strClt.append(rtn.data.c_str(), rtn.len);
  720. }
  721. return bRet;
  722. }
  723. BOOL CSIACP::SCBC_GetMAC(std::string &strMac)
  724. {
  725. BOOL bRet = SendCommand("GetMAC");
  726. if (bRet)
  727. {
  728. if (m_vtdata.size() == 0)
  729. {
  730. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  731. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  732. return FALSE;
  733. }
  734. RTN rtn = m_vtdata.at(0);
  735. strMac = Bytes2HexString((const byte *)rtn.data.c_str(), rtn.len, '-');
  736. }
  737. return bRet;
  738. }
  739. BOOL CSIACP::SCBC_GetHDCPKey(std::string &strHDCP)
  740. {
  741. BOOL bRet = SendCommand("GetHDCPKey");
  742. if (bRet)
  743. {
  744. if (m_vtdata.size() == 0)
  745. {
  746. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  747. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  748. return FALSE;
  749. }
  750. RTN rtn = m_vtdata.at(0);
  751. //strHDCP.append(rtn.data.c_str(), rtn.len);
  752. strHDCP = Bytes2HexString((const byte *)rtn.data.c_str(), rtn.len);
  753. }
  754. return bRet;
  755. }
  756. BOOL CSIACP::SCBC_GetHDCPKey22(std::string &strHDCP22)
  757. {
  758. BOOL bRet = SendCommand("GetHDCPKey22");
  759. if (bRet)
  760. {
  761. if (m_vtdata.size() == 0)
  762. {
  763. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  764. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  765. return FALSE;
  766. }
  767. RTN rtn = m_vtdata.at(0);
  768. //strHDCP22.append(rtn.data.c_str(), rtn.len);
  769. strHDCP22 = Bytes2HexString((const byte *)rtn.data.c_str(), rtn.len);
  770. }
  771. return bRet;
  772. }
  773. BOOL CSIACP::SCBC_GetWidi(std::string &strWidi)
  774. {
  775. BOOL bRet = SendCommand("GetWidi");
  776. if (bRet)
  777. {
  778. if (m_vtdata.size() == 0)
  779. {
  780. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  781. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  782. return FALSE;
  783. }
  784. RTN rtn = m_vtdata.at(0);
  785. //strWidi.append(rtn.data.c_str(), rtn.len);
  786. strWidi = Bytes2HexString((const byte *)rtn.data.c_str(), rtn.len);
  787. }
  788. return bRet;
  789. }
  790. BOOL CSIACP::SCBC_GetNetflixESN(std::string &strESN)
  791. {
  792. BOOL bRet = SendCommand("GetNetflixESN");
  793. if (bRet)
  794. {
  795. if (m_vtdata.size() == 0)
  796. {
  797. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  798. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  799. return FALSE;
  800. }
  801. RTN rtn = m_vtdata.at(0);
  802. strESN.append(rtn.data.c_str(), rtn.len);
  803. //strESN = Bytes2HexString((const byte*)rtn.data.c_str(), rtn.len, ' ');
  804. }
  805. return bRet;
  806. }
  807. BOOL CSIACP::SCBC_GetWidevine(std::string &strWidevine)
  808. {
  809. BOOL bRet = SendCommand("GetWidevine");
  810. if (bRet)
  811. {
  812. if (m_vtdata.size() == 0)
  813. {
  814. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  815. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  816. return FALSE;
  817. }
  818. RTN rtn = m_vtdata.at(0);
  819. //strWidevine.append(rtn.data.c_str(), rtn.len);
  820. strWidevine = Bytes2HexString((const byte *)rtn.data.c_str(), rtn.len);
  821. }
  822. return bRet;
  823. }
  824. BOOL CSIACP::SCBC_GetCiKey(std::string &strCikey)
  825. {
  826. BOOL bRet = SendCommand("GetCiKey");
  827. if (bRet)
  828. {
  829. if (m_vtdata.size() == 0)
  830. {
  831. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  832. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  833. return FALSE;
  834. }
  835. RTN rtn = m_vtdata.at(0);
  836. //strCikey.append(rtn.data.c_str(), rtn.len);
  837. strCikey = Bytes2HexString((const byte *)rtn.data.c_str(), rtn.len);
  838. }
  839. return bRet;
  840. }
  841. BOOL CSIACP::SCBC_GetOSDLanguage(std::string &strOSDLan)
  842. {
  843. BOOL bRet = SendCommand("GetOSDLanguage");
  844. if (bRet)
  845. {
  846. if (m_vtdata.size() == 0)
  847. {
  848. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  849. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  850. return FALSE;
  851. }
  852. RTN rtn = m_vtdata.at(0);
  853. strOSDLan.append(rtn.data.c_str(), rtn.len);
  854. strOSDLan = Bytes2HexString((const byte*)rtn.data.c_str(), rtn.len, ' ');
  855. }
  856. return bRet;
  857. }
  858. BOOL CSIACP::SCBC_GetShopLanguage(std::string &strShopLan)
  859. {
  860. BOOL bRet = SendCommand("GetShopLanguage");
  861. if (bRet)
  862. {
  863. if (m_vtdata.size() == 0)
  864. {
  865. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  866. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  867. return FALSE;
  868. }
  869. RTN rtn = m_vtdata.at(0);
  870. strShopLan.append(rtn.data.c_str(), rtn.len);
  871. strShopLan = Bytes2HexString((const byte*)rtn.data.c_str(), rtn.len, ' ');
  872. }
  873. return bRet;
  874. }
  875. BOOL CSIACP::SCBC_GetChannel(std::string& channel)
  876. {
  877. BOOL bRet = SendCommand("GetChannel");
  878. if (bRet)
  879. {
  880. if (m_vtdata.size() == 0)
  881. {
  882. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  883. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  884. return FALSE;
  885. }
  886. RTN rtn = m_vtdata.at(0);
  887. channel.append(rtn.data.c_str(), rtn.len);
  888. channel = Bytes2HexString((const byte*)rtn.data.c_str(), rtn.len, ' ');
  889. }
  890. return bRet;
  891. }
  892. BOOL CSIACP::SCBC_SetProjectId(const int &pid)
  893. {
  894. std::string data;
  895. if (pid > 0xFF)
  896. {
  897. data.append(1, (pid >> 8) & 0xFF);
  898. data.append(1, pid & 0xFF);
  899. }
  900. else
  901. {
  902. data.append(1, pid & 0xFF);
  903. }
  904. return SendCommand2("SetProjectId", data, data.size());
  905. }
  906. BOOL CSIACP::SCBC_SetProjectId(std::string pid)
  907. {
  908. return SCBC_SetProjectId(atoi(pid.c_str()));
  909. }
  910. BOOL CSIACP::SCBC_SetProjectId(const byte *pBuffer, const int &nLen)
  911. {
  912. return SendCommand("SetProjectId", pBuffer, nLen);
  913. }
  914. BOOL CSIACP::SCBC_SetDeviceId(std::string strDeviceId)
  915. {
  916. if (strDeviceId.size() < 40)
  917. {
  918. return FALSE;
  919. }
  920. return SendCommand2("SetDeviceId", strDeviceId, strDeviceId.size());
  921. }
  922. BOOL CSIACP::SCBC_SetDeviceId(const byte *pBuffer, const int &nLen)
  923. {
  924. return SendCommand("SetDeviceId", pBuffer, nLen);
  925. }
  926. BOOL CSIACP::SCBC_SetMAC(std::string strMac)
  927. {
  928. if (strMac.size() < 16)
  929. return FALSE;
  930. std::string data = HexString2Bytes(strMac);
  931. return SendCommand2("SetMAC", data, (strMac.size() + 1) / 3);
  932. }
  933. BOOL CSIACP::SCBC_SetMAC(const byte *pBuffer, const int &nLen)
  934. {
  935. return SendCommand("SetMAC", pBuffer, nLen);
  936. }
  937. BOOL CSIACP::SCBC_SetHDCPKey(std::string strHDCP, BOOL bHasSpace /* = TRUE */)
  938. {
  939. std::string data = HexString2Bytes(strHDCP, bHasSpace ? 3 : 2);
  940. return SendCommand2("SetHDCPKey", data, (strHDCP.size() + 1) / (bHasSpace ? 3 : 2));
  941. }
  942. BOOL CSIACP::SCBC_SetHDCPKey(const byte *pBuffer, const int &nLen)
  943. {
  944. return SendCommand("SetHDCPKey", pBuffer, nLen);
  945. }
  946. BOOL CSIACP::SCBC_SetHDCPKey22(std::string strHDCP22, BOOL bHasSpace /* = TRUE */)
  947. {
  948. std::string data = HexString2Bytes(strHDCP22, bHasSpace ? 3 : 2);
  949. return SendCommand2("SetHDCPKey22", data, (strHDCP22.size() + 1) / (bHasSpace ? 3 : 2));
  950. }
  951. BOOL CSIACP::SCBC_SetHDCPKey22(const byte *pBuffer, const int &nLen)
  952. {
  953. return SendCommand("SetHDCPKey22", pBuffer, nLen);
  954. }
  955. BOOL CSIACP::SCBC_SetNetflixESN(std::string strESN, BOOL bHasSpace /* = TRUE */)
  956. {
  957. std::string data = HexString2Bytes(strESN, bHasSpace ? 3 : 2);
  958. return SendCommand2("SetNetflixESN", data, (strESN.size() + 1) / (bHasSpace ? 3 : 2));
  959. }
  960. BOOL CSIACP::SCBC_SetNetflixESN(const byte *pBuffer, const int &nLen)
  961. {
  962. return SendCommand("SetNetflixESN", pBuffer, nLen);
  963. }
  964. BOOL CSIACP::SCBC_SetWidi(std::string strWidi, BOOL bHasSpace /* = TRUE */)
  965. {
  966. std::string data = HexString2Bytes(strWidi, bHasSpace ? 3 : 2);
  967. return SendCommand2("SetWidi", data, (strWidi.size() + 1) / (bHasSpace ? 3 : 2));
  968. }
  969. BOOL CSIACP::SCBC_SetWidi(const byte *pBuffer, const int &nLen)
  970. {
  971. return SendCommand("SetWidi", pBuffer, nLen);
  972. }
  973. BOOL CSIACP::SCBC_SetWidevine(std::string strWidevine, BOOL bHasSpace /* = TRUE */)
  974. {
  975. std::string data = HexString2Bytes(strWidevine, bHasSpace ? 3 : 2);
  976. return SendCommand2("SetWidevine", data, (strWidevine.size() + 1) / (bHasSpace ? 3 : 2));
  977. }
  978. BOOL CSIACP::SCBC_SetWidevine(const byte *pBuffer, const int &nLen)
  979. {
  980. return SendCommand("SetWidevine", pBuffer, nLen);
  981. }
  982. BOOL CSIACP::SCBC_SetCiKey(std::string strCiKey, BOOL bHasSpace /* = TRUE */)
  983. {
  984. std::string data = HexString2Bytes(strCiKey, bHasSpace ? 3 : 2);
  985. return SendCommand2("SetCiKey", data, (strCiKey.size() + 1) / (bHasSpace ? 3 : 2));
  986. }
  987. BOOL CSIACP::SCBC_SetCiKey(const byte *pBuffer, const int &nLen)
  988. {
  989. return SendCommand("SetCiKey", pBuffer, nLen);
  990. }
  991. BOOL CSIACP::SCBC_SetOSDLanguage(std::string lan, BOOL bHasSpace /* = TRUE */)
  992. {
  993. std::string data = HexString2Bytes(lan, bHasSpace ? 3 : 2);
  994. return SendCommand2("SetOSDLanguage", data, data.size());
  995. }
  996. BOOL CSIACP::SCBC_SetOSDLanguage(const byte *pBuffer, const int &nLen)
  997. {
  998. return SendCommand("SetOSDLanguage", pBuffer, nLen);
  999. }
  1000. BOOL CSIACP::SCBC_SetShopLanguage(std::string lan, BOOL bHasSpace /* = TRUE */)
  1001. {
  1002. std::string data = HexString2Bytes(lan, bHasSpace ? 3 : 2);
  1003. return SendCommand2("SetShopLanguage", data, data.size());
  1004. }
  1005. BOOL CSIACP::SCBC_SetShopLanguage(const byte *pBuffer, const int &nLen)
  1006. {
  1007. return SendCommand("SetShopLanguage", pBuffer, nLen);
  1008. }
  1009. BOOL CSIACP::SCBC_SetChannel(std::string channel, BOOL bHasSpace /* = TRUE */)
  1010. {
  1011. std::string data = HexString2Bytes(channel, bHasSpace ? 3 : 2);
  1012. return SendCommand2("SetChannel", data, data.size());
  1013. }
  1014. BOOL CSIACP::SCBC_SetChannel(const byte *pBuffer, const int &nLen)
  1015. {
  1016. return SendCommand("SetChannel", pBuffer, nLen);
  1017. }
  1018. BOOL CSIACP::SCBC_SetWBNormal(std::string data)
  1019. {
  1020. return SendCommand2("SetWBNormal", data, data.size());
  1021. }
  1022. BOOL CSIACP::SCBC_SetWBNormal(const byte *pBuffer, const int &nLen)
  1023. {
  1024. return SendCommand("SetWBNormal", pBuffer, nLen);
  1025. }
  1026. BOOL CSIACP::SCBC_SetWBCool(std::string data)
  1027. {
  1028. return SendCommand2("SetWBCool", data, data.size());
  1029. }
  1030. BOOL CSIACP::SCBC_SetWBCool(const byte *pBuffer, const int &nLen)
  1031. {
  1032. return SendCommand("SetWBCool", pBuffer, nLen);
  1033. }
  1034. BOOL CSIACP::SCBC_SetWBWarm(std::string data)
  1035. {
  1036. return SendCommand2("SetWBWarm", data, data.size());
  1037. }
  1038. BOOL CSIACP::SCBC_SetWBWarm(const byte *pBuffer, const int &nLen)
  1039. {
  1040. return SendCommand("SetWBWarm", pBuffer, nLen);
  1041. }
  1042. BOOL CSIACP::SCBC_CheckDeviceId()
  1043. {
  1044. BOOL bRet = SendCommand("CheckDeviceId");
  1045. if (bRet)
  1046. {
  1047. if (m_vtdata.size() == 0)
  1048. {
  1049. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  1050. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  1051. return FALSE;
  1052. }
  1053. RTN rtn = m_vtdata.at(0);
  1054. if (rtn.data.size() == 0)
  1055. {
  1056. return FALSE;
  1057. }
  1058. byte bydata = (byte)rtn.data.at(0);
  1059. #if TEMP_5659
  1060. if (bydata == 0x03 || bydata == 0x02 || bydata == 0x01)
  1061. return TRUE;
  1062. else
  1063. return FALSE;
  1064. #else
  1065. if (bydata == 0x02 || bydata == 0x03 || bydata == 0x07)
  1066. return TRUE;
  1067. else
  1068. return FALSE;
  1069. #endif
  1070. }
  1071. return bRet;
  1072. }
  1073. BOOL CSIACP::SCBC_CheckMAC()
  1074. {
  1075. BOOL bRet = SendCommand("CheckMAC");
  1076. if (bRet)
  1077. {
  1078. if (m_vtdata.size() == 0)
  1079. {
  1080. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  1081. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  1082. return FALSE;
  1083. }
  1084. RTN rtn = m_vtdata.at(0);
  1085. if (rtn.data.size() == 0)
  1086. {
  1087. return FALSE;
  1088. }
  1089. byte bydata = (byte)rtn.data.at(0);
  1090. if (bydata == 0x01 || bydata == 0x03 || bydata == 0x07)
  1091. return TRUE;
  1092. else
  1093. return FALSE;
  1094. }
  1095. return bRet;
  1096. }
  1097. BOOL CSIACP::SCBC_CheckHDCP()
  1098. {
  1099. BOOL bRet = SendCommand("CheckHDCP");
  1100. if (bRet)
  1101. {
  1102. if (m_vtdata.size() == 0)
  1103. {
  1104. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  1105. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  1106. return FALSE;
  1107. }
  1108. RTN rtn = m_vtdata.at(0);
  1109. if (rtn.data.size() == 0)
  1110. {
  1111. return FALSE;
  1112. }
  1113. byte bydata = (byte)rtn.data.at(0);
  1114. if (bydata == 0x01)
  1115. return TRUE;
  1116. else
  1117. return FALSE;
  1118. }
  1119. return bRet;
  1120. }
  1121. BOOL CSIACP::SCBC_CheckHDCP22()
  1122. {
  1123. BOOL bRet = SendCommand("CheckHDCP22");
  1124. if (bRet)
  1125. {
  1126. if (m_vtdata.size() == 0)
  1127. {
  1128. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  1129. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  1130. return FALSE;
  1131. }
  1132. RTN rtn = m_vtdata.at(0);
  1133. if (rtn.data.size() == 0)
  1134. {
  1135. return FALSE;
  1136. }
  1137. byte bydata = (byte)rtn.data.at(0);
  1138. if (bydata == 0x01)
  1139. return TRUE;
  1140. else
  1141. return FALSE;
  1142. }
  1143. return bRet;
  1144. }
  1145. BOOL CSIACP::SCBC_CheckNetflixESN()
  1146. {
  1147. BOOL bRet = SendCommand("CheckNetflixESN");
  1148. if (bRet)
  1149. {
  1150. if (m_vtdata.size() == 0)
  1151. {
  1152. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  1153. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  1154. return FALSE;
  1155. }
  1156. RTN rtn = m_vtdata.at(0);
  1157. if (rtn.data.size() == 0)
  1158. {
  1159. return FALSE;
  1160. }
  1161. byte bydata = (byte)rtn.data.at(0);
  1162. if (bydata == 0x01)
  1163. return TRUE;
  1164. else
  1165. return FALSE;
  1166. }
  1167. return bRet;
  1168. }
  1169. BOOL CSIACP::SCBC_CheckWidi()
  1170. {
  1171. BOOL bRet = SendCommand("CheckWidi");
  1172. if (bRet)
  1173. {
  1174. if (m_vtdata.size() == 0)
  1175. {
  1176. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  1177. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  1178. return FALSE;
  1179. }
  1180. RTN rtn = m_vtdata.at(0);
  1181. if (rtn.data.size() == 0)
  1182. {
  1183. return FALSE;
  1184. }
  1185. byte bydata = (byte)rtn.data.at(0);
  1186. if (bydata == 0x01)
  1187. return TRUE;
  1188. else
  1189. return FALSE;
  1190. }
  1191. return bRet;
  1192. }
  1193. BOOL CSIACP::SCBC_CheckWidevine()
  1194. {
  1195. BOOL bRet = SendCommand("CheckWidevine");
  1196. if (bRet)
  1197. {
  1198. if (m_vtdata.size() == 0)
  1199. {
  1200. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  1201. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  1202. return FALSE;
  1203. }
  1204. RTN rtn = m_vtdata.at(0);
  1205. if (rtn.data.size() == 0)
  1206. {
  1207. return FALSE;
  1208. }
  1209. byte bydata = (byte)rtn.data.at(0);
  1210. if (bydata == 0x01)
  1211. return TRUE;
  1212. else
  1213. return FALSE;
  1214. }
  1215. return bRet;
  1216. }
  1217. BOOL CSIACP::SCBC_CheckCikey()
  1218. {
  1219. BOOL bRet = SendCommand("CheckCikey");
  1220. if (bRet)
  1221. {
  1222. if (m_vtdata.size() == 0)
  1223. {
  1224. Global::WriteTextLog("%s:%s", __FUNCTION__, "No data return!");
  1225. Global::WriteReportLog(1, "Copy Key", "%s:%s", __FUNCTION__, "No data return!");
  1226. return FALSE;
  1227. }
  1228. RTN rtn = m_vtdata.at(0);
  1229. if (rtn.data.size() == 0)
  1230. {
  1231. return FALSE;
  1232. }
  1233. byte bydata = (byte)rtn.data.at(0);
  1234. if (bydata == 0x01)
  1235. return TRUE;
  1236. else
  1237. return FALSE;
  1238. }
  1239. return bRet;
  1240. }
  1241. BOOL CSIACP::SCBC_StarWarmUpMode()
  1242. {
  1243. return SendCommand("StarWarmUpMode");
  1244. }
  1245. BOOL CSIACP::SCBC_StopWarmUpMode()
  1246. {
  1247. return SendCommand("StopWarmUpMode");
  1248. }
  1249. //////////////////////////////////////////////////////////////////////////
  1250. COTA::COTA()
  1251. {
  1252. m_pMainDlg = nullptr;
  1253. m_curl.Initialize();
  1254. }
  1255. COTA::~COTA()
  1256. {
  1257. }
  1258. void COTA::SetMainDlg(CDialogEx* p)
  1259. {
  1260. m_pMainDlg = p;
  1261. }
  1262. void COTA::ShowMessage(LPCTSTR lpMsg, LOG_ENUM logtype)
  1263. {
  1264. if (m_pMainDlg && lpMsg)
  1265. {
  1266. CTCLCopyToolDlg* pMainDlg = (CTCLCopyToolDlg*)m_pMainDlg;
  1267. pMainDlg->SetOptionLog(std::string(lpMsg), logtype);
  1268. }
  1269. }
  1270. BOOL COTA::HttpGet(std::string host, std::string context, std::string &result, DATATYPE dt)
  1271. {
  1272. AUTOTIMING;
  1273. //AutoTiming at(host+";"+context);
  1274. CharEncoding::ASCII2UTF8(context.c_str(), context);
  1275. m_curl.SetHeaders("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*");
  1276. m_curl.SetHeaders("Accept-Language: zh-cn");
  1277. if (dt == DATA_JSON)
  1278. m_curl.SetHeaders("Content-Type: application/json;charset=utf-8");
  1279. int nRecCode = CURLE_OK;
  1280. if (_tcsstr(host.c_str(), "https://"))
  1281. nRecCode = m_curl.Gets(host + context, result);
  1282. else
  1283. nRecCode = m_curl.Get(host + context, result);
  1284. if (CURLE_OK != nRecCode)
  1285. {
  1286. TCHAR szMsg[250] = { 0 };
  1287. _stprintf_s(szMsg, _T("http(get) request failed, curl error code = %d\r"), nRecCode);
  1288. ShowMessage(szMsg);
  1289. LOG4C((LOG_NOTICE, "请求失败:%s, 错误码=%ld", context.c_str(), nRecCode));
  1290. Global::WriteReportLog(0, __FUNCTION__, "Request(get) Failure, Curl Error Code=%ld: host=%s, content=%s, result=%s", nRecCode, host.c_str(), context.c_str(),result.c_str());
  1291. }
  1292. return CURLE_OK == nRecCode;
  1293. }
  1294. BOOL COTA::HttpPost(std::string host, std::string context, std::string &result, DATATYPE dt)
  1295. {
  1296. AUTOTIMING;
  1297. CharEncoding::ASCII2UTF8(context.c_str(), context);
  1298. m_curl.SetHeaders("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*");
  1299. m_curl.SetHeaders("Accept-Language: zh-cn");
  1300. if (dt == DATA_JSON)
  1301. m_curl.SetHeaders("Content-Type: application/json;charset=utf-8");
  1302. int nRecCode = CURLE_OK;
  1303. if (_tcsstr(host.c_str(), "https://"))
  1304. nRecCode = m_curl.Posts(host, context, result);
  1305. else
  1306. nRecCode = m_curl.Posts(host, context, result);
  1307. result = CharEncoding::DeCode_URLUTF8(result.c_str());
  1308. if (CURLE_OK != nRecCode)
  1309. {
  1310. TCHAR szMsg[250] = {0};
  1311. _stprintf_s(szMsg, _T("http(post) request failed, curl error code = %d\r"), nRecCode);
  1312. ShowMessage(szMsg);
  1313. LOG4C((LOG_NOTICE, "请求失败:%s, 错误码=%ld\n", context.c_str(), nRecCode));
  1314. if ( _tcsicmp("https://cn.ota.qhmoka.com/ota-services/report/reportToolsLog", host.c_str()) )
  1315. Global::WriteReportLog(0, __FUNCTION__, "Request(post) Failure, Curl Error Code=%ld: host=%s, content=%s, result=%s", nRecCode, host.c_str(), context.c_str(), result.c_str());
  1316. }
  1317. std::string api = host.substr(host.find_last_of('/') + 1);
  1318. #ifdef _DEBUG
  1319. LOG4C((LOG_NOTSET, "\n地址:%s\n报文:%s\n结果:%s\n", host.c_str(), context.size() > 256 ? std::string(context.substr(0, 256) + (" ……")).c_str() : context.c_str(), result.c_str()));
  1320. #else
  1321. LOG4C((LOG_NOTSET, "\n地址:%s\n报文:%s\n结果:%s\n", api.c_str(), context.size() > 256 ? std::string(context.substr(0, 256)+(" ……")).c_str() : context.c_str(), result.c_str()));
  1322. #endif
  1323. return CURLE_OK == nRecCode;
  1324. }
  1325. BOOL COTA::GetMIDInfo(MIDInfo &mid, std::string bid, std::string strMacs, std::string iptvid, std::string version)
  1326. {
  1327. AUTOTIMING;
  1328. // Json数据;
  1329. cJSON *pJson = cJSON_CreateObject();
  1330. cJSON_AddStringToObject(pJson, "clientType", iptvid.c_str());
  1331. cJSON_AddStringToObject(pJson, "version", version.c_str());
  1332. cJSON_AddStringToObject(pJson, "mac", strMacs.c_str());
  1333. cJSON_AddStringToObject(pJson, "bid", trim(bid).c_str());
  1334. char *pJsonText = cJSON_Print(pJson);
  1335. // post请求;
  1336. std::string name, type;
  1337. std::string host, result, context;
  1338. context = pJsonText;
  1339. if (pJsonText)
  1340. delete pJsonText;
  1341. pJsonText = NULL;
  1342. cJSON_Delete(pJson);
  1343. pJson = NULL;
  1344. host = Global::g_bTestHost ? _T("http://test.admin.uc.qhmoka.com/scbc-server/clientType/getMessage.do") : _T("https://cn.uc.qhmoka.com/scbc-server/clientType/getMessage.do");
  1345. BOOL bRet = HttpPost(host, context, result, DATA_JSON);
  1346. if (!bRet)
  1347. {
  1348. LOG4C((LOG_WARN, "Post request failed!"));
  1349. goto end;
  1350. }
  1351. // 解析返回值;
  1352. pJson = cJSON_Parse(result.c_str());
  1353. if (pJson == NULL)
  1354. {
  1355. bRet = FALSE;
  1356. LOG4C((LOG_WARN, "JSON parsing failure:post=%s;return=%s\n", context.c_str(), result.c_str()));
  1357. Global::WriteReportLog(0, __FUNCTION__, "JSON Parsing Error: host=%s, content=%s, result=%s", host.c_str(), context.c_str(), result.c_str());
  1358. goto end;
  1359. }
  1360. mid.message = cJSON_GetObjectItem(pJson, "message") ? cJSON_GetObjectItem(pJson, "message")->valuestring : "";
  1361. mid.code = cJSON_GetObjectItem(pJson, "code") ? cJSON_GetObjectItem(pJson, "code")->valuestring : "";
  1362. mid.factoryname = cJSON_GetObjectItem(pJson, "factoryName") ? (cJSON_GetObjectItem(pJson, "factoryName")->valuestring != NULL ? cJSON_GetObjectItem(pJson, "factoryName")->valuestring : "") : "";
  1363. mid.factoryNum = cJSON_GetObjectItem(pJson, "factoryNum") ? (cJSON_GetObjectItem(pJson, "factoryNum")->valuestring != NULL ? cJSON_GetObjectItem(pJson, "factoryNum")->valuestring : "") : "";
  1364. mid.version = cJSON_GetObjectItem(pJson, "version") ? (cJSON_GetObjectItem(pJson, "version")->valuestring != NULL ? cJSON_GetObjectItem(pJson, "version")->valuestring : "") : "";
  1365. mid.projectid = cJSON_GetObjectItem(pJson, "projectId") ? (cJSON_GetObjectItem(pJson, "projectId")->valuestring != NULL ? cJSON_GetObjectItem(pJson, "projectId")->valuestring : "") : "";
  1366. mid.clienttype = cJSON_GetObjectItem(pJson, "clientType") ? (cJSON_GetObjectItem(pJson, "clientType")->valuestring != NULL ? cJSON_GetObjectItem(pJson, "clientType")->valuestring : "") : "";
  1367. mid.host = cJSON_GetObjectItem(pJson, "host") ? (cJSON_GetObjectItem(pJson, "host")->valuestring != NULL ? cJSON_GetObjectItem(pJson, "host")->valuestring : "") : "";
  1368. cJSON *pObj = cJSON_GetObjectItem(pJson, "obj");
  1369. if (pObj == NULL)
  1370. {
  1371. bRet = FALSE;
  1372. LOG4C((LOG_WARN, "JSON parsing failure:post=%s;return=%s\n", context.c_str(), result.c_str()));
  1373. Global::WriteReportLog(0, __FUNCTION__, "JSON Parsing Error: host=%s, content=%s, result=%s", host.c_str(), context.c_str(), result.c_str());
  1374. goto end;
  1375. }
  1376. if (_tcsicmp(mid.code.c_str(), "1000") != 0)
  1377. {
  1378. bRet = FALSE;
  1379. LOG4C((LOG_WARN, "return invalid data:post=%s;return=%s\n", context.c_str(), result.c_str()));
  1380. Global::WriteReportLog(0, __FUNCTION__, "return invalid data: host=%s, content=%s, result=%s", host.c_str(), context.c_str(), result.c_str());
  1381. goto end;
  1382. }
  1383. if (mid.host.size() == 0)
  1384. {
  1385. bRet = FALSE;
  1386. LOG4C((LOG_WARN, "return invalid data:post=%s;return=%s\n", context.c_str(), result.c_str()));
  1387. Global::WriteReportLog(0, __FUNCTION__, "return invalid data: host=%s, content=%s, result=%s", host.c_str(), context.c_str(), result.c_str());
  1388. goto end;
  1389. }
  1390. // 清空
  1391. Global::g_AutoOnlineChassis = Global::CHASSIS();
  1392. Global::g_AutoOnlineChassis.ProjectID = _ttoi(mid.projectid.c_str());
  1393. Global::g_AutoOnlineChassis.url = mid.host;
  1394. Global::g_AutoOnlineChassis.name = bid;
  1395. mid.obj.clear();
  1396. cJSON *pItem = NULL;
  1397. int nSize = cJSON_GetArraySize(pObj);
  1398. for (int i = 0; i < nSize; i++)
  1399. {
  1400. pItem = cJSON_GetArrayItem(pObj, i);
  1401. if (pItem)
  1402. {
  1403. name = cJSON_GetObjectItem(pItem, "name") ? cJSON_GetObjectItem(pItem, "name")->valuestring : "";
  1404. type = cJSON_GetObjectItem(pItem, "type") ? cJSON_GetObjectItem(pItem, "type")->valuestring : "";
  1405. mid.obj.insert(pair<std::string, std::string>(name,type));
  1406. if ( _tcsicmp(name.c_str(), _T("DeviceID")) == 0 )
  1407. {
  1408. if ( type.size() )
  1409. {
  1410. Global::g_AutoOnlineChassis.IsCopyDID = true;
  1411. Global::g_AutoOnlineChassis.ClientType = "tcl_unknown_model";
  1412. }
  1413. else
  1414. {
  1415. Global::g_AutoOnlineChassis.IsCopyDID = false;
  1416. Global::g_AutoOnlineChassis.ClientType = "";
  1417. }
  1418. }
  1419. else if (_tcsicmp(name.c_str(), _T("MAC")) == 0)
  1420. {
  1421. Global::g_AutoOnlineChassis.IsCopyMAC = true;
  1422. Global::g_AutoOnlineChassis.MACType = type;
  1423. }
  1424. else if (_tcsicmp(name.c_str(), _T("HDCP_KEY")) == 0)
  1425. {
  1426. Global::g_AutoOnlineChassis.IsCopyKEY = true;
  1427. Global::g_AutoOnlineChassis.HDCPKeyType = type;
  1428. }
  1429. else if (_tcsicmp(name.c_str(), _T("CI_PLUS_KEY")) == 0)
  1430. {
  1431. Global::g_AutoOnlineChassis.IsCopyCikey = true;
  1432. Global::g_AutoOnlineChassis.CIKeyType = type;
  1433. }
  1434. else if (_tcsicmp(name.c_str(), _T("WiDi")) == 0)
  1435. {
  1436. Global::g_AutoOnlineChassis.IsCopyWiDi = true;
  1437. Global::g_AutoOnlineChassis.WiDiType = type;
  1438. }
  1439. else if (_tcsicmp(name.c_str(), _T("Widevine_KEY")) == 0)
  1440. {
  1441. Global::g_AutoOnlineChassis.IsCopyWidevine = true;
  1442. Global::g_AutoOnlineChassis.WidevineType = type;
  1443. }
  1444. else if (_tcsicmp(name.c_str(), _T("HDCP2.2_KEY")) == 0)
  1445. {
  1446. Global::g_AutoOnlineChassis.IsCopyKEY2_2 = true;
  1447. Global::g_AutoOnlineChassis.HDCPKey22Type = type;
  1448. }
  1449. else if (_tcsicmp(name.c_str(), _T("NETFILX_ESN")) == 0)
  1450. {
  1451. Global::g_AutoOnlineChassis.IsCopyESN = true;
  1452. Global::g_AutoOnlineChassis.ESNType = type;
  1453. }
  1454. }
  1455. }
  1456. if ( mid.projectid.size() != 0 )
  1457. {
  1458. Global::g_AutoOnlineChassis.IsWritePID = true;
  1459. }
  1460. LOG4C((LOG_NOTSET, "post success:post=%s;return=%s\n", context.c_str(), result.c_str()));
  1461. end:
  1462. // 释放Json;
  1463. if (pJsonText)
  1464. delete pJsonText;
  1465. pJsonText = NULL;
  1466. cJSON_Delete(pJson);
  1467. if ( mid.factoryname.size() )
  1468. UpgradeCheck(mid.factoryNum);
  1469. if (!bRet)
  1470. {
  1471. std::map<std::string, std::string> report_data;
  1472. report_data.insert(std::pair<std::string, std::string>("host", host));
  1473. report_data.insert(std::pair<std::string, std::string>("context", context));
  1474. report_data.insert(std::pair<std::string, std::string>("result", result));
  1475. g_db.InsertReportInfo("GetMIDInfo", report_data);
  1476. }
  1477. return bRet;
  1478. }
  1479. BOOL COTA::GetKeyInfo(std::string host, std::string context, std::string keyname, std::string valuename, std::string &value)
  1480. {
  1481. AUTOTIMING;
  1482. std::string result;
  1483. if (!HttpPost(host, context, result))
  1484. {
  1485. return FALSE;
  1486. }
  1487. // 无数据;
  1488. if (result.size() == 0)
  1489. {
  1490. LOG4C((LOG_ERROR, "(http=%s) No data return!", context.c_str()));
  1491. ShowMessage(_T("http No data return!\r"));
  1492. Global::WriteReportLog(0, __FUNCTION__, "http No data return: host=%s, content=%s, result=%s", host.c_str(), context.c_str(), result.c_str());
  1493. return FALSE;
  1494. }
  1495. // 解析xml;
  1496. tinyxml2::XMLDocument doc;
  1497. if (tinyxml2::XML_SUCCESS != doc.Parse(result.c_str()))
  1498. {
  1499. LOG4C((LOG_ERROR, "(http=%s) this post return xml invalid!", context.c_str()));
  1500. ShowMessage(_T("http return invalid xml data!\r"));
  1501. Global::WriteReportLog(0, __FUNCTION__, "http return invalid xml data: host=%s, content=%s, result=%s", host.c_str(), context.c_str(), result.c_str());
  1502. return FALSE;
  1503. }
  1504. std::string code;
  1505. std::string desc;
  1506. tinyxml2::XMLElement *pXmlRoot = NULL;
  1507. if ((pXmlRoot = doc.RootElement()) != NULL)
  1508. {
  1509. if (_tcsicmp(pXmlRoot->Value(), "response") == 0)
  1510. {
  1511. // 属性;
  1512. const tinyxml2::XMLAttribute *pAttr = pXmlRoot->FirstAttribute();
  1513. while (pAttr)
  1514. {
  1515. if (_tcsicmp(pAttr->Name(), "code") == 0)
  1516. {
  1517. code = pAttr->Value();
  1518. }
  1519. if (_tcsicmp(pAttr->Name(), "desc") == 0)
  1520. {
  1521. desc = pAttr->Value();
  1522. }
  1523. pAttr = pAttr->Next();
  1524. }
  1525. if (_tcsicmp(code.c_str(), "200") != 0)
  1526. {
  1527. LOG4C((LOG_ERROR, "(http=%s) Code is not equal to 200, desc=%s!", context.c_str(), desc.c_str()));
  1528. TCHAR szMsg[250] = { 0 };
  1529. _stprintf_s(szMsg, _T("http Code is not equal to 200, desc=%s\r"), desc.c_str());
  1530. ShowMessage(szMsg);
  1531. // 如果是上报接口,500表示成功;
  1532. if (host.rfind("/report.do?") != std::string::npos && _tcsicmp(code.c_str(), "500") == 0)
  1533. return TRUE;
  1534. Global::WriteReportLog(0, __FUNCTION__, "http Code is not equal to 200: host=%s, content=%s, result=%s", host.c_str(), context.c_str(), result.c_str());
  1535. return FALSE;
  1536. }
  1537. if (keyname.size() == 0 || valuename.size() == 0)
  1538. return TRUE;
  1539. // 子项;
  1540. std::string name; // std::string value;
  1541. tinyxml2::XMLElement *pXmlElent = pXmlRoot->FirstChildElement();
  1542. while (pXmlElent)
  1543. {
  1544. // 中文;
  1545. CharEncoding::UTF82ASCII(pXmlElent->Value(), name);
  1546. if (_tcsicmp(name.c_str(), keyname.c_str()) == 0)
  1547. {
  1548. pAttr = pXmlElent->FirstAttribute();
  1549. while (pAttr)
  1550. {
  1551. if (_tcsicmp(pAttr->Name(), valuename.c_str()) == 0)
  1552. {
  1553. value = pAttr->Value();
  1554. break;
  1555. }
  1556. pAttr = pAttr->Next();
  1557. }
  1558. break;
  1559. }
  1560. pXmlElent = pXmlElent->NextSiblingElement();
  1561. }
  1562. if (value.size() == 0)
  1563. {
  1564. LOG4C((LOG_ERROR, "(http=%s)xml value is empty!", context.c_str()));
  1565. ShowMessage(_T("http xml value is empty!\r"));
  1566. Global::WriteReportLog(0, __FUNCTION__, "http xml value is empty: host=%s, content=%s, result=%s", host.c_str(), context.c_str(), result.c_str());
  1567. return FALSE;
  1568. }
  1569. return TRUE;
  1570. }
  1571. }
  1572. return FALSE;
  1573. }
  1574. void COTA::UpgradeCheck(std::string factoryNum)
  1575. {
  1576. #if TEMP_5659
  1577. // 5659特别版,不升级;
  1578. return;
  1579. #endif
  1580. AUTOTIMING;
  1581. // 当前文件版本号、产品版本号;
  1582. WORD sFileVersion[4] = {0};
  1583. WORD sProductVerion[4] = {0};
  1584. Global::GetVersion(Global::g_szCurModulePath, sFileVersion, sProductVerion);
  1585. TCHAR szVersion[128] = {0};
  1586. _stprintf_s(szVersion, _T("%d.%d.%d.%d"), sFileVersion[0], sFileVersion[1], sFileVersion[2], sFileVersion[3]);
  1587. // Json数据;
  1588. cJSON *pJson = cJSON_CreateObject();
  1589. cJSON_AddStringToObject(pJson, "appid", "SCBC_Factory_Tools");
  1590. cJSON_AddStringToObject(pJson, "devicemodel", "SCBC_Factory_Tools");
  1591. cJSON_AddStringToObject(pJson, "dnum", factoryNum.c_str()); //工厂名;
  1592. cJSON_AddStringToObject(pJson, "ver", szVersion);
  1593. cJSON_AddStringToObject(pJson, "type", "pc");
  1594. char *pJsonText = cJSON_Print(pJson);
  1595. // post请求;
  1596. std::string strHttpUrl, strResHttp, strContext, strErrCode, strErrValue, strCount;
  1597. strContext = pJsonText;
  1598. // 正式上线地址;
  1599. strHttpUrl = _T("https://cn.ota.qhmoka.com/ota-services/upmp/upgradeInterfaceForPC");
  1600. HttpPost(strHttpUrl.c_str(), pJsonText, strResHttp, DATA_JSON);
  1601. // 释放Json;
  1602. if (pJsonText)
  1603. delete pJsonText;
  1604. pJsonText = NULL;
  1605. cJSON_Delete(pJson);
  1606. pJson = NULL;
  1607. if (strResHttp.size() == 0)
  1608. {
  1609. LOG4C((LOG_WARN, "返回结果空:post=%s;return=%s", strContext.c_str(), strResHttp.c_str()));
  1610. Global::WriteReportLog(0, __FUNCTION__, "http No data return: host=%s, content=%s, result=%s", strHttpUrl.c_str(), strContext.c_str(), strResHttp.c_str());
  1611. ReportUpgrade(FALSE, szVersion, factoryNum);
  1612. return;
  1613. }
  1614. // 将json结果转换成结构体;
  1615. Global::__update_result__ upresult;
  1616. pJson = cJSON_Parse(strResHttp.c_str());
  1617. if (pJson == NULL)
  1618. {
  1619. cJSON_Delete(pJson);
  1620. LOG4C((LOG_WARN, "cJSON解析时出错:post=%s;return=%s", strContext.c_str(), strResHttp.c_str()));
  1621. Global::WriteReportLog(0, __FUNCTION__, "JSON Parsing Error: host=%s, content=%s, result=%s", strHttpUrl.c_str(), strContext.c_str(), strResHttp.c_str());
  1622. ReportUpgrade(FALSE, szVersion, factoryNum);
  1623. return;
  1624. }
  1625. upresult.servertime = cJSON_GetObjectItem(pJson, "servertime") ? cJSON_GetObjectItem(pJson, "servertime")->valuestring : "";
  1626. upresult.callid = cJSON_GetObjectItem(pJson, "callid") ? cJSON_GetObjectItem(pJson, "callid")->valuestring : "";
  1627. upresult.note = cJSON_GetObjectItem(pJson, "note") ? cJSON_GetObjectItem(pJson, "note")->valuestring : "";
  1628. upresult.status = cJSON_GetObjectItem(pJson, "state") ? cJSON_GetObjectItem(pJson, "state")->valuestring : "";
  1629. upresult.language = cJSON_GetObjectItem(pJson, "language") ? cJSON_GetObjectItem(pJson, "language")->valuestring : "";
  1630. upresult.apiversion = cJSON_GetObjectItem(pJson, "apiversion") ? cJSON_GetObjectItem(pJson, "apiversion")->valuestring : "";
  1631. cJSON *pUpdate = cJSON_GetObjectItem(pJson, "upgrade");
  1632. if (pUpdate == NULL)
  1633. {
  1634. cJSON_Delete(pJson);
  1635. LOG4C((LOG_WARN, "升级接口没有升级内容:post=%s;return=%s", strContext.c_str(), strResHttp.c_str()));
  1636. Global::WriteReportLog(0, __FUNCTION__, "Upgrade interface has no upgrade content: host = %s, content = %s, result = %s", strHttpUrl.c_str(), strContext.c_str(), strResHttp.c_str());
  1637. //ReportUpdateResult(FALSE, strVer);
  1638. return;
  1639. }
  1640. upresult.upcontent.now = cJSON_GetObjectItem(pUpdate, "now") ? cJSON_GetObjectItem(pUpdate, "now")->valuestring : "";
  1641. upresult.upcontent.type = cJSON_GetObjectItem(pUpdate, "type") ? cJSON_GetObjectItem(pUpdate, "type")->valuestring : "";
  1642. upresult.upcontent.appid = cJSON_GetObjectItem(pUpdate, "appid") ? cJSON_GetObjectItem(pUpdate, "appid")->valuestring : "";
  1643. upresult.upcontent.apptype = cJSON_GetObjectItem(pUpdate, "apptype") ? cJSON_GetObjectItem(pUpdate, "apptype")->valuestring : "";
  1644. upresult.upcontent.version = cJSON_GetObjectItem(pUpdate, "version") ? cJSON_GetObjectItem(pUpdate, "version")->valuestring : "";
  1645. upresult.upcontent.verid = cJSON_GetObjectItem(pUpdate, "verid") ? cJSON_GetObjectItem(pUpdate, "verid")->valuestring : "";
  1646. upresult.upcontent.md5 = cJSON_GetObjectItem(pUpdate, "md5") ? cJSON_GetObjectItem(pUpdate, "md5")->valuestring : "";
  1647. upresult.upcontent.size = cJSON_GetObjectItem(pUpdate, "size") ? cJSON_GetObjectItem(pUpdate, "size")->valuestring : "";
  1648. upresult.upcontent.minicon = cJSON_GetObjectItem(pUpdate, "minicon") ? cJSON_GetObjectItem(pUpdate, "minicon")->valuestring : "";
  1649. upresult.upcontent.midicon = cJSON_GetObjectItem(pUpdate, "midicon") ? cJSON_GetObjectItem(pUpdate, "midicon")->valuestring : "";
  1650. upresult.upcontent.fileurl = cJSON_GetObjectItem(pUpdate, "fileurl") ? cJSON_GetObjectItem(pUpdate, "fileurl")->valuestring : "";
  1651. upresult.upcontent.increment = cJSON_GetObjectItem(pUpdate, "increment") ? cJSON_GetObjectItem(pUpdate, "increment")->valuestring : "";
  1652. upresult.upcontent.appendver = cJSON_GetObjectItem(pUpdate, "appendver") ? cJSON_GetObjectItem(pUpdate, "appendver")->valuestring : "";
  1653. upresult.upcontent.updatetime = cJSON_GetObjectItem(pUpdate, "updatetime") ? cJSON_GetObjectItem(pUpdate, "updatetime")->valuestring : "";
  1654. // 释放cJSON资源;
  1655. cJSON_Delete(pJson);
  1656. pJson = NULL;
  1657. if (upresult.status.compare("0000") != 0)
  1658. {
  1659. LOG4C((LOG_WARN, "升级接口http返回出错:post=%s;return=%s", strContext.c_str(), strResHttp.c_str()));
  1660. Global::WriteReportLog(0, __FUNCTION__, "Error upgrading interface: host = %s, content = %s, result = %s", strHttpUrl.c_str(), strContext.c_str(), strResHttp.c_str());
  1661. ReportUpgrade(FALSE, szVersion, factoryNum);
  1662. return;
  1663. }
  1664. // 下载文件;
  1665. TCHAR szNewPath[MAX_PATH] = {0};
  1666. _stprintf_s(szNewPath, _T("%s%s.exe"), Global::g_szCurModuleDir, upresult.upcontent.version.c_str());
  1667. if (_tcsicmp(szVersion , upresult.upcontent.version.c_str()) > 0 )
  1668. {
  1669. LOG4C((LOG_NOTICE, "当前版本(%s)比服务器版本(%s)新", szVersion, upresult.upcontent.version.c_str()));
  1670. Global::WriteReportLog(0, __FUNCTION__, "The current version (%s) is newer than the server version (%s).", szVersion, upresult.upcontent.version.c_str());
  1671. return;
  1672. }
  1673. if (MessageBox(NULL, _T("found out lastest software version, you have to update."), _T("Tips"), MB_YESNO | MB_TOPMOST | MB_ICONINFORMATION) == IDNO)
  1674. return;
  1675. // 保存成文件;
  1676. if (!DownloadFile(upresult.upcontent.fileurl, szNewPath))
  1677. {
  1678. LOG4C((LOG_NOTICE, "下载升级文件失败"));
  1679. MessageBox(NULL, _T("Download failure."), _T("Tips"), MB_OK | MB_TOPMOST | MB_ICONINFORMATION);
  1680. ReportUpgrade(FALSE, szVersion, factoryNum);
  1681. Global::WriteReportLog(0, __FUNCTION__, "Failed to download upgrade file=%s", upresult.upcontent.fileurl.c_str());
  1682. return;
  1683. }
  1684. else
  1685. {
  1686. ReportUpgrade(TRUE, szVersion, factoryNum);
  1687. }
  1688. Sleep(500);
  1689. MessageBox(NULL, _T("Complete the download, you need restart apps."), _T("Tips"), MB_OK | MB_TOPMOST | MB_ICONINFORMATION);
  1690. // 启动程序;
  1691. ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); //某些情况下要初始化COM才能使用ShellExecuteEx;
  1692. SHELLEXECUTEINFO stuExecInfo = {0};
  1693. CString strParamters;
  1694. strParamters.Format(_T("--pid %ld --oldpath \"%s\" --newpath \"%s\" --killproc 1"), GetCurrentProcessId(), Global::g_szCurModulePath, szNewPath);
  1695. //strParamters.Format(_T("--pid %ld --oldpath \"%s\" --newpath \"%s\" --killproc 0"), GetCurrentProcessId(), g_szCurModulePath, szNewPath);
  1696. stuExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
  1697. stuExecInfo.lpFile = _T("rename.exe");
  1698. stuExecInfo.nShow = SW_HIDE;
  1699. stuExecInfo.lpParameters = strParamters;
  1700. stuExecInfo.lpVerb = _T("open");
  1701. stuExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
  1702. if (!ShellExecuteEx(&stuExecInfo))
  1703. {
  1704. DWORD dwError = GetLastError();
  1705. LOG4C((LOG_ERROR, "执行rename程序失败,错误码=%d", dwError));
  1706. MessageBox(NULL, _T("Upgrade failure."), _T("Tips"), MB_OK | MB_TOPMOST | MB_ICONINFORMATION);
  1707. Global::WriteReportLog(0, __FUNCTION__, "Upgrade failed, Error=%d", dwError);
  1708. return;
  1709. }
  1710. HANDLE hProcess = stuExecInfo.hProcess;
  1711. if (hProcess != NULL)
  1712. CloseHandle(hProcess);
  1713. else
  1714. {
  1715. LOG4C((LOG_WARN, "执行rename程序失败,进程句柄空"));
  1716. Global::WriteReportLog(0, __FUNCTION__, "Upgrade failed, Process handle empty");
  1717. }
  1718. // 提示升级程序执行;
  1719. LOG4C((LOG_NOTICE, "后台升级程序执行成功,程序退出后自动覆盖文件"));
  1720. }
  1721. void COTA::ReportUpgrade(BOOL bUpgrade, std::string ver, std::string num)
  1722. {
  1723. AUTOTIMING;
  1724. // Json数据;
  1725. cJSON *pJson = cJSON_CreateObject();
  1726. cJSON_AddStringToObject(pJson, "appid", "SCBC_Factory_Tools");
  1727. cJSON_AddStringToObject(pJson, "devmodel", "SCBC_Factory_Tools");
  1728. cJSON_AddStringToObject(pJson, "dnum", num.c_str());
  1729. cJSON_AddStringToObject(pJson, "ver", ver.c_str());
  1730. cJSON_AddStringToObject(pJson, "result", bUpgrade ? "Success" : "FAILURE");
  1731. cJSON_AddStringToObject(pJson, "type", "pc");
  1732. char *pJsonText = cJSON_Print(pJson);
  1733. // post请求;
  1734. std::string strHttpUrl, strResHttp, strContext, strErrCode, strErrValue, strCount;
  1735. strContext = pJsonText;
  1736. strHttpUrl = _T("https://cn.ota.qhmoka.com/ota-services/upmp/operateInterfaceForPC");
  1737. HttpPost(strHttpUrl.c_str(), strContext.c_str(), strResHttp, DATA_JSON);
  1738. // 释放Json;
  1739. if (pJsonText)
  1740. delete pJsonText;
  1741. pJsonText = NULL;
  1742. cJSON_Delete(pJson);
  1743. pJson = NULL;
  1744. pJson = cJSON_Parse(strResHttp.c_str());
  1745. if (pJson == NULL)
  1746. {
  1747. LOG4C((LOG_WARN, "解析JSON失败:post=%s;return=%s", strContext.c_str(), strResHttp.c_str()));
  1748. Global::WriteReportLog(0, __FUNCTION__, "JSON Parsing Error: host=%s, content=%s, result=%s", strHttpUrl.c_str(), strContext.c_str(), strResHttp.c_str());
  1749. return;
  1750. }
  1751. std::string result = cJSON_GetObjectItem(pJson, "state") ? cJSON_GetObjectItem(pJson, "state")->valuestring : "";
  1752. cJSON_Delete(pJson);
  1753. pJson = NULL;
  1754. }
  1755. BOOL COTA::DownloadFile(std::string url, std::string savePath)
  1756. {
  1757. AUTOTIMING;
  1758. std::string result;
  1759. if (HttpGet(url, "", result))
  1760. {
  1761. FILE* pf = nullptr;
  1762. if (fopen_s(&pf, savePath.c_str(), "wb") == 0 )
  1763. {
  1764. if ( pf )
  1765. {
  1766. fwrite(result.data(), result.size(), 1, pf);
  1767. fclose(pf);
  1768. return TRUE;
  1769. }
  1770. }
  1771. }
  1772. Global::WriteReportLog(0, __FUNCTION__, "Failed to download file: host = %s", url.c_str());
  1773. return FALSE;
  1774. }
  1775. BOOL COTA::ReportLog(TReportData& repdata)
  1776. {
  1777. AUTOTIMING;
  1778. // Json数据;
  1779. cJSON* pJson = cJSON_CreateObject();
  1780. cJSON_AddStringToObject(pJson, "reportType", repdata.report_type.c_str());
  1781. cJSON *pObj = cJSON_AddObjectToObject(pJson, _T("reportData"));
  1782. for ( auto it : repdata.report_data)
  1783. {
  1784. cJSON_AddStringToObject(pObj, it.first.c_str(), it.second.c_str());
  1785. }
  1786. char* pJsonText = cJSON_Print(pJson);
  1787. // post请求;
  1788. std::string strHttpUrl, strResHttp, strContext;
  1789. strContext = pJsonText;
  1790. strHttpUrl = _T("https://cn.ota.qhmoka.com/ota-services/report/reportToolsLog");
  1791. HttpPost(strHttpUrl.c_str(), strContext.c_str(), strResHttp, DATA_JSON);
  1792. // 释放Json;
  1793. if (pJsonText)
  1794. delete pJsonText;
  1795. pJsonText = NULL;
  1796. cJSON_Delete(pJson);
  1797. pJson = NULL;
  1798. pJson = cJSON_Parse(strResHttp.c_str());
  1799. if (pJson == NULL)
  1800. {
  1801. LOG4C((LOG_WARN, "解析JSON失败:post=%s;return=%s", strContext.c_str(), strResHttp.c_str()));
  1802. Global::WriteReportLog(0, __FUNCTION__, "JSON Parsing Error: host=%s, content=%s, result=%s", strHttpUrl.c_str(), strContext.c_str(), strResHttp.c_str());
  1803. return FALSE;
  1804. }
  1805. std::string result = cJSON_GetObjectItem(pJson, "code") ? cJSON_GetObjectItem(pJson, "code")->valuestring : "";
  1806. cJSON_Delete(pJson);
  1807. pJson = NULL;
  1808. if ( _tcsicmp(result.c_str(), _T("200")) == 0 )
  1809. {
  1810. return TRUE;
  1811. }
  1812. Global::WriteReportLog(0, __FUNCTION__, "http Code is not equal to 200: host=%s, content=%s, result=%s", strHttpUrl.c_str(), strContext.c_str(), strResHttp.c_str());
  1813. return FALSE;
  1814. }
  1815. BOOL COTA::ReportLog(std::string url, std::string content)
  1816. {
  1817. AUTOTIMING;
  1818. // post请求;
  1819. std::string result;
  1820. if (!HttpPost(url, content, result, DATA_JSON))
  1821. return FALSE;
  1822. // 释放Json;
  1823. cJSON *pJson = cJSON_Parse(result.c_str());
  1824. if (pJson == NULL)
  1825. {
  1826. LOG4C((LOG_WARN, "解析JSON失败:post=%s;return=%s", content.c_str(), result.c_str()));
  1827. //Global::WriteReportLog(0, __FUNCTION__, "JSON Parsing Error: host=%s, content=%s, result=%s", url.c_str(), content.c_str(), result.c_str());
  1828. return FALSE;
  1829. }
  1830. std::string code = cJSON_GetObjectItem(pJson, "code") ? cJSON_GetObjectItem(pJson, "code")->valuestring : "";
  1831. cJSON_Delete(pJson);
  1832. pJson = NULL;
  1833. if (_tcsicmp(code.c_str(), _T("1000")) == 0)
  1834. {
  1835. return TRUE;
  1836. }
  1837. //Global::WriteReportLog(0, __FUNCTION__, "http Code is not equal to 1000: host=%s, content=%s, result=%s", url.c_str(), content.c_str(), result.c_str());
  1838. return FALSE;
  1839. }
  1840. BOOL COTA::GetVCode(std::string mac, std::string& vcode)
  1841. {
  1842. std::string result;
  1843. std::string host = _T("http://test.admin.ota.qhmoka.com/IDManage/export/getvcode.do?");
  1844. std::string context = _T("macAddress=");
  1845. context.append(mac);
  1846. if (!HttpPost(host, context, result))
  1847. return FALSE;
  1848. // 无数据;
  1849. if (result.size() == 0)
  1850. {
  1851. LOG4C((LOG_ERROR, "(http=%s) No data return!", context.c_str()));
  1852. return FALSE;
  1853. }
  1854. // 解析xml;
  1855. tinyxml2::XMLDocument doc;
  1856. if (tinyxml2::XML_SUCCESS != doc.Parse(result.c_str()))
  1857. {
  1858. LOG4C((LOG_ERROR, "(http=%s) this post return xml invalid!", context.c_str()));
  1859. return FALSE;
  1860. }
  1861. }