def __init__(self, num_ch, file_name, sensorLoc, sensorSys, sensor_id, sensor_key, center_freq, bandwidth, meas_duration, atten, samp_rate, avoid_LO): gr.sync_block.__init__(self, name="jsonfile_sink", in_sig=[(bytes, num_ch)], out_sig=None) # Establish ssl socket connection to server self.num_ch = num_ch # Open file for output stream self.file_name = file_name self.f = open(self.file_name, 'wb') self.srvr = blocks.file_descriptor_sink(self.num_ch * gr.sizeof_char, self.f.fileno()) self.sensorLoc = sensorLoc self.sensorSys = sensorSys self.sensor_id = sensor_id self.sensor_key = sensor_key self.center_freq = center_freq self.bandwidth = bandwidth self.meas_duration = meas_duration self.atten = atten self.samp_rate = samp_rate self.avoid = avoid_LO print ("Sensor ID: ", self.sensor_id) # Send location and system info to server loc_msg = self.read_json_from_file(self.sensorLoc) sys_msg = self.read_json_from_file(self.sensorSys) ts = long(round(getLocalUtcTimeStamp())) print 'Serial no.', self.sensor_id loc_msg['t'] = ts loc_msg['SensorID'] = self.sensor_id sys_msg['t'] = ts sys_msg['SensorID'] = self.sensor_id self.post_msg(loc_msg) self.post_msg(sys_msg) # Form data header ts = long(round(getLocalUtcTimeStamp())) f_start = self.center_freq - self.bandwidth / 2.0 if self.avoid: #self.center_freq = self.center_freq + self.samp_rate/4.0 #print "Avoiding LO...\nShifting center Frequency to", self.center_freq f_start = (self.center_freq - self.samp_rate/4) - self.bandwidth/2.0 f_stop = f_start + self.bandwidth if self.avoid: print "Avoiding LO, frequencies are shifted to: [",f_start/1e6, "MHz-",f_stop/1e6,"MHz ]" mpar = Struct(fStart=f_start, fStop=f_stop, n=self.num_ch, td=-1, tm=self.meas_duration, Det='Average', Atten=self.atten) # Need to add a field for overflow indicator data_hdr = Struct(Ver='1.0.12', Type='Data', SensorID=self.sensor_id, SensorKey=self.sensor_key, t=ts, Sys2Detect='LTE', Sensitivity='Low', mType='FFT-Power', t1=ts, a=1, nM=-1, Ta=-1, OL='NaN', wnI=-77.0, Comment='Using hard-coded (not detected) system noise power for wnI', Processed='False', DataType = 'Binary - int8', ByteOrder='N/A', Compression='None', mPar=mpar) self.post_msg(data_hdr) self.f.flush() date_str = formatTimeStampLong(ts, loc_msg['TimeZone']) print date_str, "fc =", self.center_freq/1e6, "MHz. Writing data to file", self.file_name
def main_loop(tb): if not tb.set_freq(tb.center_freq): print "Failed to set frequency to", tb.center_freq sys.exit(1) print "Set frequency to", tb.center_freq/1e6, "MHz\n" time.sleep(0.25) sensor_id = "HackRF" # Establish ssl socket connection to server r = requests.post('https://'+tb.dest_host+':8443/sensordata/getStreamingPort/'+sensor_id, verify=False) print 'server response:', r.text response = r.json() print 'socket port =', response['port'] sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tb.s = s = ssl.wrap_socket(sock)#, ca_certs='dummy.crt', cert_reqs=ssl.CERT_NONE) s.connect((tb.dest_host, response['port'])) tb.set_sock(s) # Send location and system info to server loc_msg = tb.read_json_from_file('sensor.loc') sys_msg = tb.read_json_from_file('sensor.sys') ts = long(round(getLocalUtcTimeStamp())) sensor_key = sys_msg['SensorKey'] print 'Sensor Key', sensor_key #print 'Serial no.', sensor_id loc_msg['t'] = ts loc_msg['SensorID'] = sensor_id sys_msg['t'] = ts sys_msg['SensorID'] = sensor_id tb.send_obj(loc_msg) tb.send_obj(sys_msg) # Form data header ts = long(round(getLocalUtcTimeStamp())) f_start = tb.center_freq - tb.bandwidth/2.0 if tb.avoid_LO: f_start = (tb.center_freq - tb.samp_rate/4) - tb.bandwidth/2.0 f_stop = f_start + tb.bandwidth if tb.avoid_LO: print "Avoiding LO, frequencies are shifted to: [",f_start/1e6, "MHz-",f_stop/1e6,"MHz ]" mpar = Struct(fStart=f_start, fStop=f_stop, n=tb.num_ch, td=-1, tm=tb.meas_duration, Det='Average', Atten=tb.atten) # Need to add a field for overflow indicator data = Struct(Ver='1.0.12', Type='Data', SensorID='HackRF', SensorKey='12345', t=ts, Sys2Detect='LTE', Sensitivity='Low', mType='FFT-Power', t1=ts, a=1, nM=-1, Ta=-1, OL='NaN', wnI=-77.0, Comment='Using hard-coded (not detected) system noise power for wnI', Processed='False', DataType = 'Binary - int8', ByteOrder='N/A', Compression='None', mPar=mpar) tb.send_obj(data) date_str = formatTimeStampLong(ts, loc_msg['TimeZone']) print date_str, "fc =", tb.center_freq/1e6, "MHz. Sending data to", tb.dest_host # Start flow graph tb.start() tb.wait() tb.s.close() print 'Closed socket'
def main_loop(tb): sensor_id = "TestSensor" r = requests.post('https://' + tb.dest_host + '/sensordata/getStreamingPort/' + sensor_id, verify=False) print 'server response:', r.text response = r.json() print 'socket port =', response['port'] sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tb.s = s = ssl.wrap_socket(sock) s.connect((tb.dest_host, response['port'])) tb.set_sock(s) # Send location and system info to server loc_msg = tb.read_json_from_file('sensor.loc') loc_msg["SensorID"] = sensor_id sys_msg = tb.read_json_from_file('sensor.sys') sys_msg["SensorID"] = sensor_id ts = long(round(getLocalUtcTimeStamp())) print 'Serial no.', sensor_id loc_msg['t'] = ts loc_msg['SensorID'] = sensor_id sys_msg['t'] = ts sys_msg['SensorID'] = sensor_id tb.send_obj(loc_msg) tb.send_obj(sys_msg) # Form data header ts = long(round(getLocalUtcTimeStamp())) f_start = tb.center_freq - tb.bandwidth / 2.0 f_stop = f_start + tb.bandwidth # Note -- dummy atten mpar = Struct(fStart=f_start, fStop=f_stop, n=tb.num_ch, td=-1, tm=tb.meas_duration, Det='Average' if tb.det_type == 'avg' else 'Peak', Atten=tb.atten) # Need to add a field for overflow indicator data = Struct(Ver='1.0.12', Type='Data', SensorID=sensor_id, SensorKey='NaN', t=ts, Sys2Detect='LTE', \ Sensitivity='Low', mType='FFT-Power', t1=ts, a=1, nM=-1, Ta=-1, OL='NaN', wnI=-77.0, \ Comment='Using hard-coded (not detected) system noise power for wnI', \ Processed='False', DataType = 'Binary - int8', ByteOrder='N/A', Compression='None', mPar=mpar) tb.send_obj(data) date_str = formatTimeStampLong(ts, loc_msg['TimeZone']) print date_str, "fc =", tb.center_freq / 1e6, "MHz. Sending data to", tb.dest_host # Start flow graph tb.start() tb.wait() tb.s.close() print 'Closed socket'
def __init__(self, num_ch, dest_host, sensorLoc, sensorSys, sensor_id, sensor_key, center_freq, bandwidth, meas_duration, atten): gr.sync_block.__init__(self, name="sslsocket_sink", in_sig=[(bytes, num_ch)], out_sig=None) # Establish ssl socket connection to server self.num_ch = num_ch self.dest_host = dest_host self.sensorLoc = sensorLoc self.sensorSys = sensorSys self.sensor_id = sensor_id self.sensor_key = sensor_key self.center_freq = center_freq self.bandwidth = bandwidth self.meas_duration = meas_duration self.atten = atten r = requests.post('https://'+self.dest_host+':8443/sensordata/getStreamingPort/'+self.sensor_id, verify=False) print 'server response:', r.text response = r.json() print 'socket port =', response['port'] sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock = ssl.wrap_socket(sock, cert_reqs=ssl.CERT_NONE) self.sock.connect((self.dest_host, response['port'])) print ("Sensor ID: ", self.sensor_id) # Send location and system info to server loc_msg = self.read_json_from_file(self.sensorLoc) sys_msg = self.read_json_from_file(self.sensorSys) ts = long(round(getLocalUtcTimeStamp())) print 'Serial no.', self.sensor_id loc_msg['t'] = ts loc_msg['SensorID'] = self.sensor_id sys_msg['t'] = ts sys_msg['SensorID'] = self.sensor_id self.send_obj(loc_msg) self.send_obj(sys_msg) # Form data header ts = long(round(getLocalUtcTimeStamp())) f_start = self.center_freq - self.bandwidth / 2.0 f_stop = f_start + self.bandwidth mpar = Struct(fStart=f_start, fStop=f_stop, n=self.num_ch, td=-1, tm=self.meas_duration, Det='Average', Atten=self.atten) # Need to add a field for overflow indicator data = Struct(Ver='1.0.12', Type='Data', SensorID=self.sensor_id, SensorKey=self.sensor_key, t=ts, Sys2Detect='LTE', Sensitivity='Low', mType='FFT-Power', t1=ts, a=1, nM=-1, Ta=-1, OL='NaN', wnI=-77.0, Comment='Using hard-coded (not detected) system noise power for wnI', Processed='False', DataType = 'Binary - int8', ByteOrder='N/A', Compression='None', mPar=mpar) self.send_obj(data) date_str = formatTimeStampLong(ts, loc_msg['TimeZone']) print date_str, "fc =", self.center_freq/1e6, "MHz. Sending data to", self.dest_host
def main_loop(tb): if not tb.set_freq(tb.center_freq): print "Failed to set frequency to", tb.center_freq sys.exit(1) print "Set frequency to", tb.center_freq/1e6, "MHz" time.sleep(0.25) # Establish connection to server r = requests.post('http://'+tb.dest_host+':8000/sensordata/getStreamingPort') response = r.json() print 'socket port =', response['port'] tb.s = s = jsocket.JsonClient(address=tb.dest_host, port=response['port']) s.connect() tb.set_fd(s.conn.fileno()) # Send location and system info to server loc_msg = tb.read_json_from_file('sensor.loc') sys_msg = tb.read_json_from_file('sensor.sys') ts = long(round(getLocalUtcTimeStamp())) sensor_id = tb.u.get_usrp_info()['rx_serial'] print 'Serial no.', sensor_id loc_msg['t'] = ts loc_msg['SensorID'] = sensor_id sys_msg['t'] = ts sys_msg['SensorID'] = sensor_id s.send_obj(loc_msg) s.send_obj(sys_msg) # Form data header ts = long(round(getLocalUtcTimeStamp())) f_start = tb.center_freq - tb.bandwidth / 2.0 f_stop = f_start + tb.bandwidth mpar = Struct(fStart=f_start, fStop=f_stop, n=tb.num_ch, td=-1, tm=tb.meas_duration, Det='Average', Atten=tb.atten) # Need to add a field for overflow indicator data = Struct(Ver='1.0.12', Type='Data', SensorID=sensor_id, SensorKey='NaN', t=ts, Sys2Detect='LTE', Sensitivity='Low', mType='FFT-Power', t1=ts, a=1, nM=-1, Ta=-1, OL='NaN', wnI=-77.0, Comment='Using hard-coded (not detected) system noise power for wnI', Processed='False', DataType = 'Binary - int8', ByteOrder='N/A', Compression='None', mPar=mpar) s.send_obj(data) date_str = formatTimeStampLong(ts, loc_msg['TimeZone']) print date_str, "fc =", tb.center_freq/1e6, "MHz. Sending data to", tb.dest_host # Execute flow graph and wait for it to stop tb.start() tb.wait() tb.s.close() print 'Closed socket'
def testGetDayBoundaryOffset(self): global tzId t = timezone.getLocalUtcTimeStamp() startOfToday = timezone.getDayBoundaryTimeStampFromUtcTimeStamp( t, tzId) self.assertTrue(t > startOfToday) delta = t - startOfToday now = datetime.datetime.now() hourOffset = now.hour minOffset = now.minute secondOffset = now.second newDelta = hourOffset * 60 * 60 + minOffset * 60 + secondOffset self.assertTrue(abs(newDelta - delta) < 2)
def main_loop(tb): tb.set_next_freq() time.sleep(0.25) # Send location and system info to server loc_msg = tb.read_json_from_file('sensor.loc') sys_msg = tb.read_json_from_file('sensor.sys') ts = long(round(getLocalUtcTimeStamp())) sensor_id = tb.u.get_usrp_info()['rx_serial'] loc_msg['t'] = ts loc_msg['SensorID'] = sensor_id sys_msg['t'] = ts sys_msg['SensorID'] = sensor_id tb.post_msg(loc_msg) tb.post_msg(sys_msg) data_file_path = '/tmp/temp.dat' num_bands = len(tb.center_freq) pause_duration = tb.acq_period / num_bands - tb.dwell_delay n = 0 while 1: # Form data header ts = long(round(getLocalUtcTimeStamp())) if n == 0: t1s = ts center_freq = tb.center_freq[tb.band_ind] bandwidth = tb.bandwidth[tb.band_ind] f_start = center_freq - bandwidth / 2.0 f_stop = f_start + bandwidth mpar = Struct(fStart=f_start, fStop=f_stop, n=tb.num_ch, td=tb.dwell_delay, Det='Average', Atten=tb.atten) num_vectors_expected = int(tb.dwell_delay / tb.meas_duration) # Need to add a field for overflow indicator data_hdr = Struct( Ver='1.0.12', Type='Data', SensorID=sensor_id, SensorKey='NaN', t=ts, Sys2Detect='LTE', Sensitivity='Low', mType='FFT-Power', t1=t1s, a=n / num_bands + 1, nM=num_vectors_expected, Ta=tb.acq_period, OL='NaN', wnI=-77.0, Comment= 'Using hard-coded (not detected) system noise power for wnI', Processed='False', DataType='Binary - int8', ByteOrder='N/A', Compression='None', mPar=mpar) date_str = formatTimeStampLong(ts, loc_msg['TimeZone']) print date_str, "fc =", center_freq / 1e6, "MHz. Writing data to file..." # Execute flow graph and wait for it to stop f = open(data_file_path, 'wb') tb.set_fd(f.fileno()) tb.set_bin2ch_map(tb.bin2ch_map[tb.band_ind]) tb.start() tb.wait() # Check the number of power vectors generated and pad if necessary num_vectors_written = tb.stats.nitems_written(0) print '\nNum output items:', num_vectors_written if num_vectors_written != num_vectors_expected: print 'Warning: Unexpected number of power vectors generated' if num_vectors_written < num_vectors_expected: pad_len = (num_vectors_expected - num_vectors_written) * tb.num_ch pad = array.array('b', [127] * pad_len) f.write(pad.tostring()) f.close() # Post data file tb.post_data_msg(data_hdr, data_file_path) # Tune to next frequency and pause tb.set_next_freq() print "Pause..." time.sleep( max(0, ts + tb.acq_period / num_bands - getLocalUtcTimeStamp())) tb.head.reset() n += 1
def main_loop(tb): if not tb.set_freq(tb.center_freq): print "Failed to set frequency to", tb.center_freq sys.exit(1) print "Set frequency to", tb.center_freq / 1e6, "MHz\n" time.sleep(0.25) sensor_id = "HackRF" # Establish ssl socket connection to server r = requests.post('https://' + tb.dest_host + ':8443/sensordata/getStreamingPort/' + sensor_id, verify=False) print 'server response:', r.text response = r.json() print 'socket port =', response['port'] sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tb.s = s = ssl.wrap_socket( sock) #, ca_certs='dummy.crt', cert_reqs=ssl.CERT_NONE) s.connect((tb.dest_host, response['port'])) tb.set_sock(s) # Send location and system info to server loc_msg = tb.read_json_from_file('sensor.loc') sys_msg = tb.read_json_from_file('sensor.sys') ts = long(round(getLocalUtcTimeStamp())) sensor_key = sys_msg['SensorKey'] print 'Sensor Key', sensor_key #print 'Serial no.', sensor_id loc_msg['t'] = ts loc_msg['SensorID'] = sensor_id sys_msg['t'] = ts sys_msg['SensorID'] = sensor_id tb.send_obj(loc_msg) tb.send_obj(sys_msg) # Form data header ts = long(round(getLocalUtcTimeStamp())) f_start = tb.center_freq - tb.bandwidth / 2.0 if tb.avoid_LO: f_start = (tb.center_freq - tb.samp_rate / 4) - tb.bandwidth / 2.0 f_stop = f_start + tb.bandwidth if tb.avoid_LO: print "Avoiding LO, frequencies are shifted to: [", f_start / 1e6, "MHz-", f_stop / 1e6, "MHz ]" mpar = Struct(fStart=f_start, fStop=f_stop, n=tb.num_ch, td=-1, tm=tb.meas_duration, Det='Average', Atten=tb.atten) # Need to add a field for overflow indicator data = Struct( Ver='1.0.12', Type='Data', SensorID='HackRF', SensorKey='12345', t=ts, Sys2Detect='LTE', Sensitivity='Low', mType='FFT-Power', t1=ts, a=1, nM=-1, Ta=-1, OL='NaN', wnI=-77.0, Comment='Using hard-coded (not detected) system noise power for wnI', Processed='False', DataType='Binary - int8', ByteOrder='N/A', Compression='None', mPar=mpar) tb.send_obj(data) date_str = formatTimeStampLong(ts, loc_msg['TimeZone']) print date_str, "fc =", tb.center_freq / 1e6, "MHz. Sending data to", tb.dest_host # Start flow graph tb.start() tb.wait() tb.s.close() print 'Closed socket'
def __init__(self, num_ch, file_name, sensorLoc, sensorSys, sensor_id, sensor_key, center_freq, bandwidth, meas_duration, atten, samp_rate, avoid_LO): gr.sync_block.__init__(self, name="jsonfile_sink", in_sig=[(bytes, num_ch)], out_sig=None) # Establish ssl socket connection to server self.num_ch = num_ch # Open file for output stream self.file_name = file_name self.f = open(self.file_name, 'wb') self.srvr = blocks.file_descriptor_sink(self.num_ch * gr.sizeof_char, self.f.fileno()) self.sensorLoc = sensorLoc self.sensorSys = sensorSys self.sensor_id = sensor_id self.sensor_key = sensor_key self.center_freq = center_freq self.bandwidth = bandwidth self.meas_duration = meas_duration self.atten = atten self.samp_rate = samp_rate self.avoid = avoid_LO print("Sensor ID: ", self.sensor_id) # Send location and system info to server loc_msg = self.read_json_from_file(self.sensorLoc) sys_msg = self.read_json_from_file(self.sensorSys) ts = long(round(getLocalUtcTimeStamp())) print 'Serial no.', self.sensor_id loc_msg['t'] = ts loc_msg['SensorID'] = self.sensor_id sys_msg['t'] = ts sys_msg['SensorID'] = self.sensor_id self.post_msg(loc_msg) self.post_msg(sys_msg) # Form data header ts = long(round(getLocalUtcTimeStamp())) f_start = self.center_freq - self.bandwidth / 2.0 if self.avoid: #self.center_freq = self.center_freq + self.samp_rate/4.0 #print "Avoiding LO...\nShifting center Frequency to", self.center_freq f_start = (self.center_freq - self.samp_rate / 4) - self.bandwidth / 2.0 f_stop = f_start + self.bandwidth if self.avoid: print "Avoiding LO, frequencies are shifted to: [", f_start / 1e6, "MHz-", f_stop / 1e6, "MHz ]" mpar = Struct(fStart=f_start, fStop=f_stop, n=self.num_ch, td=-1, tm=self.meas_duration, Det='Average', Atten=self.atten) # Need to add a field for overflow indicator data_hdr = Struct( Ver='1.0.12', Type='Data', SensorID=self.sensor_id, SensorKey=self.sensor_key, t=ts, Sys2Detect='LTE', Sensitivity='Low', mType='FFT-Power', t1=ts, a=1, nM=-1, Ta=-1, OL='NaN', wnI=-77.0, Comment= 'Using hard-coded (not detected) system noise power for wnI', Processed='False', DataType='Binary - int8', ByteOrder='N/A', Compression='None', mPar=mpar) self.post_msg(data_hdr) self.f.flush() date_str = formatTimeStampLong(ts, loc_msg['TimeZone']) print date_str, "fc =", self.center_freq / 1e6, "MHz. Writing data to file", self.file_name
def main_loop(tb): if not tb.set_freq(tb.center_freq): print "Failed to set frequency to", tb.center_freq sys.exit(1) print "Set frequency to", tb.center_freq / 1e6, "MHz" time.sleep(0.25) # Open file for output stream f = open(tb.file_name, 'wb') tb.set_fd(f.fileno()) # Write location and system info to file loc_msg = tb.read_json_from_file('sensor.loc') sys_msg = tb.read_json_from_file('sensor.sys') ts = long(round(getLocalUtcTimeStamp())) sensor_id = tb.u.get_usrp_info()['rx_serial'] print 'Serial no.', sensor_id loc_msg['t'] = ts loc_msg['SensorID'] = sensor_id sys_msg['t'] = ts sys_msg['SensorID'] = sensor_id tb.post_msg(loc_msg, f) tb.post_msg(sys_msg, f) # Form data header ts = long(round(getLocalUtcTimeStamp())) f_start = tb.center_freq - tb.bandwidth / 2.0 f_stop = f_start + tb.bandwidth mpar = Struct(fStart=f_start, fStop=f_stop, n=tb.num_ch, td=-1, tm=tb.meas_duration, Det='Average', Atten=tb.atten) # Need to add a field for overflow indicator data_hdr = Struct( Ver='1.0.12', Type='Data', SensorID=sensor_id, SensorKey='NaN', t=ts, Sys2Detect='LTE', Sensitivity='Low', mType='FFT-Power', t1=ts, a=1, nM=-1, Ta=-1, OL='NaN', wnI=-77.0, Comment='Using hard-coded (not detected) system noise power for wnI', Processed='False', DataType='Binary - int8', ByteOrder='N/A', Compression='None', mPar=mpar) tb.post_msg(data_hdr, f) f.flush() date_str = formatTimeStampLong(ts, loc_msg['TimeZone']) print date_str, "fc =", tb.center_freq / 1e6, "MHz. Writing data to file", tb.file_name # Execute flow graph and wait for it to stop tb.start() tb.wait() f.close() tf = long(round(getLocalUtcTimeStamp())) date_str = formatTimeStampLong(tf, loc_msg['TimeZone']) print 'Closed file', date_str
def main_loop(tb): tb.set_next_freq() time.sleep(0.25) # Send location and system info to server loc_msg = tb.read_json_from_file('sensor.loc') sys_msg = tb.read_json_from_file('sensor.sys') ts = long(round(getLocalUtcTimeStamp())) sensor_id = tb.u.get_usrp_info()['rx_serial'] loc_msg['t'] = ts loc_msg['SensorID'] = sensor_id sys_msg['t'] = ts sys_msg['SensorID'] = sensor_id tb.post_msg(loc_msg) tb.post_msg(sys_msg) data_file_path = '/tmp/temp.dat' num_bands = len(tb.center_freq) pause_duration = tb.acq_period / num_bands - tb.dwell_delay n = 0 while 1: # Form data header ts = long(round(getLocalUtcTimeStamp())) if n==0: t1s = ts center_freq = tb.center_freq[tb.band_ind] bandwidth = tb.bandwidth[tb.band_ind] f_start = center_freq - bandwidth / 2.0 f_stop = f_start + bandwidth mpar = Struct(fStart=f_start, fStop=f_stop, n=tb.num_ch, td=tb.dwell_delay, Det='Average', Atten=tb.atten) num_vectors_expected = int(tb.dwell_delay / tb.meas_duration) # Need to add a field for overflow indicator data_hdr = Struct(Ver='1.0.12', Type='Data', SensorID=sensor_id, SensorKey='NaN', t=ts, Sys2Detect='LTE', Sensitivity='Low', mType='FFT-Power', t1=t1s, a=n/num_bands+1, nM=num_vectors_expected, Ta=tb.acq_period, OL='NaN', wnI=-77.0, Comment='Using hard-coded (not detected) system noise power for wnI', Processed='False', DataType = 'Binary - int8', ByteOrder='N/A', Compression='None', mPar=mpar) date_str = formatTimeStampLong(ts, loc_msg['TimeZone']) print date_str, "fc =", center_freq/1e6, "MHz. Writing data to file..." # Execute flow graph and wait for it to stop f = open(data_file_path,'wb') tb.set_fd(f.fileno()) tb.set_bin2ch_map(tb.bin2ch_map[tb.band_ind]) tb.start() tb.wait() # Check the number of power vectors generated and pad if necessary num_vectors_written = tb.stats.nitems_written(0) print '\nNum output items:', num_vectors_written if num_vectors_written != num_vectors_expected: print 'Warning: Unexpected number of power vectors generated' if num_vectors_written < num_vectors_expected: pad_len = (num_vectors_expected - num_vectors_written) * tb.num_ch pad = array.array('b', [127]*pad_len) f.write(pad.tostring()) f.close() # Post data file tb.post_data_msg(data_hdr, data_file_path) # Tune to next frequency and pause tb.set_next_freq() print "Pause..." time.sleep(max(0, ts + tb.acq_period / num_bands - getLocalUtcTimeStamp())) tb.head.reset() n += 1
def testGetLocalTimeFromUniversalTime(self): utc = timezone.getLocalUtcTimeStamp() localtime, tzName = timezone.getLocalTime(utc, tzId) now = time.time() self.assertTrue(abs(now - localtime) < 2)
def __init__(self, num_ch, dest_host, sensorLoc, sensorSys, sensor_id, sensor_key, center_freq, bandwidth, meas_duration, atten): gr.sync_block.__init__(self, name="sslsocket_sink", in_sig=[(bytes, num_ch)], out_sig=None) # Establish ssl socket connection to server self.num_ch = num_ch self.dest_host = dest_host self.sensorLoc = sensorLoc self.sensorSys = sensorSys self.sensor_id = sensor_id self.sensor_key = sensor_key self.center_freq = center_freq self.bandwidth = bandwidth self.meas_duration = meas_duration self.atten = atten r = requests.post('https://' + self.dest_host + ':8443/sensordata/getStreamingPort/' + self.sensor_id, verify=False) print 'server response:', r.text response = r.json() print 'socket port =', response['port'] sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock = ssl.wrap_socket(sock, cert_reqs=ssl.CERT_NONE) self.sock.connect((self.dest_host, response['port'])) print("Sensor ID: ", self.sensor_id) # Send location and system info to server loc_msg = self.read_json_from_file(self.sensorLoc) sys_msg = self.read_json_from_file(self.sensorSys) ts = long(round(getLocalUtcTimeStamp())) print 'Serial no.', self.sensor_id loc_msg['t'] = ts loc_msg['SensorID'] = self.sensor_id sys_msg['t'] = ts sys_msg['SensorID'] = self.sensor_id self.send_obj(loc_msg) self.send_obj(sys_msg) # Form data header ts = long(round(getLocalUtcTimeStamp())) f_start = self.center_freq - self.bandwidth / 2.0 f_stop = f_start + self.bandwidth mpar = Struct(fStart=f_start, fStop=f_stop, n=self.num_ch, td=-1, tm=self.meas_duration, Det='Average', Atten=self.atten) # Need to add a field for overflow indicator data = Struct( Ver='1.0.12', Type='Data', SensorID=self.sensor_id, SensorKey=self.sensor_key, t=ts, Sys2Detect='LTE', Sensitivity='Low', mType='FFT-Power', t1=ts, a=1, nM=-1, Ta=-1, OL='NaN', wnI=-77.0, Comment= 'Using hard-coded (not detected) system noise power for wnI', Processed='False', DataType='Binary - int8', ByteOrder='N/A', Compression='None', mPar=mpar) self.send_obj(data) date_str = formatTimeStampLong(ts, loc_msg['TimeZone']) print date_str, "fc =", self.center_freq / 1e6, "MHz. Sending data to", self.dest_host