Skip to content
This repository has been archived by the owner on Nov 21, 2021. It is now read-only.

Commit

Permalink
Merge pull request #11 from zkjs/master
Browse files Browse the repository at this point in the history
1st deliver, tag 0.9
  • Loading branch information
Ganben authored Dec 15, 2016
2 parents 72800f0 + 00d5ef4 commit dd74d3b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 deletions.
10 changes: 9 additions & 1 deletion document/hospital-iot/basestation-setting.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ alias = see configuration of bs
- tf card 05 -> 1011
- tf card 04 -> 1012
- tf card 10 -> 1009
- tf card 08 -> 1003
- 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

### TODO2
11 changes: 11 additions & 0 deletions document/to_hskcd/basestation-configs.md
Original file line number Diff line number Diff line change
@@ -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
43 changes: 37 additions & 6 deletions py/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] >=7 :
alarm_cache[bc]=0
return True
elif f == '66' and alarm_cache[bc] < 7:
alarm_cache[bc] += 1
print('alarmtimes=%s' % alarm_cache[bc])
return False


class ScanDelegate(DefaultDelegate):
def __init__(self):
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion py/protobuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions py/t.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dd74d3b

Please sign in to comment.