Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tools. #343

Merged
merged 2 commits into from
Nov 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions tools/RawToGlobalCache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
# Convert IRremoteESP8266's rawData output into Global Cache format.

function isDigits()
{
[[ "$1" =~ ^[0-9]+$ ]]
}

function usage()
{
cat << EOF
Usage: $0 Frequency_in_Hz
Reads an IRremoteESP8266 rawData declaration from STDIN and converts it to
GlobalCache format.
e.g.
uint16_t rawbuf[37] = {
7930, 3952, 494, 1482, 520, 1482, 494, 1508,
494, 520, 494, 1482, 494, 520, 494, 1482,
494, 1482, 494, 3978, 494, 520, 494, 520,
494, 520, 494, 520, 520, 520, 494, 520,
494, 520, 494, 520, 494};
EOF
exit 1
}

# We need a frequency argument.
if [[ $# -ne 1 ]]; then
usage
fi
HZ="$1"
# HZ must be a positive number
if ! isDigits "${HZ}"; then
usage
fi
# HZ must not be zero.
if [[ ${HZ} == 0 ]]; then
usage
fi


PERIOD_OFFSET=0
period=$((((1000000 + (${HZ} / 2)) / ${HZ}) + ${PERIOD_OFFSET}))
result="${HZ},1,1"
while read line; do
# Quick and Dirty Removal of any array declaration syntax, and any commas.
line="$(echo ${line} | sed 's/uint.*{//i' | sed 's/,//g' | sed 's/};.*//g')"
for msecs in ${line}; do
if isDigits "${msecs}"; then
result="${result},$((${msecs} / ${period}))"
fi
done
done
echo "GlobalCache code = \"${result}\""
30 changes: 23 additions & 7 deletions tools/gc_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include "IRsend.h"
#include "IRsend_test.h"

#define MAX_GC_CODE_LENGHT 512
#define MAX_GC_CODE_LENGTH 10000

void str_to_uint16(char *str, uint16_t *res) {
char *end;
Expand Down Expand Up @@ -45,6 +46,8 @@ std::string encoding(decode_results *results) {
case DENON: return "DENON"; break;
case COOLIX: return "COOLIX"; break;
case NIKAI: return "NIKAI"; break;
case DAIKIN: return "DAIKIN"; break;
case KELVINATOR: return "KELVINATOR"; break;
case TOSHIBA_AC: return "TOSHIBA_AC"; break;
}
}
Expand All @@ -71,13 +74,13 @@ int main(int argc, char * argv[]) {
return 1;
}

uint16_t gc_test[MAX_GC_CODE_LENGHT];
uint16_t gc_test[MAX_GC_CODE_LENGTH];
int index = 0;
char *pch;
char *saveptr1;

pch = strtok_r(argv[argv_offset], ",", &saveptr1);
while (pch != NULL && index < MAX_GC_CODE_LENGHT) {
while (pch != NULL && index < MAX_GC_CODE_LENGTH) {
str_to_uint16(pch, &gc_test[index]);
pch = strtok_r(NULL, ",", &saveptr1);
index++;
Expand All @@ -95,10 +98,23 @@ int main(int argc, char * argv[]) {
std::cout << "Code GC length " << index << std::endl
<< "Code type " << irsend.capture.decode_type
<< " (" << encoding(&irsend.capture) << ")" << std::endl
<< "Code bits " << irsend.capture.bits << std::endl
<< "Code value 0x" << std::hex << irsend.capture.value << std::endl
<< "Code address 0x" << std::hex << irsend.capture.address << std::endl
<< "Code command 0x" << std::hex << irsend.capture.command << std::endl;
<< "Code bits " << irsend.capture.bits << std::endl;
switch (irsend.capture.decode_type) {
case DAIKIN:
case KELVINATOR:
case TOSHIBA_AC:
std::cout << "State value 0x";
for (uint16_t i = 0; i < irsend.capture.bits / 8; i++)
printf("%02X", irsend.capture.state[i]);
std::cout << std::endl;
break;
default:
std::cout << "Code value 0x" <<
std::hex << irsend.capture.value << std::endl <<
"Code address 0x" << std::hex << irsend.capture.address << std::endl
<< "Code command 0x" << std::hex << irsend.capture.command <<
std::endl;
}

if (dumpraw || irsend.capture.decode_type == UNKNOWN)
irsend.dumpRawResult();
Expand Down