From d1127745f7ff59c69e46fc3597ba946a2615a1d1 Mon Sep 17 00:00:00 2001 From: ganben Date: Thu, 15 Dec 2016 00:32:38 +0800 Subject: [PATCH 1/2] :sparkles: :memo: :construction: add 2003 command, add alarm counter for detect multiple button press --- document/hospital-iot/basestation-setting.md | 9 +++- py/demo.py | 43 +++++++++++++++++--- py/protobuilder.py | 2 +- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/document/hospital-iot/basestation-setting.md b/document/hospital-iot/basestation-setting.md index b00e5d3..262711e 100644 --- a/document/hospital-iot/basestation-setting.md +++ b/document/hospital-iot/basestation-setting.md @@ -47,4 +47,11 @@ alias = see configuration of bs - tf card 05 -> 1011 - tf card 04 -> 1012 - tf card 10 -> 1009 -- tf card 08 -> 1003 \ No newline at end of file +- tf card 08 -> 1003 + +### TODOs + +- autoconfig +- command: and take some photo; compress and upload to some where; +- choose a best qualitied, big faced one; if opencv:face detection is set + diff --git a/py/demo.py b/py/demo.py index 584fa31..3e32958 100644 --- a/py/demo.py +++ b/py/demo.py @@ -157,6 +157,23 @@ def reconnect(): s.connect((socketHost,socketPort)) except socket.error as msg: print(msg) +def alarm_update(bcid, flag): + global alarm_cache + global position_cache + #position cache for time, alarm cache for counts for each bcid + bc = str(bcid) + f=str(flag) + if f == '13': + alarm_cache[bc]=0 + return False + elif f == '66' and alarm_cache[bc] >=9 : + alarm_cache[bc]=0 + return True + elif f == '66' and alarm_cache[bc] < 9: + alarm_cache[bc] += 1 + print('alarmtimes=%s' % alarm_cache[bc]) + return False + class ScanDelegate(DefaultDelegate): def __init__(self): @@ -167,6 +184,8 @@ def handleDiscovery(self, dev, isNewDev, isNewData): timestamp = time.time() global lastDiscoveryTime global s + #global alarm_cache + #global position_cache try: for (adtype,desc,value) in dev.getScanData(): data[desc]=value @@ -186,7 +205,7 @@ def handleDiscovery(self, dev, isNewDev, isNewData): #electricity = data['Manufacturer'][16:18] electricity = '64' #fixed flag = data['Manufacturer'][6:8] - local_ip = get_ip_address('wlan0') + local_ip = get_ip_address('eth0') #swap for wlan0 for convenience hex_ip = ''.join([hex(int(i)).lstrip('0x').rjust(2,'0') for i in local_ip.split('.')]) temp = 50 reserved = '010001000100' #fixed reserved bytes @@ -199,26 +218,34 @@ def handleDiscovery(self, dev, isNewDev, isNewData): BinData = bytearray.fromhex(newdata) #print "after to bin:%s" % (BinData,) newBinData= BinData+checksum(BinData[2::]) - arrs=[] - for e in newBinData: - arrs.append(str(e)) + #arrs=[] + #for e in newBinData: + # arrs.append(str(e)) #arrs.append(str(struct.unpack('B', e[0])[0])) #print('-'.join(arrs)) #newBinData = base64.b16decode(newdata) #print "send bin data: %s, last %s" % (newBinData,checksum(BinData)) #send to where + #!the sent must count first, every 3 packet sent one position packet + #!if shortly 10 + alarm count, then sent a regist count (flag=70); + #!see the method: alarm_update() + + try: #re-use present socket link; #rather than close and open a new socket; #this is only happen every 50 fails #s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) #s.connect((socketHost, socketPort)) - if SENDMODE == 'SB': + if SENDMODE == 'SB':# and alarm_update(flag): s.send(newBinData) #s.sendall(newBinData) #this caused a flush on recv side #print('-'.join(arrs)) - elif SENDMODE == 'SJ': + elif SENDMODE == 'SJ':# and alarm_update(flag): s.send(outputbuilder(flag,get_mac_address_full(),dev.addr,100,local_ip,dev.rssi)) + if alarm_update(data['bcid'], flag): + s.send(outputbuilder('70',get_mac_address_full(),dev.addr,100,local_ip,dev.rssi)) + print('sent 70xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') #s.close() except socket.error as msg: #s.close() @@ -348,6 +375,10 @@ def run(self): if __name__=='__main__': global lastDiscoveryTime global s + global position_cache + global alarm_cache + position_cache = {} + alarm_cache = {} s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) try: s.connect((socketHost,socketPort)) diff --git a/py/protobuilder.py b/py/protobuilder.py index 82569d4..2aaf996 100644 --- a/py/protobuilder.py +++ b/py/protobuilder.py @@ -14,7 +14,7 @@ def outputbuilder(bccommand,bsmac,bcmac,battery,bsip,rssi): #battery until next bc version #bccommand = key, 13, 66, 68 etc; #bccommand = value, 2004, 2001, 2002, etc - cmdict = {'13': 2004, '66': 2001, '68':2002} + cmdict = {'13': 2004, '66': 2001, '68':2002, '70':2003} cm = cmdict.get(bccommand, False) if cm: data['Command'] = cm From 00d5ef48467035a1ab2e643ab262c9e25d9dd5e0 Mon Sep 17 00:00:00 2001 From: ganben Date: Thu, 15 Dec 2016 22:07:58 +0800 Subject: [PATCH 2/2] :construction: :memo: deliver device to hskcd --- document/hospital-iot/basestation-setting.md | 1 + document/to_hskcd/basestation-configs.md | 11 +++++++++++ py/demo.py | 4 ++-- py/t.cnf | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 document/to_hskcd/basestation-configs.md diff --git a/document/hospital-iot/basestation-setting.md b/document/hospital-iot/basestation-setting.md index 262711e..66f6bfb 100644 --- a/document/hospital-iot/basestation-setting.md +++ b/document/hospital-iot/basestation-setting.md @@ -55,3 +55,4 @@ alias = see configuration of bs - command: and take some photo; compress and upload to some where; - choose a best qualitied, big faced one; if opencv:face detection is set +### TODO2 diff --git a/document/to_hskcd/basestation-configs.md b/document/to_hskcd/basestation-configs.md new file mode 100644 index 0000000..b78fe2e --- /dev/null +++ b/document/to_hskcd/basestation-configs.md @@ -0,0 +1,11 @@ +## base station configs +[Chengdu148106661] + +备用调试基站列表:有问题就简单重启一下基站。 + +No. | MAC-LAN | MAC-WLAN | SERVER SOCKET +----|------|-------|------- +01|b8:27:eb:e6:7c:11|b8:27:eb:b3:29:44|192.168.2.9:8080 +04|b8:27:eb:57:df:18|b8:27:eb:02:8a:4d|192.168.2.117:8090 +05|b8:27:eb:00:be:5c|b8:27:eb:55:eb:09|192.168.2.117:8090 +08|b8:27:eb:58:ad:06|b8:27:eb:0d:f8:53|192.168.2.117:8090 diff --git a/py/demo.py b/py/demo.py index 3e32958..8f7067b 100644 --- a/py/demo.py +++ b/py/demo.py @@ -166,10 +166,10 @@ def alarm_update(bcid, flag): if f == '13': alarm_cache[bc]=0 return False - elif f == '66' and alarm_cache[bc] >=9 : + elif f == '66' and alarm_cache[bc] >=7 : alarm_cache[bc]=0 return True - elif f == '66' and alarm_cache[bc] < 9: + elif f == '66' and alarm_cache[bc] < 7: alarm_cache[bc] += 1 print('alarmtimes=%s' % alarm_cache[bc]) return False diff --git a/py/t.cnf b/py/t.cnf index d125b62..23c4491 100644 --- a/py/t.cnf +++ b/py/t.cnf @@ -26,6 +26,8 @@ bracetlet_flag= 00ff position_manufacturer_flag= 13 call_manufacturer_flag= 66 outbody_manufacturer_flag= 68 +bracelet2_flag = 200000 +bracelet3_flag = 140000 [time] thread_cmd_sleep_time = 10.0