Richard Hoekstra / Mbed 2 deprecated TLS2-Hoofdcontroller

Dependencies:   RPCInterface mbed

main.cpp

Committer:
RichardHoekstra
Date:
2016-11-13
Revision:
1:f36fa4e37849
Parent:
0:bb1b87ed61e6
Child:
2:c3918fd40472

File content as of revision 1:f36fa4e37849:

#include "mbed.h"
#include "mbed_rpc.h"
#include "SerialRPCInterface.h"
//Example
//RPCVariable<float>  RPCbrightness(&brightness, "brightness");

//Hoofdcontroller TODO:
//1. Switch tussen drukgestuurd en flowgestuurd
//2. Ondersteuning voor meerdere druksensors en temperatuur sensors
//3. Opvragen van recente sensor data voor het LabView gebruikersinterface
//4. I2C communicatie met andere controllers


//All the settings for the motor controller
int curveMode = 0;      //curveMode 0: constant 
                        //curveMode 1: sinusoid 
                        //curveMode 2: arterial
float control_frequency = 100;  //Hz The frequency at which the PID scheme is executing
float curve_frequency = 1;      //Hz The frequency of the curve/pulse
float min_val = 80;           //mmHg or mL/h
float max_val = 120;          //mmHg or mL/h
RPCVariable<int>    RPCcurveMode(&curveMode, "curveMode");
RPCVariable<float>  RPCcontrol_frequency(&control_frequency, "control_frequency");
RPCVariable<float>  RPCcurve_frequency(&curve_frequency, "curve_frequency");
RPCVariable<float>  RPCmin_val(&min_val, "min_val");
RPCVariable<float>  RPCmax_val(&max_val, "max_val");

//All the variables for the sensor controller
float sensor_pressure_frequency = 100; //Hz
float sensor_flow_frequency = 10; //Hz
RPCVariable<float> RPCsensor_pressure_frequency(&sensor_pressure_frequency, "sensor_pressure_frequency");
RPCVariable<float> RPCsensor_flow_frequency(&sensor_flow_frequency, "sensor_flow_frequency");





Serial pc(USBTX, USBRX);

//Handles all the RPC communication. 
//Taken from the example at developer.mbed.org/cookbook
void RPC(){
    static char buf[256], outbuf[256];
    pc.gets(buf, 256);
    //Call the static call method on the RPC class
    RPC::call(buf, outbuf); 
    pc.printf("%s\n", outbuf);
}

//Only sends an I2C command if settings have changed.
void sendUpdate(){
    static int      prev_curveMode = 0;
    static float    prev_frequency = 0,
                    prev_min_press = 0,
                    prev_max_press = 0;
    if(curveMode != prev_curveMode){
        prev_curveMode = curveMode;
        //TODO: Send I2C command to Motor Controller
        //i2c(motorController_address,curveMode)    
    }
    if(frequency != prev_frequency){
        prev_frequency = frequency;
        //TODO: Send I2C command to Motor Controller    
    }
    if(min_press != prev_min_press){
        prev_min_press = min_press;
        //TODO: Send I2C command to Motor Controller    
    }
    if(max_press != prev_max_press){
        prev_max_press = max_press;
        //TODO: Send I2C command to Motor Controller    
    }
}
int main() {    
    while(1) {
        RPC();
        sendUpdate();
        wait_ms(1);
    }
}