Skip to content

Commit

Permalink
Add more logging, fix antcap setting
Browse files Browse the repository at this point in the history
  • Loading branch information
dkulp committed Aug 16, 2020
1 parent f6da9b8 commit f7a4300
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion plugin_setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function OnConnectionChanged() {
<p>Power (88-115, 116-120<sup>*</sup>): <?php PrintSettingTextSaved("Power", 2, 0, 3, 3, "fpp-vastfmt", "110"); ?>dB&mu;V
<br /><sup>*</sup>Can be set as high as 120dB&mu;V, but voltage accuracy above 115dB&mu;V is not guaranteed.</p>
<p>Preemphasis: <?php PrintSettingSelect("Preemphasis", "Preemphasis", 2, 0, "75us", Array("50&mu;s (Europe, Australia, Japan)"=>"50us", "75&mu;s (USA, default)"=>"75us"), "fpp-vastfmt", ""); ?></p>
<p>Antenna Tuning Capacitor (0=Auto, 1-191): <?php PrintSettingText("AntCap", 2, 0, 3, 3, "fpp-vastfmt", "0"); ?> * 0.25pF </p>
<p>Antenna Tuning Capacitor (0=Auto, 1-191): <?php PrintSettingTextSaved("AntCap", 2, 0, 3, 3, "fpp-vastfmt", "0"); ?> * 0.25pF </p>
</fieldset>
</div>

Expand Down
17 changes: 11 additions & 6 deletions src/I2CSi4713.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,9 @@ std::string I2CSi4713::getTuneStatus() {

float f = currFreq / 100.0f;

std::string r = "Freq:" + std::to_string(f)
+ " MHz - Power:" + std::to_string(currdBuV)
+ "dBuV - ANTcap:" + std::to_string(currAntCap);
return r;
char buf[100];
sprintf(buf, "Freq: %.1f MHz - Power: %d dBuV - ANTcap: %d", f, currdBuV, currAntCap);
return buf;
}
bool I2CSi4713::sendSi4711Command(uint8_t cmd, const std::vector<uint8_t> &data, bool ignoreFailures) {
LogDebug(VB_PLUGIN, "Sending command %X datasize: %d (no resp)(if: %d)\n", cmd, data.size(), ignoreFailures);
Expand Down Expand Up @@ -159,8 +158,10 @@ bool I2CSi4713::sendSi4711Command(uint8_t cmd, const std::vector<uint8_t> &data,
}
}
if (ignoreFailures || i >= 0) {
LogExcess(VB_PLUGIN, " resp2 %d, %X\n", i, (int)out[0]);
return true;
}
LogExcess(VB_PLUGIN, " Failed: %d\n", i);
return false;
}

Expand All @@ -173,13 +174,17 @@ bool I2CSi4713::sendSi4711Command(uint8_t cmd, const std::vector<uint8_t> &data,
std::this_thread::sleep_for(std::chrono::microseconds(10000));
if (out.size()) {
i = i2c->readI2CBlockData(0x00, &out[0], out.size());
LogExcess(VB_PLUGIN, " read1 %d\n", i);
LogExcess(VB_PLUGIN, " read1 %d %X\n", i, (int)out[0]);
} else {
uint8_t b[1];
i = i2c->readI2CBlockData(0x00, &b[0], 1);
LogExcess(VB_PLUGIN, " read2 %d %X\n", i, (int)b[0]);
if (!(b[0] & 0x80)) {
LogWarn(VB_PLUGIN, "Failed sending command: %X\n", cmd);
return false;
}
}
return false;
return true;
}


Expand Down
25 changes: 15 additions & 10 deletions src/Si4713.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include <cstring>
#include "fpp-pch.h"
#include <sys/time.h>

#include "Si4713.h"
#include "util/I2CUtils.h"

#include "log.h"
#include "bitstream.h"


Expand Down Expand Up @@ -180,8 +178,7 @@ void Si4713::setRDSBuffer(const std::string &station,
lastRDS = station;
uint8_t buf[64];
memset(buf, ' ', 64);



int sl = station.size();
if (sl > 64) {
sl = 64;
Expand All @@ -197,6 +194,7 @@ void Si4713::setRDSBuffer(const std::string &station,
}
}

std::vector<uint8_t> resp(6);
if (station.size() != 0) {
int count = (sl + 3) / 4;
//printf("%d, %s\n", count, station.c_str());
Expand All @@ -205,8 +203,12 @@ void Si4713::setRDSBuffer(const std::string &station,
if (i == 0) {
sb |= TX_RDS_BUFF_IN_MTBUFF;
}
sendSi4711Command(TX_RDS_BUFF, {sb, 0x20, i, buf[i*4], buf[(i*4)+1], buf[(i*4)+2], buf[(i*4)+3], 0});
sendSi4711Command(TX_RDS_BUFF, {sb, 0x20, i, buf[i*4], buf[(i*4)+1], buf[(i*4)+2], buf[(i*4)+3], 0}, resp);
LogExcess(VB_PLUGIN, " res: %2X %2X %2X %2X %2X %2X\n", resp[0], resp[1], resp[2], resp[3], resp[4], resp[5]);
}
uint8_t idx = count;
sendSi4711Command(TX_RDS_BUFF, {TX_RDS_BUFF_IN_LDBUFF, 0x20, idx, 0x0d, 0x00, 0x00, 0x00, 0}, resp);
LogExcess(VB_PLUGIN, " res: %2X %2X %2X %2X %2X %2X\n", resp[0], resp[1], resp[2], resp[3], resp[4], resp[5]);
sendRtPlusInfo(1, titlePos, titleLen, 4, artistPos, artistLen);
} else {
sendSi4711Command(TX_RDS_BUFF, {TX_RDS_BUFF_IN_MTBUFF, 0, 0, 0, 0, 0, 0});
Expand All @@ -225,6 +227,7 @@ void Si4713::sendRtPlusInfo(int content1, int content1_pos, int content1_len,
int content2, int content2_pos, int content2_len) {
uint8_t buff[16];
char msg[6];
std::vector<uint8_t> resp(6);

if (content1_len || content2_len) {

Expand Down Expand Up @@ -252,7 +255,8 @@ void Si4713::sendRtPlusInfo(int content1, int content1_pos, int content1_len,

sendSi4711Command(TX_RDS_BUFF, {TX_RDS_BUFF_IN_LDBUFF,
RTPLUS_GROUP_ID << 4,
msg[0], msg[1], msg[2], msg[3], msg[4]});
msg[0], msg[1], msg[2], msg[3], msg[4]}, resp);
LogExcess(VB_PLUGIN, " res+: %2X %2X %2X %2X %2X %2X\n", resp[0], resp[1], resp[2], resp[3], resp[4], resp[5]);

//send RT+ announces
// FmRadioController::HandleRDSData
Expand All @@ -270,7 +274,8 @@ void Si4713::sendRtPlusInfo(int content1, int content1_pos, int content1_len,
//zzzz - for rds server needs.
0, //template id=0
0x4B, 0xD7 //it's RT+
});
}, resp);
LogExcess(VB_PLUGIN, " res+: %2X %2X %2X %2X %2X %2X\n", resp[0], resp[1], resp[2], resp[3], resp[4], resp[5]);
}
}

Expand Down Expand Up @@ -303,14 +308,14 @@ void Si4713::sendTimestamp() {
}

uint8_t sb = TX_RDS_BUFF_IN_LDBUFF | TX_RDS_BUFF_IN_FIFO;
std::vector<uint8_t> out;
std::vector<uint8_t> out(6);

uint8_t arg1 = (MJD >> 15);
uint8_t arg2 = (MJD >> 7);
uint8_t arg3 = (MJD << 1) | ((ltm->tm_hour & 0x1F)>> 4);
uint8_t arg4 = ((ltm->tm_hour & 0x1F)<< 4)|((ltm->tm_min & 0x3F)>> 2);
uint8_t arg5 = ((ltm->tm_min & 0x3F)<< 6)|offset;
sendSi4711Command(TX_RDS_BUFF,{sb, 0x40, arg1, arg2, arg3, arg4, arg5}, out);
//printf("ts out: %2X %2X %2X %2X %2X %2X %2X %2X\n", out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]);
LogExcess(VB_PLUGIN, "ts out: %2X %2X %2X %2X %2X %2X\n", out[0], out[1], out[2], out[3], out[4], out[5]);
}

0 comments on commit f7a4300

Please sign in to comment.