1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#include <iostream>
#include <stdio.h>
#include "MotorbarAmp.h"
#include <sstream>
using namespace std;
int main(int argc, char * argv[])
{
std::shared_ptr<MotorbarAmp> mb1;
std::shared_ptr<MotorbarAmp> mb2;
std::shared_ptr<MotorbarAmp> mb3;
bool initialized = false;
string line;
int choice = ' ';
cout << "Welcome to the motor control menu \n" << endl;
cout << "----------------------------------\n" << endl;
cout << "How many motors? " << endl;
string NumOfMotors;
getline(cin, NumOfMotors);
int MotNr = atoi(NumOfMotors.c_str());
while (choice != 'Q')
{
cout << "What would you like to do ? \n" << endl;
getline(cin, line);
choice = line[0];
switch (choice)
{
case 'i':
{
cout << "Initialization1 \n" << endl;
for (int i = 0; i < MotNr; i++)
{
if (i < 1)
{
//std::shared_ptr<MotorbarAmp> mb1;
bool initialized = false;
if (initialized)
{
mb1 = NULL;
}
int ipp[4] = { 200, 51, 254, 5 };
string ips;
cout << "enter IP address, or press enter to accept default (" << ipp[0] << "." << ipp[1] << "." << ipp[2] << "." << ipp[3] << ")" << endl;
getline(cin, ips);
if (ips.length() >= 7)
{
ipp[0] = atoi(ips.substr(0, ips.find('.', 0)).c_str());
ips = ips.substr(ips.find('.', 0) + 1, 50);
ipp[1] = atoi(ips.substr(0, ips.find('.', 0)).c_str());
ips = ips.substr(ips.find('.', 0) + 1, 50);
ipp[2] = atoi(ips.substr(0, ips.find('.', 0)).c_str());
ips = ips.substr(ips.find('.', 0) + 1, 50);
ipp[3] = atoi(ips.c_str());
}
uint32_t ip;
ip = (ipp[0] << 24) | (ipp[1] << 16) | (ipp[2] << 8) | ipp[3];
cout << "ip = " << ((ip & 0xff000000) >> 24) << "." << ((ip & 0xff0000) >> 16) << "." << ((ip & 0xff00) >> 8) << "." << (ip & 0xff) << endl;
mb1 = make_shared<MotorbarAmp>(ip);
initialized = true;
}
else if (0 > i < 2)
{
//std::shared_ptr<MotorbarAmp> mb2;
bool initialized = false;
if (initialized)
{
mb2 = NULL;
}
int ipp[4] = { 200, 51, 254, 5 };
string ips;
cout << "enter IP address, or press enter to accept default (" << ipp[0] << "." << ipp[1] << "." << ipp[2] << "." << ipp[3] << ")" << endl;
getline(cin, ips);
if (ips.length() >= 7)
{
ipp[0] = atoi(ips.substr(0, ips.find('.', 0)).c_str());
ips = ips.substr(ips.find('.', 0) + 1, 50);
ipp[1] = atoi(ips.substr(0, ips.find('.', 0)).c_str());
ips = ips.substr(ips.find('.', 0) + 1, 50);
ipp[2] = atoi(ips.substr(0, ips.find('.', 0)).c_str());
ips = ips.substr(ips.find('.', 0) + 1, 50);
ipp[3] = atoi(ips.c_str());
}
uint32_t ip;
ip = (ipp[0] << 24) | (ipp[1] << 16) | (ipp[2] << 8) | ipp[3];
cout << "ip = " << ((ip & 0xff000000) >> 24) << "." << ((ip & 0xff0000) >> 16) << "." << ((ip & 0xff00) >> 8) << "." << (ip & 0xff) << endl;
mb2 = make_shared<MotorbarAmp>(ip);
initialized = true;
}
else if (1 < i < MotNr)
{
//std::shared_ptr<MotorbarAmp> mb3;
bool initialized = false;
if (initialized)
{
mb3 = NULL;
}
int ipp[4] = { 200, 51, 254, 5 };
string ips;
cout << "enter IP address, or press enter to accept default (" << ipp[0] << "." << ipp[1] << "." << ipp[2] << "." << ipp[3] << ")" << endl;
getline(cin, ips);
if (ips.length() >= 7)
{
ipp[0] = atoi(ips.substr(0, ips.find('.', 0)).c_str());
ips = ips.substr(ips.find('.', 0) + 1, 50);
ipp[1] = atoi(ips.substr(0, ips.find('.', 0)).c_str());
ips = ips.substr(ips.find('.', 0) + 1, 50);
ipp[2] = atoi(ips.substr(0, ips.find('.', 0)).c_str());
ips = ips.substr(ips.find('.', 0) + 1, 50);
ipp[3] = atoi(ips.c_str());
}
uint32_t ip;
ip = (ipp[0] << 24) | (ipp[1] << 16) | (ipp[2] << 8) | ipp[3];
cout << "ip = " << ((ip & 0xff000000) >> 24) << "." << ((ip & 0xff0000) >> 16) << "." << ((ip & 0xff00) >> 8) << "." << (ip & 0xff) << endl;
mb3 = make_shared<MotorbarAmp>(ip); //<<<- I NEED THIS TO CREATE THREE instances running of <MotorbarAmp>
initialized = true;
}
}
}
case 'C':
{
cout << "Which motor do you want to calibrate? \n" << endl;
//cin >> q;
if (initialized)
{
cout << "Performing calibration \n" << endl;
mb1->Calibrate();
}
else
{
cout << "Motor bar not initialized yet \n" << endl;
}
break;
}
return(0);
}
}
}
| |