Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 397 → Rev 399

/QMK-Groundstation/branches/own_com_lib/com/Communication.cpp
0,0 → 1,5
#include "Communication.h"
 
bool Communication::is_connected() {
return connected;
}
/QMK-Groundstation/branches/own_com_lib/com/Communication.h
9,6 → 9,8
using namespace std;
 
class Communication{
protected:
bool connected;
public:
//connect to MK
virtual void connect_MK(string) {};
15,5 → 17,7
//send command to MK
virtual bool send_cmd(char, int, char[150],unsigned int, bool) { return false; };
virtual void stop_resend() {};
bool is_connected();
};
#endif
/QMK-Groundstation/branches/own_com_lib/com/Handler.cpp
7,7 → 7,35
this->com = com;
}
 
//-------------FlightCtrl commands--------------------
/**
* read settings from FlightCtrl (settings index 0x00-0x05)
*/
void Handler::get_flightctrl_settings(int index) {
char tx_data[2] = {index, 0};
com->send_cmd('q', ADDRESS_FC, tx_data, 1, true);
}
 
/**
* write settings to FlightCtrl
*/
void Handler::set_flightctrl_settings(char * tx_data) {
com->send_cmd('s', ADDRESS_FC, tx_data, MaxParameter+2, true);
}
 
/**
* test one or more motors
*/
void Handler::motor_test(sMotor motor) {
char tx_data[12];
for (int z = 0; z<12; z++)
{
tx_data[z] = motor.Speed[z];
}
com->send_cmd('t', ADDRESS_FC, tx_data, 12, false);
}
 
/**
* read mixer values from FlightCtrl
*/
void Handler::read_mixer() {
16,9 → 44,140
com->send_cmd('n', ADDRESS_FC, tx_data, 1, true);
}
 
/**
* write motor mixer values to FlightCtrl
*/
void Handler::write_mixer(char * tx_data, int length) {
com->send_cmd('m', ADDRESS_FC, tx_data, length, true);
}
 
void Handler::get_motor_config() {
}
 
//-------------NaviCtrl commands--------------------
/**
* set debug values for NaviCtrl
*/
void Handler::set_navictrl_debug(int speed) {
char tx_data[1] = { speed };
com->send_cmd('o', ADDRESS_NC, tx_data, 1, false);
}
 
/**
* stop debug for NaviCtrl
*/
void Handler::stop_navictrl_debug() {
set_navictrl_debug(0);
}
 
/**
* send a waypoint to the NaviCtrl (the copter will fly to the position emidiately)
*/
void Handler::send_waypoint(Waypoint_t desired_pos) {
com->send_cmd('s', ADDRESS_NC, (char *)&desired_pos, sizeof(desired_pos), false);
}
 
/**
* add waypoint to waypoint list
*/
void Handler::add_waypoint(Waypoint_t wp) {
com->send_cmd('w', ADDRESS_NC, (char *)&wp, sizeof(wp), false);
}
 
/**
* clear waypoint list on MK
*/
void Handler::delete_waypoints() {
Waypoint_t wp;
wp.Position.Status = INVALID;
send_waypoint(wp);
}
//-------------switch between Hardware--------------------
void Handler::switch_navictrl() {
char tx_data[6] = { 0x1B, 0x1B, 0x55, 0xAA, 0x00, '\r'};
com->send_cmd('#', ADDRESS_NC, tx_data, 6, false);
}
 
void Handler::switch_flightctrl() {
char tx_data[1] = { 0 };
com->send_cmd('u', ADDRESS_NC, tx_data, 1, false);
}
 
void Handler::switch_mk3mag() {
char tx_data[1] = { 1 };
com->send_cmd('u', ADDRESS_NC, tx_data, 1, false);
}
 
//-------------commands for MK3MAG-----------------
 
 
//-------------commands for all--------------------
 
/**
* set debug values for all components
*/
void Handler::set_all_debug(int speed) {
char tx_data[1] = { speed };
com->send_cmd('d', ADDRESS_ALL, tx_data, 1, false);
}
 
/**
* stop debug for all components
*/
void Handler::stop_all_debug() {
set_all_debug(0);
}
 
/**
* get all analog labels
*/
void Handler::get_analog() {
char tx_data[1] = { 0 };
com->send_cmd('a', ADDRESS_ALL, tx_data, 1, true);
}
 
/**
* get values from LCD / show LCD
*/
void Handler::show_lcd() {
char tx_data[1] = {0};
com->send_cmd('l', ADDRESS_ALL, tx_data, 1, true);
}
 
/**
* got to next LCD Page
*/
void Handler::lcd_up() {
char tx_data[2] = { 0, 0 };
if (lcd_cur != lcd_max)
tx_data[0] = lcd_cur+1;
com->send_cmd('l', ADDRESS_ALL, tx_data, 1, true);
}
 
/**
* got to previous LCD Page
*/
void Handler::lcd_down() {
char tx_data[2] = { 0, 0 };
if (lcd_cur != 0)
tx_data[0] = lcd_cur-1;
com->send_cmd('l', ADDRESS_ALL, tx_data, 1, true);
}
 
void Handler::get_version() {
//TODO: Check if is this correct or do we need data from switch_...
char tx_data[1] = { 0 };
com->send_cmd('v', ADDRESS_ALL, tx_data, 0, true);
}
 
void Handler::get_ppm_channels() {
char tx_data[1] = { 0 };
com->send_cmd('p', ADDRESS_ALL, tx_data, 0, false);
}
 
/**
* receive data
*/
void Handler::receive_data(sRxData RX) {
//extract hardware ID from received Data
int hardwareID = RX.input[1] - 'a';
/QMK-Groundstation/branches/own_com_lib/com/Handler.h
5,6 → 5,7
#include "Communication.h"
#include "Kopter.h"
#include "../Parameter_Positions.h"
#include "../typedefs.h"
 
/**
* The Handler handels commands that are send from/to the Mikrokopter
15,13 → 16,48
private:
Communication * com;
 
// current LCD page
int lcd_cur;
//max count of LCD pages
int lcd_max;
//buffer to send data
//char tx_data[150];
public:
Handler(Communication * com);
//FlightCtrl commands
void get_flightctrl_settings(int index);
void set_flightctrl_settings(char * tx_data);
void motor_test(sMotor motor);
void read_mixer();
void write_mixer(char * tx_data, int length);
void get_motor_config();
 
//NaviCtrl commands
void set_navictrl_debug(int speed);
void stop_navictrl_debug();
void send_waypoint(Waypoint_t desired_pos);
void add_waypoint(Waypoint_t wp);
void delete_waypoints();
 
//switch between MK modules/components
void switch_navictrl();
void switch_flightctrl();
void switch_mk3mag();
 
//commands for MK3MAG
 
//commands for all modules/components
void set_all_debug(int speed);
void stop_all_debug();
void get_analog();
void show_lcd();
void lcd_up();
void lcd_down();
void get_version();
void get_ppm_channels();
 
void receive_data(sRxData rx);
void get_motor_config();
};
 
#endif
/QMK-Groundstation/branches/own_com_lib/com/QTCommunication.cpp
14,6 → 14,10
return true;
};
 
/**
* stop sending commands to Mikrokopter
* stop timer
*/
void QTCommunication::stop_resend() {
};