Program for the water play project for the course Software Testing Practical 2016 given at the VU University

Dependencies:   mbed DRV88255 TextLCD Ping mbed-rtos

Committer:
sbouber1
Date:
Fri Jun 24 13:51:42 2016 +0000
Revision:
80:38e274c4dafa
Parent:
57:8dc3192ff150
final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sbouber1 9:b3674516729d 1 #ifndef __CONTROLLER_H__
sbouber1 9:b3674516729d 2 #define __CONTROLLER_H__
sbouber1 9:b3674516729d 3
sbouber1 10:fd4670ec0806 4 #include <string>
sbouber1 10:fd4670ec0806 5
sbouber1 10:fd4670ec0806 6 #include "rtos.h"
sbouber1 10:fd4670ec0806 7
sbouber1 39:cb67926712d4 8 /** The base class for everything which interfaces with sensors or actuators.
sbouber1 57:8dc3192ff150 9 * Extending classes must implement \a std::string \a getName() and \a void \a update()
sbouber1 39:cb67926712d4 10 */
sbouber1 9:b3674516729d 11 class Controller {
sbouber1 9:b3674516729d 12 public:
sbouber1 39:cb67926712d4 13
sbouber1 39:cb67926712d4 14 /**
sbouber1 39:cb67926712d4 15 * Initializes the Controller.
sbouber1 39:cb67926712d4 16 * @param threaded whether or not the controller should be threaded.
sbouber1 39:cb67926712d4 17 * @param interval_ms delay between each iteration, only if threaded is set to \a true.
sbouber1 39:cb67926712d4 18 */
sbouber1 10:fd4670ec0806 19 Controller(bool threaded, int interval_ms);
sbouber1 10:fd4670ec0806 20
sbouber1 39:cb67926712d4 21 /**
sbouber1 39:cb67926712d4 22 * Returns the name of this Controller. Must be implemented by extending classes.
sbouber1 39:cb67926712d4 23 * @return The name of this Controller.
sbouber1 39:cb67926712d4 24 */
sbouber1 57:8dc3192ff150 25 virtual std::string getName() = 0;
sbouber1 10:fd4670ec0806 26
sbouber1 39:cb67926712d4 27 /**
sbouber1 39:cb67926712d4 28 * Returns whether or not this Controller is being threaded.
sbouber1 39:cb67926712d4 29 * @return \a true if this Controller is being threaded, \a false otherwise.
sbouber1 39:cb67926712d4 30 */
sbouber1 57:8dc3192ff150 31 bool isThreaded();
sbouber1 39:cb67926712d4 32
sbouber1 39:cb67926712d4 33 /**
sbouber1 39:cb67926712d4 34 * If this Controller is not threaded, \a update() is called. Otherwise, the first time a thread is spawned which repeatedly calls \a update().
sbouber1 39:cb67926712d4 35 * When the thread has already been spawned no action is taken.
sbouber1 39:cb67926712d4 36 */
sbouber1 10:fd4670ec0806 37 void run();
sbouber1 39:cb67926712d4 38
sbouber1 39:cb67926712d4 39 /**
sbouber1 39:cb67926712d4 40 * Returns the interval between each iteration if threaded.
sbouber1 39:cb67926712d4 41 * @return \a interval_ms as specified in the constructor.
sbouber1 39:cb67926712d4 42 */
sbouber1 57:8dc3192ff150 43 int getIntervalMs();
sbouber1 39:cb67926712d4 44
sbouber1 39:cb67926712d4 45 /**
sbouber1 39:cb67926712d4 46 * Sets the underlying RTOS thread priority.
sbouber1 39:cb67926712d4 47 * @see cmis_os.h
sbouber1 39:cb67926712d4 48 */
sbouber1 57:8dc3192ff150 49 void setPriority(osPriority priority);
sbouber1 39:cb67926712d4 50
sbouber1 39:cb67926712d4 51 /**
sbouber1 39:cb67926712d4 52 * Returns the thread priority.
sbouber1 39:cb67926712d4 53 * @return the thread priority.
sbouber1 39:cb67926712d4 54 */
sbouber1 57:8dc3192ff150 55 osPriority getPriority();
sbouber1 38:930469a33001 56
sbouber1 38:930469a33001 57 protected:
sbouber1 53:4e3ee54157ad 58 /**
sbouber1 53:4e3ee54157ad 59 * Updates the Controller. This is called once every \a interval_ms if \a threaded is set to \a true.
sbouber1 53:4e3ee54157ad 60 */
sbouber1 38:930469a33001 61 virtual void update() = 0;
sbouber1 38:930469a33001 62
sbouber1 39:cb67926712d4 63 /**
sbouber1 39:cb67926712d4 64 * The number of times \a run() is called.
sbouber1 39:cb67926712d4 65 */
sbouber1 38:930469a33001 66 unsigned long num_iters;
sbouber1 10:fd4670ec0806 67
sbouber1 10:fd4670ec0806 68 private:
sbouber1 39:cb67926712d4 69 /**
sbouber1 39:cb67926712d4 70 * Whether or not this Controller is threaded.
sbouber1 39:cb67926712d4 71 */
sbouber1 10:fd4670ec0806 72 bool threaded;
sbouber1 39:cb67926712d4 73
sbouber1 39:cb67926712d4 74 /**
sbouber1 39:cb67926712d4 75 * Whether or not a thread has been spawned for this Controller.
sbouber1 39:cb67926712d4 76 */
sbouber1 10:fd4670ec0806 77 bool has_spawned;
sbouber1 39:cb67926712d4 78
sbouber1 39:cb67926712d4 79 /**
sbouber1 39:cb67926712d4 80 * Pointer to the spawned thread if \a has_spawned is \a true, undefined otherwise.
sbouber1 39:cb67926712d4 81 */
sbouber1 10:fd4670ec0806 82 Thread *ctrl_thread;
sbouber1 39:cb67926712d4 83
sbouber1 39:cb67926712d4 84 /**
sbouber1 39:cb67926712d4 85 * Interval in ms between each iteration, only if \a threaded is set to \a true.
sbouber1 39:cb67926712d4 86 */
sbouber1 10:fd4670ec0806 87 int interval_ms;
sbouber1 39:cb67926712d4 88
sbouber1 39:cb67926712d4 89 /**
sbouber1 39:cb67926712d4 90 * Priority of the underlying thread.
sbouber1 39:cb67926712d4 91 */
sbouber1 10:fd4670ec0806 92 osPriority prio;
sbouber1 10:fd4670ec0806 93
sbouber1 39:cb67926712d4 94 /**
sbouber1 39:cb67926712d4 95 * This function is called when the thread is created, it repeatedly calls \a run() and waits for \a interval_ms milliseconds.
sbouber1 39:cb67926712d4 96 */
sbouber1 57:8dc3192ff150 97 static void threadStub(void const *args);
sbouber1 9:b3674516729d 98 };
sbouber1 9:b3674516729d 99
sbouber1 9:b3674516729d 100 #endif