Skip to content

Commit

Permalink
implemented #PA command see issue #71
Browse files Browse the repository at this point in the history
  • Loading branch information
kaufmanno committed Jul 4, 2017
1 parent 9704eeb commit 8a054c3
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 17 deletions.
32 changes: 20 additions & 12 deletions ardas/raspardas.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from struct import unpack_from
from threading import Thread, Lock
version = 'v1.1.2.32'
version = 'v1.1.2.33'
debug = True

local_host = '0.0.0.0'
Expand All @@ -29,6 +29,7 @@
calibration = []
calibration_file = ''
status = True
pause = False
base_path = path.dirname(__file__)
log_path = path.join(base_path, 'logs')
raw_path = path.join(base_path, 'raw')
Expand Down Expand Up @@ -71,7 +72,7 @@ def listen_slave():
the main thread ends.
"""
global stop, downloading, slave_io, data_queue, n_channels, debug, slave_queue, master_queue, raw_data, \
influxdb_logging, master_online
influxdb_logging, master_online, pause

while not stop:
# Read incoming data from slave (ArDAS)
Expand Down Expand Up @@ -131,7 +132,7 @@ def listen_slave():
cal_record += s % (instr[i], val[i], calibration[i]['unit'])
cal_record += '|\n'
slave_queue.put(cal_record.encode('utf-8'))
if influxdb_logging and not raw_data:
if influxdb_logging and not raw_data and not pause:
data = []
for i in range(n_channels):
data.append({'measurement': 'temperatures', 'tags': {'sensor': '%04d' %instr[i]},
Expand Down Expand Up @@ -220,7 +221,7 @@ def listen_master():
infinite loop, and only exit when
the main thread ends.
"""
global stop, master_connection, master_queue, master_online, raw_data
global stop, master_connection, master_queue, master_online, raw_data, pause

while not stop:
if master_online:
Expand Down Expand Up @@ -249,6 +250,12 @@ def listen_master():
elif msg[:-1] == b'#CF':
logging.info('Change file request')
save_file()
elif msg[:-1] == b'#PA':
if pause:
logging.info('Resume data logging')
else:
logging.info('Pause data logging')
pause = not pause
elif msg[:-1] == b'#RC':
raw_data = not raw_data
if raw_data:
Expand Down Expand Up @@ -304,21 +311,22 @@ def write_disk():
infinite loop, and only exit when
the main thread ends.
"""
global stop, sd_file_io, data_queue, sd_file_lock
global stop, sd_file_io, data_queue, sd_file_lock, pause

offset = sd_file_io.tell()
while not stop:
try:
msg = data_queue.get(timeout=0.1)
logging.debug('Data queue length : %d' % data_queue.qsize())
if len(msg) > 0:
logging.debug('Writing to disk :' + msg.decode('ascii'))
sd_file_lock.acquire()
sd_file_io.seek(offset)
sd_file_io.write(msg)
sd_file_io.flush()
offset = sd_file_io.tell()
sd_file_lock.release()
if not pause:
logging.debug('Writing to disk :' + msg.decode('ascii'))
sd_file_lock.acquire()
sd_file_io.seek(offset)
sd_file_io.write(msg)
sd_file_io.flush()
offset = sd_file_io.tell()
sd_file_lock.release()
except queue.Empty:
pass
sd_file_io.flush()
Expand Down
8 changes: 4 additions & 4 deletions ardas/sftp_transfert.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def download_from_remote():
remote_path = sys.argv[1]
local_path = sys.argv[2]
else:
logging.error('*** Arguments should be REMOTEPATH LOCALPATH')
sys.exit(1)
local_path = SFTP['local_path']
remote_path = SFTP['remote_path']
try:
s = sftp.Connection(host=SFTP['host'], username=SFTP['username'], password=SFTP['password'])
s.get(remote_path, local_path)
Expand All @@ -24,8 +24,8 @@ def upload_to_remote():
local_path = sys.argv[1]
remote_path = sys.argv[2]
else:
logging.error('*** Arguments should be LOCALPATH REMOTEPATH')
sys.exit(1)
local_path = SFTP['local_path']
remote_path = SFTP['remote_path']
try:
s = sftp.Connection(host=SFTP['host'], username=SFTP['username'], password=SFTP['password'])
s.put(local_path, remote_path)
Expand Down
39 changes: 39 additions & 0 deletions docs/source/commands.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Low level commands
==================

Raspardas uses a set of commands to communicate with the ardas.
It is possible to forward such commands through raspardas using a telnet connection using port 10001 or a direct
serial connection to the ardas is also possible but not recommended. Indeed, some of those commands are intercepted by
raspardas and processed before being forwarded to the ardas while other are only known to raspardas and have no effect
when sent directly to an ardas.

Note : Every data sequence send by an ardas is followed by \n\r (LFCR)
However each command end line sent to ardas must be \r (CR)

* -nnn : Call Das with netID nnn
* -999 : Call all Das

* #HE : Help
* #CF :
* #DG : Toggle ardas debug mode
* #E0 : No Echo
* #E1 : Only Data
* #E2 : Data + Time
* #ND : Set naïve data mode
* #RD : Set raspardas data mode
* #RC : Toggle between raw data and calibrated data
* #SD yyyy mm dd hh nn ss : Set Date
* #SR iiii : Set Integration Period
* #SI nnn : Set Das netID
* #SS ssss : Set Station Number
* #RI : Read Info
* #RV : Read version
* #ZR station netId integrationPeriod nbInst sensor1 ... code (Ex: #ZR 1111 222 3333 4 0001 0002 0003 0004 31): Reconfig
* #KL : Stop (Kill) raspardas and closes files

Some commands are no longer supported and will be removed in a future version:

* #ZF : erase memory and set default configuration
* #XB : Full Download
* #XP : yyyy mm dd hh ss yyyy mm dd hh nn ss : Partial Download
* #XS : Stop download
3 changes: 2 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to ardas's documentation!
Welcome to ardas documentation!
=================================

.. toctree::
Expand All @@ -12,6 +12,7 @@ Welcome to ardas's documentation!

parse_and_push_to_db
build_arduino_sketch
commands
settings

Indices and tables
Expand Down

0 comments on commit 8a054c3

Please sign in to comment.