明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 22129|回复: 74

[【不死猫】] 谁动了我的CAD? 原创Android手机与Lisp通讯成功.

    [复制链接]
发表于 2014-3-20 15:19 | 显示全部楼层 |阅读模式
本帖最后由 不死猫 于 2014-11-24 14:39 编辑

先上图:

技术分析:
由于Lisp本身不支持socket监测端口,因此我们需要找一个数据中转区.
你可以选择共享文件夹(仅局域网),也可以选择数据库,或者通过网站的页面发布进行数据交换.
(本文采用SQL数据库作为数据中转区)
一方发送消息,另一方对消息进行监控采集即可.(这个道理与socket端口消息服务是一样的)

原理:
1.Lisp信息通过反应器发送到数据库中
2.数据库建立一个名为Android2Lisp的库,表名monitor,字段id关键,字段command字符串.
3.在Android里面建立多线程并监视数据库,读到数据后立即清空数据库(避免重复读取),得到的内容+当前时间添加到视图中,并将视图自动移到最后一行显示.



下面首先是Lisp源码:

  1. (if (not myAndroidMonitor)
  2.   (setq myAndroidMonitor (vlr-command-reactor nil '((:vlr-commandWillStart . myAndroidMonitorCallback))))
  3. )
  4. (defun myAndroidMonitorCallback(a b)
  5.   (writesql (car b))
  6. )
  7. (defun writesql(str)
  8.   (Setq con (Vlax-Get-Or-Create-Object "adodb.connection" ))
  9.   (Vlax-Invoke con 'Open "Driver={SQL Server};Server=IP;UID=nameWD=password;database=Android2Lisp;")
  10.   (Setq Record (Vlax-Get-Or-Create-Object "adodb.Recordset" ))
  11.   (Vlax-Invoke Record 'Open (strcat "update Monitor set command = '"  str " ' where id = '1'") con 1 3)
  12.   (vlax-invoke Record 'close)
  13.   (vlax-invoke con 'close)
  14.   (vlax-release-object Record )
  15.   (vlax-release-object con)
  16. )



Android界面代码
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.     xmlns:tools="http://schemas.android.com/tools"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent"
  5.     android:paddingBottom="@dimen/activity_vertical_margin"
  6.     android:paddingLeft="@dimen/activity_horizontal_margin"
  7.     android:paddingRight="@dimen/activity_horizontal_margin"
  8.     android:paddingTop="@dimen/activity_vertical_margin"
  9.     tools:context=".MainActivity" >

  10.     <Button
  11.         android:id="@+id/button1"
  12.         android:layout_width="wrap_content"
  13.         android:layout_height="wrap_content"
  14.         android:layout_alignBaseline="@+id/editText1"
  15.         android:layout_alignBottom="@+id/editText1"
  16.         android:layout_alignParentRight="true"
  17.         android:text="发送" />

  18.     <Button
  19.         android:id="@+id/button2"
  20.         android:layout_width="wrap_content"
  21.         android:layout_height="wrap_content"
  22.         android:layout_alignParentTop="true"
  23.         android:text="开始监视用户绘图" />
  24. <ScrollView
  25.     android:id="@+id/scrollview1"
  26.     android:layout_width="fill_parent"
  27.     android:layout_height="fill_parent"
  28.     android:scrollbars="vertical"
  29.     android:layout_below="@+id/button2"
  30.     android:layout_above="@+id/button1"
  31.         >
  32.     <TextView
  33.         android:id="@+id/textView1"
  34.         android:layout_width="wrap_content"
  35.         android:layout_height="wrap_content"
  36.         android:layout_alignParentLeft="true"
  37.         android:layout_alignRight="@+id/button1"
  38.         android:scrollbars="vertical" />
  39. </ScrollView>

  40. <EditText
  41.     android:id="@+id/editText1"
  42.     android:layout_width="wrap_content"
  43.     android:layout_height="wrap_content"
  44.     android:layout_alignParentBottom="true"
  45.     android:layout_marginBottom="18dp"
  46.     android:layout_toLeftOf="@+id/button1"
  47.     android:ems="10" />

  48. </RelativeLayout>
复制代码
Android主程序代码
  1. package com.example.nonsmallMonitorlisp;

  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.Statement;
  6. import java.text.SimpleDateFormat;
  7. import android.os.Bundle;
  8. import android.os.Handler;
  9. import android.os.Message;
  10. import android.app.Activity;
  11. import android.database.SQLException;
  12. import android.view.Menu;
  13. import android.view.View;
  14. import android.view.View.OnClickListener;
  15. import android.widget.*;

  16. public class CopyOfMainActivity extends Activity {

  17.   public String serverName = "jdbc:jtds:sqlserver://xx.xx.xx.xx:1433/Android2Lisp";
  18.   public String UserName = "name";//用户名
  19.   public String Password = "password";//密码
  20.   private Button button2;
  21.   private TextView textView1;
  22.   private Handler handler;
  23.   private Thread thread;
  24.   private String ListeningCommand;
  25.   private ScrollView mScrollView;
  26.   
  27.   @Override
  28.   protected void onCreate(Bundle savedInstanceState) {
  29.     super.onCreate(savedInstanceState);
  30.     setContentView(R.layout.activity_main);
  31.     button2 = (Button)findViewById(R.id.button2);
  32.     textView1 = (TextView)findViewById(R.id.textView1);
  33.     mScrollView =(ScrollView)findViewById(R.id.scrollview1);
  34.    
  35.     button2.setOnClickListener(new OnClickListener() {      
  36.       @Override
  37.       public void onClick(View v) {
  38.         // TODO 自动生成的方法存根
  39.         handler = new Handler(){
  40.           @Override
  41.               public void handleMessage(Message msg) {
  42.                   switch(msg.what){
  43.                     case 0:
  44.                       if (!isteningCommand.equals(""))
  45.                       {
  46.                         SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss");  
  47.                         String date=sdf.format(new java.util.Date());
  48.                         textView1.append("\n" + date + "\n执行了" + ListeningCommand + "命令");
  49.                         mScrollView.post(new Runnable() {   
  50.                             public void run() {
  51.                                 mScrollView.scrollTo(0, 9999);  
  52.                             }
  53.                         });
  54.                       }
  55.                         break;
  56.                     default:
  57.                         //do something
  58.                         break;
  59.                   }
  60.               }
  61.           };
  62.         thread = new Thread(new Runnable() {
  63.           @Override
  64.           public void run() {
  65.             // TODO 自动生成的方法存根
  66.             try
  67.                   {
  68.               while (true) {
  69.                     Listening();
  70.                     handler.sendEmptyMessage(0);
  71.                 thread.sleep(500);
  72.               }
  73.                   }
  74.                   catch (Exception e)
  75.                   {
  76.                   e.printStackTrace();
  77.                   }
  78.                   finally
  79.                   {
  80.                   //handler.sendEmptyMessage(0);
  81.                   }
  82.           }
  83.         });
  84.         thread.start();
  85.       }
  86.     });
  87.   }
  88.   @Override
  89.   public boolean onCreateOptionsMenu(Menu menu) {
  90.     // Inflate the menu; this adds items to the action bar if it is present.
  91.     getMenuInflater().inflate(R.menu.main, menu);
  92.     return true;
  93.   }
  94.   private void Listening(){
  95.     String sql = "select * from Monitor where id='1'";
  96.     Connection con = null;
  97.     try { // 加载驱动程序
  98.       Class.forName("net.sourceforge.jtds.jdbc.Driver");
  99.       con = DriverManager.getConnection(serverName,UserName,Password);
  100.     } catch (ClassNotFoundException e) {
  101.       System.out.println("加载驱动程序出错");
  102.     } catch (SQLException e) {
  103.       System.out.println(e.getMessage());
  104.     } catch (Exception e) {
  105.       System.out.println(e.getMessage());
  106.     }
  107.     try {
  108.       try {
  109.         Statement stmt = con.createStatement();//创建Statement
  110.         ResultSet rs = stmt.executeQuery(sql);//ResultSet类似Cursor
  111.         while (rs.next()) {
  112.           ListeningCommand = rs.getString("command");
  113.         }
  114.         stmt.executeUpdate("update Monitor set command = '' where id = '1'");
  115.         rs.close();
  116.         stmt.close();
  117.       } catch (SQLException e) {
  118.         System.out.println(e.getMessage().toString());
  119.       } finally {
  120.         if (con != null)
  121.           try {
  122.             con.close();
  123.           } catch (SQLException e) {
  124.           }
  125.       }
  126.     } catch (java.sql.SQLException e) {
  127.       e.printStackTrace();
  128.     }
  129.   }  
  130. }
反过来发送指令原理相同,直接上图




ps:本文仅作技术讨论,无需担心实际应用的可能性.
担心被应用监视?呵呵直接装摄像头就完事了,成本低又方便,还能防盗,何必如此麻烦.所以大家无需担心.
首先通过编程可以实现绘图指令自动执行欺骗监视.再说敢这样监视员工的老板,是没人愿意跟他混滴:)

楼下的,你的看法呢?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

点评

猫总走在前面,望尘莫及!(怎么不能评分?)  发表于 2014-3-21 16:58

评分

参与人数 1明经币 +3 收起 理由
mccad + 3 很给力!

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2023-4-1 10:44 | 显示全部楼层
猫老师,你厉害呀,这也行
发表于 2014-3-20 15:27 | 显示全部楼层
争取到头位。猫老师的要支持!
发表于 2014-3-20 15:29 | 显示全部楼层
猫老师,lisp我们很熟。请问Android 的代码如何使用,可否给些视频或动画?

点评

这个说起来实在是复杂的很,别说一言,百言都难尽. 仅仅开发环境的配置就要求很多,另外还需要安装数据库等等. 如果有兴趣可以找些相关的Android书籍学习下.  发表于 2014-3-20 15:35
发表于 2014-3-20 16:08 | 显示全部楼层
猫老师玩大了,可惜安卓系统门在哪 我们都不清楚呢
发表于 2014-3-20 16:19 | 显示全部楼层
在猫老师手里。。。CAD就是一切啊。。。。
哪天我看你都可以用CAD控制你家冰箱和微波炉了
太高深了。。。。。。。
发表于 2014-3-20 16:26 | 显示全部楼层
厉害厉害,瞧瞧先
发表于 2014-3-20 16:27 | 显示全部楼层
神马情况
发表于 2014-3-20 16:31 | 显示全部楼层
观望...太高深..彻底瞎...
发表于 2014-3-20 16:34 | 显示全部楼层
猫你厉害啊!!
发表于 2014-3-20 17:01 | 显示全部楼层
真厉害啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-3-29 20:52 , Processed in 0.258949 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表