From 565c4f00094c6894911b47fae031c4777539b616 Mon Sep 17 00:00:00 2001
From: 沈斌 <bluelazysb@hotmail.com>
Date: Mon, 26 Dec 2016 15:48:25 +0800
Subject: [PATCH] 服务端代码优化与测试
---
queue.js | 4 +---
method.js | 46 ++++++++++++++++++++++++++--------------------
client.js | 2 +-
3 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/client.js b/client.js
index 11d6da0..52027f1 100644
--- a/client.js
+++ b/client.js
@@ -15,7 +15,7 @@
//client.write(new Buffer([ 0x5a, 0x00, 0x10, 0x01, 0x00, 0x07, 0xac, 0xcf, 0x23, 0xb8, 0x7f, 0xa2 ]));
//client.write(new Buffer([ 0x5A, 0x00, 0x33, 0x01, 0x00, 0x01 ]));
//client.write(new Buffer([0x5a,0x00,0x10,0x01,0x00,0x01,0xac,0xcf,0x23,0xb8,0x7f,0xbf]));
- client.write(new Buffer([0x5a,0x00,0x10,0x01,0x00,0x01,0xac, 0xcf, 0x23, 0xb8, 0x7d, 0xa4]));
+ client.write(new Buffer([0x5a,0x00,0x00,0x01,0x00,0x01,0xac, 0xcf, 0x23, 0xb8, 0x7d, 0xa4, 0xa4, 0xa4, 0xa4, 0xa4]));
//client.write(new Buffer([0x5a, 0x00, 0x3d, 0x01, 0x00, 0x06, 0xac, 0xcf, 0x23, 0xb8, 0x7f, 0xbf, 0xa6, 0x6a, 0x00, 0x51, 0x01, 0x02, 0x03, 0x04, 0x10, 0x06, 0x01, 0x02, 0x00,
// , 0x03, 0xfa, 0xae, 0x3e, 0x64, 0x5e, 0x9c, 0xb3, 0xcf, 0xbb, 0x91, 0xf9, 0xe4, 0x6e, 0xab, 0xef, 0xea, 0xcf, 0x42, 0x79, 0x9a, 0xf8, 0x22, 0x18, 0xec, 0x88, 0x6c, 0x4b, 0xf0, 0x4f, 0x9f, 0xef, 0x29, 0x00, 0x00]))
diff --git a/method.js b/method.js
index a215c48..48aea6b 100644
--- a/method.js
+++ b/method.js
@@ -170,6 +170,7 @@
var _config = global.configs[mac];
if(_config == null) {
_config = {
+ mac: mac,
address: "���������������������������������",
location: {���
lat:31.430616,
@@ -180,6 +181,7 @@
email: "it01@moral.org.cn",���
open_id: "o-RTuwvMHWotyirPHLmdSB_dKoQU"
}
+ configs[mac] = _config;
}
}
@@ -353,29 +355,33 @@
db.collection("devices").find().toArray(function(err, docs) {
docs.forEach(function(doc) {
var mac = doc.mac;
- var address = doc.address;
- var location = doc.location;
- var notice = doc.notice;
- if(notice == null) {
- var userID = doc.userID;
- db.collection("users").find({"_id": userID}).limit(1).next(function(err, user){
- if(user) {
- global.configs[mac] = {
- address: address,
- location: location,
- notice: {
- tel: user.username,
- email: user.email,
- open_id: user.open_id
+ if(mac != null) {
+ var address = doc.address || "";
+ var location = doc.location || {};
+ var notice = doc.notice;
+ if(notice == null || notice == {}) {
+ var userID = doc.userID;
+ db.collection("users").find({"_id": userID}).limit(1).next(function(err, user){
+ if(user) {
+ global.configs[mac] = {
+ mac: mac,
+ address: address,
+ location: location,
+ notice: {
+ tel: user.username,
+ email: user.email,
+ open_id: user.open_id
+ }
}
}
+ });
+ } else {
+ global.configs[mac] = {
+ mac: mac,
+ address: address,
+ location: location,
+ notice: notice
}
- });
- } else {
- global.configs[mac] = {
- address: address,
- location: location,
- notice: notice
}
}
});
diff --git a/queue.js b/queue.js
index 7d84d0c..2b20268 100644
--- a/queue.js
+++ b/queue.js
@@ -34,9 +34,7 @@
ch.bindQueue(q.queue, ex, '');
ch.consume(q.queue, function(msg) {
var message = JSON.parse(msg.content);
- var mac = message.mac;
- var data = message.data;
- global.configs[mac] = data;
+ global.configs[message.mac] = message;
}, { noAck: true });
});
});
--
Gitblit v1.8.0