author | Florian Pose <fp@igh-essen.com> |
Mon, 21 Jul 2008 22:20:23 +0000 | |
changeset 1122 | ee305a780a02 |
child 1125 | 9976f7b9fe66 |
permissions | -rw-r--r-- |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/***************************************************************************** |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
5 |
****************************************************************************/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
6 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
#include <iostream> |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
8 |
#include <iomanip> |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
9 |
#include <sstream> |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
10 |
using namespace std; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
11 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
12 |
#include "globals.h" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
13 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
14 |
/*****************************************************************************/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
15 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
16 |
const char *help_alias = |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
17 |
"[OPTIONS] <ALIAS>\n" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
18 |
"\n" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
19 |
"Write the secondary slave address (alias) for either\n" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
20 |
"one or for multiple slaves.\n" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
"\n" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
22 |
"Arguments:\n" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
23 |
" ALIAS must be a 16 bit unsigned integer, specified\n" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
24 |
" either in decimal (no prefix), octal (prefix '0')\n" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
25 |
" or hexadecimal (prefix '0x').\n" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
26 |
"\n" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
27 |
"Command-specific options:\n" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
" -s <SLAVE> Write the alias of the slave with the given\n" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
" ring position. If this option is not\n" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
" specified, the alias of all slaves is set.\n" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
31 |
" The --force option is required in this\n" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
" case.\n"; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
/*****************************************************************************/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
void writeSlaveAlias(uint16_t, uint16_t); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
/*****************************************************************************/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
40 |
/** Writes the Secondary slave address (alias) to the slave's SII. |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
*/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
void command_alias(void) |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
{ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
uint16_t alias; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
45 |
stringstream err, strAlias; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
int number; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
unsigned int numSlaves, i; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
48 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
49 |
if (commandArgs.size() != 1) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
50 |
err << "'" << command << "' takes exactly one argument!"; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
51 |
throw InvalidUsageException(err); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
52 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
53 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
54 |
strAlias << commandArgs[0]; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
55 |
strAlias |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
56 |
>> resetiosflags(ios::basefield) // guess base from prefix |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
57 |
>> number; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
58 |
if (strAlias.fail() || number < 0x0000 || number > 0xffff) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
59 |
err << "Invalid alias '" << commandArgs[0] << "'!"; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
throw InvalidUsageException(err); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
61 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
62 |
alias = number; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
63 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
64 |
if (slavePosition == -1) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
65 |
if (!force) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
err << "This will write the alias addresses of all slaves to " |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
67 |
<< alias << "! Please specify --force to proceed."; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
68 |
throw ExecutionFailureException(err); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
70 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
71 |
masterDev.open(MasterDevice::ReadWrite); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
72 |
numSlaves = masterDev.slaveCount(); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
73 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
for (i = 0; i < numSlaves; i++) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
75 |
writeSlaveAlias(i, alias); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
76 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
77 |
} else { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
78 |
masterDev.open(MasterDevice::ReadWrite); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
writeSlaveAlias(slavePosition, alias); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
80 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
81 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
82 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
83 |
/*****************************************************************************/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
84 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
85 |
/** Calculates the SII checksum field. |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
86 |
* |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
87 |
* The checksum is generated with the polynom x^8+x^2+x+1 (0x07) and an |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
* initial value of 0xff (see IEC 61158-6-12 ch. 5.4). |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
89 |
* |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
90 |
* The below code was originally generated with PYCRC |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
91 |
* http://www.tty1.net/pycrc |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
92 |
* |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
* ./pycrc.py --width=8 --poly=0x07 --reflect-in=0 --xor-in=0xff |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
* --reflect-out=0 --xor-out=0 --generate c --algorithm=bit-by-bit |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
95 |
* |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
* \return CRC8 |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
97 |
*/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
uint8_t calcSiiCrc( |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
99 |
const uint8_t *data, /**< pointer to data */ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
100 |
size_t length /**< number of bytes in \a data */ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
) |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
{ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
103 |
unsigned int i; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
uint8_t bit, byte, crc = 0x48; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
105 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
106 |
while (length--) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
107 |
byte = *data++; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
for (i = 0; i < 8; i++) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
109 |
bit = crc & 0x80; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
110 |
crc = (crc << 1) | ((byte >> (7 - i)) & 0x01); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
111 |
if (bit) crc ^= 0x07; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
112 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
113 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
114 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
115 |
for (i = 0; i < 8; i++) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
116 |
bit = crc & 0x80; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
117 |
crc <<= 1; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
118 |
if (bit) crc ^= 0x07; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
121 |
return crc; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
122 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
123 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
124 |
/*****************************************************************************/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
125 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
126 |
/** Writes the Secondary slave address (alias) to the slave's SII. |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
127 |
*/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
128 |
void writeSlaveAlias( |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
129 |
uint16_t slavePosition, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
130 |
uint16_t alias |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
131 |
) |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
132 |
{ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
133 |
ec_ioctl_slave_sii_t data; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
134 |
ec_ioctl_slave_t slave; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
135 |
stringstream err; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
136 |
uint8_t crc; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
137 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
138 |
masterDev.getSlave(&slave, slavePosition); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
139 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
140 |
if (slave.sii_nwords < 8) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
141 |
err << "Current SII contents are too small to set an alias " |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
142 |
<< "(" << slave.sii_nwords << " words)!"; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
143 |
throw ExecutionFailureException(err); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
144 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
145 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
146 |
// read first 8 SII words |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
147 |
data.slave_position = slavePosition; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
148 |
data.offset = 0; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
149 |
data.nwords = 8; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
150 |
data.words = new uint16_t[data.nwords]; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
151 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
152 |
try { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
153 |
masterDev.readSii(&data); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
154 |
} catch (MasterDeviceException &e) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
155 |
delete [] data.words; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
156 |
err << "Failed to read SII: " << e.what(); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
157 |
throw ExecutionFailureException(err); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
158 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
159 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
160 |
// write new alias address in word 4 |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
161 |
data.words[4] = cputole16(alias); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
162 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
163 |
// calculate checksum over words 0 to 6 |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
164 |
crc = calcSiiCrc((const uint8_t *) data.words, 14); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
165 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
166 |
// write new checksum into first byte of word 7 |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
167 |
*(uint8_t *) (data.words + 7) = crc; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
168 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
169 |
// write first 8 words with new alias and checksum |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
170 |
try { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
171 |
masterDev.writeSii(&data); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
172 |
} catch (MasterDeviceException &e) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
173 |
delete [] data.words; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
174 |
err << "Failed to read SII: " << e.what(); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
175 |
throw ExecutionFailureException(err); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
176 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
177 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
178 |
delete [] data.words; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
179 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
180 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
181 |
/*****************************************************************************/ |