/Types/* added
This commit is contained in:
parent
7f3e5fc0d9
commit
ad92736b74
18 changed files with 306 additions and 81 deletions
|
@ -21,11 +21,11 @@
|
||||||
//#include <linux/if_link.h>
|
//#include <linux/if_link.h>
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
#include "Host.h"
|
#include "Host.h"
|
||||||
#include "Types.h"
|
#include "Types/Types.h"
|
||||||
#include "Types/bytes.h"
|
//#include "bytes.h"
|
||||||
|
|
||||||
macAddr Host::getMac() {
|
macAddr Host::getMac() {
|
||||||
macAddr ret { 0x08, 0x3e, 0x8e, 0x16, 0x17, 0x2c }; //TODO find actual MAC Address
|
macAddr ret { 0x6a,0x49,0x16,0x17,0x2e,0x8d }; //TODO find actual MAC Address
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#ifndef HOST_H_
|
#ifndef HOST_H_
|
||||||
#define HOST_H_
|
#define HOST_H_
|
||||||
|
|
||||||
#include "Types.h"
|
#include "Types/Types.h"
|
||||||
|
|
||||||
class Host {
|
class Host {
|
||||||
public:
|
public:
|
||||||
|
|
65
src/Lookup.h
Normal file
65
src/Lookup.h
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
* Switch.cpp
|
||||||
|
*
|
||||||
|
* Created on: 29.09.2015
|
||||||
|
* Author: jdi
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <boost/bimap.hpp>
|
||||||
|
|
||||||
|
class lookupTable: public boost::bimap<short, std::string> {
|
||||||
|
struct set{
|
||||||
|
short n;
|
||||||
|
std::string s;
|
||||||
|
};
|
||||||
|
public:
|
||||||
|
lookupTable(std::initializer_list<set> l) {
|
||||||
|
for (set s : l) {
|
||||||
|
this->left[s.n]=s.s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const short& operator[](std::string s){
|
||||||
|
return this->right[s];
|
||||||
|
}
|
||||||
|
const std::string& operator[](short n){
|
||||||
|
return this->left[n];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static lookupTable rcv_lookup = { { 1, "type" }, //string
|
||||||
|
{ 2, "hostname" }, //string
|
||||||
|
{ 3, "mac" }, //byte[6]
|
||||||
|
{ 4, "ip_addr" }, //byte[4]
|
||||||
|
{ 5, "ip_mask" }, //byte[4]
|
||||||
|
{ 6, "gateway" }, //byte[4]
|
||||||
|
{ 7, "firmware_version" }, //string
|
||||||
|
{ 8, "hardware_version" }, //string
|
||||||
|
{ 9, "dhcp" }, //bool byte
|
||||||
|
{ 8704, "802.1q vlan" }, //???
|
||||||
|
//{0000," "},
|
||||||
|
};
|
||||||
|
|
||||||
|
static lookupTable snd_lookup = {
|
||||||
|
|
||||||
|
// TODO find out if id is unique in response
|
||||||
|
{ 10, "???" }, //after login
|
||||||
|
{ 2, "???" }, //after login
|
||||||
|
{ 512, "login_user" }, //string
|
||||||
|
{ 513, "new_user" }, //string
|
||||||
|
{ 514, "login_password" }, //string
|
||||||
|
{ 515, "new_passwoord" }, //string
|
||||||
|
{ 2200, "vlan" },
|
||||||
|
{ 2305, "???" }, //sent before login and before change hostname
|
||||||
|
{ 4608, "port_trunk" }, //byte[5] last byte bitmask??
|
||||||
|
{ 8192, "mtu_vlan" }, //byte[2] first byte bool, second byte port id
|
||||||
|
{ 8449, "port_vlan" }, //???
|
||||||
|
|
||||||
|
{ 8704, "802.1q vlan" }, //??? get vlan / set status
|
||||||
|
{ 8705, "802.1q vlan" }, //???
|
||||||
|
{ 8706, "802.1q vlan pvid" }, //????
|
||||||
|
|
||||||
|
{ 12288, "QoS Basic" }, //bool = QoS Mod
|
||||||
|
{ 16640, "port_mirror" }, //byte[10] second byte port id??
|
||||||
|
{ 17152, "loop_prevention" }, //bool byte
|
||||||
|
//{0000," "},
|
||||||
|
};
|
|
@ -8,7 +8,7 @@
|
||||||
#ifndef OPTIONS_H_
|
#ifndef OPTIONS_H_
|
||||||
#define OPTIONS_H_
|
#define OPTIONS_H_
|
||||||
|
|
||||||
#include "Types.h"
|
#include "Types/Types.h"
|
||||||
|
|
||||||
#define VERSION "smrtlink (v1 Linux)\n"
|
#define VERSION "smrtlink (v1 Linux)\n"
|
||||||
#define USAGE "usage: %s [-bhrvx] [-i interface] [-u [password:]username]\n\
|
#define USAGE "usage: %s [-bhrvx] [-i interface] [-u [password:]username]\n\
|
||||||
|
|
|
@ -9,9 +9,7 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include "Packet.h"
|
#include "Packet.h"
|
||||||
#include "Types.h"
|
#include "Types/Types.h"
|
||||||
#include "Types/bytes.h"
|
|
||||||
#include "Types/datasets.h"
|
|
||||||
|
|
||||||
Packet::Packet(OpCode c) {
|
Packet::Packet(OpCode c) {
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
@ -22,7 +20,7 @@ Packet::Packet(OpCode c) {
|
||||||
void Packet::printHeader() {
|
void Packet::printHeader() {
|
||||||
std::cout << "Header:\n";
|
std::cout << "Header:\n";
|
||||||
std::cout << "\tID:\t\t" << sequenceId << "\n";
|
std::cout << "\tID:\t\t" << sequenceId << "\n";
|
||||||
std::cout << "\tVersion:\t" << version << "\n";
|
std::cout << "\tVersion:\t" << (int) version << "\n";
|
||||||
std::cout << "\tError:\t\t" << errorCode << "\n";
|
std::cout << "\tError:\t\t" << errorCode << "\n";
|
||||||
std::cout << "\tSwitch MAC:\t" << switchMac << "\n";
|
std::cout << "\tSwitch MAC:\t" << switchMac << "\n";
|
||||||
std::cout << "\tHost MAC: \t" << hostMac << "\n";
|
std::cout << "\tHost MAC: \t" << hostMac << "\n";
|
||||||
|
@ -34,8 +32,8 @@ void Packet::printHeader() {
|
||||||
|
|
||||||
bytes Packet::getBytes() {
|
bytes Packet::getBytes() {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (unsigned j = 0; j < payload.size(); j++)
|
for (auto d : payload)
|
||||||
push(body, i, payload[j]);
|
push(body, i, d.second);
|
||||||
push(body, i, (int) PACKET_END);
|
push(body, i, (int) PACKET_END);
|
||||||
i = 0;
|
i = 0;
|
||||||
push(head, i, version);
|
push(head, i, version);
|
||||||
|
@ -133,7 +131,7 @@ const datasets& Packet::getPayload() const {
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Packet::setPayload(const datasets& payload) {
|
void Packet::setPayload(datasets payload) {
|
||||||
this->payload = payload;
|
this->payload = payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,24 +155,24 @@ std::string Packet::opCodeToString() {
|
||||||
|
|
||||||
void Packet::encode(bytes &data) {
|
void Packet::encode(bytes &data) {
|
||||||
int len = data.size();
|
int len = data.size();
|
||||||
bytes key = { 191, 155, 227, 202, 99, 162, 79, 104, 49,
|
bytes key = { 191, 155, 227, 202, 99, 162, 79, 104, 49, 18, 190, 164, 30,
|
||||||
18, 190, 164, 30, 76, 189, 131, 23, 52, 86, 106, 207, 125, 126, 169,
|
76, 189, 131, 23, 52, 86, 106, 207, 125, 126, 169, 196, 28, 172, 58,
|
||||||
196, 28, 172, 58, 188, 132, 160, 3, 36, 120, 144, 168, 12, 231, 116,
|
188, 132, 160, 3, 36, 120, 144, 168, 12, 231, 116, 44, 41, 97, 108,
|
||||||
44, 41, 97, 108, 213, 42, 198, 32, 148, 218, 107, 247, 112, 204, 14,
|
213, 42, 198, 32, 148, 218, 107, 247, 112, 204, 14, 66, 68, 91, 224,
|
||||||
66, 68, 91, 224, 206, 235, 33, 130, 203, 178, 1, 134, 199, 78, 249,
|
206, 235, 33, 130, 203, 178, 1, 134, 199, 78, 249, 123, 7, 145, 73,
|
||||||
123, 7, 145, 73, 208, 209, 100, 74, 115, 72, 118, 8, 22, 243, 147,
|
208, 209, 100, 74, 115, 72, 118, 8, 22, 243, 147, 64, 96, 5, 87, 60,
|
||||||
64, 96, 5, 87, 60, 113, 233, 152, 31, 219, 143, 174, 232, 153, 245,
|
113, 233, 152, 31, 219, 143, 174, 232, 153, 245, 158, 254, 70, 170,
|
||||||
158, 254, 70, 170, 75, 77, 215, 211, 59, 71, 133, 214, 157, 151, 6,
|
75, 77, 215, 211, 59, 71, 133, 214, 157, 151, 6, 46, 81, 94, 136,
|
||||||
46, 81, 94, 136, 166, 210, 4, 43, 241, 29, 223, 176, 67, 63, 186,
|
166, 210, 4, 43, 241, 29, 223, 176, 67, 63, 186, 137, 129, 40, 248,
|
||||||
137, 129, 40, 248, 255, 55, 15, 62, 183, 222, 105, 236, 197, 127,
|
255, 55, 15, 62, 183, 222, 105, 236, 197, 127, 54, 179, 194, 229,
|
||||||
54, 179, 194, 229, 185, 37, 90, 237, 184, 25, 156, 173, 26, 187,
|
185, 37, 90, 237, 184, 25, 156, 173, 26, 187, 220, 2, 225, 0, 240,
|
||||||
220, 2, 225, 0, 240, 50, 251, 212, 253, 167, 17, 193, 205, 177, 21,
|
50, 251, 212, 253, 167, 17, 193, 205, 177, 21, 181, 246, 82, 226,
|
||||||
181, 246, 82, 226, 38, 101, 163, 182, 242, 92, 20, 11, 95, 13, 230,
|
38, 101, 163, 182, 242, 92, 20, 11, 95, 13, 230, 16, 121, 124, 109,
|
||||||
16, 121, 124, 109, 195, 117, 39, 98, 239, 84, 56, 139, 161, 47, 201,
|
195, 117, 39, 98, 239, 84, 56, 139, 161, 47, 201, 51, 135, 250, 10,
|
||||||
51, 135, 250, 10, 19, 150, 45, 111, 27, 24, 142, 80, 85, 83, 234,
|
19, 150, 45, 111, 27, 24, 142, 80, 85, 83, 234, 138, 216, 57, 93,
|
||||||
138, 216, 57, 93, 65, 154, 141, 122, 34, 140, 128, 238, 88, 89, 9,
|
65, 154, 141, 122, 34, 140, 128, 238, 88, 89, 9, 146, 171, 149, 53,
|
||||||
146, 171, 149, 53, 102, 61, 114, 69, 217, 175, 103, 228, 35, 180,
|
102, 61, 114, 69, 217, 175, 103, 228, 35, 180, 252, 200, 192, 165,
|
||||||
252, 200, 192, 165, 159, 221, 244, 110, 119, 48 };
|
159, 221, 244, 110, 119, 48 };
|
||||||
bytes s = key;
|
bytes s = key;
|
||||||
int i, j = 0;
|
int i, j = 0;
|
||||||
for (int k = 0; k < len; k++) {
|
for (int k = 0; k < len; k++) {
|
||||||
|
|
|
@ -11,9 +11,7 @@
|
||||||
#define HEADER_LEN 32
|
#define HEADER_LEN 32
|
||||||
#define PACKET_END 0xFFFF0000
|
#define PACKET_END 0xFFFF0000
|
||||||
|
|
||||||
#include "Types.h"
|
#include "Types/Types.h"
|
||||||
#include "Types/bytes.h"
|
|
||||||
#include "Types/datasets.h"
|
|
||||||
|
|
||||||
class Packet {
|
class Packet {
|
||||||
public:
|
public:
|
||||||
|
@ -38,7 +36,7 @@ public:
|
||||||
void setSwitchMac(macAddr);
|
void setSwitchMac(macAddr);
|
||||||
void setCheckSum(int);
|
void setCheckSum(int);
|
||||||
void setSequenceId(short);
|
void setSequenceId(short);
|
||||||
void setPayload(const datasets& payload);
|
void setPayload(datasets payload);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bytes head = bytes(32);
|
bytes head = bytes(32);
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "Socket.h"
|
#include "Socket.h"
|
||||||
#include "Switch.h"
|
#include "Switch.h"
|
||||||
#include "Packet.h"
|
#include "Packet.h"
|
||||||
|
#include "Lookup.h"
|
||||||
|
|
||||||
int Program::list() {
|
int Program::list() {
|
||||||
|
|
||||||
|
@ -123,11 +124,11 @@ int Program::setProperty() {
|
||||||
int Program::getProperty() {
|
int Program::getProperty() {
|
||||||
Host h = Host();
|
Host h = Host();
|
||||||
printf("Get:\n");
|
printf("Get:\n");
|
||||||
Packet p = Packet(Packet::DISCOVERY);
|
Packet p = Packet(Packet::GET);
|
||||||
macAddr d = {0x14,0xcc,0x20,0x49,0x5e,0x07};
|
macAddr d = {0x14,0xcc,0x20,0x49,0x5e,0x07};
|
||||||
p.setSwitchMac(d);
|
p.setSwitchMac(d);
|
||||||
p.setHostMac(h.getMac());
|
p.setHostMac(h.getMac());
|
||||||
datasets t = { { 2200, 0, { } } };
|
datasets t = { { 2305, 0, { } } };
|
||||||
p.setPayload(t);
|
p.setPayload(t);
|
||||||
bytes a = p.getBytes();
|
bytes a = p.getBytes();
|
||||||
p.encode(a);
|
p.encode(a);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#ifndef PROGRAM_H_
|
#ifndef PROGRAM_H_
|
||||||
#define PROGRAM_H_
|
#define PROGRAM_H_
|
||||||
|
|
||||||
#include "Types.h"
|
#include "Types/Types.h"
|
||||||
|
|
||||||
#define SRC_PORT 29809
|
#define SRC_PORT 29809
|
||||||
#define DST_PORT 29808
|
#define DST_PORT 29808
|
||||||
|
|
|
@ -4,18 +4,18 @@
|
||||||
* Created on: 02.09.2015
|
* Created on: 02.09.2015
|
||||||
* Author: jdi
|
* Author: jdi
|
||||||
*/
|
*/
|
||||||
#include <cstdio>
|
//#include <cstdio>
|
||||||
#include <cerrno>
|
//#include <cerrno>
|
||||||
#include <cstring>
|
//#include <cstring>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <asio.hpp>
|
#include <asio.hpp>
|
||||||
#include "Socket.h"
|
#include "Socket.h"
|
||||||
#include "Packet.h"
|
#include "Packet.h"
|
||||||
#include "Types.h"
|
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
#include "Host.h"
|
#include "Host.h"
|
||||||
|
#include "Types/Types.h"
|
||||||
|
|
||||||
Socket::Socket(asio::io_service& io_service) :
|
Socket::Socket(asio::io_service& io_service) :
|
||||||
send_socket_(io_service), receive_socket_(io_service) {
|
send_socket_(io_service), receive_socket_(io_service) {
|
||||||
|
|
|
@ -10,8 +10,7 @@
|
||||||
|
|
||||||
#include <asio.hpp>
|
#include <asio.hpp>
|
||||||
#include "Packet.h"
|
#include "Packet.h"
|
||||||
#include "Types.h"
|
#include "Types/Types.h"
|
||||||
//#include "Types.h"
|
|
||||||
|
|
||||||
#define MAX_LENGTH 1024
|
#define MAX_LENGTH 1024
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Types/bytes.h"
|
#include "Types/Types.h"
|
||||||
#include "Switch.h"
|
#include "Switch.h"
|
||||||
|
#include "Lookup.h"
|
||||||
|
#include "Options.h"
|
||||||
|
|
||||||
void Switch::parse(datasets arr) {
|
void Switch::parse(datasets arr) {
|
||||||
device.type = arr[1].value;
|
device.type = arr[1].value;
|
||||||
|
@ -18,6 +20,19 @@ void Switch::parse(datasets arr) {
|
||||||
settings.gateway = arr[6].value;
|
settings.gateway = arr[6].value;
|
||||||
device.firmware_version = arr[7].value;
|
device.firmware_version = arr[7].value;
|
||||||
device.hardware_version = arr[8].value;
|
device.hardware_version = arr[8].value;
|
||||||
settings.dhcp=arr[9].value[0];
|
settings.dhcp = arr[9].value[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
void Switch::parse(dataset d) {
|
||||||
|
auto lookup = (options.flags & FLAG_REVERSE) ? snd_lookup : rcv_lookup;
|
||||||
|
if(d.type==lookup["type"]){
|
||||||
|
device.type = d.value;
|
||||||
|
}
|
||||||
|
if(d.type==lookup["mac"]){
|
||||||
|
device.mac = d.value;
|
||||||
|
}
|
||||||
|
if(d.type==lookup["type"]){
|
||||||
|
device.type = d.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
37
src/Switch.h
37
src/Switch.h
|
@ -10,45 +10,11 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "Types.h"
|
#include "Types/Types.h"
|
||||||
#include "Types/bytes.h"
|
|
||||||
#include "Types/datasets.h"
|
|
||||||
|
|
||||||
#define DEFAULT_USER "admin"
|
#define DEFAULT_USER "admin"
|
||||||
#define DEFAULT_PASS "admin"
|
#define DEFAULT_PASS "admin"
|
||||||
|
|
||||||
static std::map<int,std::string> rcv_lookup= {
|
|
||||||
{ 1, "type"},//string
|
|
||||||
{ 2, "hostname"},//string
|
|
||||||
{ 3, "mac"},//byte[6]
|
|
||||||
{ 4, "ip_addr"},//byte[4]
|
|
||||||
{ 5, "ip_mask"},//byte[4]
|
|
||||||
{ 6, "gateway"},//byte[4]
|
|
||||||
{ 7, "firmware_version"},//string
|
|
||||||
{ 8, "hardware_version"},//string
|
|
||||||
{ 9, "dhcp"}};//bool byte
|
|
||||||
|
|
||||||
static std::map<int,std::string> snd_lookup= {
|
|
||||||
{10,"???"},//after login
|
|
||||||
{2,"???"},//after login
|
|
||||||
{512,"login_user"},//string
|
|
||||||
{513,"new_user"},//string
|
|
||||||
{514,"login_password"},//string
|
|
||||||
{515,"new_passwoord"},//string
|
|
||||||
{2200,"vlan"},
|
|
||||||
{2305,"???"},//sent before login and before change hostname
|
|
||||||
{4608,"port_trunk"},//byte[5] last byte bitmask??
|
|
||||||
{8192,"mtu_vlan"},//byte[2] first byte bool, second byte port id
|
|
||||||
{8449,"port_vlan"},//???
|
|
||||||
{8705,"802.1q vlan"},//???
|
|
||||||
{8706,"802.1q vlan pvid"},//????
|
|
||||||
{12288,"QoS Basic"},//bool = QoS Mod
|
|
||||||
{16640,"port_mirror"},//byte[10] second byte port id??
|
|
||||||
{17152,"loop_prevention"},//bool byte
|
|
||||||
//{0000," "},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct vlan {
|
struct vlan {
|
||||||
int vlan_id;
|
int vlan_id;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
@ -69,6 +35,7 @@ public:
|
||||||
Switch() {
|
Switch() {
|
||||||
}
|
}
|
||||||
void parse(datasets);
|
void parse(datasets);
|
||||||
|
void parse(dataset);
|
||||||
struct {
|
struct {
|
||||||
std::string type;
|
std::string type;
|
||||||
std::string hardware_version;
|
std::string hardware_version;
|
||||||
|
|
|
@ -14,7 +14,9 @@
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "Types/bytes.h"
|
|
||||||
|
#include "bytes.h"
|
||||||
|
#include "datasets.h"
|
||||||
|
|
||||||
class macAddr: public std::array<byte, 6> {
|
class macAddr: public std::array<byte, 6> {
|
||||||
public:
|
public:
|
28
src/Types/bytes.cpp
Normal file
28
src/Types/bytes.cpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Bytes.cpp
|
||||||
|
*
|
||||||
|
* Created on: 02.10.2015
|
||||||
|
* Author: jdi
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bytes.h"
|
||||||
|
|
||||||
|
bytes::bytes(std::string d) {
|
||||||
|
vector();
|
||||||
|
std::string delimiter = ":";
|
||||||
|
std::string token;
|
||||||
|
size_t pos = 0;
|
||||||
|
int hex;
|
||||||
|
byte b;
|
||||||
|
resize(0);
|
||||||
|
while ((pos = d.find(delimiter)) != std::string::npos) {
|
||||||
|
token = d.substr(0, pos);
|
||||||
|
sscanf(token.c_str(), "%x", &hex);
|
||||||
|
d.erase(0, pos + delimiter.length());
|
||||||
|
b = hex & 0xFF;
|
||||||
|
push_back(b);
|
||||||
|
}
|
||||||
|
sscanf(d.c_str(), "%x", &hex);
|
||||||
|
b = hex & 0xFF;
|
||||||
|
push_back(b);
|
||||||
|
}
|
86
src/Types/bytes.h
Normal file
86
src/Types/bytes.h
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* Bytes.h
|
||||||
|
*
|
||||||
|
* Created on: 02.10.2015
|
||||||
|
* Author: jdi
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BYTES_H_
|
||||||
|
#define BYTES_H_
|
||||||
|
|
||||||
|
#include <initializer_list>
|
||||||
|
#include <functional>
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
typedef unsigned char byte;
|
||||||
|
|
||||||
|
class bytes: public std::vector<unsigned char> {
|
||||||
|
typedef std::vector<unsigned char> vector;
|
||||||
|
public:
|
||||||
|
using vector::operator[];
|
||||||
|
bytes() {
|
||||||
|
}
|
||||||
|
bytes(int n) :
|
||||||
|
vector(n) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes(std::string);
|
||||||
|
|
||||||
|
bytes(std::initializer_list<uint8_t> s)
|
||||||
|
{
|
||||||
|
for (uint8_t b : s) {
|
||||||
|
this->push_back(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes(const vector &B) {
|
||||||
|
this->reserve(B.size());
|
||||||
|
this->insert(this->begin(), B.begin(), B.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes readHex(std::string s){
|
||||||
|
return bytes(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes operator=(const vector &B) {
|
||||||
|
this->reserve(B.size());
|
||||||
|
this->insert(this->begin(), B.begin(), B.end());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes &operator+=(const bytes &B) {
|
||||||
|
this->reserve(this->size() + B.size());
|
||||||
|
this->insert(this->end(), B.begin(), B.end());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes operator+(const bytes &B) {
|
||||||
|
bytes AB;
|
||||||
|
AB.reserve(this->size() + B.size());
|
||||||
|
AB.insert(AB.end(), this->begin(), this->end());
|
||||||
|
AB.insert(AB.end(), B.begin(), B.end());
|
||||||
|
return AB;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend std::ostream& operator<<(std::ostream& out, const bytes& arr) {
|
||||||
|
if (arr.size() > 0) {
|
||||||
|
out << std::hex << std::setw(2) << std::setfill('0')
|
||||||
|
<< (unsigned) arr[0];
|
||||||
|
}
|
||||||
|
for (unsigned i = 1; i < arr.size(); i++) {
|
||||||
|
out << ":" << std::setw(2) << std::setfill('0') << (unsigned) arr[i];
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator std::string() {
|
||||||
|
std::string s(this->begin(),this->end());
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* BYTES_H_ */
|
8
src/Types/datasets.cpp
Normal file
8
src/Types/datasets.cpp
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
/*
|
||||||
|
* Datasets.cpp
|
||||||
|
*
|
||||||
|
* Created on: 02.10.2015
|
||||||
|
* Author: jdi
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "datasets.h"
|
31
src/Types/datasets.h
Normal file
31
src/Types/datasets.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Datasets.h
|
||||||
|
*
|
||||||
|
* Created on: 02.10.2015
|
||||||
|
* Author: jdi
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DATASETS_H_
|
||||||
|
#define DATASETS_H_
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include "bytes.h"
|
||||||
|
|
||||||
|
struct dataset {
|
||||||
|
short type;
|
||||||
|
short len;
|
||||||
|
bytes value;
|
||||||
|
};
|
||||||
|
|
||||||
|
class datasets : public std::map<short, dataset> {
|
||||||
|
public:
|
||||||
|
datasets(){};
|
||||||
|
datasets(std::initializer_list<dataset> s)
|
||||||
|
{
|
||||||
|
for (dataset b : s) {
|
||||||
|
(*this)[b.type]=b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* DATASETS_H_ */
|
|
@ -118,11 +118,38 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
switch (caseArg(cmd.c_str())) {
|
switch (caseArg(cmd.c_str())) {
|
||||||
case caseArg("set"):
|
case caseArg("set"):
|
||||||
|
if (p.setProperty())
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
fprintf(stderr, "Not yet implemented.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
break;
|
||||||
case caseArg("reboot"):
|
case caseArg("reboot"):
|
||||||
|
if (p.reboot())
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
fprintf(stderr, "Not yet implemented.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
break;
|
||||||
case caseArg("reset"):
|
case caseArg("reset"):
|
||||||
|
if (p.reset())
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
fprintf(stderr, "Not yet implemented.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
break;
|
||||||
case caseArg("save"):
|
case caseArg("save"):
|
||||||
|
if (p.save())
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
fprintf(stderr, "Not yet implemented.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
break;
|
||||||
case caseArg("restore"):
|
case caseArg("restore"):
|
||||||
|
if (p.restore())
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
fprintf(stderr, "Not yet implemented.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
break;
|
||||||
case caseArg("flash"):
|
case caseArg("flash"):
|
||||||
|
if (p.flash())
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
fprintf(stderr, "Not yet implemented.\n");
|
fprintf(stderr, "Not yet implemented.\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue