protocol.h
1 #pragma once
2 
3 #include <QByteArray>
4 
14 namespace Command {
15  enum Command {
17  Run,
20  };
21 };
22 
23 namespace Propeller {
24 
25 const int _max_data_size = 1392;
26 
27 const int request_size = 69;
28 const quint8 request[69] = {
29  0x49,
30  0xAA,0x52,0xA5,0xAA,0x25,0xAA,0xD2,0xCA,0x52,0x25,0xD2,0xD2,0xD2,0xAA,0x49,0x92,
31  0xC9,0x2A,0xA5,0x25,0x4A,0x49,0x49,0x2A,0x25,0x49,0xA5,0x4A,0xAA,0x2A,0xA9,0xCA,
32  0xAA,0x55,0x52,0xAA,0xA9,0x29,0x92,0x92,0x29,0x25,0x2A,0xAA,0x92,0x92,0x55,0xCA,
33  0x4A,0xCA,0xCA,0x92,0xCA,0x92,0x95,0x55,0xA9,0x92,0x2A,0xD2,0x52,0x92,0x52,0xCA,
34  0xD2,0xCA,0x2A,0xFF
35 };
36 
37 
38 const int reply_size = 125;
39 const quint8 reply[reply_size] = {
40  0xEE,0xCE,0xCE,0xCF,0xEF,0xCF,0xEE,0xEF,0xCF,0xCF,0xEF,0xEF,0xCF,0xCE,0xEF,0xCF,
41  0xEE,0xEE,0xCE,0xEE,0xEF,0xCF,0xCE,0xEE,0xCE,0xCF,0xEE,0xEE,0xEF,0xCF,0xEE,0xCE,
42  0xEE,0xCE,0xEE,0xCF,0xEF,0xEE,0xEF,0xCE,0xEE,0xEE,0xCF,0xEE,0xCF,0xEE,0xEE,0xCF,
43  0xEF,0xCE,0xCF,0xEE,0xEF,0xEE,0xEE,0xEE,0xEE,0xEF,0xEE,0xCF,0xCF,0xEF,0xEE,0xCE,
44  0xEF,0xEF,0xEF,0xEF,0xCE,0xEF,0xEE,0xEF,0xCF,0xEF,0xCF,0xCF,0xCE,0xCE,0xCE,0xCF,
45  0xCF,0xEF,0xCE,0xEE,0xCF,0xEE,0xEF,0xCE,0xCE,0xCE,0xEF,0xEF,0xCF,0xCF,0xEE,0xEE,
46  0xEE,0xCE,0xCF,0xCE,0xCE,0xCF,0xCE,0xEE,0xEF,0xEE,0xEF,0xEF,0xCF,0xEF,0xCE,0xCE,
47  0xEF,0xCE,0xEE,0xCE,0xEF,0xCE,0xCE,0xEE,0xCF,0xCF,0xCE,0xCF,0xCF
48 };
49 
61 // Propeller Download Stream Translator array. Index into this array using the "Binary Value" (usually 5 bits) to translate,
62 // the incoming bit size (again, usually 5), and the desired data element to retrieve (dtTx = translation, dtBits = bit count
63 // actually translated.
64 
65 // Binary Incoming Translation
66 // Value, Bit Size, or Bit Count
67 const quint8 translator[32][5][2] = {
68  // *** 1-BIT *** *** 2-BIT *** *** 3-BIT *** *** 4-BIT *** *** 5-BIT ***
69  { /*%00000*/ {0xFE, 1}, /*%00000*/ {0xF2, 2}, /*%00000*/ {0x92, 3}, /*%00000*/ {0x92, 3}, /*%00000*/ {0x92, 3} },
70  { /*%00001*/ {0xFF, 1}, /*%00001*/ {0xF9, 2}, /*%00001*/ {0xC9, 3}, /*%00001*/ {0xC9, 3}, /*%00001*/ {0xC9, 3} },
71  { {0, 0}, /*%00010*/ {0xFA, 2}, /*%00010*/ {0xCA, 3}, /*%00010*/ {0xCA, 3}, /*%00010*/ {0xCA, 3} },
72  { {0, 0}, /*%00011*/ {0xFD, 2}, /*%00011*/ {0xE5, 3}, /*%00011*/ {0x25, 4}, /*%00011*/ {0x25, 4} },
73  { {0, 0}, {0, 0}, /*%00100*/ {0xD2, 3}, /*%00100*/ {0xD2, 3}, /*%00100*/ {0xD2, 3} },
74  { {0, 0}, {0, 0}, /*%00101*/ {0xE9, 3}, /*%00101*/ {0x29, 4}, /*%00101*/ {0x29, 4} },
75  { {0, 0}, {0, 0}, /*%00110*/ {0xEA, 3}, /*%00110*/ {0x2A, 4}, /*%00110*/ {0x2A, 4} },
76  { {0, 0}, {0, 0}, /*%00111*/ {0xFA, 3}, /*%00111*/ {0x95, 4}, /*%00111*/ {0x95, 4} },
77  { {0, 0}, {0, 0}, {0, 0}, /*%01000*/ {0x92, 3}, /*%01000*/ {0x92, 3} },
78  { {0, 0}, {0, 0}, {0, 0}, /*%01001*/ {0x49, 4}, /*%01001*/ {0x49, 4} },
79  { {0, 0}, {0, 0}, {0, 0}, /*%01010*/ {0x4A, 4}, /*%01010*/ {0x4A, 4} },
80  { {0, 0}, {0, 0}, {0, 0}, /*%01011*/ {0xA5, 4}, /*%01011*/ {0xA5, 4} },
81  { {0, 0}, {0, 0}, {0, 0}, /*%01100*/ {0x52, 4}, /*%01100*/ {0x52, 4} },
82  { {0, 0}, {0, 0}, {0, 0}, /*%01101*/ {0xA9, 4}, /*%01101*/ {0xA9, 4} },
83  { {0, 0}, {0, 0}, {0, 0}, /*%01110*/ {0xAA, 4}, /*%01110*/ {0xAA, 4} },
84  { {0, 0}, {0, 0}, {0, 0}, /*%01111*/ {0xD5, 4}, /*%01111*/ {0xD5, 4} },
85  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%10000*/ {0x92, 3} },
86  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%10001*/ {0xC9, 3} },
87  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%10010*/ {0xCA, 3} },
88  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%10011*/ {0x25, 4} },
89  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%10100*/ {0xD2, 3} },
90  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%10101*/ {0x29, 4} },
91  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%10110*/ {0x2A, 4} },
92  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%10111*/ {0x95, 4} },
93  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%11000*/ {0x92, 3} },
94  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%11001*/ {0x49, 4} },
95  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%11010*/ {0x4A, 4} },
96  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%11011*/ {0xA5, 4} },
97  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%11100*/ {0x52, 4} },
98  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%11101*/ {0xA9, 4} },
99  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%11110*/ {0xAA, 4} },
100  { {0, 0}, {0, 0}, {0, 0}, {0, 0}, /*%11111*/ {0x55, 5} }
101 };
102 };
103 
104 // Generate Propeller Loader Download Stream from adjusted LoaderImage (above); Output delivered to LoaderStream and LoaderStreamSize.
105 
106 // It should be noted that the Propeller Protocol is **Little-Endian**
107 
108 class PropellerProtocol
109 {
110 
111 private:
112  QByteArray _reply;
113  QByteArray _request;
114 
115  int lfsr(int * seed);
116  QList<char> buildLfsrSequence(int size);
117 
118 public:
119  PropellerProtocol();
120  QByteArray buildRequest(Command::Command command = Command::Shutdown);
121  static QByteArray encodeData(QByteArray image);
122  static QByteArray encodeLong(quint32 value);
123  static QByteArray packLong(quint32 value);
124 
125  QByteArray reply();
126  QByteArray request();
127 
128 };
Definition: protocol.h:14
Definition: protocol.h:18
const quint8 reply[reply_size]
Definition: protocol.h:39
Definition: protocol.h:23
const quint8 request[69]
Definition: protocol.h:28
Definition: protocol.h:19
Definition: protocol.h:17
const int _max_data_size
Definition: protocol.h:25
const int reply_size
Definition: protocol.h:38
Definition: protocol.h:16
const int request_size
Definition: protocol.h:27
const quint8 translator[32][5][2]
Definition: protocol.h:67
Command
Definition: protocol.h:15