{"id":1328,"date":"2020-04-14T21:59:51","date_gmt":"2020-04-14T13:59:51","guid":{"rendered":"https:\/\/www.jarvisw.com\/?p=1328"},"modified":"2020-04-14T22:25:12","modified_gmt":"2020-04-14T14:25:12","slug":"%e5%a4%a7%e7%96%86dji-robomaster-s1%e6%9c%ba%e5%99%a8%e4%ba%ba%e9%80%9a%e8%bf%874g%e7%bd%91%e7%bb%9c%e8%bf%9c%e7%a8%8b%e6%8e%a7%e5%88%b6%e7%9a%84%e6%96%b9%e6%b3%95%ef%bc%88%e6%97%a0%e9%9c%80%e6%94%b9","status":"publish","type":"post","link":"https:\/\/www.jarvisw.com\/?p=1328","title":{"rendered":"\u5927\u7586DJI Robomaster S1\u673a\u5668\u4eba\u901a\u8fc74G\u7f51\u7edc\u8fdc\u7a0b\u63a7\u5236\u7684\u65b9\u6cd5\uff08\u65e0\u9700\u6539\u786c\u4ef6\uff09"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/timgsa.baidu.com\/timg?image&amp;quality=80&amp;size=b9999_10000&amp;sec=1586880366612&amp;di=816c7ed84ae97ed2610ff1618f4124b2&amp;imgtype=0&amp;src=http%3A%2F%2Fwww.watchstore.com.cn%2Fdata%2Fattachment%2Fforum%2F201906%2F13%2F145641pnpsa5qsaq5c2vxf.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u3000\u3000\u53bb\u5e74\u4e70\u4e86\u4e00\u53f0Robomaster S1\u673a\u5668\u4eba\uff0c\u7ec4\u88c5\u5b8c\u6210\u4e4b\u540e\u73a9\u4e86\u4e00\u4f1a\u89c9\u5f97\u53ea\u80fd\u5728\u8def\u7531\u5668\u7684\u65e0\u7ebf\u4fe1\u53f7\u8ddd\u79bb\u91cc\u9762\u73a9\u7565\u6709\u70b9\u5c40\u9650\u6027\uff0c\u6709\u4e9b\u4e4f\u5473\u4e86\uff0c\u5c31\u5728\u60f3\u80fd\u4e0d\u80fd\u6539\u62104G\u8fdc\u7a0b\u63a7\u5236\u673a\u5668\u4eba\u5462\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u5f00\u51fa\u53bb\u4e70\u4e2a\u83dc\u5565\u7684\uff1f\u6216\u8005\u5728\u5916\u9762\u63a7\u5236\u5bb6\u91cc\u7684\u673a\u5668\u4eba\uff1f<\/p>\n\n\n\n<p>\u3000\u3000\u7f51\u4e0a\u53c2\u8003\u4e86\u4e00\u4e9b\u5927\u7586\u534f\u8bae\u7684\u8d44\u6599\uff0c\u6709hack  CAN\u603b\u7ebf\u76f8\u5173\u7684\u65b9\u6cd5\u5b9e\u73b0\u81ea\u5b9a\u4e49\u63a7\u5236\u7684\uff0c\u8fd9\u79cd\u65b9\u6cd5\u7684\u597d\u5904\u5c31\u662f\u53ef\u4ee5\u8131\u79bb\u624b\u673aapp\uff0c\u800c\u4e14\u53ef\u4ee5\u5b9e\u73b0\u5b8c\u5168\u63a7\u5236\u673a\u5668\u4eba\u7684\u4efb\u4f55\u4e00\u4e2a\u90e8\u4ef6\u3002\u4f46\u8fd9\u5e76\u4e0d\u662f\u6211\u6700\u60f3\u8fbe\u5230\u7684\u6548\u679c\u3002\u6211\u5e0c\u671b\u6539\u88c5\u5b8c\u6210\u540e\u7684\u6548\u679c\u662f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u673a\u5668\u4eba\u53ef\u4ee5\u901a\u8fc74G\u7f51\u7edc\u88ab\u8fdc\u7a0b\u63a7\u5236\u3002<\/li><li>\u65e0\u9700\u5bf9\u673a\u5668\u4eba\u7684\u786c\u4ef6\u505a\u4fee\u6539\u3002<\/li><li>\u63a7\u5236\u7aef\u4ecd\u7136\u53ef\u4ee5\u4f7f\u7528\u5927\u7586\u5b98\u65b9\u7684Robomaster App\u6765\u63a7\u5236\uff0c\u800c\u65e0\u9700\u81ea\u5df1\u5bf9\u63a7\u5236\u534f\u8bae\u8fdb\u884c\u9006\u5411\u5de5\u7a0b\u4ee5\u540e\u518d\u91cd\u5199\u4e00\u4e2a\u63a7\u5236\u754c\u9762\u3002<\/li><\/ol>\n\n\n\n<p>\u3000\u3000\u660e\u786e\u4e86\u6548\u679c\u4ee5\u540e\uff0c\u90a3\u4e48\u9996\u5148\u6765\u770b\u770b\u5927\u7586\u7684App\u662f\u5982\u4f55\u63a7\u5236\u673a\u5668\u4eba\u7684\u5427\uff0c\u6700\u5f00\u59cb\u5b9e\u9a8c\u7684\u65f6\u5019\uff0c\u6211\u5728PC\u4e0a\u865a\u62df\u4e86\u4e00\u4e2a\u65e0\u7ebf\u70ed\u70b9\uff0c\u7136\u540e\u5728\u8fd9\u4e2a\u65e0\u7ebf\u70ed\u70b9\u4e0a\u6293\u5305\uff0c\u770b\u770bApp\u548c\u673a\u5668\u4eba\u4e4b\u95f4\u7684\u6d41\u91cf\uff0c\u540e\u6765\u53d1\u73b0\u4ec0\u4e48\u90fd\u6ca1\u6293\u5230\u3002\u7591\u60d1\u4e86\u5f88\u4e45\uff0c\u540e\u6765\u624d\u9192\u609f\uff0c\u540c\u4e00\u4e2aWLAN\u5c40\u57df\u7f51\u4e0b\u4e24\u4e2aSTA\u4e4b\u95f4\u7684\u901a\u4fe1\u662f\u76f4\u63a5\u901a\u8fc7AP\u4e2d\u7ee7\u8f6c\u53d1\u4e86\uff0c\u800c\u4e0d\u4f1a\u88ab\u8f6c\u53d1\u5230\u4ea4\u6362\u673a\u4e0a\u3002\u6240\u4ee5\u6362\u4e86\u4e00\u4e2a\u53ef\u4ee5\u6293802.11\u6570\u636e\u5305\u7684macbook\u76f4\u63a5\u6293\u65e0\u7ebf\u6d41\u91cf\uff0c\u7136\u540e\u89e3\u5bc6802.11\u6570\u636e\u5305\uff0c\u6700\u540e\u624d\u6293\u5230\u4e86\u901a\u4fe1\u7684\u6d41\u91cf\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"986\" src=\"https:\/\/www.jarvisw.com\/wp-content\/uploads\/2020\/04\/image-1024x986.png\" alt=\"\" class=\"wp-image-1329\" srcset=\"https:\/\/www.jarvisw.com\/wp-content\/uploads\/2020\/04\/image-1024x986.png 1024w, https:\/\/www.jarvisw.com\/wp-content\/uploads\/2020\/04\/image-300x289.png 300w, https:\/\/www.jarvisw.com\/wp-content\/uploads\/2020\/04\/image-768x739.png 768w, https:\/\/www.jarvisw.com\/wp-content\/uploads\/2020\/04\/image.png 1371w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u5982\u4e0a\u56fe\uff0c\u901a\u8fc7\u89c2\u5bdf\u53ef\u4ee5\u53d1\u73b0\uff0c\u534f\u8bae\u5176\u5b9e\u6bd4\u8f83\u7b80\u5355\uff0c\u673a\u5668\u4eba\u5728\u8fde\u5165\u7f51\u7edc\u4e4b\u540e\uff0c\u4f1a\u752856789\u7aef\u53e3\u5411.255\u5e7f\u64ad\u5730\u5740\u768445678\u7aef\u53e3\u53d1\u9001\u4e00\u4e2a24\u4e2a\u5b57\u8282\u7684UDP\u5e7f\u64ad\u5305\uff0c\u63a8\u6d4b\u662f\u7528\u6765\u544a\u77e5\u673a\u5668\u4eba\u7684\u4e00\u4e9b\u4fe1\u606f\u7684\uff0c\u624b\u673aApp\u5c31\u662f\u901a\u8fc7\u8fd9\u4e2a\u5730\u5740\u6765\u63a2\u6d4b\u5c40\u57df\u7f51\u4e2d\u7684\u673a\u5668\u4eba\uff0c\u7136\u540e\u5f53\u624b\u673aApp\u63a2\u6d4b\u5230\u673a\u5668\u4eba\u7684\u5b58\u5728\u540e\uff0c\u5c31\u4f1a\u901a\u8fc7UDP\u534f\u8bae\u548c\u673a\u5668\u4eba\u768410607\u7aef\u53e3\u901a\u4fe1\u3002\u901a\u8fc7\u89c2\u5bdf\u8fd8\u53ef\u4ee5\u53d1\u73b0\uff0c\u56fe\u4f20\u4f3c\u4e4e\u4e5f\u662f\u901a\u8fc7\u8fd9\u4e2a\u7aef\u53e3\u5b9e\u73b0\u7684\u3002\u5b9e\u73b0\u5e76\u4e0d\u590d\u6742\uff0c\u6240\u4ee5\u5176\u5b9e\u6709\u4e2a\u6700\u7b80\u5355\u7684\u601d\u8def\u90a3\u5c31\u662f\u6211\u4e0d\u9700\u8981\u77e5\u9053\u534f\u8bae\u7684\u5177\u4f53\u7ec6\u8282\uff0c\u6211\u53ea\u9700\u8981\u505a\u4e00\u4e2aUDP\u4e2d\u7ee7\u5c31\u597d\u4e86\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u601d\u8def\u5f88\u7b80\u5355\uff0c\u8fd9\u4e2aUDP\u4e2d\u7ee7\u7684\u5b9e\u73b0\u5927\u6982\u5206\u4e3a\u4e09\u90e8\u5206\uff1a<\/p>\n\n\n\n<p><strong>\u673a\u5668\u4eba\u90e8\u5206\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u673a\u5668\u4eba\u9700\u8981\u8fde\u63a5\u5230\u4e00\u4e2a4G\u8def\u7531\u5668\uff0c\u540c\u65f6\u6700\u597d\u8fd9\u4e2a4G\u8def\u7531\u5668\u80fd\u591f\u7f16\u7a0b\uff08\u6bd4\u5982Openwrt\u64cd\u4f5c\u7cfb\u7edf\u53ef\u4ee5\u81ea\u5df1\u7f16\u8bd1\u4ee3\u7801\u8fdb\u53bb\uff09<\/li><li>4G\u8def\u7531\u5668\u65e2\u4f5c\u4e3a\u8bbf\u95ee\u516c\u7f51\u7684\u7f51\u5173\uff0c\u672c\u8eab\u4f5c\u4e3a\u4e00\u4e2a\u4f2a\u624b\u673a\u7ec8\u7aef\uff0c\u76d1\u542c\u5230\u673a\u5668\u4eba\u53d1\u9001\u7684\u6570\u636e\u5305\u540e\uff0c\u6253\u5305\u53d1\u9001\u7ed9\u4e91\u7aef\u7684\u670d\u52a1\u5668\u3002<\/li><li>\u63a5\u6536\u4e91\u7aef\u670d\u52a1\u5668\u53d1\u9001\u7684\u6765\u81ea\u771f\u5b9e\u624b\u673a\u7684\u63a7\u5236\u6307\u4ee4\uff0c\u7136\u540e\u4ee5\u81ea\u5df1\u7684\u8eab\u4efd\u53d1\u9001\u7ed9\u673a\u5668\u4eba\u3002<\/li><\/ol>\n\n\n\n<p><strong>\u4e91\u7aef\u90e8\u5206\uff1a<\/strong><\/p>\n\n\n\n<p> \u3000\u3000\u4e91\u7aef\u90e8\u5206\u5c31\u6bd4\u8f83\u7b80\u5355\u4e86\uff0c\u53ea\u9700\u8981\u5f00\u542f\u4e00\u4e2aTCP Server\uff08\u6ce8\u610f\uff0c\u7531\u4e8e\u516c\u7f51\u6709\u53ef\u80fd\u4e22\u5305\uff0c\u6240\u4ee5\u6211\u8fd9\u91cc\u9009\u62e9\u4e86\u7528TCP\u534f\u8bae\u6765\u8f6c\u53d1\uff09\uff0c\u7136\u540e\u5206\u522b\u63a5\u53d7\u6765\u81ea\u4e8e\u4f2a\u624b\u673a\u548c\u4f2a\u673a\u5668\u4eba\u53d1\u6765\u7684\u6d41\u91cf\uff0c\u8f6c\u53d1\u7ed9\u5bf9\u4fa7\uff0c\u5b8c\u6210\u4e2d\u7ee7\u3002<\/p>\n\n\n\n<p><strong>\u624b\u673aApp\u90e8\u5206\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u624b\u673aApp\u90e8\u5206\u81ea\u7531\u5ea6\u5c31\u6bd4\u8f83\u9ad8\u4e86\uff0c\u53ea\u9700\u8981\u6709WiFi\u53ef\u4ee5\u4e0a\u7f51\u5373\u53ef\uff0c\u5728\u8fd9\u4e2aWiFi\u7f51\u7edc\u91cc\u9700\u8981\u7528\u53e6\u4e00\u53f0PC\uff08\u5176\u5b9e\u7528\u8def\u7531\u5668\u672c\u8eab\u4e5f\u53ef\u4ee5\uff0c\u4f46\u662f\u7528\u53e6\u4e00\u53f0PC\u66f4\u65b9\u4fbf\uff09\u865a\u62df\u4e00\u4e2a\u4f2a\u673a\u5668\u4eba\u3002<\/li><li>\u4f2a\u673a\u5668\u4eba\u5c06\u4e91\u7aef\u8f6c\u53d1\u7684\u673a\u5668\u4eba\u53d1\u9001\u7684\u6d41\u91cf\u4ee5\u81ea\u5df1\u7684\u8eab\u4efd\u53d1\u9001\u7ed9\u624b\u673aApp\u3002<\/li><li>\u540c\u65f6\uff0c\u4f2a\u673a\u5668\u4eba\u63a5\u6536\u624b\u673a\u53d1\u9001\u8fc7\u6765\u7684\u63a7\u5236\u6307\u4ee4\uff0c\u6253\u5305\u8f6c\u53d1\u7ed9\u4e91\u7aef\uff0c\u7531\u4e91\u7aef\u8f6c\u53d1\u7ed9\u771f\u5b9e\u7684\u673a\u5668\u4eba\uff0c\u5b8c\u6210\u63a7\u5236\u3002<\/li><\/ol>\n\n\n\n<p>\u3000\u3000\u601d\u8def\u660e\u786e\u4e86\u4e4b\u540e\uff0c\u90a3\u4e48\u63a5\u4e0b\u6765\u4ee3\u7801\u5176\u5b9e\u4e0d\u96be\u5199\uff0c\u4e0d\u8fc7\u673a\u5668\u4eba\u8fd9\u8fb9\u7684\u8bdd\uff0c\u7406\u8bba\u4e0a\u6765\u8bf4\u6700\u65b9\u4fbf\u7684\u65b9\u6cd5\u5c31\u662f\u7528\u53e6\u4e00\u4e2a\u72ec\u7acb\u7684\u7ec8\u7aef\u6765\u6a21\u62df\u4f2a\u624b\u673a\uff0c\u4f46\u662f\u53d7\u9650\u4e8e\u673a\u5668\u4eba\u7684\u88c5\u8f7d\u80fd\u529b\uff0c\u6240\u4ee5\u6700\u4f73\u65b9\u6848\u8fd8\u662f\u628a4G\u8def\u7531\u5668\u548c\u6a21\u62df\u624b\u673aApp\u7684\u529f\u80fd\u5408\u4e8c\u4e3a\u4e00\u3002\u90a3\u4e48\u5982\u4f55\u6bd4\u8f83\u65b9\u4fbf\u7684\u5b8c\u6210\u8fd9\u6837\u7684\u5de5\u4f5c\u5462\uff0c\u8fd9\u91cc\u7ed9\u5927\u5bb6\u63a8\u8350\u4e00\u4e2a\u4ea7\u54c1\uff1a<\/p>\n\n\n\n<p>gl.inet\u6709\u4e00\u6b3e4G\u8def\u7531\u5668\uff0c\u91cc\u9762\u662fopenwrt\u7cfb\u7edf\uff0c\u53ef\u4ee5\u81ea\u5df1\u7f16\u8bd1\u56fa\u4ef6\uff0c\u8fd9\u6837\u5c31\u6bd4\u8f83\u65b9\u4fbf\u5f00\u53d1\u4e86\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"877\" height=\"899\" src=\"https:\/\/www.jarvisw.com\/wp-content\/uploads\/2020\/04\/image-1.png\" alt=\"\" class=\"wp-image-1330\" srcset=\"https:\/\/www.jarvisw.com\/wp-content\/uploads\/2020\/04\/image-1.png 877w, https:\/\/www.jarvisw.com\/wp-content\/uploads\/2020\/04\/image-1-293x300.png 293w, https:\/\/www.jarvisw.com\/wp-content\/uploads\/2020\/04\/image-1-768x787.png 768w\" sizes=\"auto, (max-width: 877px) 100vw, 877px\" \/><\/figure>\n\n\n\n<p>\u3000\u3000\u5927\u5c0f\u5c3a\u5bf8\u4e5f\u8fd8\u5408\u9002\uff0c\u7eed\u822a\u4e5f\u53ef\u4ee5\uff0c\u7ed1\u5728\u673a\u5668\u4eba\u7684\u9876\u90e8\u6b63\u597d\uff0c\u800c\u4e14\u81ea\u5e26\u7535\u6c60\u4f9b\u7535\uff0c\u8fd8\u662f\u6bd4\u8f83\u5b8c\u7f8e\u7684\u3002\u6240\u4ee5\u5c31\u7528\u4ed6\u4e86\u3002<\/p>\n\n\n\n<p>\u6700\u7ec8\uff0c\u6574\u4e2a\u67b6\u6784\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.jarvisw.com\/wp-content\/uploads\/2020\/04\/image-3-1024x300.png\" alt=\"\" class=\"wp-image-1332\" srcset=\"https:\/\/www.jarvisw.com\/wp-content\/uploads\/2020\/04\/image-3-1024x300.png 1024w, https:\/\/www.jarvisw.com\/wp-content\/uploads\/2020\/04\/image-3-300x88.png 300w, https:\/\/www.jarvisw.com\/wp-content\/uploads\/2020\/04\/image-3-768x225.png 768w, https:\/\/www.jarvisw.com\/wp-content\/uploads\/2020\/04\/image-3.png 1450w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>\u4ee3\u7801\u5b9e\u73b0<\/strong><\/p>\n\n\n\n<p>\u3000\u3000\u6700\u7ec8\u5b9e\u73b0\u7684\u4ee3\u7801\u5176\u5b9e\u6bd4\u8f83\u7b80\u5355\uff0c\u6211\u8fd9\u91cc\u4e3a\u4e86\u65b9\u4fbf\uff0c\u4f7f\u7528\u4e86Tornado\u6846\u67b6\u6765\u7ba1\u7406TCP\u548cUDP\u8fde\u63a5\u3002\u4f46\u662f\u5b8c\u6210\u540e\u5b9e\u9645\u8c03\u8bd5\u7684\u65f6\u5019\u53d1\u73b0\u4e00\u4e2a\u95ee\u9898\uff0c\u90a3\u5c31\u662f\u8f6c\u53d1\u7684\u5e7f\u64ad\u5305\u6700\u7ec8\u4e0d\u80fd\u88abApp\u6b63\u5e38\u8bc6\u522b\uff0c\u4e5f\u5c31\u662f\u8bf4\u4f2a\u9020\u6210\u673a\u5668\u4eba\u5728\u53e6\u4e00\u4e2a\u7f51\u7edc\u4e2d\u53d1\u9001\u7531\u771f\u5b9e\u7684\u673a\u5668\u4eba\u53d1\u9001\u7684\u5e7f\u64ad\u5305\uff0c\u5e76\u4e0d\u80fd\u8ba9App\u8bc6\u522b\u5e76\u53d1\u8d77\u8fde\u63a5\u3002\u8fd9\u4e00\u70b9\u8ba9\u6211\u7591\u60d1\u4e86\u5f88\u4e45\u3002\u6700\u7ec8\u5bf9RoboMaster App\u505a\u4e86\u4e00\u4e9b\u9006\u5411\u5de5\u7a0b\u7684\u5206\u6790\uff0c\u53d1\u73b0\u539f\u676545678\u7aef\u53e3\u768424\u4e2a\u5b57\u8282\u7684\u5e7f\u64ad\u5305\u5b9e\u9645\u4e0a\u5176\u4e2d\u5305\u542b\u4e86\u673a\u5668\u4eba\u5728\u5c40\u57df\u7f51\u4e2d\u7684IP\u5730\u5740\u548cMAC\u5730\u5740\uff0c\u4ee5\u53ca\u662f\u5426\u5904\u4e8e\u914d\u5bf9\u72b6\u6001\u7684\u6807\u5fd7\u3002\u673a\u5668\u4eba\u5728\u7b2c\u4e00\u6b21\u914d\u5bf9\uff08\u4e5f\u5c31\u662f\u6309\u4e0bConnect\u952e\u7b2c\u4e00\u6b21\u626b\u63cf\u4e8c\u7ef4\u7801\u8fde\u63a5\u7f51\u7edc\u7684\u65f6\u5019\uff09\u65f6\uff0c\u4f1a\u5c06pair\u6807\u5fd7\u4f4d\u7f6e1\uff0c\u5f53App\u5728\u7b2c\u4e00\u6b21\u548c\u673a\u5668\u4eba\u914d\u5bf9\u4e4b\u540e\uff0c\u4f1a\u4f7f\u7528IP\u5730\u5740\u548cAppID\u6765\u8bb0\u4f4f\u673a\u5668\u4eba\uff0c\u5728\u6b64\u4e4b\u540e\u53ea\u6709\u63a5\u6536\u5230\u8fd9\u4e2aIP\u5730\u5740\u53d1\u51fa\u7684\u5e7f\u64ad\u5305\u624d\u4f1a\u8bc6\u522b\u5230\u673a\u5668\u4eba\uff0c\u7531\u4e8e\u6211\u4eec\u8de8\u7f51\u7edc\uff0cIP\u5730\u5740\u662f\u6709\u53d8\u5316\u7684\uff0c\u6240\u4ee5\u5c31\u5fc5\u987b\u5c06\u5176\u8f6c\u6362\u4e3a\u4f2a\u673a\u5668\u4eba\u7684IP\u548cMAC\u5730\u5740\u624d\u884c\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u6700\u7ec8\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>\u7531\u4e8eTornado\u6ca1\u6709UDPServer\u7684\u4f8b\u5b50\uff0c\u6240\u4ee5\u6211\u8fd9\u91cc\u53c2\u8003\u522b\u4eba\u81ea\u5df1\u5199\u4e86\u4e00\u4e2a\uff1a<\/p>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">#!\/usr\/bin\/env python3\n# coding=utf-8\n# File: udpserver.py\n\nimport socket\nimport os\nimport errno\nfrom tornado.ioloop import IOLoop\nfrom tornado import process\nfrom tornado.platform.auto import set_close_exec\n\n\ndef bind_sockets(port, address=None, family=socket.AF_UNSPEC, backlog=25):\n    sockets = []\n    if address == \"\":\n        address = None\n    flags = socket.AI_PASSIVE\n    if hasattr(socket, \"AI_ADDRCONFIG\"):\n        flags |= socket.AI_ADDRCONFIG\n    for res in set(socket.getaddrinfo(address, port, family, socket.SOCK_DGRAM, 0, flags)):\n        af, socktype, proto, canonname, sockaddr = res\n        sock = socket.socket(af, socktype, proto)\n        set_close_exec(sock.fileno())\n        if os.name != 'nt':\n            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)\n        if af == socket.AF_INET6 and hasattr(sock, \"IPPROTO_IPV6\") and hasattr(sock, \"IPV6_V6ONLY\"):\n            sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)\n        sock.setblocking(0)\n        sock.bind(sockaddr)\n        sockets.append(sock)\n        print(\"Server Listen On:\", sockaddr)\n    return sockets\n\n\ndef add_accept_handler(sock, callback, io_loop=None):\n    if io_loop is None:\n        io_loop = IOLoop.instance()\n\n    def accept_handler(fd, events):\n        while True:\n            try:\n                data, address = sock.recvfrom(2500)\n            # print(\"received_data\")\n            except socket.error as e:\n                if e.args[0] in (errno.EWOULDBLOCK, errno.EAGAIN):\n                    return\n                raise\n            callback(sock, data, address)\n\n    io_loop.add_handler(sock.fileno(), accept_handler, IOLoop.READ)\n\n\nclass UDPServer(object):\n    def __init__(self, io_loop=None):\n        self.io_loop = io_loop\n        self._sockets = {}\n        self._pending_sockets = []\n        self._started = False\n        self._port = 0\n\n    def add_sockets(self, sockets):\n        if self.io_loop is None:\n            self.io_loop = IOLoop.instance()\n\n        for sock in sockets:\n            self._sockets[sock.fileno()] = sock\n            add_accept_handler(sock, self._on_receive, io_loop=self.io_loop)\n\n    def bind(self, port, address=None, family=socket.AF_UNSPEC, backlog=25):\n        self._port = port\n        sockets = bind_sockets(port, address=address, family=family, backlog=backlog)\n\n        if self._started:\n            self.add_sockets(sockets)\n        else:\n            self._pending_sockets.extend(sockets)\n\n    def start(self, num_processes=1):\n        assert not self._started\n        self._started = True\n        if num_processes != 1:\n            process.fork_processes(num_processes)\n        sockets = self._pending_sockets\n        self._pending_sockets = []\n        self.add_sockets(sockets)\n\n    def stop(self):\n        for fd, sock in self._sockets.iteritems():\n            self.io_loop.remove_handler(fd)\n            sock.close()\n\n    def _on_receive(self, sock, data, address):\n        print(\"receive from address:\", address, \"data:\", data.hex())\n\n    def send_pkt_to_peer(self, data,address):\n        for sock in self._sockets.values():\n            sock.sendto(data,address)\n\n# if address[1]==56789:\n#\tprint(robotpkt_encdec(data).hex())\n\n# sock.sendto(data, address)\n\n\nif __name__ == \"__main__\":\n    server = UDPServer()\n    server.bind(9876)\n    server.start()\n    server2 = UDPServer()\n    server2.bind(9877)\n    server2.start()\n    IOLoop.instance().start()\n\n<\/pre>\n\n\n<p>\u4f2a\u673a\u5668\u4eba\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">#!\/usr\/bin\/env python3\n#coding=utf-8\n#File fake_robot.py\n\n\nfrom udpserver import UDPServer\nfrom tornado import gen, iostream\nfrom tornado.ioloop import IOLoop\nfrom tornado.tcpclient import TCPClient\nimport socket\nimport os\n\ncenter_server = ('47.116.100.159',7777)   #\u6539\u6210\u4f60\u81ea\u5df1\u7684\u4e2d\u7ee7\u670d\u52a1\u5668\u5730\u5740\nrobot_register_message = b'\\xdd\\xcc\\xbb\\xaa\\x00\\x00\\x00\\x00\\x00\\x01\\x01'\nMyIp = '192.168.0.173'  #\u6539\u6210\u4f5c\u4e3a\u4f2a\u673a\u5668\u4eba\u7684PC\u5728\u5c40\u57df\u7f51\u4e2d\u7684IP\nBroadcast_addr = '192.168.0.255' #\u5e7f\u64ad\u5730\u5740\uff0c\u81ea\u5df1\u770b\u7740\u6539\nMyMac = '00:0c:29:f5:ad:d1'   #\u673a\u5668\u5728\u5c40\u57df\u7f51\u4e2d\u7684MAC\u5730\u5740\nrobot_server = None\nPhone_Ip = None\n\ndef mac_to_bytes(macaddr):\n\tmacaddr_bytes = b''\n\tbts = macaddr.split(\":\")\n\tfor s in bts:\n\t\tmacaddr_bytes += int(s,16).to_bytes(1,'little')\n\treturn macaddr_bytes\n\ndef ip_to_bytes(ipaddr):\n\tipaddr_bytes = b''\n\tbts = ipaddr.split(\".\")\n\tfor s in bts:\n\t\tipaddr_bytes += int(s).to_bytes(1,'little')\n\treturn ipaddr_bytes\n\ndef pkt_encdec(data):\n\tb = 7\n\torig_data = b''\n\tfor ch in data:\n\t\torig_data += bytes([ch ^ b])\n\t\tb = ((b + 7) ^ 178) &amp; 0xff\n\treturn orig_data\n\n@gen.coroutine\ndef RobotClient():\n\tstream = yield TCPClient().connect(center_server[0], center_server[1])\n\tbcastsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n\tbcastsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)\n\tbcastsock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)\n\tbcastsock.bind((MyIp,56789))\n\ttry:\n\t\twhile True:\n\t\t\tif (RobotUDPServer.center_server_stream == None):\n\t\t\t\tRobotUDPServer.center_server_stream = stream\n\t\t\t\tprint(\"Center Server Connected.\",RobotUDPServer.center_server_stream)\n\t\t\t\tyield RobotUDPServer.center_server_stream.write(robot_register_message)\n\t\t\tdata = yield stream.read_bytes(4)\n\t\t\tif (data == b'\\x44\\x33\\x22\\x11'):\n\t\t\t\tsrc_port = yield stream.read_bytes(2)\n\t\t\t\tdst_port = yield stream.read_bytes(2)\n\t\t\t\tlen_bytes = yield stream.read_bytes(2)\n\t\t\t\tsport = int.from_bytes(src_port,byteorder = 'big',signed = False)\n\t\t\t\tdport = int.from_bytes(dst_port,byteorder = 'big',signed = False)\n\t\t\t\tpayload_len = int.from_bytes(len_bytes,byteorder = 'big',signed = False)\n\t\t\t\tpayload = yield stream.read_bytes(payload_len)\n\t\t\t\tif (dport == 45678):\n\t\t\t\t\torig_data = pkt_encdec(payload)\n\t\t\t\t\t#print(orig_data.hex())\n\t\t\t\t\tnew_pkt = orig_data[:2] + b'\\x01' + orig_data[3:6] + ip_to_bytes(MyIp) + mac_to_bytes(MyMac) + orig_data[16:]\n\t\t\t\t\tpkt2send = pkt_encdec(new_pkt)\n\t\t\t\t\t#print(pkt2send.hex())\n\t\t\t\t\t#print(payload.hex())\n\t\t\t\t\t#print(pkt2send == payload)\n\t\t\t\t\tbcastsock.sendto(pkt2send,(Broadcast_addr,dport))\n\t\t\t\tif (sport == 10607):\n\t\t\t\t\tglobal Phone_Ip,robot_server\n\t\t\t\t\tif (robot_server != None and Phone_Ip != None):\n\t\t\t\t\t\trobot_server.send_pkt_to_peer(payload, (Phone_Ip, dport))\n\t\t\t\t\t\n\texcept iostream.StreamClosedError:\n\t\tbcastsock.close()\n\t\tos._exit(1)\n\n\ndef pack_robot_data(src_port,dst_port,data):\n\treturn b'\\xdd\\xcc\\xbb\\xaa' + src_port.to_bytes(2,'big') + dst_port.to_bytes(2,'big') + len(data).to_bytes(2,'big') + data\n\nclass RobotUDPServer(UDPServer):\n\tcenter_server_stream = None\n\t@gen.coroutine\n\tdef _on_receive(self, sock, data, address):\n\t\t#print(\"receive from address:\", address, \"data:\", data.hex())\n\t\tif (self._port == 10607):\n\t\t\tglobal Phone_Ip\n\t\t\tif Phone_Ip == None:\n\t\t\t\tPhone_Ip = address[0]\n\t\t\t\tprint(\"Got Real Phone Ip:\",Phone_Ip)\n\t\t\tupload_pkt = pack_robot_data(address[1],self._port,data)\n\t\t\t#print(upload_pkt.hex())\n\t\t\t#print(RobotUDPServer.center_server_stream)\n\t\t\tif (RobotUDPServer.center_server_stream != None):\n\t\t\t\tRobotUDPServer.center_server_stream.write(upload_pkt)\n\nif __name__==\"__main__\":\n\trobot_server = RobotUDPServer()\n\trobot_server.bind(10607,MyIp)\n\trobot_server.start()\n\tIOLoop.current().run_sync(RobotClient)\n\tIOLoop.instance().start(2)\n\t\n<\/pre>\n\n\n<p>\u4f2a\u624b\u673aApp\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">#!\/usr\/bin\/env python3\n#coding=utf-8\n# File: fake_phone.py\n\nfrom udpserver import UDPServer\nfrom tornado import gen, iostream\nfrom tornado.ioloop import IOLoop\nfrom tornado.tcpclient import TCPClient\nimport os\n\ncenter_server = ('47.116.100.159',7777)  #\u6539\u6210\u4f60\u81ea\u5df1\u7684\u4e2d\u7ee7\u670d\u52a1\u5668\u5730\u5740\nMyIp =  '192.168.8.1'    #\u4f2aApp\u5728\u5c40\u57df\u7f51\u4e2d\u7684IP\uff0c\u5728\u8fd9\u91cc\u5c31\u662f4G\u8def\u7531\u5668\u672c\u8eab\u7684LAN\u5730\u5740\u4e86\nRobot_Ip = None\nphone_register_message = b'\\x44\\x33\\x22\\x11\\x00\\x00\\x00\\x00\\x00\\x01\\x01'\nfake_phone_server = None\n\n@gen.coroutine\ndef PhoneClient():\n\tstream = yield TCPClient().connect(center_server[0], center_server[1])\n\ttry:\n\t\twhile True:\n\t\t\tif (PhoneUDPServer.center_server_stream == None):\n\t\t\t\tPhoneUDPServer.center_server_stream = stream\n\t\t\t\tyield stream.write(phone_register_message)\n\t\t\tdata = yield stream.read_bytes(4)\n\t\t\tif (data == b'\\xdd\\xcc\\xbb\\xaa'):\n\t\t\t\tsrc_port = yield stream.read_bytes(2)\n\t\t\t\tdst_port = yield stream.read_bytes(2)\n\t\t\t\tlen_bytes = yield stream.read_bytes(2)\n\t\t\t\tsport = int.from_bytes(src_port, byteorder='big', signed=False)\n\t\t\t\tdport = int.from_bytes(dst_port, byteorder='big', signed=False)\n\t\t\t\tpayload_len = int.from_bytes(len_bytes, byteorder='big', signed=False)\n\t\t\t\tpayload = yield stream.read_bytes(payload_len)\n\t\t\t\t#print(payload.hex())\n\t\t\t\tglobal Robot_Ip,fake_phone_server\n\t\t\t\tif (fake_phone_server == None):\n\t\t\t\t\tfake_phone_server = PhoneUDPServer()\n\t\t\t\t\tfake_phone_server.bind(sport,MyIp)\n\t\t\t\t\tfake_phone_server.start()\n\t\t\t\telif (Robot_Ip != None):\n\t\t\t\t\t#print(\"Payload sent...\")\n\t\t\t\t\tfake_phone_server.send_pkt_to_peer(payload,(Robot_Ip, dport))\n\t\t\t#print(data.hex())\n\texcept iostream.StreamClosedError:\n\t\tos._exit(1)\ndef pack_phone_data(src_port,dst_port,data):\n\treturn b'\\x44\\x33\\x22\\x11' + src_port.to_bytes(2,'big') + dst_port.to_bytes(2,'big') + len(data).to_bytes(2,'big') + data\nclass PhoneUDPServer(UDPServer):\n\tcenter_server_stream = None\n\t@gen.coroutine\n\tdef _on_receive(self, sock, data, address):\n\t\t#print(\"receive from address:\", address, \"data:\", data.hex())\n\t\tif (address[1] == 56789):\n\t\t\tupload_pkt = pack_phone_data(address[1],self._port,data)\n\t\t\tglobal Robot_Ip\n\t\t\tif (Robot_Ip == None):\n\t\t\t\tRobot_Ip = address[0]\n\t\t\t\tprint(\"Got Real Robot Ip address:\",Robot_Ip)\n\t\t\t#print(upload_pkt.hex())\n\t\t\tif (PhoneUDPServer.center_server_stream != None):\n\t\t\t\tPhoneUDPServer.center_server_stream.write(upload_pkt)\n\t\tif (address[1] == 10607):\n\t\t\tupload_pkt = pack_phone_data(address[1], self._port, data)\n\t\t\tif (PhoneUDPServer.center_server_stream != None):\n\t\t\t\tPhoneUDPServer.center_server_stream.write(upload_pkt)\nif __name__==\"__main__\":\n\tserver = PhoneUDPServer()\n\tserver.bind(45678, MyIp)\n\tserver.start()\n\tIOLoop.current().run_sync(PhoneClient)\n\tIOLoop.instance().start(2)<\/pre>\n<p><\/p>\n\n\n<p>\u4e2d\u7ee7\u670d\u52a1\u5668\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">#!\/usr\/bin\/env python3\n#File: centerserver.py\n\n\nfrom tornado.tcpserver import TCPServer\nfrom tornado.iostream import StreamClosedError\nfrom tornado import gen\nfrom tornado.ioloop import IOLoop\n\n'''\nServer Communication Protocol\nData From Robot Magic: 0xaabbccdd\nData From Phone Magic: 0x11223344\nFormat:\n[Magic]  [Src Port]  [Dst Port]  [Payload len]  [Payload]\n(4bytes)  (2bytes)    (2bytes)      (2bytes)     (...)\n'''\n\nclass CenterServer(TCPServer):\n\tFakeRobot_Stream = None\n\tFakePhone_Stream = None\n\t@gen.coroutine\n\tdef handle_stream(self,stream,address):\n\t\twhile True:\n\t\t\ttry:\n\t\t\t\tdata = yield stream.read_bytes(4)\n\t\t\t\t#print data.encode('hex')\n\t\t\t\tif data == b'\\xdd\\xcc\\xbb\\xaa':\n\t\t\t\t\tif (CenterServer.FakeRobot_Stream == None):\n\t\t\t\t\t\tCenterServer.FakeRobot_Stream = stream\n\t\t\t\t\t\tprint(\"Fake Robot Connected!\\n\",address,CenterServer.FakeRobot_Stream)\n\t\t\t\t\tport_pair_data = yield stream.read_bytes(4)\n\t\t\t\t\tlen_bytes = yield stream.read_bytes(2)\n\t\t\t\t\tpayload_len = int.from_bytes(len_bytes,byteorder = 'big',signed = False)\n\t\t\t\t\t#print \"payload_len =\",payload_len\n\t\t\t\t\tpayload = yield stream.read_bytes(payload_len)\n\t\t\t\t\t#print(CenterServer.FakePhone_Stream)\n\t\t\t\t\tif (CenterServer.FakePhone_Stream != None):\n\t\t\t\t\t\tif (port_pair_data != b'\\x00\\x00\\x00\\x00'):\n\t\t\t\t\t\t\tpayload_relayed = data + port_pair_data + payload_len.to_bytes(2,'big') + payload\n\t\t\t\t\t\t\t#print(\"Received from Robot:\",payload_relayed.hex())\n\t\t\t\t\t\t\tCenterServer.FakePhone_Stream.write(payload_relayed)\n\t\t\t\telif data == b'\\x44\\x33\\x22\\x11': \n\t\t\t\t\tif (CenterServer.FakePhone_Stream == None):\n\t\t\t\t\t\tCenterServer.FakePhone_Stream = stream\n\t\t\t\t\t\tprint(\"Fake Phone Connected!\\n\",address,CenterServer.FakeRobot_Stream)\n\t\t\t\t\tport_pair_data = yield stream.read_bytes(4)\n\t\t\t\t\tlen_bytes = yield stream.read_bytes(2)\n\t\t\t\t\tpayload_len = int.from_bytes(len_bytes,byteorder = 'big',signed = False)\n\t\t\t\t\tpayload = yield stream.read_bytes(payload_len)\n\t\t\t\t\tif (CenterServer.FakeRobot_Stream != None):\n\t\t\t\t\t\tif (port_pair_data != b'\\x00\\x00\\x00\\x00'):\n\t\t\t\t\t\t\tpayload_relayed = data + port_pair_data + payload_len.to_bytes(2,'big') + payload\n\t\t\t\t\t\t\t#print(\"Received from Phone:\",payload_relayed.hex())\n\t\t\t\t\t\t\tCenterServer.FakeRobot_Stream.write(payload_relayed)\n\t\t\t\telse:\n\t\t\t\t\tpass\n\t\t\texcept StreamClosedError:\n\t\t\t\tbreak\n\t\t\nif __name__==\"__main__\":\n\tserver = CenterServer()\n\tserver.bind(7777)\n\tprint(\"Server Lisen on tcp:7777\")\n\tserver.start()\n\tIOLoop.current().start()\n<\/pre>\n<p><\/p>\n\n\n<p>\u5b8c\u6210\u540e\u6309\u7167\u524d\u9762\u7684\u67b6\u6784\u56fe\uff0c\u90e8\u7f72\u597d\u4ee3\u7801\uff0c\u4f9d\u8d56\u5e93\u5c31\u53ea\u6709\u4e00\u4e2a\u2014\u2014tornado\uff0c\u662f\u4e0d\u662f\u7279\u522b\u7b80\u5355\uff1f<\/p>\n\n\n\n<p>\u7136\u540e\u542f\u52a8fake_phone\u548cfake_robot\uff0c\u7136\u540e\u6253\u5f00\u624b\u673aApp\uff0c\u5c31\u53ef\u4ee5\u542c\u5230\u673a\u5668\u4eba\u719f\u6089\u7684\u88ab\u8fde\u63a5\u4e0a\u7684\u58f0\u97f3\u4e86\uff0c\u4ece\u6b64\u53ef\u4ee5\u6109\u5feb\u7684\u8fdc\u7a0b\u63a7\u5236\u5b83\u505a\u5404\u79cd\u4e8b\u60c5\u4e86\u3002<\/p>\n\n\n\n<p><strong>\u5173\u4e8e\u5ef6\u8fdf\uff1a<\/strong><\/p>\n\n\n\n<p>\u3000\u3000\u6839\u636e\u6d4b\u8bd5\u6765\u770b\uff0c\u5ef6\u8fdf\u8fd8\u662f\u6709\u4e00\u4e9b\u7684\uff0c\u4e0d\u8fc7\u603b\u7684\u6765\u8bf4\u8fd8\u53ef\u4ee5\u63a5\u53d7\uff0c\u4e0d\u7b97\u592a\u79bb\u8c31\uff0c\u6240\u4ee5\u5c3d\u91cf\u8981\u9009\u62e9ping\u503c\u5c0f\u7684\u670d\u52a1\u5668\uff0c\u80fd\u591f\u83b7\u5f97\u66f4\u597d\u7684\u63a7\u5236\u4f53\u9a8c\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u8865\u5145\uff1a\u7406\u8bba\u4e0a\u65b0\u51fa\u7684EP\u4e5f\u80fd\u7528\u8fd9\u79cd\u65b9\u6cd5\u6765\u5b9e\u73b0\uff0c\u4e0d\u8fc7EP\u63d0\u4f9b\u7684SDK\u548c\u6587\u6863\u66f4\u5f3a\u5927\uff0c\u76f8\u5bf9\u6765\u8bf4\u96be\u5ea6\u4f1a\u66f4\u4f4e\u4e00\u4e9b\uff0c\u53ef\u73a9\u6027\u4f1a\u66f4\u9ad8\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u3000\u53bb\u5e74\u4e70\u4e86\u4e00\u53f0Robomaster S1\u673a\u5668\u4eba\uff0c\u7ec4\u88c5\u5b8c\u6210\u4e4b\u540e\u73a9\u4e86\u4e00\u4f1a\u89c9\u5f97\u53ea\u80fd\u5728\u8def\u7531\u5668\u7684\u65e0\u7ebf\u4fe1\u53f7\u8ddd\u79bb\u91cc\u9762\u73a9\u7565\u6709 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5,7],"tags":[256,251,85,253,255,254,252,257],"class_list":["post-1328","post","type-post","status-publish","format-standard","hentry","category-iot","category-5","category-7","tag-4g","tag-dji","tag-python","tag-robomaster","tag-rs1","tag-s1","tag-252","tag-257"],"_links":{"self":[{"href":"https:\/\/www.jarvisw.com\/index.php?rest_route=\/wp\/v2\/posts\/1328","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jarvisw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jarvisw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jarvisw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jarvisw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1328"}],"version-history":[{"count":7,"href":"https:\/\/www.jarvisw.com\/index.php?rest_route=\/wp\/v2\/posts\/1328\/revisions"}],"predecessor-version":[{"id":1339,"href":"https:\/\/www.jarvisw.com\/index.php?rest_route=\/wp\/v2\/posts\/1328\/revisions\/1339"}],"wp:attachment":[{"href":"https:\/\/www.jarvisw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jarvisw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jarvisw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}