|
def | __init__ (self, name, q, lock, fileLockDict, syncTimeFunc, dataDir, stopEvt) |
|
def | getFormattedRow (self, row) |
|
def | createDataFile (self, outFile) |
|
def | decodeADCCID (self, coded) |
|
def | getFile (self, row) |
|
def | releaseFile (self, filename) |
|
def | do_work (self, thing) |
|
def | run (self) |
|
def master.WriterThread.__init__ |
( |
|
self, |
|
|
|
name, |
|
|
|
q, |
|
|
|
lock, |
|
|
|
fileLockDict, |
|
|
|
syncTimeFunc, |
|
|
|
dataDir, |
|
|
|
stopEvt |
|
) |
| |
Consumer class instanciation:
The Writer thread implements the consumer in the producer/consumer paradigm.
The number of threads created is not known by the individual threads. They
simply pop things off the shared thread-safe queue, extract the data, and
write to the correct data (csv) file, creating it and the data directory if needed.
The file names for the data files are created from the data elts themselves, in combination
with the information obtained by callingthe syncTimeFunc provided as argument.
Data file names are used as keys in the shared fileLockDict, whre the values are semaphores
ensuring unique access to each file.
@param self
@param name a string naming the thread, legacy but left to allow for easier debugging
@param q the thread-safe q which will be popped to get data
@param lock the semaphore ensure unique access to the fileLockDict
@param dataDir the path to the data directory
@param syncTimeFunc a function that will be called to get the synch time to be used
in naming the data files.
#param stopEvt an event that is set in case this thread has detected
a failure contidition
def master.WriterThread.createDataFile |
( |
|
self, |
|
|
|
outFile |
|
) |
| |
Called to create the data csv file and write the header row.
def master.WriterThread.decodeADCCID |
( |
|
self, |
|
|
|
coded |
|
) |
| |
Decodes the ADC and Channel values which were encoded onto a single byte such that
the top 4 bits are the ADC id, and the lower four are the channel id.
@param coded a single byte containing the encoded values
@return a list as decoded into [ADC_ID, Channel_ID]
def master.WriterThread.do_work |
( |
|
self, |
|
|
|
thing |
|
) |
| |
This method handles the 'consuming' of the thing popped from the queue.
After obtaining a lock for the appropriate data file, a csv row is written,
the lock is released.
@param the object popped from the queue, in our case a list of length 4:
ADCCID,Timestamp,value, Board_ID
def master.WriterThread.getFile |
( |
|
self, |
|
|
|
row |
|
) |
| |
the filename is computed, then the dictLock is acquired to access the fileLockDict and
get a lock for the data file, creating the lock if needed.
the dictLock is released and the fileLock is aquire before returning
@param row the data to be used to get the file name
def master.WriterThread.getFormattedRow |
( |
|
self, |
|
|
|
row |
|
) |
| |
Formats a row by rounding the float values to 4 decimals
@param row the data row,
@return the row as a list ready to be written to the csv data file.
def master.WriterThread.releaseFile |
( |
|
self, |
|
|
|
filename |
|
) |
| |
Simply releases the fileLock
def master.WriterThread.run |
( |
|
self | ) |
|
Thread run method. pops the queue, sends the popped thing to be consumed.
if a None value is popped, the method exits properply and the thread ends.
master.WriterThread.dataDir |
path to the data file target directory
master.WriterThread.dictLock |
semaphore for exclusive access to the fileLockDict
master.WriterThread.fileLock |
semaphore locking access to the file currently being written
master.WriterThread.fileLockDict |
master.WriterThread.getSynchTimeFunc |
function which when called will return the synchronisation time of the boards
string name of the thread, used for debugging or information messages
work q, source of data to be written to files
master.WriterThread.stopEvent |
setting this event cause the main program to exit
The documentation for this class was generated from the following file:
- /home/bob/Desktop/temp/Yannick/PhD_Support/temp/SPI/RPI/Python/serialApp/master.py