Example #1
0
	def test_logData(self,text='default test string'):
		logs.objects().delete()
		testTime=int(time.time())
		l=logs(deviceId=text.decode('utf8','ignore'),data=text.decode('utf8','ignore'),time=testTime)
		l.save()
		res=logs.objects().get(time=testTime)
		self.assertEqual(res.deviceId.encode('utf8','ignore'),text)
		self.assertEqual(res.data.encode('utf8','ignore'),text)
Example #2
0
	def dataReceived(self, data):
#		print 'recv',data
		self.fulldata+=data
		#~ if self.logProtocol.parsePacket(self.fulldata):
		try:
			if self.logProtocol.validatePacket(self.fulldata):
				#~ print 'parse ok'
				self.logProtocol.parsePacket(self.fulldata)
				if self.logProtocol.cmd==LogProtocolCmds['SendText']:
					parser=RecordParser(self.logProtocol.packetData)
					text=parser.getVarcharUtf2()
					print 'recv text',text
					#~ l=logs(deviceId=self.logProtocol.deviceId.decode('utf8','ignore').encode('ascii','ignore'),data=text.decode('utf8','ignore').encode('ascii','ignore'),time=int(time.time()))
					#~ l=logs(deviceId=unicode(self.logProtocol.deviceId),data=unicode(text),time=int(time.time()))
					l=logs(deviceId=self.logProtocol.deviceId.decode('utf8','ignore'),data=text.decode('utf8','ignore'),time=int(time.time()))
					l.save()
					currentTime=int(time.time())
					try:
						#~ d=Device.objects.get(deviceId=self.logProtocol.deviceId)
						#~ d=Device.objects.get(deviceId=unicode(self.logProtocol.deviceId))
						d=Device.objects.get(deviceId=self.logProtocol.deviceId.decode('utf8','ignore'))
						#~ d.update(lastActivityTime=currentTime)
						d.lastActivityTime=currentTime
						d.ipAddress=self.transport.client[0]
						d.save()
					except DoesNotExist:
						#~ d=Device(deviceId=self.logProtocol.deviceId,ipAddress=self.transport.client[0],lastActivityTime=currentTime)
						#~ d=Device(deviceId=unicode(self.logProtocol.deviceId),ipAddress=self.transport.client[0],lastActivityTime=currentTime)
						print 'add new deviceId',self.logProtocol.deviceId
						d=Device(deviceId=self.logProtocol.deviceId.decode('utf8','ignore'),ipAddress=self.transport.client[0],lastActivityTime=currentTime)
						d.save()
						
					
					res=self.logProtocol.sendAck()
					self.transport.write(res)
				self.fulldata=''
				self.transport.loseConnection( )
		except:
			print traceback.format_exc()
			pass