فهرست منبع

Merge pull request #16 from leedave/feature/td157

Feature/td157
David Lee 2 سال پیش
والد
کامیت
908eb0ba0e

+ 1 - 1
README.md

@@ -6,7 +6,7 @@ This app triggers restaurant pagers in a brute force manner, useful to test if d
 
 ## Supported Pagers
 - Retekess T119
-- Retekess TD157 (coming soon)
+- Retekess TD157
 - Retekess TD165 (coming soon)
 - Retekess TD174 (coming soon)
 

+ 0 - 8
assets/1-2-0.sub

@@ -1,8 +0,0 @@
-Filetype: Flipper SubGhz Key File
-Version: 1
-Frequency: 433920000
-Preset: FuriHalSubGhzPresetOok650Async
-Protocol: Princeton
-Bit: 24
-Key: 00 00 00 00 00 80 02 00
-TE: 271

+ 0 - 8
assets/1-3-0.sub

@@ -1,8 +0,0 @@
-Filetype: Flipper SubGhz Key File
-Version: 1
-Frequency: 433920000
-Preset: FuriHalSubGhzPresetOok650Async
-Protocol: Princeton
-Bit: 24
-Key: 00 00 00 00 00 80 06 00
-TE: 271

+ 0 - 8
assets/1-4-0.sub

@@ -1,8 +0,0 @@
-Filetype: Flipper SubGhz Key File
-Version: 1
-Frequency: 433920000
-Preset: FuriHalSubGhzPresetOok650Async
-Protocol: Princeton
-Bit: 24
-Key: 00 00 00 00 00 80 01 00
-TE: 271

+ 0 - 6
assets/1_1-1_1-0.sub

@@ -1,6 +0,0 @@
-Filetype: Flipper SubGhz RAW File
-Version: 1
-Frequency: 433920000
-Preset: FuriHalSubGhzPresetOok650Async
-Protocol: RAW
-RAW_Data: -6000 600 -200 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 600 -200 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -6000

+ 0 - 9
assets/1_1-1_4-0.sub

@@ -1,9 +0,0 @@
-Filetype: Flipper SubGhz RAW File
-Version: 1
-Frequency: 433920000
-Preset: FuriHalSubGhzPresetOok650Async
-Protocol: RAW
-RAW_Data: -6000 600 -200 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 600 -200 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -6000
-RAW_Data: -6000 600 -200 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 600 -200 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -6000
-RAW_Data: -6000 600 -200 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 600 -200 600 -200 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -6000
-RAW_Data: -6000 600 -200 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 600 -200 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -6000

+ 0 - 9
assets/8191_8191-1_4-0.sub

@@ -1,9 +0,0 @@
-Filetype: Flipper SubGhz RAW File
-Version: 1
-Frequency: 433920000
-Preset: FuriHalSubGhzPresetOok650Async
-Protocol: RAW
-RAW_Data: -6000 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -6000
-RAW_Data: -6000 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 200 -600 600 -200 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -6000
-RAW_Data: -6000 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -6000
-RAW_Data: -6000 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 600 -200 200 -600 200 -600 600 -200 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -600 200 -6000

+ 0 - 514
assets/Pagger - Retekess T119.html

@@ -1,514 +0,0 @@
-<!DOCTYPE html>
-<!-- saved from url=(0064)https://meoker.github.io/pagger/retekess-t119/retekess-t119.html -->
-<html lang="en" data-theme="light">
-
-<head>
-  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-
-  <meta name="viewport" content="width=device-width, initial-scale=1">
-  <link rel="stylesheet" href="./Pagger - Retekess T119_files/pico.min.css">
-  <title>Pagger - Retekess T119</title>
-
-  <style>
-    [data-theme="light"],
-    :root:not([data-theme="dark"]) {
-      --primary: #757575;
-      --primary-hover: #616161;
-      --primary-focus: rgba(117, 117, 117, 0.125);
-      --primary-inverse: #FFF;
-    }
-
-    :root {
-      --font-size: 15px;
-      --spacing: 0.25rem;
-      --form-element-spacing-vertical: 0.375rem;
-    }
-
-    h1 {
-      margin-bottom: 0;
-    }
-
-    h3 {
-      color: #757575;
-      --typography-spacing-vertical: 0rem;
-    }
-
-    article {
-      padding-left: 0.75rem;
-      padding-right: 0.75rem;
-      margin: 1.75rem 0;
-    }
-
-    article>header,
-    article>footer {
-      text-align: center;
-      margin-left: -0.75rem;
-      margin-right: -0.75rem;
-      padding: 0.375rem;
-    }
-
-    .container>header {
-      text-align: center;
-    }
-
-    .container>footer {
-      display: flex;
-    }
-
-    .container>footer .title {
-      flex: 1;
-    }
-
-    .container>footer .github,
-    .container>footer .home {
-      margin-left: 10px;
-    }
-
-    .orange-theme {
-      --primary: #fb8c00;
-      --primary-hover: #f57c00;
-      --primary-focus: rgba(251, 140, 0, 0.125);
-      --primary-inverse: #FFF;
-    }
-
-    .orange-theme h3 {
-      color: #fb8c00;
-    }
-
-    .orange-theme input:not([type=submit], [type=button], [type=reset], [role=switch], [readonly]):is(:active, :focus) {
-      --border-color: #fb8c00;
-    }
-
-    .orange-theme input:not([type=submit], [type=button], [type=reset], [type=range], [type=file], [readonly]):focus,
-    .orange-theme select:focus,
-    .orange-theme textarea:focus {
-      --box-shadow: 0 0 0 3px rgba(251, 140, 0, 0.125);
-    }
-
-    .green-theme {
-      --primary: #7cb342;
-      --primary-hover: #689f38;
-      --primary-focus: rgba(124, 179, 66, 0.125);
-      --primary-inverse: #FFF;
-    }
-
-    .green-theme h3 {
-      color: #7cb342;
-    }
-
-    .green-theme input:not([type=submit], [type=button], [type=reset], [role=switch], [readonly]):is(:active, :focus) {
-      --border-color: #7cb342;
-    }
-
-    .green-theme input:not([type=submit], [type=button], [type=reset], [type=range], [type=file], [readonly]):focus,
-    .green-theme select:focus,
-    .green-theme textarea:focus {
-      --box-shadow: 0 0 0 3px rgba(124, 179, 66, 0.125);
-    }
-
-    .blue-theme {
-      --primary: #039be5;
-      --primary-hover: #0288d1;
-      --primary-focus: rgba(3, 155, 229, 0.125);
-      --primary-inverse: #FFF;
-    }
-
-    .blue-theme h3 {
-      color: #039be5;
-    }
-
-    .blue-theme input:not([type=submit], [type=button], [type=reset], [role=switch], [readonly]):is(:active, :focus) {
-      --border-color: #039be5;
-    }
-
-    .blue-theme input:not([type=submit], [type=button], [type=reset], [type=range], [type=file], [readonly]):focus,
-    .blue-theme select:focus,
-    .blue-theme textarea:focus {
-      --box-shadow: 0 0 0 3px rgba(3, 155, 229, 0.125);
-    }
-
-    @media (max-width: 992px) {
-      .grid .grid {
-        display: flex;
-      }
-
-      .grid .grid div {
-        display: flex;
-        flex-direction: column;
-        flex: 1;
-      }
-    }
-  </style>
-
-  <script>
-    function decToBin(num, length) {
-      var res = (num >>> 0).toString(2);
-
-      while (res.length < length) {
-        res = '0' + res;
-      }
-
-      return res;
-    }
-
-    function binToDec(bits) {
-      return parseInt(bits, 2);
-    }
-
-    function hexToBin(hex) {
-      return (parseInt(hex, 16).toString(2)).toUpperCase().padStart(24, '0');
-    }
-
-    function binToHex(bits) {
-      return parseInt(bits, 2).toString(16).toUpperCase().padStart(6, '0');
-    }
-
-    function invert(bits) {
-      return bits.split('').map(function (b) {
-        return (1 - b).toString();
-      }).join('');
-    }
-
-    function reverse(bits) {
-      return bits.split('').reverse().join('');
-    }
-
-    function encManchester(bits, mode) {
-      var res = '';
-
-      for (var i = 0; i < bits.length; i++) {
-        var c = bits.charAt(i);
-        '0' == c ? res += mode ? '10' : '01' : '1' == c ? res += mode ? '01' : '10' : res += 'EE';
-      }
-
-      return res;
-    }
-
-    function decManchester(bits, mode) {
-      var res = '';
-
-      for (var i = 1; i < bits.length; i += 2) {
-        var c = bits.charAt(i);
-        var p = bits.charAt(i - 1);
-        '0' == p && '1' == c ? res += mode ? '1' : '0' : '1' == p && '0' == c ? res += mode ? '0' : '1' : res += 'E';
-      }
-
-      return res;
-    }
-
-    function genKeyData(hex) {
-      var formatted = hex.replace(/(.{2})/g, '$1 ').trim();
-      var res = 'Key: ' + formatted + '\n';
-
-      return res;
-    }
-
-    function genRawData(zero, one, repeats, bits) {
-      bits += '0';
-      var line = 'RAW_Data: -6000';
-      //alert(bits);
-      console.log('bitsLen = ' + bits.length);
-      for (var i = 0; i < bits.length; i++) {
-        var c = bits.charAt(i);
-        var p = bits.charAt(i - 1);
-        var t = c == '0' ? zero : one;
-
-        if (i % 2 == 0) {
-          line += ' ' + t;
-        } else {
-          line += ' -' + t;
-        }
-      }
-
-      line += ' -6000\n';
-
-      var res = '';
-
-      for (var r = 0; r < repeats; r++) {
-        res += line;
-      }
-
-      return res;
-    }
-
-    function genKeyFile(keyData) {
-      var header = 'Filetype: Flipper SubGhz Key File\nVersion: 1\nFrequency: 433920000\nPreset: FuriHalSubGhzPresetOok650Async\nProtocol: Princeton\nBit: 24\n';
-      var footer = 'TE: 271\n';
-
-      return header + keyData + footer;
-    }
-
-    function genRawFile(rawData) {
-      var header = 'Filetype: Flipper SubGhz RAW File\nVersion: 1\nFrequency: 433920000\nPreset: FuriHalSubGhzPresetOok650Async\nProtocol: RAW\n'
-
-      return header + rawData;
-    }
-
-    function calcNumToHex(station, pager, action) {
-      station = reverse(decToBin(station, 13));
-      pager = reverse(decToBin(pager, 10));
-      action = reverse(decToBin(action, 1));
-
-      var hex = binToHex(station + pager + action);
-
-      return hex;
-    }
-
-    function calcHexToNum() {
-      var hex = document.getElementById('hex-key-sp').value.toString();
-      var bin = hexToBin(hex);
-
-      var station = binToDec(reverse(bin.substring(0, 13)));
-      var pager = binToDec(reverse(bin.substring(13, 23)));
-      var action = binToDec(reverse(bin.substring(23, 24)));
-
-      document.getElementById('station-num-kp').value = station;
-      document.getElementById('pager-num-kp').value = pager;
-      document.getElementById('action-num-kp').value = action;
-
-      document.getElementById('station-num-from-rp').value = station;
-      document.getElementById('station-num-to-rp').value = station;
-      document.getElementById('pager-num-from-rp').value = 1;
-      document.getElementById('pager-num-to-rp').value = 100;
-      document.getElementById('action-num-rp').value = action;
-
-      document.getElementById('station-num-tp').value = station;
-    }
-
-    function downloadKeyFile() {
-      document.getElementById('key-download').setAttribute('aria-busy', true);
-
-      var station = Number(document.getElementById('station-num-kp').value);
-      var pager = Number(document.getElementById('pager-num-kp').value);
-      var action = Number(document.getElementById('action-num-kp').value);
-
-      var hex = calcNumToHex(station, pager, action).toString().padStart(16, '0');
-      var keyData = genKeyData(hex);
-      var file = genKeyFile(keyData);
-
-      var hiddenElement = document.createElement('a');
-      hiddenElement.href = 'data:attachment/text,' + encodeURI(file);
-      hiddenElement.target = '_blank';
-      hiddenElement.download = station + '-' + pager + '-' + action + '.sub';
-      hiddenElement.click();
-
-      document.getElementById('key-download').setAttribute('aria-busy', false);
-    }
-
-    function downloadRawFile() {
-      document.getElementById('raw-download').setAttribute('aria-busy', true);
-
-      var stationFrom = Number(document.getElementById('station-num-from-rp').value);
-      var stationTo = Number(document.getElementById('station-num-to-rp').value);
-      var pagerFrom = Number(document.getElementById('pager-num-from-rp').value);
-      var pagerTo = Number(document.getElementById('pager-num-to-rp').value);
-      var action = Number(document.getElementById('action-num-rp').value);
-
-      var rawData = '';
-      var actionBin = reverse(decToBin(action, 1));
-
-      for (var s = stationFrom; s <= stationTo; s++) {
-        var stationBin = reverse(decToBin(s, 13));
-        //alert(stationBin);
-
-        for (var p = pagerFrom; p <= pagerTo; p++) {
-          var pagerBin = reverse(decToBin(p, 10));
-
-          //console.log('bin stationBin: ' + stationBin);
-          //console.log('bin stationPager: ' + stationBin + pagerBin);
-          console.log('bin fullId: ' + stationBin + pagerBin + actionBin);
-
-          var bin = encManchester(stationBin + pagerBin + actionBin, 0);
-          console.log('manchester: ' + bin);
-          //alert(bin);
-          var raw26 = genRawData(200, 600, 10, bin);
-          var raw38 = genRawData(300, 800, 10, bin);
-
-          console.log(raw26);
-          rawData += raw26 + raw38;
-        }
-      }
-      return;
-
-      var file = genRawFile(rawData);
-
-      var hiddenElement = document.createElement('a');
-      hiddenElement.href = 'data:attachment/text,' + encodeURI(file);
-      hiddenElement.target = '_blank';
-      hiddenElement.download = stationFrom + '_' + stationTo + '-' + pagerFrom + '_' + pagerTo + '-' + action + '.sub';
-      hiddenElement.click();
-
-      document.getElementById('raw-download').setAttribute('aria-busy', false);
-    }
-
-    function downloadTurnOffFile() {
-      document.getElementById('turnoff-download').setAttribute('aria-busy', true);
-
-      var station = Number(document.getElementById('station-num-tp').value);
-      var pager = Number(1005);
-      var action = Number(0);
-
-      var hex = calcNumToHex(station, pager, action).toString().padStart(16, '0');
-      var keyData = genKeyData(hex);
-      var file = genKeyFile(keyData);
-
-      var hiddenElement = document.createElement('a');
-      hiddenElement.href = 'data:attachment/text,' + encodeURI(file);
-      hiddenElement.target = '_blank';
-      hiddenElement.download = station + '-turnoff.sub';
-      hiddenElement.click();
-
-      document.getElementById('turnoff-download').setAttribute('aria-busy', false);
-    }
-  </script>
-</head>
-
-<body>
-  <main class="container">
-
-    <header>
-      <h1 class="title">RETEKESS T119</h1>
-    </header>
-
-    <article id="signal-pane" class="orange-theme">
-      <header>
-        <h3>SIGNAL</h3>
-      </header>
-      <div class="grid">
-        <div></div>
-        <div>
-          <label for="hex-key-sp">Hex key:</label>
-          <input name="hex-key-sp" id="hex-key-sp" placeholder="00AABB" minlength="6" maxlength="6">
-        </div>
-        <div></div>
-      </div>
-      <div class="grid">
-        <div></div>
-        <button onclick="calcHexToNum()">Calculate ↓</button>
-        <div></div>
-      </div>
-      <footer>
-        Put here the hex key you got from the read.
-      </footer>
-    </article>
-
-    <article id="key-pane" class="green-theme">
-      <header>
-        <h3>KEY FILE</h3>
-      </header>
-      <div class="grid">
-        <div>
-          <label for="station-num-kp">Station:</label>
-          <input type="number" name="station-num-kp" id="station-num-kp" min="0" max="8191" placeholder="0 - 8191">
-        </div>
-        <div>
-          <label for="pager-num-kp">Pager:</label>
-          <input type="number" name="pager-num-kp" id="pager-num-kp" min="0" max="999" placeholder="0 - 999">
-        </div>
-        <div>
-          <label for="action-num-kp">Action:</label>
-          <input type="number" name="action-num-kp" id="action-num-kp" min="0" max="1" placeholder="0 ring - 1 mute">
-        </div>
-      </div>
-      <div class="grid">
-        <div></div>
-        <button id="key-download" onclick="downloadKeyFile()">Download</button>
-        <div></div>
-      </div>
-      <footer>
-        This single key file will call a single pager.
-      </footer>
-    </article>
-
-    <article id="raw-pane" class="green-theme">
-      <header>
-        <h3>RAW FILE</h3>
-      </header>
-      <div class="grid">
-        <div class="grid">
-          <div>
-            <label for="station-num-from-rp">Station (from):</label>
-            <input type="number" name="station-num-from-rp" id="station-num-from-rp" min="0" max="8191"
-              placeholder="0 - 8191">
-          </div>
-          <div>
-            <label for="station-num-to-rp">Station (to):</label>
-            <input type="number" name="station-num-to-rp" id="station-num-to-rp" min="0" max="8191"
-              placeholder="0 - 8191">
-          </div>
-        </div>
-        <div class="grid">
-          <div>
-            <label for="pager-num-from-rp">Pager (from):</label>
-            <input type="number" name="pager-num-from-rp" id="pager-num-from-rp" min="0" max="999"
-              placeholder="0 - 999">
-          </div>
-          <div>
-            <label for="pager-num-to-rp">Pager (to):</label>
-            <input type="number" name="pager-num-to-rp" id="pager-num-to-rp" min="0" max="999" placeholder="0 - 999">
-          </div>
-        </div>
-        <div class="grid">
-          <div>
-            <label for="action-num-rp">Action:</label>
-            <input type="number" name="action-num-rp" id="action-num-rp" min="0" max="1" placeholder="0 ring - 1 mute">
-          </div>
-        </div>
-      </div>
-      <div class="grid">
-        <div></div>
-        <button id="raw-download" onclick="downloadRawFile()" aria-busy="false">Download</button>
-        <div></div>
-      </div>
-      <footer>
-        This combo raw file will call multiple pagers.
-      </footer>
-    </article>
-
-    <article id="turnoff-pane" class="green-theme">
-      <header>
-        <h3>TURN-OFF FILE</h3>
-      </header>
-      <div class="grid">
-        <div></div>
-        <div>
-          <label for="station-num-tp">Station:</label>
-          <input type="number" name="station-num-tp" id="station-num-tp" min="0" max="8191" placeholder="0 - 8191">
-          <button id="turnoff-download" onclick="downloadTurnOffFile()">Download</button>
-        </div>
-        <div></div>
-      </div>
-      <footer>
-        This special action file will turn off all the pagers of a given station.
-      </footer>
-    </article>
-
-    <article id="bruteforce-pane" class="blue-theme">
-      <header>
-        <h3>BRUTEFORCE FILES</h3>
-      </header>
-      <div class="grid">
-        <div></div>
-        <button
-          onclick="window.location.href=&#39;https://github.com/meoker/pagger/tree/main/retekess-t119/bruteforce-t119.zip&#39;">Download</button>
-        <div></div>
-      </div>
-      <footer>
-        As explained <a href="https://meoker.github.io/pagger/#why-not-a-bruteforcer">here</a> I don't think the
-        bruteforce is a viable approach... <br>Anyway if you wanted to try it, these are the files to call the first 10
-        pagers for all stations.
-      </footer>
-    </article>
-
-    <footer>
-      <div class="title">Pagger - Flipper Zero Generator</div>
-      <div class="github"><a href="https://github.com/meoker/pagger">Github</a></div>
-      <div class="home"><a href="https://meoker.github.io/pagger">Home</a></div>
-    </footer>
-
-  </main>
-
-
-</body>
-
-</html>

+ 8 - 0
docs/changelog.md

@@ -1,3 +1,11 @@
+## v0.7
+
+- Added support for TD157
+- Some log & comment cleaning
+- Moved common code to new location
+- Removed testing assets
+- Fixed bad menu label (from "scene1" to "send data")
+
 ## v0.6
 
 - Display when data is being generated and when it is being sent

+ 80 - 0
helpers/meal_pager_calc.c

@@ -0,0 +1,80 @@
+#include "meal_pager_calc.h"
+
+void customConcat(char* dest, const char* src) {
+    // Find the end of the destination string
+    while (*dest != '\0') {
+        dest++;
+    }
+
+    // Copy characters from src to dest
+    while (*src != '\0') {
+        *dest = *src;
+        dest++;
+        src++;
+    }
+
+    // Null-terminate the concatenated string
+    *dest = '\0';
+}
+
+char* encManchester(const char* bits, int mode) {
+    // Allocate memory for the result string
+    char* res = (char*)malloc((strlen(bits) * 2 + 1) * sizeof(char));
+
+    int index = 0;
+    for (int i = 0; bits[i] != '\0'; i++) {
+        char c = bits[i];
+        if (c == '0') {
+            if (mode) {
+                res[index++] = '1';
+                res[index++] = '0';
+            } else {
+                res[index++] = '0';
+                res[index++] = '1';
+            }
+        } else if (c == '1') {
+            if (mode) {
+                res[index++] = '0';
+                res[index++] = '1';
+            } else {
+                res[index++] = '1';
+                res[index++] = '0';
+            }
+        } else {
+            // Handle 'EE' case (error)
+            res[index++] = 'E';
+            res[index++] = 'E';
+        }
+    }
+
+    // Null-terminate the result string
+    res[index] = '\0';
+
+    return res;
+}
+
+void uint32ToBinaray(uint32_t number, char* str, int8_t length) {
+    int i = 0;
+    length--; // count length without 0
+    for (i = length; i >= 0; i--) {
+        // Bitwise AND extration of the i-th bit
+        int bit = (number >> i) & 1;
+        // convert the bit to a character of 1 or 0
+        str[length - i] = bit + '0';
+    }
+    // Terminate the string
+    str[length+1] = '\0';
+}
+
+void reverse(char* str) {
+    int length = strlen(str);
+    int start = 0;
+    int end = length - 1;
+    while (start < end) {
+        char temp = str[start];
+        str[start] = str[end];
+        str[end] = temp;
+        start++;
+        end--;
+    }
+}

+ 12 - 0
helpers/meal_pager_calc.h

@@ -0,0 +1,12 @@
+
+#pragma once
+
+#include "../meal_pager_i.h"
+
+char* encManchester(const char* bits, int mode);
+
+void uint32ToBinaray(uint32_t number, char* str, int8_t length);
+
+void reverse(char* str);
+
+void customConcat(char* dest, const char* src);

+ 3 - 95
helpers/retekess/meal_pager_retekess_t119.c

@@ -1,44 +1,22 @@
 
 #include "meal_pager_retekess_t119.h"
 
-void customConcat(char* dest, const char* src) {
-    //FURI_LOG_D(TAG, "adding %s to %s", src, dest);
-    // Find the end of the destination string
-    while (*dest != '\0') {
-        dest++;
-    }
-
-    // Copy characters from src to dest
-    while (*src != '\0') {
-        *dest = *src;
-        dest++;
-        src++;
-    }
 
-    // Null-terminate the concatenated string
-    *dest = '\0';
-}
 
-char* genRawData(int zero, int one, const char* bits) {
+static char* genRawDataT119(int zero, int one, const char* bits) {
     int bitsLen = strlen(bits);
     int lineLen = 256; // Adjust the line length as needed
     char* line = (char*)malloc(lineLen * sizeof(char));
 
-    //FURI_LOG_D(TAG, "bitLen = %u", bitsLen);
     // Initialize the line with the first part
-    //snprintf(line, lineLen, "-6000");
-
-    //char* res = (char*)malloc((bitsLen * 4) * sizeof(char));
     char* res = (char*)malloc(lineLen * sizeof(char));
     res[0] = '\0'; // Null-terminate the result string
 
-    //customConcat(res, line);
     customConcat(res, "-6000");
 
     // Append bits and create the line
     for (int i = 0; i < bitsLen; i++) {
         char c = bits[i];
-        //char p = (i > 0) ? bits[i - 1] : '0';
         int t = (c == '0') ? zero : one;
 
         if (i % 2 == 0) {
@@ -48,93 +26,23 @@ char* genRawData(int zero, int one, const char* bits) {
         }
 
         // Concatenate the line to the result string
-        //strncat(res, line, bitsLen * 4);
         customConcat(res, line);
     }
 
     // Append the closing part to the line
-    //strncat(line, " -6000\n", lineLen);
     customConcat(res, " 200 -6000");
-    //FURI_LOG_D(TAG, "res is: %s", res);
-
+    
     free(line); // Free memory allocated for the line
 
     return res;
 }
 
-char* encManchester(const char* bits, int mode) {
-    // Allocate memory for the result string
-    char* res = (char*)malloc((strlen(bits) * 2 + 1) * sizeof(char));
-
-    int index = 0;
-    for (int i = 0; bits[i] != '\0'; i++) {
-        char c = bits[i];
-        if (c == '0') {
-            if (mode) {
-                res[index++] = '1';
-                res[index++] = '0';
-            } else {
-                res[index++] = '0';
-                res[index++] = '1';
-            }
-        } else if (c == '1') {
-            if (mode) {
-                res[index++] = '0';
-                res[index++] = '1';
-            } else {
-                res[index++] = '1';
-                res[index++] = '0';
-            }
-        } else {
-            // Handle 'EE' case (error)
-            res[index++] = 'E';
-            res[index++] = 'E';
-        }
-    }
-
-    // Null-terminate the result string
-    res[index] = '\0';
-
-    return res;
-}
-
-void uint32ToBinaray(uint32_t number, char* str, int8_t length) {
-    int i = 0;
-    length--; // count length without 0
-    for (i = length; i >= 0; i--) {
-        // Bitwise AND extration of the i-th bit
-        int bit = (number >> i) & 1;
-        // convert the bit to a character of 1 or 0
-        str[length - i] = bit + '0';
-    }
-    // Terminate the string
-    str[length+1] = '\0';
-}
-
-void reverse(char* str) {
-    int length = strlen(str);
-    int start = 0;
-    int end = length - 1;
-    while (start < end) {
-        char temp = str[start];
-        str[start] = str[end];
-        str[end] = temp;
-        start++;
-        end--;
-    }
-}
- 
 static void meal_pager_retekess_t119_generate_pager(void* context, char* stationId, uint32_t pager, FlipperFormat* ff) {
     Meal_Pager* app = context;
     char pagerId[11];
-    //char stationPagerId[25];
-    //char fullId[25];
     char* fullId = (char*)malloc(25 * sizeof(char));
     uint32_t action = 0; // 0 = ring, 1 = mute
     char actionId[2];
-    //char action[2];
-    //action[0] = '0'; // 0 = ring, 1 = mute
-    //action[1] = '\0';
     //FURI_LOG_D(TAG, "Generating T119 Data for Pager %lu", pager);
     app->current_pager = pager;
     meal_pager_transmit_model_set_pager(app->meal_pager_transmit, app->current_pager);
@@ -155,7 +63,7 @@ static void meal_pager_retekess_t119_generate_pager(void* context, char* station
     //FURI_LOG_D(TAG, "Station & Pager & Action: %s", fullId);
     char* manchester = encManchester(fullId, 0);
     //FURI_LOG_D(TAG, "Manchester: %s", manchester);
-    char* rawSignal = genRawData(200, 600, manchester);
+    char* rawSignal = genRawDataT119(200, 600, manchester);
     //FURI_LOG_D(TAG, "RAW_Data: %s", rawSignal);
     flipper_format_write_string_cstr(ff, "RAW_Data", rawSignal);
     free(manchester);

+ 1 - 12
helpers/retekess/meal_pager_retekess_t119.h

@@ -2,17 +2,6 @@
 #pragma once
 
 #include "../../meal_pager_i.h"
-
-char* encManchester(const char* bits, int mode);
-
-void uint32ToBinaray(uint32_t number, char* str, int8_t length);
-
-void reverse(char* str);
-
-void customConcat(char* dest, const char* src);
-
-//void meal_pager_retekess_t119_generate_pager(void* context, char* stationId, uint32_t pager);
-
-//void meal_pager_retekess_t119_generate_station(void* context, uint32_t station);
+#include "../meal_pager_calc.h"
 
 bool meal_pager_retekess_t119_generate_all(void* context);

+ 106 - 0
helpers/retekess/meal_pager_retekess_td157.c

@@ -0,0 +1,106 @@
+
+#include "meal_pager_retekess_td157.h"
+
+
+
+static char* genRawDataTD157(int zero, int one, const char* bits) {
+    int bitsLen = strlen(bits);
+    int lineLen = 256; // Adjust the line length as needed
+    char* line = (char*)malloc(lineLen * sizeof(char));
+
+    // Initialize the line with the first part
+    char* res = (char*)malloc(lineLen * sizeof(char));
+    res[0] = '\0'; // Null-terminate the result string
+
+    customConcat(res, "-6000");
+
+    // Append bits and create the line
+    for (int i = 0; i < bitsLen; i++) {
+        char c = bits[i];
+        int t = (c == '0') ? zero : one;
+
+        if (i % 2 == 0) {
+            snprintf(line, lineLen, " %d", t);
+        } else {
+            snprintf(line, lineLen, " -%d", t);
+        }
+
+        // Concatenate the line to the result string
+        customConcat(res, line);
+    }
+
+    // Append the closing part to the line
+    customConcat(res, " 200 -6000");
+    
+    free(line); // Free memory allocated for the line
+
+    return res;
+}
+
+static void meal_pager_retekess_td157_generate_pager(void* context, char* stationId, uint32_t pager, FlipperFormat* ff) {
+    Meal_Pager* app = context;
+    char pagerId[11];
+    char* fullId = (char*)malloc(25 * sizeof(char));
+    uint32_t action = 2;
+    char actionId[4];
+    app->current_pager = pager;
+    meal_pager_transmit_model_set_pager(app->meal_pager_transmit, app->current_pager);
+    FURI_LOG_D(TAG, "Generating TD157 Data for Pager %lu", pager);
+    uint32ToBinaray(pager, pagerId, 10);
+    customConcat(fullId, stationId);
+    customConcat(fullId, pagerId);
+    uint32ToBinaray(action, actionId, 4);
+    customConcat(fullId, actionId);
+    char* manchester = encManchester(fullId, 0);
+    char* rawSignal = genRawDataTD157(200, 600, manchester);
+    flipper_format_write_string_cstr(ff, "RAW_Data", rawSignal);
+    free(manchester);
+    free(rawSignal);
+}
+
+static void meal_pager_retekess_td157_generate_station(void* context, uint32_t station, FlipperFormat* ff) {
+    Meal_Pager* app = context;
+    FURI_LOG_D(TAG, "Generating TD157 Data for Station %lu. Pagers From %lu to %lu", station, app->first_pager, app->last_pager);
+    app->current_station = station;
+    app->current_pager = app->first_pager;
+    char stationId[14];
+    uint32ToBinaray(station, stationId, 10);
+    //reverse(stationId);
+    meal_pager_transmit_model_set_station(app->meal_pager_transmit, app->current_station);
+    for (u_int32_t i = app->current_pager;i <= app->last_pager; i++) {
+        meal_pager_retekess_td157_generate_pager(app, stationId, i, ff);
+        if (app->stop_transmit) {
+            break;
+        }
+    }
+}
+
+bool meal_pager_retekess_td157_generate_all(void* context) {
+    Meal_Pager* app = context;
+
+    app->current_pager = 1;
+    app->current_station = app->first_station;
+
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    FlipperFormat* ff = flipper_format_file_alloc(storage);
+    bool success = meal_pager_save_subghz_buffer_file_start(app, ff, storage);
+
+    if (!success) {
+        FURI_LOG_D(TAG, "failed to save to buffer");
+        meal_pager_save_subghz_buffer_stop(app, ff);
+        furi_record_close(RECORD_STORAGE);
+        return success;
+    }
+    
+    for (u_int32_t i = app->current_station;i <= app->last_station; i++) {
+        meal_pager_retekess_td157_generate_station(app, i, ff);
+        if (app->stop_transmit) {
+            break;
+        }
+    }
+
+    meal_pager_save_subghz_buffer_stop(app, ff);
+    furi_record_close(RECORD_STORAGE);
+    return success;
+}
+

+ 7 - 0
helpers/retekess/meal_pager_retekess_td157.h

@@ -0,0 +1,7 @@
+
+#pragma once
+
+#include "../../meal_pager_i.h"
+#include "../meal_pager_calc.h"
+
+bool meal_pager_retekess_td157_generate_all(void* context);

+ 1 - 2
scenes/meal_pager_scene_menu.c

@@ -19,7 +19,7 @@ void meal_pager_scene_menu_submenu_callback(void* context, uint32_t index) {
 void meal_pager_scene_menu_on_enter(void* context) {
     Meal_Pager* app = context;
 
-    submenu_add_item(app->submenu, "Scene 1 (empty)", SubmenuIndexTransmit, meal_pager_scene_menu_submenu_callback, app);
+    submenu_add_item(app->submenu, "Send Data", SubmenuIndexTransmit, meal_pager_scene_menu_submenu_callback, app);
     submenu_add_item(app->submenu, "Settings", SubmenuIndexSettings, meal_pager_scene_menu_submenu_callback, app);
 
     submenu_set_selected_item(app->submenu, scene_manager_get_scene_state(app->scene_manager, Meal_PagerSceneMenu));
@@ -58,7 +58,6 @@ bool meal_pager_scene_menu_on_event(void* context, SceneManagerEvent event) {
             subghz_txrx_stop(app->subghz->txrx);
             meal_pager_blink_stop(app);
             meal_pager_transmit_model_set_sending(app->meal_pager_transmit, 0);
-            //notification_message(app->notification, &sequence_blink_magenta_10);
         }
         return true;
     }

+ 1 - 1
scenes/meal_pager_scene_settings.c

@@ -145,7 +145,7 @@ void meal_pager_scene_settings_on_enter(void* context) {
         app->variable_item_list,
         "Pager Type:",
         //4,
-        1,
+        2,
         meal_pager_scene_settings_set_pager_type,
         app);
     value_index = value_index_uint32(app->pager_type, pager_type_value, 4);

+ 13 - 4
scenes/meal_pager_scene_transmit.c

@@ -1,6 +1,7 @@
 #include "../meal_pager_i.h"
 #include "../helpers/meal_pager_custom_event.h"
 #include "../helpers/retekess/meal_pager_retekess_t119.h"
+#include "../helpers/retekess/meal_pager_retekess_td157.h"
 #include "../views/meal_pager_transmit.h"
 #include "../helpers/meal_pager_led.h"
 #include "../helpers/subghz/subghz.h"
@@ -25,22 +26,30 @@ void meal_pager_scene_transmit_on_enter(void* context) {
     meal_pager_transmit_model_set_pager(app->meal_pager_transmit, app->current_pager);
     meal_pager_transmit_set_callback(app->meal_pager_transmit, meal_pager_transmit_callback, app);
     view_dispatcher_switch_to_view(app->view_dispatcher, Meal_PagerViewIdTransmit);
-    bool generated = meal_pager_retekess_t119_generate_all(app);
+    bool generated = false;
+    switch (app->pager_type) {
+        case Meal_PagerPagerTypeT119:
+            generated = meal_pager_retekess_t119_generate_all(app);
+            break;
+        case Meal_PagerPagerTypeTD157:
+            generated = meal_pager_retekess_td157_generate_all(app);
+            break;
+        default:
+            generated = false;
+            break;
+    }
     if (!generated) {
         FURI_LOG_D(TAG, "Could not generate temp file");
         meal_pager_blink_stop(app);
         return;
     }
     FURI_LOG_D(TAG, "Generated tmp.sub");
-    //meal_pager_blink_start_subghz(app);
     FURI_LOG_D(TAG, "Start Transmitting");
     if (!app->stop_transmit) {
         meal_pager_transmit_model_set_sending(app->meal_pager_transmit, 1);
         subghz_send(app);
     }
     dolphin_deed(DolphinDeedSubGhzSend);
-    //FURI_LOG_D(TAG, "Finished Transmitting");
-    //meal_pager_blink_stop(app);
 }