ir_Pronto_test.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. // Copyright 2017 David Conran
  2. #include "IRsend.h"
  3. #include "IRsend_test.h"
  4. #include "gtest/gtest.h"
  5. // Tests for sendPronto().
  6. TEST(TestSendPronto, CodeTooShort) {
  7. IRsendTest irsend(4);
  8. irsend.begin();
  9. irsend.reset();
  10. // Less entries than the smallest possible (practical) Pronto code.
  11. uint16_t pronto_test[5] = {0x0000, 0x0067, 0x0034, 0x0000, 0x0000};
  12. irsend.sendPronto(pronto_test, 5);
  13. EXPECT_EQ("", irsend.outputStr()); // Should do nothing.
  14. }
  15. TEST(TestSendPronto, NormalSequenceTooLong) {
  16. IRsendTest irsend(4);
  17. irsend.begin();
  18. irsend.reset();
  19. // The First 'Normal' sequence is declared to be longer than the data we have.
  20. uint16_t pronto_test[6] = {0x0000, 0x0067, 0x0010, 0x0000, 0x0000, 0x0000};
  21. irsend.sendPronto(pronto_test, 6);
  22. EXPECT_EQ("", irsend.outputStr()); // Should do nothing.
  23. }
  24. TEST(TestSendPronto, RepeatSequenceTooLong) {
  25. IRsendTest irsend(4);
  26. irsend.begin();
  27. irsend.reset();
  28. // The 2nd 'Repeat' sequence is declared to be longer than the data we have.
  29. uint16_t pronto_test[6] = {0x0000, 0x0067, 0x0000, 0x0010, 0x0000, 0x0000};
  30. irsend.sendPronto(pronto_test, 6);
  31. EXPECT_EQ("", irsend.outputStr()); // Should do nothing.
  32. }
  33. TEST(TestSendPronto, BothSequencesTooLong) {
  34. IRsendTest irsend(4);
  35. irsend.begin();
  36. irsend.reset();
  37. // All sequences are declared to be longer than the data we have.
  38. uint16_t pronto_test[6] = {0x0000, 0x0067, 0x0010, 0x0010, 0x0000, 0x0000};
  39. irsend.sendPronto(pronto_test, 6);
  40. EXPECT_EQ("", irsend.outputStr()); // Should do nothing.
  41. }
  42. TEST(TestSendPronto, MoreDataThanNeededInNormal) {
  43. IRsendTest irsend(4);
  44. irsend.begin();
  45. irsend.reset();
  46. // We should handle when we are given more data than needed. (normal seq.)
  47. uint16_t pronto_test[8] = {0x0000, 0x0067, 0x0001, 0x0000,
  48. 0x0001, 0x0002, 0x0003, 0x0004};
  49. irsend.sendPronto(pronto_test, 8);
  50. EXPECT_EQ("m25s50", irsend.outputStr()); // Only send the data required.
  51. }
  52. TEST(TestSendPronto, MoreDataThanNeededInRepeat) {
  53. IRsendTest irsend(4);
  54. irsend.begin();
  55. irsend.reset();
  56. // We should handle when we are given more data than needed. (repeat seq.)
  57. uint16_t pronto_test[8] = {0x0000, 0x0067, 0x0000, 0x0001,
  58. 0x0001, 0x0002, 0x0003, 0x0004};
  59. irsend.sendPronto(pronto_test, 8);
  60. EXPECT_EQ("m25s50", irsend.outputStr()); // Only send the data required.
  61. }
  62. TEST(TestSendPronto, MoreDataThanNeededInBoth) {
  63. IRsendTest irsend(4);
  64. irsend.begin();
  65. irsend.reset();
  66. // We should handle when we are given more data than needed. (repeat seq.)
  67. uint16_t pronto_test[10] = {0x0000, 0x0067, 0x0001, 0x0001, 0x0001,
  68. 0x0002, 0x0003, 0x0004, 0x5, 0x6};
  69. irsend.sendPronto(pronto_test, 10);
  70. EXPECT_EQ("m25s50", irsend.outputStr()); // Only send the data required.
  71. irsend.sendPronto(pronto_test, 10, 1);
  72. EXPECT_EQ("m25s50m75s100", irsend.outputStr()); // Only the data required.
  73. }
  74. TEST(TestSendPronto, ShortestValidCodeThatSendsNothing) {
  75. IRsendTest irsend(4);
  76. irsend.begin();
  77. irsend.reset();
  78. uint16_t pronto_test[6] = {0x0000, 0x0067, 0x0000, 0x0000, 0x0001, 0x0002};
  79. irsend.sendPronto(pronto_test, 6);
  80. EXPECT_EQ("", irsend.outputStr()); // Nothing Happens.
  81. irsend.sendPronto(pronto_test, 6, 1);
  82. EXPECT_EQ("", irsend.outputStr()); // Twice as much Nothing Happens. ;-)
  83. }
  84. // Test sending a Pronto code that only has a normal (first) sequence.
  85. // i.e. No Pronto repeat sequence.
  86. TEST(TestSendPronto, NonRepeatingCode) {
  87. IRsendTest irsend(4);
  88. IRrecv irrecv(4);
  89. irsend.begin();
  90. // A random Pronto code I found on the Internet that has no repeat sequence.
  91. // It was an example of a poor Pronto code.
  92. // It turned out to be a 4 copies of a Sony 12-bit code. Who knew!?!
  93. uint16_t pronto_test[108] = {
  94. 0x0000, 0x0067, 0x0034, 0x0000, 0x0060, 0x0018, 0x0018, 0x0018, 0x0018,
  95. 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
  96. 0x0018, 0x0018, 0x0030, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
  97. 0x0018, 0x0018, 0x0452, 0x0060, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
  98. 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
  99. 0x0018, 0x0030, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
  100. 0x0018, 0x0452, 0x0060, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
  101. 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
  102. 0x0030, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
  103. 0x0452, 0x0060, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
  104. 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0030,
  105. 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018};
  106. // Send the Pronto code without any repeats set.
  107. irsend.reset();
  108. irsend.sendPronto(pronto_test, 108);
  109. irsend.makeDecodeResult();
  110. EXPECT_TRUE(irrecv.decode(&irsend.capture));
  111. EXPECT_EQ(SONY, irsend.capture.decode_type);
  112. EXPECT_EQ(kSony12Bits, irsend.capture.bits);
  113. EXPECT_EQ(0x10, irsend.capture.value);
  114. EXPECT_EQ(0x1, irsend.capture.address);
  115. EXPECT_EQ(0x0, irsend.capture.command);
  116. EXPECT_EQ(
  117. "m2400s600"
  118. "m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
  119. "m600s600m600s600m600s600m600s27650"
  120. "m2400s600"
  121. "m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
  122. "m600s600m600s600m600s600m600s27650"
  123. "m2400s600"
  124. "m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
  125. "m600s600m600s600m600s600m600s27650"
  126. "m2400s600"
  127. "m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
  128. "m600s600m600s600m600s600m600s600",
  129. irsend.outputStr());
  130. // Now try repeating it.
  131. // As it has no repeat sequence, we shouldn't repeat it. (I think)
  132. irsend.reset();
  133. irsend.sendPronto(pronto_test, 108, 3);
  134. irsend.makeDecodeResult();
  135. EXPECT_TRUE(irrecv.decode(&irsend.capture));
  136. EXPECT_EQ(SONY, irsend.capture.decode_type);
  137. EXPECT_EQ(kSony12Bits, irsend.capture.bits);
  138. EXPECT_EQ(0x10, irsend.capture.value);
  139. EXPECT_EQ(0x1, irsend.capture.address);
  140. EXPECT_EQ(0x0, irsend.capture.command);
  141. EXPECT_EQ(
  142. "m2400s600"
  143. "m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
  144. "m600s600m600s600m600s600m600s27650"
  145. "m2400s600"
  146. "m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
  147. "m600s600m600s600m600s600m600s27650"
  148. "m2400s600"
  149. "m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
  150. "m600s600m600s600m600s600m600s27650"
  151. "m2400s600"
  152. "m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
  153. "m600s600m600s600m600s600m600s600",
  154. irsend.outputStr());
  155. }
  156. // Test sending a Pronto code that only has a repeat sequence (Sony).
  157. TEST(TestSendPronto, RepeatSequenceOnlyForSony) {
  158. IRsendTest irsend(4);
  159. IRrecv irrecv(4);
  160. irsend.begin();
  161. // Sony 20-bit command.
  162. uint16_t pronto_test[46] = {
  163. 0x0000, 0x0067, 0x0000, 0x0015, 0x0060, 0x0018, 0x0018, 0x0018,
  164. 0x0030, 0x0018, 0x0030, 0x0018, 0x0030, 0x0018, 0x0018, 0x0018,
  165. 0x0030, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0030, 0x0018,
  166. 0x0018, 0x0018, 0x0030, 0x0018, 0x0030, 0x0018, 0x0030, 0x0018,
  167. 0x0018, 0x0018, 0x0018, 0x0018, 0x0030, 0x0018, 0x0018, 0x0018,
  168. 0x0018, 0x0018, 0x0030, 0x0018, 0x0018, 0x03f6};
  169. // Send the Pronto code without any repeats set.
  170. irsend.reset();
  171. irsend.sendPronto(pronto_test, 46);
  172. irsend.makeDecodeResult();
  173. EXPECT_TRUE(irrecv.decode(&irsend.capture));
  174. EXPECT_EQ(SONY, irsend.capture.decode_type);
  175. EXPECT_EQ(kSony20Bits, irsend.capture.bits);
  176. EXPECT_EQ(0x74B92, irsend.capture.value);
  177. EXPECT_EQ(0x1A, irsend.capture.address);
  178. EXPECT_EQ(0x24AE, irsend.capture.command);
  179. EXPECT_EQ(
  180. "m2400s600"
  181. "m600s600m1200s600m1200s600m1200s600m600s600m1200s600m600s600m600s600"
  182. "m1200s600m600s600m1200s600m1200s600m1200s600m600s600m600s600m1200s600"
  183. "m600s600m600s600m1200s600m600s25350",
  184. irsend.outputStr());
  185. // Send the Pronto code with 2 repeats.
  186. irsend.reset();
  187. irsend.sendPronto(pronto_test, 46, kSonyMinRepeat);
  188. irsend.makeDecodeResult();
  189. EXPECT_TRUE(irrecv.decode(&irsend.capture));
  190. EXPECT_EQ(SONY, irsend.capture.decode_type);
  191. EXPECT_EQ(kSony20Bits, irsend.capture.bits);
  192. EXPECT_EQ(0x74B92, irsend.capture.value);
  193. EXPECT_EQ(0x1A, irsend.capture.address);
  194. EXPECT_EQ(0x24AE, irsend.capture.command);
  195. EXPECT_EQ(
  196. "m2400s600"
  197. "m600s600m1200s600m1200s600m1200s600m600s600m1200s600m600s600m600s600"
  198. "m1200s600m600s600m1200s600m1200s600m1200s600m600s600m600s600m1200s600"
  199. "m600s600m600s600m1200s600m600s25350"
  200. "m2400s600"
  201. "m600s600m1200s600m1200s600m1200s600m600s600m1200s600m600s600m600s600"
  202. "m1200s600m600s600m1200s600m1200s600m1200s600m600s600m600s600m1200s600"
  203. "m600s600m600s600m1200s600m600s25350"
  204. "m2400s600"
  205. "m600s600m1200s600m1200s600m1200s600m600s600m1200s600m600s600m600s600"
  206. "m1200s600m600s600m1200s600m1200s600m1200s600m600s600m600s600m1200s600"
  207. "m600s600m600s600m1200s600m600s25350",
  208. irsend.outputStr());
  209. }
  210. // Test sending a Pronto code that only has a repeat sequence (Panasonic).
  211. TEST(TestSendPronto, RepeatSequenceOnlyForPanasonic) {
  212. IRsendTest irsend(4);
  213. IRrecv irrecv(4);
  214. irsend.begin();
  215. // Panasonic Plasma TV Descrete code (Power On).
  216. uint16_t pronto_test[104] = {
  217. 0x0000, 0x0071, 0x0000, 0x0032, 0x0080, 0x003F, 0x0010, 0x0010, 0x0010,
  218. 0x0030, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
  219. 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
  220. 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0030, 0x0010, 0x0010,
  221. 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
  222. 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0030,
  223. 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
  224. 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
  225. 0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0030, 0x0010,
  226. 0x0030, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0030,
  227. 0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0030, 0x0010,
  228. 0x0010, 0x0010, 0x0030, 0x0010, 0x0A98};
  229. // Send the Pronto code without any repeats set.
  230. irsend.reset();
  231. irsend.sendPronto(pronto_test, 104);
  232. irsend.makeDecodeResult();
  233. EXPECT_TRUE(irrecv.decode(&irsend.capture));
  234. EXPECT_EQ(PANASONIC, irsend.capture.decode_type);
  235. EXPECT_EQ(kPanasonicBits, irsend.capture.bits);
  236. EXPECT_EQ(0x400401007C7D, irsend.capture.value);
  237. EXPECT_EQ(0x4004, irsend.capture.address);
  238. EXPECT_EQ(0x1007C7D, irsend.capture.command);
  239. EXPECT_EQ(
  240. "m3456s1701"
  241. "m432s432m432s1296m432s432m432s432m432s432m432s432m432s432m432s432"
  242. "m432s432m432s432m432s432m432s432m432s432m432s1296m432s432m432s432"
  243. "m432s432m432s432m432s432m432s432m432s432m432s432m432s432m432s1296"
  244. "m432s432m432s432m432s432m432s432m432s432m432s432m432s432m432s432"
  245. "m432s432m432s1296m432s1296m432s1296m432s1296m432s1296m432s432m432s432"
  246. "m432s432m432s1296m432s1296m432s1296m432s1296m432s1296m432s432m432s1296"
  247. "m432s73224",
  248. irsend.outputStr());
  249. }
  250. // Test sending a Pronto code that has a normal & arepeat sequence (NEC).
  251. TEST(TestSendPronto, NormalPlusRepeatSequence) {
  252. IRsendTest irsend(4);
  253. IRrecv irrecv(4);
  254. irsend.begin();
  255. // NEC 32 bit power on command.
  256. uint16_t pronto_test[76] = {
  257. 0x0000, 0x006D, 0x0022, 0x0002, 0x0156, 0x00AB, 0x0015, 0x0015, 0x0015,
  258. 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015,
  259. 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015,
  260. 0x0040, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040,
  261. 0x0015, 0x0040, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
  262. 0x0040, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
  263. 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015, 0x0015,
  264. 0x0040, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x05FD,
  265. 0x0156, 0x0055, 0x0015, 0x0E4E};
  266. // Send the Pronto code without any repeats set.
  267. irsend.reset();
  268. irsend.sendPronto(pronto_test, 76);
  269. irsend.makeDecodeResult();
  270. EXPECT_TRUE(irrecv.decode(&irsend.capture));
  271. EXPECT_EQ(NEC, irsend.capture.decode_type);
  272. EXPECT_EQ(kNECBits, irsend.capture.bits);
  273. EXPECT_EQ(0x18E710EF, irsend.capture.value);
  274. EXPECT_EQ(0x18, irsend.capture.address);
  275. EXPECT_EQ(0x8, irsend.capture.command);
  276. EXPECT_EQ(
  277. "m8892s4446"
  278. "m546s546m546s546m546s546m546s1664m546s1664m546s546m546s546m546s546"
  279. "m546s1664m546s1664m546s1664m546s546m546s546m546s1664m546s1664m546s1664"
  280. "m546s546m546s546m546s546m546s1664m546s546m546s546m546s546m546s546"
  281. "m546s1664m546s1664m546s1664m546s546m546s1664m546s1664m546s1664m546s1664"
  282. "m546s39858",
  283. irsend.outputStr());
  284. // Send it again with a single repeat.
  285. irsend.reset();
  286. irsend.sendPronto(pronto_test, 76, 1);
  287. irsend.makeDecodeResult();
  288. EXPECT_TRUE(irrecv.decode(&irsend.capture));
  289. EXPECT_EQ(NEC, irsend.capture.decode_type);
  290. EXPECT_EQ(kNECBits, irsend.capture.bits);
  291. EXPECT_EQ(0x18E710EF, irsend.capture.value);
  292. EXPECT_EQ(0x18, irsend.capture.address);
  293. EXPECT_EQ(0x8, irsend.capture.command);
  294. EXPECT_EQ(
  295. "m8892s4446"
  296. "m546s546m546s546m546s546m546s1664m546s1664m546s546m546s546m546s546"
  297. "m546s1664m546s1664m546s1664m546s546m546s546m546s1664m546s1664m546s1664"
  298. "m546s546m546s546m546s546m546s1664m546s546m546s546m546s546m546s546"
  299. "m546s1664m546s1664m546s1664m546s546m546s1664m546s1664m546s1664m546s1664"
  300. "m546s39858"
  301. "m8892s2210m546s95212",
  302. irsend.outputStr());
  303. // Send it again with a two repeats.
  304. irsend.reset();
  305. irsend.sendPronto(pronto_test, 76, 2);
  306. irsend.makeDecodeResult();
  307. EXPECT_TRUE(irrecv.decode(&irsend.capture));
  308. EXPECT_EQ(NEC, irsend.capture.decode_type);
  309. EXPECT_EQ(kNECBits, irsend.capture.bits);
  310. EXPECT_EQ(0x18E710EF, irsend.capture.value);
  311. EXPECT_EQ(0x18, irsend.capture.address);
  312. EXPECT_EQ(0x8, irsend.capture.command);
  313. EXPECT_EQ(
  314. "m8892s4446"
  315. "m546s546m546s546m546s546m546s1664m546s1664m546s546m546s546m546s546"
  316. "m546s1664m546s1664m546s1664m546s546m546s546m546s1664m546s1664m546s1664"
  317. "m546s546m546s546m546s546m546s1664m546s546m546s546m546s546m546s546"
  318. "m546s1664m546s1664m546s1664m546s546m546s1664m546s1664m546s1664m546s1664"
  319. "m546s39858"
  320. "m8892s2210m546s95212"
  321. "m8892s2210m546s95212",
  322. irsend.outputStr());
  323. }