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

Milestag2 #1380

Merged
merged 23 commits into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4a4ac62
Adding initial support for MilesTag2 protocol/testing github commits
vitos1k Jan 3, 2021
eb01a28
Added support for MilesTag protocol Sending and Decoding(recieving).
vitos1k Jan 9, 2021
774fa53
Added some constants
vitos1k Jan 9, 2021
8aac0ce
MilesTag now have own function for sending and encoding, because of "…
vitos1k Jan 9, 2021
e224eee
My commit
vitos1k Jan 10, 2021
7952e79
Added forgotten newline at the end of file. Sorry
vitos1k Jan 10, 2021
3c84a75
- travis-ci autobuilding system was failing, on some constants borrow…
vitos1k Jan 10, 2021
816475c
Tuned some repeat constants. Basically there is no documented informa…
vitos1k Jan 10, 2021
7797d62
addressed all issues reported here https://github.com/crankyoldgit/IR…
vitos1k Jan 11, 2021
d67b180
fixed own typo
vitos1k Jan 11, 2021
3603708
src/ir_MilesTag2.cpp:6 and 9: Line ends in whitespace. Consider del…
vitos1k Jan 11, 2021
fc121ac
Fixed Support comment. But I don't have actual hardware on my hands r…
vitos1k Jan 11, 2021
4c20517
Removing some blank lines
vitos1k Jan 13, 2021
366fac6
extra space fix
vitos1k Jan 13, 2021
cb02efe
Replaced my functions with Built-in generic
vitos1k Jan 13, 2021
4862e3b
default offset is set to kStartOffset
vitos1k Jan 13, 2021
1eaac7d
decodeMiles() is set above decodeSony() to reduce false detection, si…
vitos1k Jan 14, 2021
22fc177
As suggested, added MilesTag2 data decoding code https://github.com/c…
vitos1k Jan 14, 2021
0d1e1e2
spaces in comments
vitos1k Jan 14, 2021
981fc4d
Extend `matchData()` & `matchGeneric()` to handle no trailing space.
crankyoldgit Jan 15, 2021
556c651
Add support for no trailing space for `matchBytes()`.
crankyoldgit Jan 15, 2021
d112a3e
Add basic unit tests
crankyoldgit Jan 15, 2021
5811b50
Fix off-by-one error in calculating min_remaining.
crankyoldgit Jan 16, 2021
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
8 changes: 8 additions & 0 deletions src/IRrecv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,14 @@ bool IRrecv::decode(decode_results *results, irparams_t *save,
DPRINTLN("Attempting NEC decode");
if (decodeNEC(results, offset)) return true;
#endif
#if DECODE_MILESTAG2
DPRINTLN("Attempting MilesTag2 decode");
// Try decodeMiles() before decodeSony() because the protocols are
// similar in timings & structure, but the Miles one differs in nbits
// so this one should be tried first to try to reduce false detection
if (decodeMiles(results, offset, kMilesTag2ShotBits) ||
decodeMiles(results, offset, kMilesTag2MsgBits)) return true;
#endif
#if DECODE_SONY
DPRINTLN("Attempting Sony decode");
if (decodeSony(results, offset)) return true;
Expand Down
5 changes: 5 additions & 0 deletions src/IRrecv.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,11 @@ class IRrecv {
const uint16_t nbits = kLasertagBits,
const bool strict = true);
#endif
#if DECODE_MILESTAG2
bool decodeMiles(decode_results *results, uint16_t offset = kStartOffset,
const uint16_t nbits = kMilesTag2ShotBits,
const bool strict = true);
#endif
#if DECODE_CARRIER_AC
bool decodeCarrierAC(decode_results *results, uint16_t offset = kStartOffset,
const uint16_t nbits = kCarrierAcBits,
Expand Down
13 changes: 12 additions & 1 deletion src/IRremoteESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,13 @@
#define SEND_ELITESCREENS _IR_ENABLE_DEFAULT_
#endif // SEND_ELITESCREENS

#ifndef DECODE_MILESTAG2
#define DECODE_MILESTAG2 _IR_ENABLE_DEFAULT_
#endif // DECODE_MILESTAG2
#ifndef SEND_MILESTAG2
#define SEND_MILESTAG2 _IR_ENABLE_DEFAULT_
#endif // SEND_MILESTAG2

#if (DECODE_ARGO || DECODE_DAIKIN || DECODE_FUJITSU_AC || DECODE_GREE || \
DECODE_KELVINATOR || DECODE_MITSUBISHI_AC || DECODE_TOSHIBA_AC || \
DECODE_TROTEC || DECODE_HAIER_AC || DECODE_HITACHI_AC || \
Expand Down Expand Up @@ -867,8 +874,9 @@ enum decode_type_t {
MIRAGE,
ELITESCREENS, // 95
PANASONIC_AC32,
MILESTAG2,
// Add new entries before this one, and update it to point to the last entry.
kLastDecodeType = PANASONIC_AC32,
kLastDecodeType = MILESTAG2,
};

// Message lengths & required repeat values
Expand Down Expand Up @@ -1094,6 +1102,9 @@ const uint16_t kZepealBits = 16;
const uint16_t kZepealMinRepeat = 4;
const uint16_t kVoltasBits = 80;
const uint16_t kVoltasStateLength = 10;
const uint16_t kMilesTag2ShotBits = 14;
const uint16_t kMilesTag2MsgBits = 24;
const uint16_t kMilesMinRepeat = 0;

vitos1k marked this conversation as resolved.
Show resolved Hide resolved

// Legacy defines. (Deprecated)
Expand Down
7 changes: 7 additions & 0 deletions src/IRsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,8 @@ uint16_t IRsend::defaultBits(const decode_type_t protocol) {
return kHitachiAc424Bits;
case KELVINATOR:
return kKelvinatorBits;
case MILESTAG2:
return kMilesTag2ShotBits;
case MIRAGE:
return kMirageBits;
case MITSUBISHI_AC:
Expand Down Expand Up @@ -897,6 +899,11 @@ bool IRsend::send(const decode_type_t type, const uint64_t data,
sendMidea24(data, nbits, min_repeat);
break;
#endif // SEND_MIDEA24
#if SEND_MILESTAG2
case MILESTAG2:
sendMilestag2(data, nbits, min_repeat);
break;
#endif // SEND_MILESTAG2
#if SEND_MITSUBISHI
case MITSUBISHI:
sendMitsubishi(data, nbits, min_repeat);
Expand Down
7 changes: 7 additions & 0 deletions src/IRsend.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,13 @@ class IRsend {
const uint16_t nbits = kEliteScreensBits,
const uint16_t repeat = kEliteScreensDefaultRepeat);
#endif // SEND_ELITESCREENS
#if SEND_MILESTAG2
// Since There 2 types of transmissions
// (14bits for Shooting by default, you can set 24 bit for msg delivery)
void sendMilestag2(const uint64_t data,
const uint16_t nbits = kMilesTag2ShotBits,
const uint16_t repeat = kMilesMinRepeat);
#endif // SEND_MILESTAG2

protected:
#ifdef UNIT_TEST
Expand Down
1 change: 1 addition & 0 deletions src/IRtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,6 @@ const PROGMEM char *kAllProtocolNamesStr =
D_STR_MIRAGE "\x0"
D_STR_ELITESCREENS "\x0"
D_STR_PANASONIC_AC32 "\x0"
D_STR_MILESTAG2 "\x0"
///< New protocol strings should be added just above this line.
"\x0"; ///< This string requires double null termination.
102 changes: 102 additions & 0 deletions src/ir_MilesTag2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright 2020 Victor Mukayev (vitos1k)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2021 ;-)

/// @file
/// @brief Support for the MilesTag2 IR protocol for LaserTag gaming
/// @see http://hosting.cmalton.me.uk/chrism/lasertag/MT2Proto.pdf

// Supports:
// Brand: Milestag2, Model: Various

// TODO(vitos1k): This implementation would support only
// short SHOT packets(14bits) and MSGs = 24bits. Support
// for long MSGs > 24bits is TODO

#include <algorithm>
#include "IRrecv.h"
#include "IRsend.h"
#include "IRutils.h"

// Constants
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add constants:

const uint16_t kMilesShotMask = 1 << (kMilesTag2ShotBits - 1);   // Shot packets have this bit as `0`
const uint32_t kMilesMsgMask = 1 << (kMilesTag2MsgBits - 1);   // Msg packets  have this bit as `1`
const uint8_t  kMilesMsgTerminator = 0xE8;

Per http://hosting.cmalton.me.uk/chrism/lasertag/MT2Proto.pdf Section 2.1 & 2.2

const uint16_t kMilesHdrMark = 2400;
const uint16_t kMilesSpace = 600;
const uint16_t kMilesOneMark = 1200;
const uint16_t kMilesZeroMark = 600;
const uint16_t kMilesRptLength = 32000;
const uint16_t kMilesMinGap = 32000;
const uint16_t kMilesStdFreq = 38000; // kHz
const uint16_t kMilesStdDuty = 25;



Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove two of these blank lines.

#if SEND_MILESTAG2
/// Send a MilesTag2 formatted Shot packet.
/// Status: NEEDS TESTING
/// @param[in] data The message to be sent.
/// @param[in] nbits The number of bits of message to be sent.
/// @param[in] repeat The number of times the command is to be repeated.

void IRsend::sendMilestag2(const uint64_t data, const uint16_t nbits,
const uint16_t repeat) {
sendGeneric(
kMilesHdrMark, kMilesSpace, // Header
kMilesOneMark, kMilesSpace, // 1 bit
kMilesZeroMark, kMilesSpace, // 0 bit
0, // No footer mark
kMilesRptLength, data, nbits, kMilesStdFreq, true, // MSB First
repeat, kMilesStdDuty);
}
#endif // SEND_MILESTAG2

#if DECODE_MILESTAG2
/// Decode the supplied MilesTag2 message.
/// Status: NEEDS TESTING
/// @param[in,out] results Ptr to the data to decode & where to store the result
/// @param[in] offset The starting index to use when attempting to decode the
/// raw data. Typically/Defaults to kStartOffset.
/// @param[in] nbits The number of data bits to expect.
/// @param[in] strict Flag indicating if we should perform strict matching.
/// @return True if it can decode it, false if it can't.
/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/706
bool IRrecv::decodeMiles(decode_results *results, uint16_t offset,
const uint16_t nbits, const bool strict) {
/*
uint16_t gap_pos = 0;
// we got alot more data than we thought,
// let's find last GAP and work from it
if (results->rawlen >= (2 * nbits + 1))
{
for (uint16_t ind = 0 ; ind < results->rawlen; ind++)
{
if (matchAtLeast(*(results->rawbuf+ind),34000)) gap_pos = ind;
}
}

if (results->rawlen>gap_pos) offset = gap_pos+1;
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this commented out code.

// Compliance
if (strict) {
switch (nbits) { // Check we've been called with a correct bit size.
case 14:
case 24:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case kMilesTag2ShotBits:
case kMilesTag2MsgBits:

break;
default:
DPRINT("incorrect nbits:");
DPRINTLN(nbits);
return false; // The request doesn't strictly match the protocol defn.
}
}
uint64_t data = 0;
if (!matchGeneric(results->rawbuf + offset, &data,
results->rawlen - offset, nbits,
kMilesHdrMark, kMilesSpace,
kMilesOneMark, kMilesSpace,
kMilesZeroMark, kMilesSpace,
0, kMilesRptLength, true)) return false;
// Success
Copy link
Owner

@crankyoldgit crankyoldgit Jan 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add before // Success:

  results->command = 0;
  results->address = 0;

  // Compliance
  if (strict) {
    switch (nbits) {
      case kMilesTag2ShotBits:
        // Is it a valid shot packet?
        if (data & kMilesShotMask) return false;
        results->command = data & 0x3F;  // Team & Damage
        results->address = data >> 6;  // Player ID.
        break;
      case kMilesTag2MsgBits:
        // Is it a valid msg packet? i.e. Msg bit set & Terminator present.
        if (!(data & kMilesMsgMask) || ((data & 0xFF) != kMilesMsgTerminator))
          return false;
        results->command = (data >> 8) & 0xFF;  // Message data
        results->address = (data >> 16) & 0x7F;  // Message ID
        break;
    }
  }

Note: I haven't tested or compiled that code, so there could be errors.

results->bits = nbits;
results->value = data;
results->decode_type = decode_type_t::MILESTAG2;
results->command = 0;
results->address = 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove. (Because it has been moved.)

return true;
}
#endif // DECODE_MILESTAG2
3 changes: 3 additions & 0 deletions src/locale/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@
#ifndef D_STR_MIDEA24
#define D_STR_MIDEA24 "MIDEA24"
#endif // D_STR_MIDEA24
#ifndef D_STR_MILESTAG2
#define D_STR_MILESTAG2 "MILESTAG2"
#endif // D_STR_MILESTAG2
#ifndef D_STR_MIRAGE
#define D_STR_MIRAGE "MIRAGE"
#endif // D_STR_MIRAGE
Expand Down