Futaba: T-FHSS Surface, SR and Air sub protocols (#1213)

* Futaba: T-FHSS Surface, SR and Air sub protocols

New sub protocols of Futaba (21) next to SFHSS, on the CC2500:

- TFHSS: T-FHSS Surface (R334SBS...). 384 kbps MSK, 3 ms frames,
  CH1-4 every frame and CH5-8 in turn, bind packets on channel 1,
  failsafe, telemetry.
- TFH-SR: T-FHSS SR, 1.2 ms frames, no telemetry.
- TF-Air: T-FHSS Air (R3008SB...). 128 kbps 2-FSK, 15 ms frames, 16
  channels, link with the receiver's ID, telemetry. No failsafe frames
  (the receiver's own).

From the R334SBS receiver and T18SZ transmitter firmware, checked
against captures of a 4PM Plus (Surface, SR) and a T6K (Air) shared on
issue #507.

Telemetry (FUTABA_FW_TELEMETRY): the link frame (A1 = receiver voltage,
RSSI = its link quality) and a new MULTI_TELEMETRY_FUTABA (0x13) frame
with the S.BUS2 sensor slots as the receiver sends them, for the radio
to decode (Multiprotocol.h).

Tested against a CC2652/CC2755 receiver of the packets, not on real
Futaba receivers yet. Size: +3.0 KB on the STM32 builds, Futaba alone
on the ATmega328p 14.9 KB.

* Futaba: T-FHSS on STM32 only

T-FHSS adds 3.9 KB on the ATmega328p, and the CC2500 release build
(all its CC2500 protocols) no longer fits. FUTABA_TFHSS (Validate.h)
enables the T-FHSS sub protocols on STM32 boards only; on the ATmega
Futaba is S-FHSS alone, as before (same build size as master).

* Futaba: no T-FHSS on the 64KB STM32

The CC2500 64KB release build was 1 KB over with T-FHSS (+3.1 KB).
FUTABA_TFHSS now needs a 128KB STM32 (not MCU_STM32F103C8, as the
surface protocols in Validate.h). All release recipes build: 64KB as
master (53200 bytes), 4-in-1 117940, T18 118856.

* Futaba: T-FHSS bind hops the list and waits for the reply

The R334SBS scans the 16-channel list in its link mode, answers a bind
packet on that channel (type 24 / 25, keyed as its telemetry) and only
stores the bind after packets with byte 1 bit 7. The 4PM Plus sets bit 7
once it has heard the reply and binds 9.1 s without one. So the bind
now hops the list at 3 ms per packet (channel 1 every 48 ms, as
captured), listens on the same channel, then sends 240 packets with
bit 7; 9.6 s at most.

* Futaba: T-FHSS binds at the normal power

The bind (Surface, SR) and the Air link now use the radio's power
setting (low / high, range), not CC2500_BIND_POWER. The R334SBS takes a
bind packet only above about -79 dBm (its RSSI check); at bind power
the packets were 41 dB below the servo frames. The 4PM Plus binds 33 dB
down from a higher level, the T6K links at full power. Checked on the
bench with a 4-in-1 answering as the receiver (Surface and Air).

* Futaba: T-FHSS Air picks slot channels as the T18SZ

Slots 0..5 and 8 carry their own channel or the alternate (ch11..16,
ch10), chosen as the T18SZ does: a channel moved = more than 3 us from
the value last sent, age = frames since sent. Own moved: the alternate
if it moved too and is 2 frames old, or is 64 old. Own still: the
alternate if it moved (unless own is 64 old), else the older one, own
on a tie. Was: the halves in turn, so moving sticks went out every
other frame.

* Futaba: T-FHSS bind reply on the next list channel

The R334SBS hops before it replies to a bind packet, as it does for its
telemetry: the module now listens on the next list channel after each
bind packet, not on the same one. A 4PM Plus bind followed over the
list: no reply on the bind packet's channel, and byte 7 of the bind
packet is the channel it is sent on (the receiver echoes it), not 01.
Bench (4-in-1 answering as the receiver): normal and SR link.

* Futaba: T-FHSS Surface keys with the receiver's ID

The last 4 key bytes of T-FHSS Surface are the receiver's own ID (its
serial number), not a number of the TX: the receiver keeps only the TX
ID from the bind. The module sent its own, so the R334SBS bound but
decoded no servo packet. The ID now comes from the receiver's bind
reply and is stored per RX number (TFHSS_EEPROM_OFFSET 1527, 4 bytes
per model, end 1783). Bench (4-in-1 answering as the receiver with its
own ID): bind, servo packets OK, again after a restart without bind.

* Futaba: T-FHSS Surface reads the reply before the next packet

The reply comes 1.9 ms after the TX packet's start, the read was 2.5 ms
after the callback: on the MPM v2 replies were taken up to 1.5 ms only.
Now the next frame's packet is built, the reply read, then the packet
sent.

* Futaba: S.BUS2 sensors Lua tool

S.BUS2 sensors don't tell their type on the bus: the radio shows each
slot with data (telemetry type 19) as a raw sensor. The tool turns a
slot into a typed sensor the radio decodes (SBS-01T/TE, RPM, voltage,
current), with an ESCape32 preset. Uses model.setSensor() and
model.deleteSensor() when the radio has them (EdgeTX/edgetx#8105),
else setTelemetryValue() with "Discover new sensors" on.

---------

Co-authored-by: Raphael Coeffic <1050031+raphaelcoeffic@users.noreply.github.com>
This commit is contained in:
Raphael CoefficandRaphael Coeffic authored and GitHub committed 2026-11-21 16:04:09 +01:00
1 parent 54ad3d26fd
commit 2a13543cdc
10 files changed
+1158 -8

No files matched your search

+348
View File
@@ -0,0 +1,348 @@
local toolName = "TNS|Futaba S.BUS2 sensors|TNE"
-- Sets up the S.BUS2 sensors of a Futaba receiver on a MULTI-Module (T-FHSS): EdgeTX's Futaba telemetry (radio/src/telemetry/futaba.h)
-- shows a slot with data that no sensor claims as a raw sensor "S<slot>"
-- (ID 0x1310, instance = the slot). S.BUS2 sensors don't tell their type
-- on the bus, so this tool creates the typed sensors: ID = the type,
-- instance = its first slot, subId = the value (types with several). Once
-- a typed sensor claims a slot, EdgeTX decodes it. With model.setSensor()
-- and model.deleteSensor() (EdgeTX/edgetx#8105): sensors are created directly, the
-- raw ones of the slots taken deleted, a slot's type can be changed.
-- Before: setTelemetryValue(), which needs "Discover new sensors" on (the
-- model's telemetry page), and old sensors are deleted on that page.
local RAW = 0x1310
local canSet = type(model.setSensor) == "function" and type(model.deleteSensor) == "function"
local colorLcd = type(lcd.RGB) == "function"
local SLOTS = 32
-- Types (futaba.h): ID, name, slots, values { name, unit, prec }; the name
-- gets the type's count (Tmp1, Tmp2...)
local TYPES = {
{ id = 0x1311, name = "Temp (SBS-01T)", slots = 1, values = { { "Tmp", UNIT_CELSIUS, 0 } } },
{ id = 0x1312, name = "Temp 125 (SBS-01TE)", slots = 1, values = { { "Tmp", UNIT_CELSIUS, 0 } } },
{ id = 0x1313, name = "RPM (SBS-01RM)", slots = 1, values = { { "RPM", UNIT_RPMS, 0 } } },
{ id = 0x1314, name = "Voltage (SBS-01V)", slots = 2,
values = { { "Vlt", UNIT_VOLTS, 1 }, { "Vlt", UNIT_VOLTS, 1 } } },
{ id = 0x1315, name = "Current (SBS-01C)", slots = 3,
values = { { "Cur", UNIT_AMPS, 2 }, { "Vcu", UNIT_VOLTS, 2 }, { "Cap", UNIT_MAH, 0 } } },
}
local function typeById(id)
for i = 1, #TYPES do
if TYPES[i].id == id then return i end
end
return nil
end
-- Presets: { slot offset in the group, type index, names }; ESCape32: its
-- telemetry ID 1..4 = the group of 8 slots, slots 2..7 of it
local PRESETS = {
{ name = "ESCape32", groups = 4, sensors = {
{ 2, 1, { "TEsc" } }, { 3, 1, { "TMot" } }, { 4, 5, { "Curr", "VEsc", "Capa" } }, { 7, 3, { "RPM" } } } },
}
local claims = {} -- slot -> { type = i, first = slot, sensors = { index... } } (all slots of a typed sensor)
local raws = {} -- slot -> { name = raw sensor name, index = n }
local pending = {} -- slot -> type index chosen here, not created yet
local lines = {}
local sel, top, edit, blink = 1, 1, false, 0
local preset, presetGroup = 1, 1
local status = ""
local function limit(v, mn, mx)
if v < mn then return mn end
if v > mx then return mx end
return v
end
local function screenLines()
if colorLcd then return limit(math.floor(((LCD_H or 272) - 46) / 20), 8, 12) end
return 6
end
local function drawTitle(title)
if colorLcd and lcd.drawFilledRectangle then
lcd.drawFilledRectangle(0, 0, LCD_W, 30, COLOR_THEME_SECONDARY1)
lcd.drawText(3, 5, title, COLOR_THEME_PRIMARY2)
elseif lcd.drawScreenTitle then
lcd.drawScreenTitle(title, 0, 0)
else
lcd.drawText(0, 0, title, INVERS)
end
end
-- The model's sensors: the typed ones' slots, the raw ones
local function scan()
claims, raws = {}, {}
for i = 0, 59 do
local s = model.getSensor(i)
if s and s.type == 0 and s.id then
local t = typeById(s.id)
if t and s.instance > 0 then
local c = claims[s.instance]
if not (c and c.first == s.instance and c.type == t) then
c = { type = t, first = s.instance, sensors = {} }
for k = 0, TYPES[t].slots - 1 do claims[s.instance + k] = c end
end
c.sensors[#c.sensors + 1] = i
elseif s.id == RAW and s.instance > 0 then
raws[s.instance] = { name = s.name, index = i }
end
end
end
end
local function rebuildLines()
lines = {}
for slot = 1, SLOTS - 1 do
if claims[slot] or raws[slot] or pending[slot] then
lines[#lines + 1] = { kind = "slot", slot = slot }
end
end
lines[#lines + 1] = { kind = "preset" }
lines[#lines + 1] = { kind = "create" }
sel = limit(sel, 1, #lines)
end
-- Slot covered by a pending multi-slot type starting before it
local function pendingCover(slot)
for s = slot - 1, math.max(1, slot - 2), -1 do
local t = pending[s]
if t and s + TYPES[t].slots > slot then return s end
end
return nil
end
local function slotText(slot)
local t = pending[slot]
if t then return "* " .. TYPES[t].name end
if pending[slot] == false then return "* raw" end
local c = claims[slot]
if c then
return (c.first == slot and "" or " ") .. TYPES[c.type].name
end
local cov = pendingCover(slot)
if cov then return " (slot " .. cov .. ")" end
local v = raws[slot] and getValue(raws[slot].name)
if type(v) == "number" then return string.format("raw %04X", v) end
return "raw"
end
local function lineText(line)
if line.kind == "slot" then return "Slot " .. line.slot, slotText(line.slot) end
if line.kind == "preset" then
local p = PRESETS[preset]
return "Preset", p.name .. " ID " .. presetGroup
end
return "Create sensors", ">"
end
local function applyPreset()
local p = PRESETS[preset]
local base = 8 * (presetGroup - 1)
for _, s in ipairs(p.sensors) do
local slot = base + s[1]
if not claims[slot] or canSet then pending[slot] = s[2] end
end
status = "Preset set: Create sensors"
rebuildLines()
end
-- pending[slot]: a type index, or false = back to raw (its typed sensor
-- deleted); nil = unchanged
local function changeSlot(slot, dir)
local c = claims[slot]
if c and not canSet then
status = "Has a sensor: delete it first"
return
end
if c and c.first ~= slot then
status = "Part of slot " .. c.first
return
end
local cur = pending[slot]
if cur == nil then cur = c and c.type or 0 elseif cur == false then cur = 0 end
local t = cur + dir
if t < 0 then t = #TYPES end
if t > #TYPES then t = 0 end
if c and t == c.type then pending[slot] = nil
elseif t == 0 then pending[slot] = c and false or nil
else pending[slot] = t end
end
-- Names: the type's base + a count (the preset's own names if given)
local function nextName(base, used)
for n = 1, 9 do
local name = base .. n
if not used[name] then
used[name] = true
return name
end
end
return base
end
-- With model.setSensor(): a free sensor index
local function freeIndex()
for i = 0, 59 do
local s = model.getSensor(i)
if s and s.name == "" then return i end
end
return nil
end
local function createSensor(id, sub, slot, unit, prec, name)
if not canSet then
return setTelemetryValue(id, sub, slot, 0, unit, prec, name)
end
local i = freeIndex()
return i ~= nil and model.setSensor(i, { name = name, id = id, subId = sub,
instance = slot, unit = unit, prec = prec })
end
-- With model.deleteSensor(): the old sensors of the slots a change takes
local function deleteOld()
if not canSet then return end
local del = {}
for slot, t in pairs(pending) do
local c = claims[slot]
if c and c.first == slot then
for _, i in ipairs(c.sensors) do del[i] = true end
end
local n = t and TYPES[t].slots or 1
for k = 0, n - 1 do
if t and raws[slot + k] then del[raws[slot + k].index] = true end
end
end
for i in pairs(del) do model.deleteSensor(i) end
end
local function createSensors()
local used, made, failed = {}, 0, 0
local changed = next(pending) ~= nil
deleteOld()
for i = 0, 59 do
local s = model.getSensor(i)
if s and s.name and s.name ~= "" then used[s.name] = true end
end
local names = {}
local p = PRESETS[preset]
for _, s in ipairs(p.sensors) do names[8 * (presetGroup - 1) + s[1]] = s[3] end
for slot = 1, SLOTS - 1 do
local t = pending[slot]
if t then
local ty = TYPES[t]
for sub, v in ipairs(ty.values) do
local name = names[slot] and names[slot][sub]
if name and not used[name] then used[name] = true else name = nextName(v[1], used) end
if createSensor(ty.id, sub - 1, slot, v[2], v[3], name) then
made = made + 1
else
failed = failed + 1
end
end
end
end
pending = {}
scan()
rebuildLines()
if failed > 0 then
status = canSet and "No free sensor" or "Turn on Discover new sensors"
elseif made > 0 then
status = made .. " sensors created"
elseif changed and canSet then
status = "Sensors deleted"
else
status = "Nothing to create"
end
end
local function handleEvent(event)
local line = lines[sel]
local nextEvent = edit and EVT_VIRTUAL_INC or EVT_VIRTUAL_NEXT
local prevEvent = edit and EVT_VIRTUAL_DEC or EVT_VIRTUAL_PREV
if event == nextEvent or event == prevEvent then
local dir = event == nextEvent and 1 or -1
if not edit then
sel = limit(sel + dir, 1, #lines)
elseif line.kind == "slot" then
changeSlot(line.slot, dir)
elseif line.kind == "preset" then
presetGroup = limit(presetGroup + dir, 1, PRESETS[preset].groups)
end
elseif event == EVT_VIRTUAL_ENTER then
if line.kind == "create" then
createSensors()
elseif line.kind == "preset" and edit then
edit = false
applyPreset()
else
edit = not edit
if not edit then rebuildLines() end
end
end
local count = screenLines()
if sel < top then top = sel end
if sel >= top + count then top = sel - count + 1 end
end
local function draw()
lcd.clear()
drawTitle("Futaba S.BUS2 sensors")
local font = colorLcd and 0 or SMLSIZE
local x = 2
local y = colorLcd and 34 or 9
local dy = colorLcd and 20 or 8
local valueX = colorLcd and 150 or 50
if status ~= "" then
lcd.drawText(LCD_W - 2, colorLcd and 5 or 0, status, (colorLcd and COLOR_THEME_PRIMARY2 or SMLSIZE + INVERS) + RIGHT)
end
if #lines <= 2 then
lcd.drawText(x, y + dy * (screenLines() - 1), "No slot data yet (raw S<n> sensors)", font)
end
for i = top, math.min(#lines, top + screenLines() - 1) do
local attr = font
if i == sel then
attr = attr + INVERS
if edit then
blink = (blink + 1) % 30
if blink > 15 then attr = font end
end
end
local label, value = lineText(lines[i])
local yy = y + (i - top) * dy
lcd.drawText(x, yy, label, attr)
lcd.drawText(valueX, yy, value, attr)
end
end
local scanTime = 0
local function init()
scan()
rebuildLines()
end
local function run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
elseif event == EVT_VIRTUAL_EXIT and not edit then
return 2
elseif event == EVT_VIRTUAL_EXIT then
edit = false
rebuildLines()
end
-- new raw slots show up as they are discovered
if not edit and getTime() > scanTime then
scanTime = getTime() + 100
scan()
rebuildLines()
end
handleEvent(event)
draw()
return 0
end
return { init = init, run = run }
+6
View File
@@ -40,6 +40,12 @@ Script to set the channels function (switch, servo, pwm, ppm, sbus) on a [LOLI R
[![MultiLOLIconfig](https://img.youtube.com/vi/e698pQxfv-A/0.jpg)](https://www.youtube.com/watch?v=e698pQxfv-A)
## Futaba S.BUS2 sensors
Sets up the S.BUS2 sensors of a Futaba receiver bound with the [Futaba protocol](https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/blob/master/Protocols_Details.md#futaba---21) (T-FHSS sub protocols). S.BUS2 sensors don't tell their type on the bus: the radio shows each slot with data as a raw sensor "S1", "S2"... and this tool turns it into a typed sensor that the radio decodes: temperature (SBS-01T, SBS-01TE), RPM (SBS-01RM), voltage (SBS-01V, 2 slots) and current (SBS-01C, 3 slots: current, voltage, capacity). A preset sets up an ESCape32 ESC (its telemetry ID 1 to 4).
Needs a radio firmware with the Multi Futaba telemetry. With `model.setSensor()` the sensors are created directly and the raw ones replaced; without it, "Discover new sensors" must be on and the raw sensors are deleted by hand. Located on the radio SD card under \SCRIPTS\TOOLS.
## Graupner HoTT
Enable text configuration of the HoTT RX and sensors: Vario, GPS, ESC, GAM and EAM.
+9 -1
View File
@@ -187,7 +187,11 @@ const char STR_SUBTYPE_REALACC[] = "\x06""R11\0 ""WLV8TX";
const char STR_SUBTYPE_KYOSHO[] = "\x04""FHSS""Hype";
const char STR_SUBTYPE_KYOSHO2[] = "\x05""KT-17";
const char STR_SUBTYPE_KYOSHO3[] = "\x03""ASF";
const char STR_SUBTYPE_FUTABA[] = "\x05""SFHSS";
#ifdef FUTABA_TFHSS
const char STR_SUBTYPE_FUTABA[] = "\x06""SFHSS\0""TFHSS\0""TFH-SR""TF-Air";
#else
const char STR_SUBTYPE_FUTABA[] = "\x05""SFHSS";
#endif
const char STR_SUBTYPE_JJRC345[] = "\x08""JJRC345\0""SkyTmblr";
const char STR_SUBTYPE_MOULDKG[] = "\x05""A4444""D4444""A664\0";
const char STR_SUBTYPE_KF606[] = "\x06""KF606\0""MIG320""ZCZ50\0";
@@ -349,7 +353,11 @@ const mm_protocol_definition multi_protocols[] = {
#endif
#endif
#if defined(FUTABA_CC2500_INO)
#if defined(FUTABA_TFHSS)
{PROTO_FUTABA, STR_FUTABA, STR_SUBTYPE_FUTABA, 4, OPTION_RFTUNE, 1, 1, SW_CC2500, FUTABA_init, FUTABA_callback },
#else
{PROTO_FUTABA, STR_FUTABA, STR_SUBTYPE_FUTABA, 1, OPTION_RFTUNE, 1, 1, SW_CC2500, SFHSS_init, SFHSS_callback },
#endif
#endif
#if defined(FX_NRF24L01_INO)
{PROTO_FX, STR_FX, STR_SUBTYPE_FX, 7, OPTION_NONE, 0, 0, SW_NRF, FX_init, FX_callback },
+24 -1
View File
@@ -426,6 +426,13 @@ enum FQ777
FQ777 = 0,
XBM37 = 1,
};
enum FUTABA
{
SFHSS = 0,
TFHSS = 1,
TFHSS_SR = 2,
TFHSS_AIR = 3,
};
enum FRSKY_RX
{
FRSKY_RX = 0,
@@ -595,6 +602,7 @@ enum MultiPacketTypes
MULTI_TELEMETRY_CONFIG = 16,
MULTI_TELEMETRY_PROTO = 17,
MULTI_TELEMETRY_RLINK = 18,
MULTI_TELEMETRY_FUTABA = 19,
};
// Macros
@@ -892,7 +900,8 @@ enum {
#define TRAXXAS_EEPROM_OFFSET 1079 // RX ID and SOP index, 3 bytes per model id, end is 1079+192=1271
#define XK2_EEPROM_OFFSET 1271 // RX ID checksum, 1 byte per model, end is 1271+64=1335
#define JIABAILE_EEPROM_OFFSET 1335 // RX ID, 3 bytes per model, end is 1335+64*3=1527
//#define CONFIG_EEPROM_OFFSET 1527 // Current configuration of the multimodule
#define TFHSS_EEPROM_OFFSET 1527 // RX ID, 4 bytes per model, end is 1527+64*4=1783
//#define CONFIG_EEPROM_OFFSET 1783 // Current configuration of the multimodule
/* STM32 Flash Size */
#ifndef DISABLE_FLASH_SIZE_CHECK
@@ -1210,6 +1219,11 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
sub_protocol==JJRC345
JJRC345 0
SKYTMBLR 1
sub_protocol==FUTABA
SFHSS 0
TFHSS 1
TFHSS_SR 2
TFHSS_AIR 3
sub_protocol==RLINK
RLINK_SURFACE 0
RLINK_AIR 1
@@ -1399,4 +1413,13 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
length: variable
data[0..] = raw command payload, used to send failsafe and gyro settings
Type 0x13 Futaba telemetry (T-FHSS): S.BUS2 slots as the sensors send them
length: variable, 3 + 2 x number of slots
data[0] = number of the first slot (0..31)
data[1] = RSSI of the receiver's reply at the module in dBm (signed)
data[2] = link quality % sent by the receiver, 0xFF if none in this reply
data[3..] = 2 bytes per slot as on the S.BUS2 bus. Slot 0 is the
receiver's: byte 0 bits 7..6 = link quality bars (0..3),
bit 2 = 0: byte 1 = its voltage in 0.1 V
*/
+3
View File
@@ -265,6 +265,9 @@ uint8_t packet_in[TELEMETRY_BUFFER_SIZE];//telemetry receiving packets
uint8_t CONFIG_SerialRX_val[7];
bool CONFIG_SerialRX=false;
#endif
#ifdef FUTABA_FW_TELEMETRY
uint8_t futaba_telem[3 + 16], futaba_telem_len; // MULTI_TELEMETRY_FUTABA
#endif
#ifdef RLINK_HUB_TELEMETRY
uint8_t RLINK_SerialRX_val[8];
uint8_t RLINK_SerialRX_len=0;
+695
View File
@@ -0,0 +1,695 @@
/*
This project is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Multiprotocol is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
*/
// Futaba T-FHSS (Surface: cars, boats) and T-FHSS Air, sub protocols of
// Futaba (Futaba_cc2500), on the CC2500 as Futaba's own radios (their RF is
// a CC2500 too). From the R334SBS receiver's and the T18SZ transmitter's
// firmware, checked against captures of a 4PM Plus (Surface, SR) and a T6K
// (Air).
//
// Both: 31 channels n = 1..31 at 2407.5 + 2 (n - 1) MHz (CHANNR 5 (n - 1)),
// sync D391, hop rows of a Welch-Costas array (row r: row 0 + r), the next
// channel the next of the row, one TX packet per frame. The packets XOR a
// key made of the TX ID and the channel, then the CRC-16/MCRF4XX of the
// plain bytes. The receiver takes the row from the packets.
//
// Surface (TFHSS): 384 kbps MSK, 14 bytes, a frame every 3 ms; 4 channels
// of 12 bits ((v + 2816) x 0.3125 us: 2048 = 1520 us) and an extra one in
// turn (ch5..8: a guess, the 4PM Plus sends none); the receiver's reply
// 1.9 ms after the TX packet on the next channel (S.BUS2 slots, 4 per
// reply). SR (TFHSS_SR, "Super Response"): 1.2 ms frames, no telemetry,
// the receiver bound in SR mode. The key also holds the receiver's ID (its
// serial number, not set by the TX): learnt at the bind, kept in the EEPROM
// per model (TFHSS_EEPROM_OFFSET). Bind (link), at the normal power: plain
// packets (the TX ID, the channel, the receiver's ID or 0) on the
// 16-channel list, one per 3 ms (the 4PM Plus: channel 1 every 48 ms),
// until the receiver in its link mode answers (plain, type 24 / 25, with
// its ID, on the next list channel: it hops before replying, as for its
// telemetry); then TFHSS_BIND_ACKED more with byte 1 bit 7 and its ID,
// which make the receiver store the bind (R334SBS firmware). Failsafe: every 5 s a group of 4 frames, one
// per channel: its F/S position, or hold (the 4PM Plus' default).
// The per channel "high speed" flags (3 ms output frames) are left off.
//
// Air (TFHSS_AIR): 128 kbps 2-FSK (the S-FHSS modem), 17 bytes, a frame
// every 15.04 ms; 16 channels in 9 slots of 11 bits (us - 880), a slot's
// channel or its alternate as the T18SZ picks them (moved, age). Bind (link), at the normal power: plain link
// frames on a 16-channel list; the receiver answers with its ID, which
// keys its telemetry (8 S.BUS2 slots per reply, 6.3 ms after the TX packet
// on the next channel).
// Without a bind since the start, the receiver's ID is found in its
// replies. No failsafe frames yet (the T6K's not fully decoded): the
// receiver's own failsafe applies.
//
// 128KB STM32 only (FUTABA_TFHSS, Validate.h): too large for the ATmega328p
// and the 64KB STM32.
//
// Telemetry (FUTABA_FW_TELEMETRY): the link frame (A1 = the receiver's
// voltage at the 13.2 V ratio, RSSI = its link quality (Surface), TX_RSSI
// = its replies here), then the S.BUS2 slots as the sensors send them
// (MULTI_TELEMETRY_FUTABA: the first slot, the reply's RSSI in dBm, the
// link quality % or 0xFF, 2 bytes per slot).
#if defined(FUTABA_TFHSS)
#include "iface_cc2500.h"
#define TFHSS_CHANNELS 31
#define TFHSS_LIST 16
#define TFHSS_PERIOD 3000
#define TFHSS_SR_PERIOD 1200
#define TFHSS_RX_ON 1000 // from the TX packet's start: RX on the next channel
// The reply (1.9 ms after the TX packet's start, 0.4 ms long) is read in the
// next frame's callback, before its TX packet: the TX packet goes on air 0.4 ms
// after the callback on the MPM v2, a read 2.5 ms after the callback missed it
#define TFHSS_LEN 14
#define TFHSS_FS_EVERY 1667 // frames, 5 s
#define TFHSS_SR_FS_EVERY 4167
#define TFHSS_BIND_FRAMES 3200 // 9.6 s without a reply (the 4PM Plus' 9.1 s)
#define TFHSS_BIND_ACKED 240 // after the reply (the 4PM Plus: 720 ms)
#define TFHSS_TELEM_EVERY 5 // replies to the radio: 1 in 5 (all groups in turn)
#define TFHSS_AIR_PERIOD 15040
#define TFHSS_AIR_RX_ON 2000
#define TFHSS_AIR_RX_READ 9500
#define TFHSS_AIR_LEN 17
#define TFHSS_AIR_REPLY_LEN 20
#define TFHSS_AIR_LINK_FRAMES 1330 // 20 s without a reply
#define TFHSS_AIR_LINK_AFTER 50 // link frames with the receiver's ID after its reply
#define TFHSS_AIR_T_EVERY 9 // the "telemetry on" bit, as the T6K
#define TFHSS_ID_MISSES 16 // Air: replies in a row with a bad CRC, the ID forgotten
enum {
TFHSS_CAL = 0,
TFHSS_DATA,
TFHSS_RX,
TFHSS_READ,
};
// Row 0: 31, then 3^i mod 31 (i = 0..29)
const PROGMEM uint8_t TFHSS_row0[TFHSS_CHANNELS] = {
31, 1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10,
30, 28, 22, 4, 12, 5, 15, 14, 11, 2, 6, 18, 23, 7, 21 };
// Air's link list
const PROGMEM uint8_t TFHSS_list[TFHSS_LIST] = {
1, 25, 3, 22, 4, 21, 6, 19, 7, 18, 9, 16, 10, 15, 12, 13 };
// Surface: 384 kbps MSK, 14 bytes, no CC2500 CRC (the R334SBS' setup)
const PROGMEM uint8_t TFHSS_init_values[] = {
/* 00 */ 0x2F, 0x2E, 0x2F, 0x07, 0xD3, 0x91, TFHSS_LEN, 0x04,
/* 08 */ 0x00, 0x00, 0x00, 0x0A, 0x00, 0x5C, 0x98, 0x9D,
/* 10 */ 0x1D, 0xE4, 0x72, 0x23, 0xF8, 0x00, 0x07, 0x00,
/* 18 */ 0x08, 0x1D, 0x1C, 0x1F, 0x40, 0xB0, 0x57, 0x6B,
/* 20 */ 0xF8, 0xB6, 0x10, 0xEA, 0x0A, 0x00, 0x19
};
// Air: 128 kbps 2-FSK 38 kHz, 17 bytes (the T18SZ's), FOCCFG 1E: the
// receiver's replies up to +-58 kHz off
const PROGMEM uint8_t TFHSS_AIR_init_values[] = {
/* 00 */ 0x2F, 0x2E, 0x2F, 0x07, 0xD3, 0x91, TFHSS_AIR_LEN, 0x04,
/* 08 */ 0x00, 0x00, 0x00, 0x1F, 0x00, 0x5C, 0x98, 0x9D,
/* 10 */ 0x7C, 0x43, 0x02, 0x23, 0xF8, 0x44, 0x07, 0x0C,
/* 18 */ 0x08, 0x1E, 0x1C, 0x43, 0x40, 0x91, 0x57, 0x6B,
/* 20 */ 0xF8, 0xB6, 0x10, 0xEA, 0x0A, 0x11, 0x11
};
static uint8_t TFHSS_id[4]; // TX ID, little endian
static uint8_t TFHSS_rx_id[4]; // the receiver's ID (Surface: stored per model)
static bool TFHSS_rx_known;
static uint8_t TFHSS_misses;
static uint8_t TFHSS_row;
static bool TFHSS_list_mode; // bind (link): hopping on the list
static bool TFHSS_rx_pending; // Surface: RX on for a reply, read at the next frame
static uint8_t TFHSS_ch; // the channel of the next TX packet
static uint16_t TFHSS_frame;
static uint16_t TFHSS_link; // link frames left (after the reply) or sent
static uint8_t TFHSS_replies;
static uint16_t TFHSS_sent[16]; // Air: the last value sent of each channel
static uint8_t TFHSS_age[16]; // and the frames since
static uint16_t __attribute__((unused)) TFHSS_crc(const uint8_t *p, uint8_t len)
{
uint16_t c = 0xFFFF;
while(len--)
{
c ^= *p++;
for(uint8_t i = 0; i < 8; i++)
c = (c & 1) ? (c >> 1) ^ 0x8408 : c >> 1;
}
return c;
}
// Key byte i on channel n. Surface: 00 00 a0..a3 x n b0..b3 (TX: a = the TX
// ID, b = the receiver's ID; replies swapped). Air: 00 a0..a3 x n a0..a3 x n a0..a3 x
// (TX: the TX ID; replies: the receiver's). x = 0
static uint8_t __attribute__((unused)) TFHSS_key(uint8_t i, uint8_t n, const uint8_t *a, const uint8_t *b)
{
if(i == 0)
return 0;
if(sub_protocol != TFHSS_AIR)
{
if(i == 1 || i == 6) return 0;
if(i < 6) return a[i - 2];
if(i == 7) return n;
return b[i - 8];
}
uint8_t m = (i - 1) % 6;
return m < 4 ? a[m] : m == 4 ? 0 : n;
}
// packet[0..len-3] plain -> keyed (or not), the CRC appended
static void __attribute__((unused)) TFHSS_build(uint8_t len, bool keyed)
{
uint8_t data = len - 2;
uint16_t c = TFHSS_crc(packet, data);
if(keyed)
for(uint8_t i = 1; i < data; i++)
packet[i] ^= TFHSS_key(i, TFHSS_ch, TFHSS_id, TFHSS_rx_id);
packet[data] = c;
packet[data + 1] = c >> 8;
}
static void __attribute__((unused)) TFHSS_transmit(uint8_t len)
{
CC2500_SetTxRxMode(TX_EN);
CC2500_WriteReg(CC2500_06_PKTLEN, len);
CC2500_WriteData(packet, len);
}
static void __attribute__((unused)) TFHSS_send(uint8_t len, bool keyed)
{
TFHSS_build(len, keyed);
TFHSS_transmit(len);
}
// in (len bytes) -> out plain: CRC ok?
static bool __attribute__((unused)) TFHSS_unkey(const uint8_t *in, uint8_t len, uint8_t n, const uint8_t *a, const uint8_t *b, uint8_t *out)
{
uint8_t data = len - 2;
for(uint8_t i = 0; i < data; i++)
out[i] = a ? in[i] ^ TFHSS_key(i, n, a, b) : in[i];
return TFHSS_crc(out, data) == (in[data] | in[data + 1] << 8);
}
// The bind (link) at the normal power, not CC2500_BIND_POWER: the R334SBS
// takes a bind packet only above about -79 dBm (its RSSI check), the 4PM
// Plus binds 33 dB down from its normal power, the T6K links at full power
static void __attribute__((unused)) TFHSS_SetPower()
{
if(!TFHSS_list_mode)
{
CC2500_SetPower();
return;
}
uint8_t power = CC2500_HIGH_POWER;
#ifdef CC2500_ENABLE_LOW_POWER
if(!IS_POWER_FLAG_on)
power = CC2500_LOW_POWER;
#endif
if(IS_RANGE_FLAG_on)
power = CC2500_RANGE_POWER;
if(prev_power != power)
{
CC2500_WriteReg(CC2500_3E_PATABLE, power);
prev_power = power;
}
}
static uint8_t __attribute__((unused)) TFHSS_channel(uint8_t pos)
{
if(TFHSS_list_mode)
return pgm_read_byte_near(&TFHSS_list[pos % TFHSS_LIST]);
return (pgm_read_byte_near(&TFHSS_row0[pos % TFHSS_CHANNELS]) + TFHSS_row - 1) % TFHSS_CHANNELS + 1;
}
static void __attribute__((unused)) TFHSS_next()
{
hopping_frequency_no++;
if(hopping_frequency_no >= (TFHSS_list_mode ? TFHSS_LIST : TFHSS_CHANNELS))
hopping_frequency_no = 0;
TFHSS_ch = TFHSS_channel(hopping_frequency_no);
}
static void __attribute__((unused)) TFHSS_tune(uint8_t n)
{
CC2500_Strobe(CC2500_SIDLE);
CC2500_WriteReg(CC2500_0A_CHANNR, 5 * (n - 1));
CC2500_WriteReg(CC2500_25_FSCAL1, calData[n - 1]);
}
// RX on the next channel for len bytes
static void __attribute__((unused)) TFHSS_rx_on(uint8_t len)
{
TFHSS_tune(TFHSS_ch);
CC2500_WriteReg(CC2500_06_PKTLEN, len);
CC2500_SetTxRxMode(RX_EN);
CC2500_Strobe(CC2500_SFRX);
CC2500_Strobe(CC2500_SRX);
}
// The reply in packet_in (len bytes + RSSI + LQI), or false
static bool __attribute__((unused)) TFHSS_rx_read(uint8_t len)
{
uint8_t n = CC2500_ReadReg(CC2500_3B_RXBYTES | CC2500_READ_BURST) & 0x7F;
bool ok = n >= len + 2 && len + 2 <= TELEMETRY_BUFFER_SIZE;
if(ok)
CC2500_ReadData(packet_in, len + 2);
CC2500_Strobe(CC2500_SIDLE);
CC2500_Strobe(CC2500_SFRX);
return ok;
}
// A reply to the radio: n slots from first (lq 0xFF: none), every
// TFHSS_TELEM_EVERY-th reply (Surface's 333 a second would fill the link)
static void __attribute__((unused)) TFHSS_telemetry(uint8_t first, const uint8_t *slots, uint8_t n, uint8_t lq, uint8_t rssi, uint8_t lqi)
{
#ifdef FUTABA_FW_TELEMETRY
if(sub_protocol != TFHSS_AIR && ++TFHSS_replies < TFHSS_TELEM_EVERY)
return;
TFHSS_replies = 0;
// The link frame: slot 0 half 0 = the receiver's voltage (0.1 V)
if(first == 0 && !(slots[0] & 0x04))
v_lipo1 = (uint16_t)slots[1] * 255 / 132;
if(lq != 0xFF)
RX_RSSI = lq;
TX_RSSI = rssi >= 128 ? rssi - 128 : rssi + 128;
TX_LQI = lqi & 0x7F;
telemetry_link |= 1;
#ifdef MULTI_TELEMETRY
futaba_telem[0] = first;
futaba_telem[1] = (uint8_t)(((int8_t)rssi) / 2 - 72); // dBm
futaba_telem[2] = lq;
memcpy(futaba_telem + 3, slots, 2 * n);
futaba_telem_len = 3 + 2 * n;
telemetry_link |= 2; // after the link frame
#endif
#else
(void)first; (void)slots; (void)n; (void)lq; (void)rssi; (void)lqi;
#endif
}
// Surface: the 12-bit value of a channel, 1020..2020 us at +-100 %
static uint16_t __attribute__((unused)) TFHSS_value(uint8_t num, bool failsafe)
{
int16_t v = convert_channel_16b_nolimit(CH_AETR[num], 448, 3648, failsafe);
return v < 0 ? 0 : v > 4095 ? 4095 : v;
}
static void __attribute__((unused)) TFHSS_surface_bind_packet()
{
bool sr = sub_protocol == TFHSS_SR;
// Bit 7: the receiver's reply heard
packet[0] = (sr ? 9 : 8) | (TFHSS_row & 7) << 5;
packet[1] = TFHSS_row >> 3 | (sr ? 0x10 : 0) | (TFHSS_rx_known ? 0x80 : 0);
memcpy(packet + 2, TFHSS_id, 4);
packet[6] = 0;
packet[7] = TFHSS_ch; // the channel (the 4PM Plus; echoed in the reply)
// The receiver's ID after its reply, 0 before (the 4PM Plus sends the
// last one it knows; the receiver ignores these bytes)
if(TFHSS_rx_known)
memcpy(packet + 8, TFHSS_rx_id, 4);
else
memset(packet + 8, 0, 4);
TFHSS_build(TFHSS_LEN, false);
}
static void __attribute__((unused)) TFHSS_surface_packet()
{
bool sr = sub_protocol == TFHSS_SR;
uint16_t ch[4];
for(uint8_t i = 0; i < 4; i++)
ch[i] = TFHSS_value(i, false);
uint8_t f = 0x13, fs = 0; // 0x13: a normal frame
uint16_t k = TFHSS_frame % (sr ? TFHSS_SR_FS_EVERY : TFHSS_FS_EVERY);
if(k < 4)
{ // Failsafe group: ch D, C, B, A (the 4PM Plus' order); code 0 + the
// group flag: hold, 4: F/S with this frame's value as the position
static const uint8_t ch_code[4] = { 0x12, 0x02, 0x01, 0x00 };
uint8_t c = 3 - k;
f = ch_code[k];
fs = 0x10;
#ifdef FAILSAFE_ENABLE
uint16_t v = Failsafe_data[CH_AETR[c]];
if(IS_FAILSAFE_VALUES_on && v != FAILSAFE_CHANNEL_HOLD && v != FAILSAFE_CHANNEL_NOPULSES)
{
f |= 0x04;
ch[c] = TFHSS_value(c, true);
}
#endif
}
uint8_t slot = TFHSS_frame & 3;
uint16_t e = TFHSS_value(4 + slot, false);
packet[0] = (sr ? 1 : 0) | (TFHSS_row & 7) << 5;
packet[1] = TFHSS_row >> 3 | (sr ? 0 : 0x10) | (f & 3) << 6;
packet[2] = (f >> 2) | (ch[0] & 0x0F) << 4;
packet[3] = ch[0] >> 4;
packet[4] = ch[1];
packet[5] = (ch[1] >> 8) | (ch[2] & 0x0F) << 4;
packet[6] = ch[2] >> 4;
packet[7] = ch[3];
packet[8] = (ch[3] >> 8) | 0x10;
packet[9] = fs; // bits 0..3: the high speed flags
packet[10] = e;
packet[11] = (e >> 8) | slot << 4;
TFHSS_build(TFHSS_LEN, true);
}
// Surface reply: type 16 = 4 S.BUS2 slots of group byte 1 >> 4; byte 10
// bit 6: byte 11 is the link quality % (0) or something else (1)
static void __attribute__((unused)) TFHSS_surface_reply(uint8_t n)
{
uint8_t pl[TFHSS_LEN - 2];
if(!TFHSS_unkey(packet_in, TFHSS_LEN, n, TFHSS_rx_id, TFHSS_id, pl) || (pl[0] & 0x1F) != 16)
return;
TFHSS_telemetry(4 * ((pl[1] >> 4) & 7), pl + 2, 4, pl[10] & 0x40 ? 0xFF : pl[11],
packet_in[TFHSS_LEN], packet_in[TFHSS_LEN + 1]);
}
// EEPROM address of this model's receiver ID
static uint16_t __attribute__((unused)) TFHSS_eeprom()
{
return TFHSS_EEPROM_OFFSET + (RX_num & 63) * 4;
}
// The receiver's bind reply: plain, type 24 / 25, our ID, x, the channel,
// its ID (not 0) -> stored for this model
static void __attribute__((unused)) TFHSS_surface_bind_reply()
{
uint8_t pl[TFHSS_LEN - 2];
if(TFHSS_rx_known || !TFHSS_unkey(packet_in, TFHSS_LEN, 0, NULL, NULL, pl)
|| (pl[0] & 0x1E) != 24 || memcmp(pl + 2, TFHSS_id, 4)
|| (pl[8] | pl[9] | pl[10] | pl[11]) == 0)
return;
uint16_t addr = TFHSS_eeprom();
for(uint8_t i = 0; i < 4; i++)
{
TFHSS_rx_id[i] = pl[8 + i];
eeprom_write_byte((EE_ADDR)(addr + i), TFHSS_rx_id[i]);
}
TFHSS_rx_known = true;
TFHSS_link = TFHSS_BIND_ACKED;
}
// Bind (link) frame: over (the radio ended the bind, the frames after the
// reply sent, or none in frames) -> back to the row
static bool __attribute__((unused)) TFHSS_link_over(uint16_t frames)
{
if(!IS_BIND_DONE && (TFHSS_rx_known ? TFHSS_link-- != 0 : ++TFHSS_link <= frames))
return false;
TFHSS_list_mode = false;
hopping_frequency_no = 0;
TFHSS_ch = TFHSS_channel(0);
BIND_DONE;
return true;
}
// Air: the 11-bit value of a channel, us - 880
static uint16_t __attribute__((unused)) TFHSS_air_value(uint8_t num)
{
int16_t v = convert_channel_16b_nolimit(CH_AETR[num], 140, 1140, false);
return v < 0 ? 0 : v > 2047 ? 2047 : v;
}
// Slot 0..8: its own channel (ch1..9) or the alternate (ch11..16, ch10;
// slots 6, 7: ch7, ch8 only). The T18SZ's choice (ffea4153): a channel
// moved = more than 3 us (5 of its steps) from the value last sent; the
// age = frames since it was sent. Own moved: the alternate if it moved too
// and is 2 frames old, or is 64 old; else own. Own still: the alternate if
// it moved (unless own is 64 old), else the older one, own on a tie
static bool __attribute__((unused)) TFHSS_air_alt(uint8_t own, uint8_t alt, const uint16_t *v)
{
bool om = v[own] > TFHSS_sent[own] + 3 || v[own] + 3 < TFHSS_sent[own];
bool am = v[alt] > TFHSS_sent[alt] + 3 || v[alt] + 3 < TFHSS_sent[alt];
if(om)
return TFHSS_age[alt] >= (am ? 2 : 64);
if(am)
return TFHSS_age[own] < 64;
return TFHSS_age[alt] > TFHSS_age[own];
}
static void __attribute__((unused)) TFHSS_air_packet()
{
static const uint8_t alt_of[9] = { 10, 11, 12, 13, 14, 15, 0xFF, 0xFF, 9 };
uint16_t v[16];
for(uint8_t i = 0; i < 16; i++)
{
v[i] = TFHSS_air_value(i);
if(TFHSS_age[i] < 255)
TFHSS_age[i]++;
}
memset(packet, 0, TFHSS_AIR_LEN);
for(uint8_t i = 0, bit = 0; i < 9; i++)
{
uint8_t num = i;
if(alt_of[i] != 0xFF && TFHSS_air_alt(i, alt_of[i], v))
{
num = alt_of[i];
if(i < 6)
packet[14] |= 1 << i; // flags b14 bits 0..5
else
packet[13] |= 0x08; // slot 8: b13 bit 3
}
TFHSS_sent[num] = v[num];
TFHSS_age[num] = 0;
for(uint8_t j = 0; j < 11; j++, bit++)
if(v[num] >> j & 1)
packet[1 + bit / 8] |= 1 << (bit & 7);
}
packet[0] = TFHSS_row << 3;
if(IS_DISABLE_TELEM_off && TFHSS_frame % TFHSS_AIR_T_EVERY == 0)
packet[0] |= 0x04;
TFHSS_send(TFHSS_AIR_LEN, true);
}
// Link frame (plain): the TX ID, the channel, the receiver's ID once known
static void __attribute__((unused)) TFHSS_air_link_packet()
{
memset(packet, 0, TFHSS_AIR_LEN);
packet[0] = TFHSS_rx_known ? 0xFC : 0xF8;
memcpy(packet + 1, TFHSS_id, 4);
packet[6] = TFHSS_ch;
if(TFHSS_rx_known)
memcpy(packet + 7, TFHSS_rx_id, 4);
TFHSS_send(TFHSS_AIR_LEN, false);
}
// The receiver's link reply (plain, 17 bytes): our ID echoed, its own
static void __attribute__((unused)) TFHSS_air_link_reply()
{
uint8_t pl[TFHSS_AIR_LEN - 2];
if(!TFHSS_unkey(packet_in, TFHSS_AIR_LEN, 0, NULL, NULL, pl) || memcmp(pl + 1, TFHSS_id, 4))
return;
memcpy(TFHSS_rx_id, pl + 7, 4);
if(!TFHSS_rx_known)
TFHSS_link = TFHSS_AIR_LINK_AFTER;
TFHSS_rx_known = true;
TFHSS_misses = 0;
}
// Air telemetry: type 3 = 8 S.BUS2 slots of group byte 17 & 15, keyed with
// the receiver's ID. Not known: tried from the bytes of slots 3-4 and 6-7
// (the key itself when no sensor is there)
static void __attribute__((unused)) TFHSS_air_reply(uint8_t n)
{
uint8_t pl[TFHSS_AIR_REPLY_LEN - 2];
bool ok = TFHSS_rx_known && TFHSS_unkey(packet_in, TFHSS_AIR_REPLY_LEN, n, TFHSS_rx_id, NULL, pl);
for(uint8_t o = 7; !TFHSS_rx_known && o <= 13; o += 6)
{
memcpy(TFHSS_rx_id, packet_in + o, 4);
ok = TFHSS_rx_known = TFHSS_unkey(packet_in, TFHSS_AIR_REPLY_LEN, n, TFHSS_rx_id, NULL, pl);
}
if(!ok)
{
if(TFHSS_rx_known && ++TFHSS_misses >= TFHSS_ID_MISSES)
TFHSS_rx_known = false;
return;
}
TFHSS_misses = 0;
if((pl[0] & 0x03) == 3 && (pl[17] & 0x0F) < 4)
TFHSS_telemetry(8 * (pl[17] & 0x0F), pl + 1, 8, 0xFF,
packet_in[TFHSS_AIR_REPLY_LEN], packet_in[TFHSS_AIR_REPLY_LEN + 1]);
}
static uint16_t __attribute__((unused)) TFHSS_air_callback()
{
switch(phase)
{
case TFHSS_DATA:
#ifdef MULTI_SYNC
telemetry_set_input_sync(TFHSS_AIR_PERIOD);
#endif
CC2500_SetFreqOffset();
TFHSS_SetPower();
TFHSS_tune(TFHSS_ch);
if(TFHSS_list_mode)
{ // Link: until the reply and TFHSS_AIR_LINK_AFTER frames
if(TFHSS_link_over(TFHSS_AIR_LINK_FRAMES))
return TFHSS_AIR_PERIOD;
TFHSS_air_link_packet();
}
else
TFHSS_air_packet();
TFHSS_frame++;
TFHSS_next();
phase = TFHSS_RX;
return TFHSS_AIR_RX_ON;
case TFHSS_RX:
TFHSS_rx_on(TFHSS_list_mode ? TFHSS_AIR_LEN : TFHSS_AIR_REPLY_LEN);
phase = TFHSS_READ;
return TFHSS_AIR_RX_READ - TFHSS_AIR_RX_ON;
case TFHSS_READ:
if(TFHSS_list_mode)
{
if(TFHSS_rx_read(TFHSS_AIR_LEN))
TFHSS_air_link_reply();
}
else if(TFHSS_rx_read(TFHSS_AIR_REPLY_LEN))
TFHSS_air_reply(TFHSS_ch);
phase = TFHSS_DATA;
return TFHSS_AIR_PERIOD - TFHSS_AIR_RX_READ;
}
return TFHSS_AIR_PERIOD;
}
// Surface: the reply, if RX was on for one (on the current channel)
static void __attribute__((unused)) TFHSS_surface_read(bool list)
{
if(!TFHSS_rx_pending)
return;
TFHSS_rx_pending = false;
if(!TFHSS_rx_read(TFHSS_LEN))
return;
if(list)
TFHSS_surface_bind_reply();
else
TFHSS_surface_reply(TFHSS_ch);
}
static uint16_t __attribute__((unused)) TFHSS_callback()
{
if(phase == TFHSS_CAL)
{ // Calibration of the 31 channels, one per call
if(rf_ch_num)
calData[rf_ch_num - 1] = CC2500_ReadReg(CC2500_25_FSCAL1);
if(rf_ch_num < TFHSS_CHANNELS)
{
rf_ch_num++;
CC2500_Strobe(CC2500_SIDLE);
CC2500_WriteReg(CC2500_0A_CHANNR, 5 * (rf_ch_num - 1));
CC2500_Strobe(CC2500_SCAL);
return 1000;
}
phase = TFHSS_DATA;
return 1000;
}
if(sub_protocol == TFHSS_AIR)
return TFHSS_air_callback();
bool sr = sub_protocol == TFHSS_SR;
switch(phase)
{
case TFHSS_DATA:
#ifdef MULTI_SYNC
telemetry_set_input_sync(sr ? TFHSS_SR_PERIOD : TFHSS_PERIOD);
#endif
if(TFHSS_list_mode && TFHSS_link_over(TFHSS_BIND_FRAMES))
{ // Bind over: back to the row
TFHSS_surface_read(true);
return TFHSS_PERIOD;
}
// The packet built first, then the reply read (on this frame's
// channel), as late as possible, then the packet sent
if(TFHSS_list_mode)
TFHSS_surface_bind_packet();
else
TFHSS_surface_packet();
TFHSS_surface_read(TFHSS_list_mode);
CC2500_SetFreqOffset();
TFHSS_SetPower();
TFHSS_tune(TFHSS_ch);
TFHSS_transmit(TFHSS_LEN);
TFHSS_next();
if(TFHSS_list_mode)
{ // Bind: 3 ms frames, the reply on the next list channel
phase = TFHSS_RX;
return TFHSS_RX_ON;
}
TFHSS_frame++;
if(sr || IS_DISABLE_TELEM_on)
return sr ? TFHSS_SR_PERIOD : TFHSS_PERIOD;
phase = TFHSS_RX;
return TFHSS_RX_ON;
case TFHSS_RX:
TFHSS_rx_on(TFHSS_LEN);
TFHSS_rx_pending = true;
phase = TFHSS_DATA;
return TFHSS_PERIOD - TFHSS_RX_ON;
}
return TFHSS_PERIOD;
}
static void __attribute__((unused)) TFHSS_init()
{
// The TX ID: 9 decimal digits (as Futaba's), little endian
uint32_t id = 100000000 + MProtocol_id % 900000000;
for(uint8_t i = 0; i < 4; i++)
TFHSS_id[i] = id >> (8 * i);
// Surface: the receiver's ID from the last bind of this model
uint16_t addr = TFHSS_eeprom();
for(uint8_t i = 0; i < 4; i++)
TFHSS_rx_id[i] = sub_protocol == TFHSS_AIR ? 0 : eeprom_read_byte((EE_ADDR)(addr + i));
TFHSS_row = id % TFHSS_CHANNELS;
TFHSS_rx_known = false;
TFHSS_misses = 0;
TFHSS_frame = 0;
TFHSS_replies = 0;
TFHSS_link = 0;
TFHSS_rx_pending = false;
memset(TFHSS_sent, 0, sizeof(TFHSS_sent));
memset(TFHSS_age, 0, sizeof(TFHSS_age));
TFHSS_list_mode = IS_BIND_IN_PROGRESS;
hopping_frequency_no = 0;
TFHSS_ch = TFHSS_channel(0);
const uint8_t *regs = sub_protocol == TFHSS_AIR ? TFHSS_AIR_init_values : TFHSS_init_values;
CC2500_Strobe(CC2500_SIDLE);
for(uint8_t i = 0; i < 0x27; i++)
CC2500_WriteReg(i, pgm_read_byte_near(&regs[i]));
CC2500_WriteReg(CC2500_2C_TEST2, 0x88);
CC2500_WriteReg(CC2500_2D_TEST1, 0x31);
CC2500_WriteReg(CC2500_2E_TEST0, 0x0B);
prev_option = option;
CC2500_WriteReg(CC2500_0C_FSCTRL0, option);
CC2500_SetTxRxMode(TX_EN);
TFHSS_SetPower();
rf_ch_num = 0;
phase = TFHSS_CAL;
}
// Futaba (21): S-FHSS (Futaba_cc2500.ino) or T-FHSS
void SFHSS_init();
uint16_t SFHSS_callback();
uint16_t FUTABA_callback()
{
return sub_protocol == SFHSS ? SFHSS_callback() : TFHSS_callback();
}
void FUTABA_init()
{
if(sub_protocol == SFHSS)
SFHSS_init();
else
TFHSS_init();
}
#endif
+17
View File
@@ -324,6 +324,15 @@ static void multi_send_status()
}
#endif
#ifdef FUTABA_FW_TELEMETRY
void FUTABA_frame()
{
multi_send_header(MULTI_TELEMETRY_FUTABA, futaba_telem_len);
for (uint8_t i = 0; i < futaba_telem_len; i++) // first slot, RSSI, LQ, S.BUS2 slots (TFHSS_cc2500)
Serial_write(futaba_telem[i]);
}
#endif
static void multi_send_frskyhub()
{
multi_send_header(MULTI_TELEMETRY_HUB, 9);
@@ -1009,6 +1018,14 @@ void TelemetryUpdate()
return;
}
#endif
#if defined FUTABA_FW_TELEMETRY
if(telemetry_link == 2 && protocol == PROTO_FUTABA)
{
FUTABA_frame();
telemetry_link=0;
return;
}
#endif
#if defined SCANNER_TELEMETRY
if (telemetry_link && protocol == PROTO_SCANNER)
{
+10 -1
View File
@@ -477,6 +477,11 @@
#define FRSKY_RX_CC2500_INO
#endif
//Futaba T-FHSS sub protocols (TFHSS_cc2500.ino): 128KB STM32 only, too large for the ATmega328p and the 64KB STM32
#if defined(FUTABA_CC2500_INO) && defined(STM32_BOARD) && not defined(MCU_STM32F103C8)
#define FUTABA_TFHSS
#endif
//Make sure telemetry is selected correctly
#ifndef TELEMETRY
#undef INVERT_TELEMETRY
@@ -501,6 +506,7 @@
#undef AFHDS2A_RX_TELEMETRY
#undef AFHDS2A_RX_A7105_INO
#undef HOTT_FW_TELEMETRY
#undef FUTABA_FW_TELEMETRY
#undef BAYANG_RX_TELEMETRY
#undef BAYANG_RX_NRF24L01_INO
#undef DEVO_HUB_TELEMETRY
@@ -613,6 +619,9 @@
#if not defined(HOTT_CC2500_INO)
#undef HOTT_FW_TELEMETRY
#endif
#if not defined(FUTABA_TFHSS)
#undef FUTABA_FW_TELEMETRY
#endif
#if not defined(WFLY2_A7105_INO)
#undef WFLY2_HUB_TELEMETRY
#endif
@@ -626,7 +635,7 @@
//protocols using FRSKYD user frames
#undef HUB_TELEMETRY
#endif
#if not defined(HOTT_FW_TELEMETRY) && not defined(DSM_TELEMETRY) && not defined(SPORT_TELEMETRY) && not defined(HUB_TELEMETRY) && not defined(HUBSAN_HUB_TELEMETRY) && not defined(BUGS_HUB_TELEMETRY) && not defined(NCC1701_HUB_TELEMETRY) && not defined(BAYANG_HUB_TELEMETRY) && not defined(CABELL_HUB_TELEMETRY) && not defined(RLINK_HUB_TELEMETRY) && not defined(AFHDS2A_HUB_TELEMETRY) && not defined(AFHDS2A_FW_TELEMETRY) && not defined(MULTI_TELEMETRY) && not defined(MULTI_STATUS) && not defined(HITEC_HUB_TELEMETRY) && not defined(HITEC_FW_TELEMETRY) && not defined(SCANNER_TELEMETRY) && not defined(FRSKY_RX_TELEMETRY) && not defined(AFHDS2A_RX_TELEMETRY) && not defined(BAYANG_RX_TELEMETRY) && not defined(DEVO_HUB_TELEMETRY) && not defined(PROPEL_HUB_TELEMETRY) && not defined(OMP_HUB_TELEMETRY) && not defined(V761_HUB_TELEMETRY) && not defined(SGF22_HUB_TELEMETRY) && not defined(XK_HUB_TELEMETRY) && not defined(XK2_HUB_TELEMETRY) && not defined(FX_HUB_TELEMETRY) && not defined(KAMTOM_HUB_TELEMETRY) && not defined(YUXIANG_HUB_TELEMETRY) && not defined(WFLY2_HUB_TELEMETRY) && not defined(LOLI_HUB_TELEMETRY) && not defined(MLINK_HUB_TELEMETRY) && not defined(MLINK_FW_TELEMETRY) && not defined(MT99XX_HUB_TELEMETRY) && not defined(MULTI_CONFIG_INO)
#if not defined(HOTT_FW_TELEMETRY) && not defined(FUTABA_FW_TELEMETRY) && not defined(DSM_TELEMETRY) && not defined(SPORT_TELEMETRY) && not defined(HUB_TELEMETRY) && not defined(HUBSAN_HUB_TELEMETRY) && not defined(BUGS_HUB_TELEMETRY) && not defined(NCC1701_HUB_TELEMETRY) && not defined(BAYANG_HUB_TELEMETRY) && not defined(CABELL_HUB_TELEMETRY) && not defined(RLINK_HUB_TELEMETRY) && not defined(AFHDS2A_HUB_TELEMETRY) && not defined(AFHDS2A_FW_TELEMETRY) && not defined(MULTI_TELEMETRY) && not defined(MULTI_STATUS) && not defined(HITEC_HUB_TELEMETRY) && not defined(HITEC_FW_TELEMETRY) && not defined(SCANNER_TELEMETRY) && not defined(FRSKY_RX_TELEMETRY) && not defined(AFHDS2A_RX_TELEMETRY) && not defined(BAYANG_RX_TELEMETRY) && not defined(DEVO_HUB_TELEMETRY) && not defined(PROPEL_HUB_TELEMETRY) && not defined(OMP_HUB_TELEMETRY) && not defined(V761_HUB_TELEMETRY) && not defined(SGF22_HUB_TELEMETRY) && not defined(XK_HUB_TELEMETRY) && not defined(XK2_HUB_TELEMETRY) && not defined(FX_HUB_TELEMETRY) && not defined(KAMTOM_HUB_TELEMETRY) && not defined(YUXIANG_HUB_TELEMETRY) && not defined(WFLY2_HUB_TELEMETRY) && not defined(LOLI_HUB_TELEMETRY) && not defined(MLINK_HUB_TELEMETRY) && not defined(MLINK_FW_TELEMETRY) && not defined(MT99XX_HUB_TELEMETRY) && not defined(MULTI_CONFIG_INO)
#undef TELEMETRY
#undef INVERT_TELEMETRY
#undef MULTI_TELEMETRY
+7 -3
View File
@@ -91,7 +91,7 @@
//#define ORANGE_TX_BLUE
/** CC2500 Fine Frequency Tuning **/
//For optimal performance the CC2500 RF module used by the CORONA, FrSkyD, FrSkyV, FrSkyX, Hitec, HoTT, Futaba/SFHSS and Redpine protocols needs to be tuned for each protocol.
//For optimal performance the CC2500 RF module used by the CORONA, FrSkyD, FrSkyV, FrSkyX, Hitec, HoTT, Futaba (SFHSS, T-FHSS) and Redpine protocols needs to be tuned for each protocol.
//Initial tuning should be done via the radio menu with a genuine CORONA/FrSky/Hitec/HoTT/Futaba/Redpine receiver.
//Once a good tuning value is found it can be set here and will override the radio's 'option' setting for all existing and new models which use that protocol.
//For more information: https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/tree/master/docs/Frequency_Tuning.md
@@ -312,7 +312,7 @@
/**************************/
/*** FAILSAFE SETTINGS ***/
/**************************/
//The following protocols are supporting failsafe: FrSkyX, FrSkyX2, FRSKYR9, Devo, WK2x01, Futaba/SFHSS, HISKY/HK310, HoTT, LOLI, MLINK, WFLY, WFLY2 and AFHDS2A
//The following protocols are supporting failsafe: FrSkyX, FrSkyX2, FRSKYR9, Devo, WK2x01, Futaba/SFHSS, Futaba/T-FHSS (Surface, SR), HISKY/HK310, HoTT, LOLI, MLINK, WFLY, WFLY2 and AFHDS2A
//In Serial mode failsafe is configured on the radio itself.
//In PPM mode and only after the module is up and fully operational, press the bind button for at least 5sec to send all the current channels positions as failsafe to the RX.
//If you want to disable failsafe globally comment the line below using "//".
@@ -375,6 +375,7 @@
#define FRSKY_RX_TELEMETRY // Forward channels data to TX
#define AFHDS2A_RX_TELEMETRY // Forward channels data to TX
#define HOTT_FW_TELEMETRY // Forward received telemetry packets to be decoded by erskyTX and OpenTX
#define FUTABA_FW_TELEMETRY // Forward received T-FHSS telemetry (S.BUS2 slots) to TX
#define BAYANG_RX_TELEMETRY // Forward channels data to TX
/**************************/
@@ -702,7 +703,10 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= {
FRSKY_RX
FRSKY_CLONE
PROTO_FUTABA
NONE
SFHSS
TFHSS
TFHSS_SR
TFHSS_AIR
PROTO_FX
FX816
FX620
+39 -2
View File
@@ -99,7 +99,7 @@ CFlie|AIR|38|CFlie||||||||NRF24L01|
[FrskyX](Protocols_Details.md#FRSKYX---15)||15|CH_16|CH_8|EU_16|EU_8|Cloned|Cloned_8|||CC2500|
[FrskyX2](Protocols_Details.md#FRSKYX2---64)||64|CH_16|CH_8|EU_16|EU_8|Cloned|Cloned_8|||CC2500|
[Frsky_RX](Protocols_Details.md#FRSKY_RX---55)||55|Multi|CloneTX|EraseTX|CPPM|||||CC2500|
[Futaba/SFHSS](Protocols_Details.md#Futaba---21)||21|SFHSS||||||||CC2500|
[Futaba](Protocols_Details.md#Futaba---21)||21|SFHSS|TFHSS|TFH-SR|TF-Air|||||CC2500|
[FX](Protocols_Details.md#FX---58)||58|FX816|FX620|9630|Q560|QF012|BM26|A570||NRF24L01|
[FY326](Protocols_Details.md#FY326---20)||20|FY326|FY319|||||||NRF24L01|
[GD00X](Protocols_Details.md#GD00X---47)||47|GD_V1*|GD_V2*|||||||NRF24L01|XN297L
@@ -1135,7 +1135,7 @@ Settings include:
* setting failsafe values
## Futaba - *21*
Also called SFHSS depending on radio version.
Also called SFHSS depending on radio version. Sub protocols S-FHSS, T-FHSS (Surface), T-FHSS SR and T-FHSS Air. The T-FHSS sub protocols are only available on the 128KB STM32 modules.
### Sub_protocol SFHSS - *0*
Models: Futaba SFHSS RXs and some XK models.
@@ -1153,6 +1153,43 @@ CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8
---|---|---|---|---|---|---|---
A|E|T|R|CH5|CH6|CH7|CH8
### Sub_protocol TFHSS - *1*
T-FHSS Surface. Models: Futaba T-FHSS surface receivers (cars, boats) like the R334SBS.
Failsafe and telemetry supported. Extended limits supported.
RX output will match the Futaba standard servo throw, mid point and the channel order AETR independently of the input configuration AETR, RETA... unless if on OpenTX 2.3.3+ you use the "Disable channel mapping" feature on the GUI.
Option for this protocol corresponds to fine frequency tuning, the same value as for S-FHSS.
Bind: put the receiver in its link mode (see its manual) and start a bind on the TX side close to the receiver. The bind ends about 1 s after the receiver answers, 10 s at most. The TX ID comes from the RX number (model match). The receiver's ID, learnt at the bind and needed to drive it, is stored per RX number in the module: bind again after changing the RX number or the receiver.
Telemetry: the receiver's voltage (A1) and link quality (RSSI), and its S.BUS2 sensor slots (Futaba telemetry frame, decoded by the radio).
CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8
---|---|---|---|---|---|---|---
A|E|T|R|CH5|CH6|CH7|CH8
CH1 to CH4 are sent every frame (3 ms), CH5 to CH8 one per frame.
### Sub_protocol TFHSS_SR - *2*
T-FHSS SR (Super Response), the receiver bound in SR mode: frames every 1.2 ms, digital servos only. No telemetry. Otherwise as T-FHSS.
### Sub_protocol TFHSS_AIR - *3*
T-FHSS Air. Models: Futaba T-FHSS Air receivers like the R3006SB and R3008SB.
Telemetry supported. Failsafe: the receiver's own (set it on the receiver).
Option for this protocol corresponds to fine frequency tuning, the same value as for S-FHSS.
Bind: start a bind on the TX side, then put the receiver in its link mode (see its manual) close to the module. The bind ends when the receiver answers, 20 s at most. Without a bind, the module finds the receiver's ID in its telemetry.
Telemetry: the receiver's voltage (A1) and its S.BUS2 sensor slots (Futaba telemetry frame, decoded by the radio).
CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12|CH13|CH14|CH15|CH16
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---
A|E|T|R|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12|CH13|CH14|CH15|CH16
## Skyartec - *68*
Option for this protocol corresponds to fine frequency tuning. This value is different for each Module and **must** be accurate otherwise the link will not be stable.