MCPcopy Create free account
hub / github.com/crankyoldgit/IRremoteESP8266 / main

Function main

tools/code_to_raw.cpp:25–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23}
24
25int main(int argc, char *argv[]) {
26 int argv_offset = 1;
27 int repeats = 0;
28 uint64_t code = 0;
29 uint8_t state[kStateSizeMax] = {0}; // All array elements are set to 0.
30 decode_type_t input_type = decode_type_t::UNKNOWN;
31 bool timinginfo = false;
32
33 // Check the invocation/calling usage.
34 if (argc < 5 || argc > 8) {
35 usage_error(argv[0]);
36 return 1;
37 }
38
39 if (strncmp("--protocol", argv[argv_offset], 11) == 0) {
40 argv_offset++;
41 input_type = strToDecodeType(argv[argv_offset]);
42 switch (input_type) {
43 // Unsupported types
44 case decode_type_t::UNUSED:
45 case decode_type_t::UNKNOWN:
46 case decode_type_t::GLOBALCACHE:
47 case decode_type_t::PRONTO:
48 case decode_type_t::RAW:
49 std::cerr << "The protocol specified is not supported by this program."
50 << std::endl;
51 return 1;
52 default:
53 break;
54 }
55 argv_offset++;
56 }
57
58 uint16_t nbits = IRsend::defaultBits(input_type);
59 uint16_t stateSize = nbits / 8;
60 if (strncmp("--code", argv[argv_offset], 7) == 0) {
61 argv_offset++;
62 String hexstr = String(argv[argv_offset]);
63 uint64_t strOffset = 0;
64 if (hexstr.rfind("0x", 0) || hexstr.rfind("0X", 0)) strOffset = 2;
65
66 // Calculate how many hexadecimal characters there are.
67 uint64_t hexstrlength = hexstr.length() - strOffset;
68
69 // Ptr to the least significant byte of the resulting state for this
70 // protocol.
71 uint8_t *statePtr = &state[stateSize - 1];
72
73 // Convert the string into a state array of the correct length.
74 for (uint16_t i = 0; i < hexstrlength; i++) {
75 // Grab the next least sigificant hexadecimal digit from the string.
76 uint8_t c = tolower(hexstr[hexstrlength + strOffset - i - 1]);
77 if (isxdigit(c)) {
78 if (isdigit(c))
79 c -= '0';
80 else
81 c = c - 'a' + 10;
82 } else {

Callers

nothing calls this directly

Calls 12

strToDecodeTypeFunction · 0.85
hasACStateFunction · 0.85
typeToStringFunction · 0.85
resultAcToStringFunction · 0.85
resultToSourceCodeFunction · 0.85
resultToTimingInfoFunction · 0.85
makeDecodeResultMethod · 0.80
decodeMethod · 0.80
usage_errorFunction · 0.70
beginMethod · 0.45
resetMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected