Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ros_lib_kinetic
LLComms.h
- Committer:
- WD40andTape
- Date:
- 2019-03-13
- Revision:
- 33:9877ca32e43c
- Parent:
- 29:10a5cf37a875
- Child:
- 34:54e9ebe9e87f
File content as of revision 33:9877ca32e43c:
// LLComms.h
#ifndef LLCOMMS_H
#define LLCOMMS_H
// STANDARD IMPORTS
#include "math.h"
#include <algorithm>
// MBED IMPORTS
#include "mbed.h"
#include "mbed_events.h"
// CUSTOM IMPORTS
#include "MLSettings.h"
// ADC SPI DEFINES
#define PREAMBLE 0x06
#define CHAN_1 0x30
#define CHAN_2 0x70
#define CHAN_3 0xB0
#define CHAN_4 0xF0
#define DATA_MASK 0x0F
class LLComms
{
public:
EventQueue queue;
Mutex mutChannel[N_CHANNELS];
bool isDataReady[N_CHANNELS]; // Flag to indicate path data is ready for transmission to low level.
double demandPosition_mm[N_CHANNELS];
double demandSpeed_mmps[N_CHANNELS];
char chrErrorFlag[N_CHANNELS]; // 3 error bits from LL
unsigned int positionSensor_uint[N_CHANNELS];
double positionSensor_mm[N_CHANNELS]; // The actual chamber lengths in meters given as the change in length relative to neutral (should always be >=0)
unsigned int pressureSensor_uint[N_CHANNELS];
double pressureSensor_bar[N_CHANNELS]; // The pressure in a given chamber in bar (1 bar = 100,000 Pa)
LLComms(); // Constructor
//~LLComms(); // Destructor
private:
// PIN DECLARATIONS
InterruptIn pinGate6; // This pin HAS TO BE defined before SPI set up. No Clue Why.
SPI spi_0; // mosi, miso, sclk
SPI spi_1;
DigitalOut* cs_LL[N_CHANNELS]; // Chip select for low level controller
DigitalOut* cs_ADC[N_CHANNELS]; // Chip select for ADC
// These interrupt pins have to be declared AFTER SPI declaration. No Clue Why.
InterruptIn pinGate0;
InterruptIn pinGate1;
InterruptIn pinGate2;
InterruptIn pinGate3;
InterruptIn pinGate4;
InterruptIn pinGate5;
InterruptIn pinGate7;
DigitalOut pinReset; // Reset pin for all controllers.
int ThreadID[N_CHANNELS];
unsigned int formatMessage(short int type, double dblValue, double dblMaxValue);
//bool CheckMessage(int msg, short int trueType);
bool CheckMessage(int msg);
bool PerformMasterSPI(SPI *spi, unsigned int outboundMsgs[], unsigned int inboundMsgsData[]);
void SendReceiveData(int channel);
void common_rise_handler(int channel);
void common_fall_handler(int channel);
void rise0(void);
void rise1(void);
void rise2(void);
void rise3(void);
void rise4(void);
void rise5(void);
void rise6(void);
void rise7(void);
void fall0(void);
void fall1(void);
void fall2(void);
void fall3(void);
void fall4(void);
void fall5(void);
void fall6(void);
void fall7(void);
};
#endif