diff --git a/configure.cpp b/configure.cpp index 01a3330..81b9326 100644 --- a/configure.cpp +++ b/configure.cpp @@ -74,16 +74,15 @@ Configure::Configure(int argc, char** argv) : exit(EXIT_FAILURE); } - /// @ scan for overriding the configuration file + // TODO: allow overriding config file from command line std::cerr << "[Configure::Configure] Pages directory is " << _pageDir << std::endl; std::cerr << "[Configure::Configure] Config file is " << _configFile << std::endl; - /// @todo load the configuration file. + std::string path; path = _pageDir; path += "/"; path += _configFile; LoadConfigFile(path); - /// @todo scan the command line for other overrides. } Configure::~Configure() @@ -108,7 +107,6 @@ int Configure::LoadConfigFile(std::string filename) TTXLine* header = new TTXLine(); while (std::getline(filein >> std::ws, line)){ if (line.front() != ';'){ // ignore comments - /// todo: parsing! std::size_t delim = line.find("=", 0); int error = 0; @@ -252,7 +250,6 @@ int Configure::LoadConfigFile(std::string filename) } break; case 11: // "magazine_priority" - // TODO: implement parsing from config std::stringstream ss(value); std::string temps; int tmp[8]; diff --git a/filemonitor.cpp b/filemonitor.cpp index 60e08a0..90ab5c2 100644 --- a/filemonitor.cpp +++ b/filemonitor.cpp @@ -55,9 +55,7 @@ std::thread FileMonitor::run() void FileMonitor::run() { - // @todo This thread will clash. They need proper protection. - - std::string path=_configure->GetPageDirectory() ; // + std::string path=_configure->GetPageDirectory() ; std::cerr << "[FileMonitor::run] Monitoring " << path << std::endl; while (true) diff --git a/packet.cpp b/packet.cpp index 370dce3..1d66148 100644 --- a/packet.cpp +++ b/packet.cpp @@ -80,7 +80,6 @@ Packet::~Packet() void Packet::Set_packet(char *val) { - //std::cerr << "[Packet::Set_packet] todo. Implement copy" << std::endl; strncpy(&_packet[5],val,40); } @@ -150,7 +149,7 @@ bool Packet::get_offset_time(char* str) strftime(strTime, 21, "%H:%M", &tmGMT); stringToBytes(str,strTime,5); - return true; // @todo + return true; } /* Ideally we would set _packet[0] for other hardware, or _packet[3] for Alistair Buxton raspi-teletext/ @@ -159,178 +158,176 @@ bool Packet::get_offset_time(char* str) */ char* Packet::tx(bool reverse) { - // Get local time - time_t rawtime; - struct tm * timeinfo; - time(&rawtime); - timeinfo=localtime(&rawtime); - - // @TODO: parity - if (_isHeader) // We can do header substitutions - { - // mpp page number. Use %%# - char* ptr2=strstr(_packet,"%%#"); - if (ptr2) - { - if (_mag==0) - ptr2[0]='8'; - else - ptr2[0]=_mag+'0'; - //std::cerr << "[Packet::tx]page=" << _page << std::endl; - ptr2[1]=_page/0x10+'0'; - if (ptr2[1]>'9') - ptr2[1]=ptr2[1]-'0'-10+'A'; // Particularly poor hex conversion algorithm - //std::cerr << "[Packet::tx]ptr[1]=" << ptr2[1] << std::endl; - - ptr2[2]=_page%0x10+'0'; - if (ptr2[2]>'9') - ptr2[2]=ptr2[2]-'0'-10+'A'; // Particularly poor hex conversion algorithm - //std::cerr << "[Packet::tx]ptr[2]=" << ptr2[2] << std::endl; - } - - char tmpstr[11]; - ptr2=strstr(_packet,"%%a"); // Tue - if (ptr2) - { - strftime(tmpstr,10,"%a",timeinfo); - ptr2[0]=tmpstr[0]; - ptr2[1]=tmpstr[1]; - ptr2[2]=tmpstr[2]; - } - - ptr2=strstr(_packet,"%%b"); // Jan - if (ptr2) - { - strftime(tmpstr,10,"%b",timeinfo); - ptr2[0]=tmpstr[0]; - ptr2[1]=tmpstr[1]; - ptr2[2]=tmpstr[2]; - } - - ptr2=strstr(_packet,"%d"); // day of month with leading zero - if (ptr2) - { - strftime(tmpstr,10,"%d",timeinfo); - ptr2[0]=tmpstr[0]; - ptr2[1]=tmpstr[1]; - } - - ptr2=strstr(_packet,"%e"); // day of month with no leading zero - if (ptr2) - { - #ifndef WIN32 - strftime(tmpstr,10,"%e",timeinfo); - ptr2[0]=tmpstr[0]; - #else - strftime(tmpstr,10,"%d",timeinfo); - if (tmpstr[0] == '0') - ptr2[0]=' '; - else - ptr2[0]=tmpstr[0]; - #endif - ptr2[1]=tmpstr[1]; - } - - ptr2=strstr(_packet,"%m"); // month number with leading 0 - if (ptr2) - { - strftime(tmpstr,10,"%m",timeinfo); - ptr2[0]=tmpstr[0]; - ptr2[1]=tmpstr[1]; - } - - ptr2=strstr(_packet,"%y"); // year. 2 digits - if (ptr2) - { - strftime(tmpstr,10,"%y",timeinfo); - ptr2[0]=tmpstr[0]; - ptr2[1]=tmpstr[1]; - } - - ptr2=strstr(_packet,"%H"); // hour. - if (ptr2) - { - strftime(tmpstr,10,"%H",timeinfo); - ptr2[0]=tmpstr[0]; - ptr2[1]=tmpstr[1]; - } - - ptr2=strstr(_packet,"%M"); // minutes. - if (ptr2) - { - strftime(tmpstr,10,"%M",timeinfo); - ptr2[0]=tmpstr[0]; - ptr2[1]=tmpstr[1]; - } - - ptr2=strstr(_packet,"%S"); // seconds. - if (ptr2) - { - strftime(tmpstr,10,"%S",timeinfo); - ptr2[0]=tmpstr[0]; - ptr2[1]=tmpstr[1]; - } - - Parity(13); // apply parity to the text of the header + // Get local time + time_t rawtime; + struct tm * timeinfo; + time(&rawtime); + timeinfo=localtime(&rawtime); - } - else if (_coding == CODING_7BIT_TEXT) // Other text rows - { - char *tmpptr; - for (int i=5;i<45;i++) _packet[i]=_packet[i] & 0x7f; - // ======= TEMPERATURE ======== - char strtemp[]=" "; - tmpptr=strstr((char*)_packet,"%%%T"); - if (tmpptr) { - #ifdef RASPBIAN - get_temp(strtemp); - stringToBytes(tmpptr,strtemp,4); - #else - stringToBytes(tmpptr,(char *)"err",4); - #endif - } - // ======= WORLD TIME ======== - // Special case for world time. Put %t<+|-> to get local time HH:MM offset by +/- half hours - for (;;) - { - tmpptr=strstr((char*) _packet,"%t+"); - if (!tmpptr) { - tmpptr=strstr((char*) _packet,"%t-"); - } - if (tmpptr) { - //std::cout << "[test 1]" << _packet << std::endl; - get_offset_time(tmpptr); - //exit(4); - } - else - break; - } - // ======= NETWORK ======== - // Special case for network address. Put %%%%%%%%%%%%%%n to get network address in form xxx.yyy.zzz.aaa with trailing spaces (15 characters total) - tmpptr=strstr((char*)_packet,"%%%%%%%%%%%%%%n"); - if (tmpptr) { - #ifndef WIN32 - get_net(strtemp); - stringToBytes(tmpptr,strtemp,15); - #else - stringToBytes(tmpptr,(char *)"not implemented",15); - #endif - } - // ======= TIME AND DATE ======== - // Special case for system time. Put %%%%%%%%%%%%timedate to get time and date - tmpptr=strstr((char*) _packet,"%%%%%%%%%%%%timedate"); - if (tmpptr) { - get_time(strtemp); - stringToBytes(tmpptr,strtemp,20); - } - // ======= VERSION ======== - // %%%V version number eg. 2.00 - tmpptr=strstr((char*) _packet,"%%%%%V"); - if (tmpptr) { - stringToBytes(tmpptr,(char *)VBIT2_VERSION,6); - } - Parity(5); // redo the parity because substitutions will need processing - } + if (_isHeader) // We can do header substitutions + { + // mpp page number. Use %%# + char* ptr2=strstr(_packet,"%%#"); + if (ptr2) + { + if (_mag==0) + ptr2[0]='8'; + else + ptr2[0]=_mag+'0'; + //std::cerr << "[Packet::tx]page=" << _page << std::endl; + ptr2[1]=_page/0x10+'0'; + if (ptr2[1]>'9') + ptr2[1]=ptr2[1]-'0'-10+'A'; // Particularly poor hex conversion algorithm + //std::cerr << "[Packet::tx]ptr[1]=" << ptr2[1] << std::endl; + + ptr2[2]=_page%0x10+'0'; + if (ptr2[2]>'9') + ptr2[2]=ptr2[2]-'0'-10+'A'; // Particularly poor hex conversion algorithm + //std::cerr << "[Packet::tx]ptr[2]=" << ptr2[2] << std::endl; + } + + char tmpstr[11]; + ptr2=strstr(_packet,"%%a"); // Tue + if (ptr2) + { + strftime(tmpstr,10,"%a",timeinfo); + ptr2[0]=tmpstr[0]; + ptr2[1]=tmpstr[1]; + ptr2[2]=tmpstr[2]; + } + + ptr2=strstr(_packet,"%%b"); // Jan + if (ptr2) + { + strftime(tmpstr,10,"%b",timeinfo); + ptr2[0]=tmpstr[0]; + ptr2[1]=tmpstr[1]; + ptr2[2]=tmpstr[2]; + } + + ptr2=strstr(_packet,"%d"); // day of month with leading zero + if (ptr2) + { + strftime(tmpstr,10,"%d",timeinfo); + ptr2[0]=tmpstr[0]; + ptr2[1]=tmpstr[1]; + } + + ptr2=strstr(_packet,"%e"); // day of month with no leading zero + if (ptr2) + { + #ifndef WIN32 + strftime(tmpstr,10,"%e",timeinfo); + ptr2[0]=tmpstr[0]; + #else + strftime(tmpstr,10,"%d",timeinfo); + if (tmpstr[0] == '0') + ptr2[0]=' '; + else + ptr2[0]=tmpstr[0]; + #endif + ptr2[1]=tmpstr[1]; + } + + ptr2=strstr(_packet,"%m"); // month number with leading 0 + if (ptr2) + { + strftime(tmpstr,10,"%m",timeinfo); + ptr2[0]=tmpstr[0]; + ptr2[1]=tmpstr[1]; + } + + ptr2=strstr(_packet,"%y"); // year. 2 digits + if (ptr2) + { + strftime(tmpstr,10,"%y",timeinfo); + ptr2[0]=tmpstr[0]; + ptr2[1]=tmpstr[1]; + } + + ptr2=strstr(_packet,"%H"); // hour. + if (ptr2) + { + strftime(tmpstr,10,"%H",timeinfo); + ptr2[0]=tmpstr[0]; + ptr2[1]=tmpstr[1]; + } + + ptr2=strstr(_packet,"%M"); // minutes. + if (ptr2) + { + strftime(tmpstr,10,"%M",timeinfo); + ptr2[0]=tmpstr[0]; + ptr2[1]=tmpstr[1]; + } + + ptr2=strstr(_packet,"%S"); // seconds. + if (ptr2) + { + strftime(tmpstr,10,"%S",timeinfo); + ptr2[0]=tmpstr[0]; + ptr2[1]=tmpstr[1]; + } + + Parity(13); // apply parity to the text of the header + } + else if (_coding == CODING_7BIT_TEXT) // Other text rows + { + char *tmpptr; + for (int i=5;i<45;i++) _packet[i]=_packet[i] & 0x7f; + // ======= TEMPERATURE ======== + char strtemp[]=" "; + tmpptr=strstr((char*)_packet,"%%%T"); + if (tmpptr) { + #ifdef RASPBIAN + get_temp(strtemp); + stringToBytes(tmpptr,strtemp,4); + #else + stringToBytes(tmpptr,(char *)"err",4); + #endif + } + // ======= WORLD TIME ======== + // Special case for world time. Put %t<+|-> to get local time HH:MM offset by +/- half hours + for (;;) + { + tmpptr=strstr((char*) _packet,"%t+"); + if (!tmpptr) { + tmpptr=strstr((char*) _packet,"%t-"); + } + if (tmpptr) { + //std::cout << "[test 1]" << _packet << std::endl; + get_offset_time(tmpptr); // TODO: something with return value + //exit(4); + } + else + break; + } + // ======= NETWORK ======== + // Special case for network address. Put %%%%%%%%%%%%%%n to get network address in form xxx.yyy.zzz.aaa with trailing spaces (15 characters total) + tmpptr=strstr((char*)_packet,"%%%%%%%%%%%%%%n"); + if (tmpptr) { + #ifndef WIN32 + get_net(strtemp); + stringToBytes(tmpptr,strtemp,15); + #else + stringToBytes(tmpptr,(char *)"not implemented",15); + #endif + } + // ======= TIME AND DATE ======== + // Special case for system time. Put %%%%%%%%%%%%timedate to get time and date + tmpptr=strstr((char*) _packet,"%%%%%%%%%%%%timedate"); + if (tmpptr) { + get_time(strtemp); + stringToBytes(tmpptr,strtemp,20); + } + // ======= VERSION ======== + // %%%V version number eg. 2.00 + tmpptr=strstr((char*) _packet,"%%%%%V"); + if (tmpptr) { + stringToBytes(tmpptr,(char *)VBIT2_VERSION,6); + } + Parity(5); // redo the parity because substitutions will need processing + } if (reverse) { @@ -384,13 +381,13 @@ void Packet::Header(unsigned char mag, unsigned char page, unsigned int subcode, // cbit|=0x08; // TEMPORARY! _packet[10]=HamTab[(subcode&0x03) | cbit]; // S4 C6, C5 cbit=0; - if (control & 0x0004) cbit=0x01; // C7 Suppress Header TODO: Check if these should be reverse order + if (control & 0x0004) cbit=0x01; // C7 Suppress Header if (control & 0x0008) cbit|=0x02; // C8 Update if (control & 0x0010) cbit|=0x04; // C9 Interrupted sequence if (control & 0x0020) cbit|=0x08; // C10 Inhibit display _packet[11]=HamTab[cbit]; // C7 to C10 - cbit=(control & 0x0380) >> 6; // Shift the language bits C12,C13,C14. TODO: Check if C12/C14 need swapping. CHECKED OK. + cbit=(control & 0x0380) >> 6; // Shift the language bits C12,C13,C14. // if (control & 0x0040) cbit|=0x01; // C11 serial/parallel *** We only work in parallel mode, Serial would mean a different packet ordering. _packet[12]=HamTab[cbit]; // C11 to C14 (C11=0 is parallel, C12,C13,C14 language) diff --git a/packet830.cpp b/packet830.cpp index ceadb9b..7f86367 100644 --- a/packet830.cpp +++ b/packet830.cpp @@ -37,7 +37,6 @@ Packet* Packet830::GetPacket(Packet* p) uint8_t muxed = _configure->GetMultiplexedSignalFlag(); - // @todo initial page uint8_t m = _configure->GetInitialMag(); uint8_t pn = _configure->GetInitialPage(); uint16_t sc = _configure->GetInitialSubcode(); @@ -50,7 +49,6 @@ Packet* Packet830::GetPacket(Packet* p) memcpy(&val[20],_configure->GetServiceStatusString().data(),20); // copy status display from std::string into packet data - // @todo Find which event happened and send the relevant packet if (GetEvent(EVENT_P830_FORMAT_1)) { ClearEvent(EVENT_P830_FORMAT_1); diff --git a/packetmag.cpp b/packetmag.cpp index 96573ff..50bc76d 100644 --- a/packetmag.cpp +++ b/packetmag.cpp @@ -5,7 +5,6 @@ using namespace vbit; -// @todo Initialise the magazine data PacketMag::PacketMag(uint8_t mag, std::list* pageSet, ttx::Configure *configure, uint8_t priority) : _pageSet(pageSet), _configure(configure), @@ -40,7 +39,6 @@ PacketMag::~PacketMag() delete _specialPages; } -// @todo Invent a packet sequencer similar to mag.cpp which this will replace Packet* PacketMag::GetPacket(Packet* p) { // std::cerr << "[PacketMag::GetPacket] mag=" << _magNumber << " state=" << _state << std::endl; diff --git a/pagelist.cpp b/pagelist.cpp index 23c9a87..ceef02c 100644 --- a/pagelist.cpp +++ b/pagelist.cpp @@ -155,7 +155,6 @@ bool PageList::CheckForPacket29(TTXPageStream* page) TTXLine* tempLine = page->GetTxRow(29); while (tempLine != nullptr) { - // TODO: when the page is deleted the packets will remain. //std::cerr << "page includes packet 29" << std::endl; switch (tempLine->GetCharAt(0)) { @@ -184,7 +183,6 @@ bool PageList::CheckForPacket29(TTXPageStream* page) TTXPageStream* PageList::Locate(std::string filename) { // This is called from the FileMonitor thread - // std::cerr << "[PageList::Locate] *** TODO *** " << filename << std::endl; for (int mag=0;mag<8;mag++) { //for (auto p : _pageList[mag]) @@ -406,13 +404,13 @@ void PageList::DeleteOldPages() if (ptr->GetStatusFlag()==TTXPageStream::GONE) { if (((ptr->GetPageNumber() >> 8) & 0xFF) == 0xFF) - { - // page mFF - make sure packet 29 is removed - _magPacket29[mag][0] = nullptr; - _magPacket29[mag][1] = nullptr; - _magPacket29[mag][2] = nullptr; - _mag[mag]->SetPacket29(_magPacket29[mag]); - } + { + // page mFF - make sure packet 29 is removed + _magPacket29[mag][0] = nullptr; + _magPacket29[mag][1] = nullptr; + _magPacket29[mag][2] = nullptr; + _mag[mag]->SetPacket29(_magPacket29[mag]); + } //std::cerr << "[PageList::DeleteOldPages] Deleted " << ptr->GetSourcePage() << std::endl; // page has been removed from lists diff --git a/service.cpp b/service.cpp index 03a4a8f..2d53504 100644 --- a/service.cpp +++ b/service.cpp @@ -15,8 +15,6 @@ Service::Service(Configure *configure, PageList *pageList) : _lineCounter(0), _fieldCounter(50) // roll over immediately { - // @todo Add commands to allow updates to priority. - vbit::PacketMag **magList=_pageList->GetMagazines(); // Register all the packet sources for (uint8_t mag=0;mag<8;mag++) @@ -50,7 +48,7 @@ int Service::run() vbit::Packet* pkt=new vbit::Packet(8,25," "); // This just allocates storage. - static vbit::Packet* filler=new vbit::Packet(8,25," "); // @todo Again, we should have a pre-prepared quiet packet to avoid eating the heap + static vbit::Packet* filler=new vbit::Packet(8,25," "); // A pre-prepared quiet packet to avoid eating the heap bool reverse = _configure->GetReverseFlag(); if (reverse) diff --git a/vbit2.cpp b/vbit2.cpp index ec319de..8cc8342 100644 --- a/vbit2.cpp +++ b/vbit2.cpp @@ -71,8 +71,6 @@ int main(int argc, char** argv) monitorThread.join(); serviceThread.join(); - std::cout << "VBIT2 ended. Press any key to continue" << std::endl; - system("pause"); // @todo Only apply this line in debug - // return 0; + return 0; }