From c638e4c1b8a291bddd90ad948b09dd6026efce01 Mon Sep 17 00:00:00 2001 From: Mateusz Date: Fri, 5 Jul 2019 08:01:41 +0200 Subject: [PATCH] Wip: Refactor part 1 --- module-cellular/Modem/GSM0710.cpp | 14 ++ module-cellular/Modem/GSM0710.hpp | 99 +++++----- module-cellular/Modem/InputSerialWorker.cpp | 170 +++++++----------- module-cellular/Modem/InputSerialWorker.hpp | 14 +- module-cellular/Modem/MuxDaemon.cpp | 4 +- module-cellular/Modem/MuxDaemon.hpp | 11 +- .../service-cellular/ServiceCellular.cpp | 2 +- 7 files changed, 145 insertions(+), 169 deletions(-) diff --git a/module-cellular/Modem/GSM0710.cpp b/module-cellular/Modem/GSM0710.cpp index 04a5d2085..853e30346 100644 --- a/module-cellular/Modem/GSM0710.cpp +++ b/module-cellular/Modem/GSM0710.cpp @@ -228,4 +228,18 @@ unsigned char GSM0710Buffer::frameCalcCRC(const unsigned char *input, int length for (i = 0; i < length; i++) fcs = crcTable[fcs ^ input[i]]; return 0xFF - fcs; +} + +void GSM0710Buffer::ReorganizeBuffer() { + if (readp != + data) { //relayout data in cache_buf + if (GetDataLength()) { + LOG_DEBUG("memmove(0, %ld, %d)", (long)(readp - data), GetDataLength()); + memmove(data, readp, + GetDataLength()); + } + readp = data; + writep = + data + GetDataLength(); + } } \ No newline at end of file diff --git a/module-cellular/Modem/GSM0710.hpp b/module-cellular/Modem/GSM0710.hpp index 72a5c5a32..52960102a 100644 --- a/module-cellular/Modem/GSM0710.hpp +++ b/module-cellular/Modem/GSM0710.hpp @@ -65,49 +65,8 @@ struct GSM0710Frame { class GSM0710Buffer { - //reversed, 8-bit, poly=0x07 - static constexpr unsigned char crcTable[] = { - - 0x00, 0x91, 0xE3, 0x72, 0x07, 0x96, 0xE4, 0x75, 0x0E, 0x9F, 0xED, - 0x7C, 0x09, 0x98, 0xEA, 0x7B, 0x1C, 0x8D, 0xFF, 0x6E, 0x1B, 0x8A, - 0xF8, 0x69, 0x12, 0x83, 0x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7A, 0xEB, 0x8C, - 0x1D, 0x6F, 0xFE, 0x8B, 0x1A, 0x68, 0xF9, 0x82, 0x13, 0x61, 0xF0, - 0x85, 0x14, 0x66, 0xF7, 0xA8, 0x39, 0x4B, 0xDA, 0xAF, 0x3E, 0x4C, - 0xDD, 0xA6, 0x37, 0x45, 0xD4, 0xA1, 0x30, 0x42, 0xD3, 0xB4, 0x25, - 0x57, 0xC6, 0xB3, 0x22, 0x50, 0xC1, 0xBA, 0x2B, 0x59, 0xC8, 0xBD, - 0x2C, 0x5E, 0xCF, - }; - - enum class State{ - SearchForNewFrame, - ParseFrameHeader, - ParseFramePayload - }; - - State state = State ::SearchForNewFrame; - size_t lengthNeeded = 5;// channel, type, length, fcs, flag - uint8_t fcs = 0xff; - std::unique_ptr currentFrame; - public: - // some state // +CMUX=[,[,[,[,[,[,[,[,]]]]]]]] uint32_t cmux_mode = 0; uint32_t vir_ports = 3; /* number of virtual ports to create */ @@ -122,9 +81,7 @@ public: unsigned char *endp = nullptr; unsigned int datacount = 0; unsigned int max_count = 0; - int flag_found = 0;// set if last character read was flag - unsigned long received_count = 0; - unsigned long dropped_count = 0; + GSM0710Buffer(uint32_t virtualPortsCount, uint32_t frameSize=127, uint32_t mode=0) : @@ -161,12 +118,6 @@ public: } } - inline void Update(unsigned char* rdp, unsigned int count){ - readp = rdp; - datacount -= count; - } - - static inline bool GSM0710_FRAME_IS(MuxDefines type, GSM0710Frame *frame) { return (frame->control & ~static_cast(MuxDefines::GSM0710_PF)) == @@ -184,6 +135,54 @@ public: GSM0710Frame *GetCompleteFrame(GSM0710Frame *frame); + void ReorganizeBuffer(); + +private: + + //reversed, 8-bit, poly=0x07 + static constexpr unsigned char crcTable[] = { + + 0x00, 0x91, 0xE3, 0x72, 0x07, 0x96, 0xE4, 0x75, 0x0E, 0x9F, 0xED, + 0x7C, 0x09, 0x98, 0xEA, 0x7B, 0x1C, 0x8D, 0xFF, 0x6E, 0x1B, 0x8A, + 0xF8, 0x69, 0x12,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 0x08, 0x7A, 0xEB, 0x8C, + 0x1D, 0x6F, 0xFE, 0x8B, 0x1A, 0x68, 0xF9, 0x82, 0x13, 0x61, 0xF0, + 0x85, 0x14, 0x66, 0xF7, 0xA8, 0x39, 0x4B, 0xDA, 0xAF, 0x3E, 0x4C, + 0xDD, 0xA6, 0x37, 0x45, 0xD4, 0xA1, 0x30, 0x42, 0xD3, 0xB4, 0x25, + 0x57, 0xC6, 0xB3, 0x22, 0x50, 0xC1, 0xBA, 0x2B, 0x59, 0xC8, 0xBD, + 0x2C, 0x5E, 0xCF, + }; + + enum class State{ + SearchForNewFrame, + ParseFrameHeader, + ParseFramePayload + }; + + int flag_found = 0;// set if last character read was flag + unsigned long received_count = 0; + unsigned long dropped_count = 0; + + State state = State ::SearchForNewFrame; + size_t lengthNeeded = 5;// channel, type, length, fcs, flag + uint8_t fcs = 0xff; + std::unique_ptr currentFrame; + }; #endif //PUREPHONE_GSM0710_HPP diff --git a/module-cellular/Modem/InputSerialWorker.cpp b/module-cellular/Modem/InputSerialWorker.cpp index ce8195712..878575063 100644 --- a/module-cellular/Modem/InputSerialWorker.cpp +++ b/module-cellular/Modem/InputSerialWorker.cpp @@ -15,7 +15,22 @@ InputSerialWorker::InputSerialWorker(MuxDaemon *mux) : muxDaemon(mux) { + BaseType_t task_error = xTaskCreate( + workerTaskFunction, + "cellInSerWorker", + 512, // in words + this, + taskPriority, + &taskHandle); + if (task_error != pdPASS) { + LOG_ERROR("Failed to start inputSerialWorker task"); + } +} +InputSerialWorker::~InputSerialWorker() { + if (taskHandle) { + vTaskDelete(taskHandle); + } } @@ -31,43 +46,13 @@ void workerTaskFunction(void *ptr) { //TODO:M.P implement error handling ? } - if (worker->muxDaemon->inputBuffer->readp != - worker->muxDaemon->inputBuffer->data) { //relayout data in cache_buf - if (worker->muxDaemon->inputBuffer->GetDataLength()) { - LOG_DEBUG("memmove(0, %ld, %d)", (long)(worker->muxDaemon->inputBuffer->readp - worker->muxDaemon->inputBuffer->data), worker->muxDaemon->inputBuffer->GetDataLength()); - memmove(worker->muxDaemon->inputBuffer->data, worker->muxDaemon->inputBuffer->readp, - worker->muxDaemon->inputBuffer->GetDataLength()); - } - worker->muxDaemon->inputBuffer->readp = worker->muxDaemon->inputBuffer->data; - worker->muxDaemon->inputBuffer->writep = - worker->muxDaemon->inputBuffer->data + worker->muxDaemon->inputBuffer->GetDataLength(); - } + // Reorganize data in buffer if necessary + worker->muxDaemon->inputBuffer->ReorganizeBuffer(); } } } } -bool InputSerialWorker::Init() { - BaseType_t task_error = xTaskCreate( - workerTaskFunction, - "cellInSerWorker", - 512, // in words - this, - taskPriority, - &taskHandle); - if (task_error != pdPASS) { - LOG_ERROR("Failed to start inputSerialWorker task"); - return false; - } - return true; -} - -bool InputSerialWorker::Deinit() { - if (taskHandle) { - vTaskDelete(taskHandle); - } -} - int InputSerialWorker::ReadIncomingData() { int length = 0; @@ -133,13 +118,13 @@ int InputSerialWorker::ExtractFrames() { LOG_DEBUG("Writing %d byte frame received on channel %d to %s", frame->length, frame->channel, muxDaemon->channels[frame->channel].GetName().c_str()); - int write_result=0; + int write_result = 0; if (muxDaemon->channels[frame->channel].GetState() == MuxChannel::State::Opened) {//reopening, discard the data // Send received message to virtual channel for further processing - write_result = muxDaemon->channels[frame->channel].DistributeMsg(frame->data,frame->length); + write_result = muxDaemon->channels[frame->channel].DistributeMsg(frame->data, frame->length); } else { LOG_INFO("channel %d closed, discard the frame", frame->channel); write_result = frame->length; @@ -183,13 +168,8 @@ int InputSerialWorker::ExtractFrames() { muxDaemon->channels[frame->channel].disc_ua_pending = 0; } } - //TODO: M.P dunno what is this for ?? -#if 0 - if (frame->channel == muxDaemon->virtualPortsCount){ - ql_cmux_debug = 0; - } -#endif - break; + break; + case MuxDefines::GSM0710_TYPE_DM: if (muxDaemon->channels[frame->channel].GetState() == MuxChannel::State::Opened) { // Remove channel @@ -247,13 +227,8 @@ int InputSerialWorker::ExtractFrames() { muxDaemon->WriteMuxFrame(frame->channel, NULL, 0, static_cast(MuxDefines::GSM0710_TYPE_UA) | static_cast(MuxDefines::GSM0710_PF)); -//TODO: M.P dunno what is this for ?? -#if 0 - if (frame->channel == muxDaemon->virtualPortsCount){ - ql_cmux_debug = 0; - } -#endif - break; + + break; default: break; @@ -265,50 +240,47 @@ int InputSerialWorker::ExtractFrames() { } -int InputSerialWorker::HandleCtrlChannelCommands(GSM0710Frame* frame) { +int InputSerialWorker::HandleCtrlChannelCommands(GSM0710Frame *frame) { unsigned char type, signals; int length = 0, i, type_length, channel, supported = 1; unsigned char *response; //struct ussp_operation op; - if (frame->length > 0) - { + if (frame->length > 0) { type = frame->data[0];// only a byte long types are handled now skip extra bytes - for (i = 0; (frame->length > i && (frame->data[i] & static_cast(MuxDefines ::GSM0710_EA)) == 0); i++); + for (i = 0; (frame->length > i && + (frame->data[i] & static_cast(MuxDefines::GSM0710_EA)) == 0); i++); i++; type_length = i; - if ((type & static_cast(MuxDefines ::GSM0710_CR)) == static_cast(MuxDefines ::GSM0710_CR)) - { + if ((type & static_cast(MuxDefines::GSM0710_CR)) == + static_cast(MuxDefines::GSM0710_CR)) { //command not ack extract frame length - while (frame->length > i) - { + while (frame->length > i) { length = (length * 128) + ((frame->data[i] & 254) >> 1); if ((frame->data[i] & 1) == 1) break; i++; } i++; - MuxDefines ftype = static_cast(type & ~static_cast(MuxDefines ::GSM0710_CR)); - switch (ftype) - { - case MuxDefines ::GSM0710_CONTROL_CLD: + MuxDefines ftype = static_cast(type & ~static_cast(MuxDefines::GSM0710_CR)); + switch (ftype) { + case MuxDefines::GSM0710_CONTROL_CLD: //TODO: M.P implement CMUX close LOG_INFO("The mobile station requested mux-mode termination"); - muxDaemon->state = MuxDaemon::States ::MUX_STATE_CLOSING; + muxDaemon->state = MuxDaemon::States::MUX_STATE_CLOSING; break; - case MuxDefines ::GSM0710_CONTROL_PSC: + case MuxDefines::GSM0710_CONTROL_PSC: LOG_INFO("Power Service Control command: ***"); LOG_INFO("Frame->data = %s / frame->length = %d", frame->data + i, frame->length - i); break; - case MuxDefines ::GSM0710_CONTROL_TEST: + case MuxDefines::GSM0710_CONTROL_TEST: LOG_INFO("Test command: "); LOG_INFO("Frame->data = %s / frame->length = %d", frame->data + i, frame->length - i); //serial->ping_number = 0; break; - case MuxDefines ::GSM0710_CONTROL_MSC: + case MuxDefines::GSM0710_CONTROL_MSC: LOG_INFO("GET MSC"); - if (i + 1 < frame->length) - { + if (i + 1 < frame->length) { channel = ((frame->data[i] & 252) >> 2); i++; signals = (frame->data[i]); @@ -317,61 +289,59 @@ int InputSerialWorker::HandleCtrlChannelCommands(GSM0710Frame* frame) { //op.len = 0; LOG_INFO("Modem status command on channel %d", channel); muxDaemon->channels[channel].frameAllowed = ((signals & - static_cast(MuxDefines ::GSM0710_SIGNAL_FC)) != static_cast(MuxDefines ::GSM0710_SIGNAL_FC)); - if ((signals & static_cast(MuxDefines ::GSM0710_SIGNAL_FC)) == static_cast(MuxDefines ::GSM0710_SIGNAL_FC)) + static_cast(MuxDefines::GSM0710_SIGNAL_FC)) != + static_cast(MuxDefines::GSM0710_SIGNAL_FC)); + if ((signals & static_cast(MuxDefines::GSM0710_SIGNAL_FC)) == + static_cast(MuxDefines::GSM0710_SIGNAL_FC)) LOG_INFO("No frames allowed"); - else - { + else { //op.arg |= USSP_CTS; LOG_INFO("Frames allowed"); } - if ((signals & static_cast(MuxDefines ::GSM0710_SIGNAL_RTC)) == static_cast(MuxDefines ::GSM0710_SIGNAL_RTC)) - { + if ((signals & static_cast(MuxDefines::GSM0710_SIGNAL_RTC)) == + static_cast(MuxDefines::GSM0710_SIGNAL_RTC)) { //op.arg |= USSP_DSR; LOG_INFO("Signal RTC"); } - if ((signals & static_cast(MuxDefines ::GSM0710_SIGNAL_IC)) == static_cast(MuxDefines ::GSM0710_SIGNAL_IC)) - { + if ((signals & static_cast(MuxDefines::GSM0710_SIGNAL_IC)) == + static_cast(MuxDefines::GSM0710_SIGNAL_IC)) { //op.arg |= USSP_RI; LOG_INFO("Signal Ring"); } - if ((signals & static_cast(MuxDefines ::GSM0710_SIGNAL_DV)) == static_cast(MuxDefines ::GSM0710_SIGNAL_DV)) - { + if ((signals & static_cast(MuxDefines::GSM0710_SIGNAL_DV)) == + static_cast(MuxDefines::GSM0710_SIGNAL_DV)) { //op.arg |= USSP_DCD; LOG_INFO("Signal DV"); } - } - else + } else LOG_ERROR("Modem status command, but no info. i: %d, len: %d, data-len: %d", - i, length, frame->length); + i, length, frame->length); break; default: LOG_ERROR("Unknown command (%d) from the control channel", type); - if ((response = static_cast(malloc(sizeof(char) * (2 + type_length)))) != NULL) - { + if ((response = static_cast(malloc(sizeof(char) * (2 + type_length)))) != NULL) { i = 0; - response[i++] = static_cast(MuxDefines ::GSM0710_CONTROL_NSC); + response[i++] = static_cast(MuxDefines::GSM0710_CONTROL_NSC); type_length &= 127; //supposes that type length is less than 128 - response[i++] = static_cast(MuxDefines ::GSM0710_EA) | (type_length << 1); - while (type_length--) - { + response[i++] = static_cast(MuxDefines::GSM0710_EA) | (type_length << 1); + while (type_length--) { response[i] = frame->data[i - 2]; i++; } - muxDaemon->WriteMuxFrame(0, response, i, static_cast(MuxDefines ::GSM0710_TYPE_UIH)); + muxDaemon->WriteMuxFrame(0, response, i, + static_cast(MuxDefines::GSM0710_TYPE_UIH)); free(response); supported = 0; - } - else + } else LOG_ERROR("Out of memory, when allocating space for response"); break; } - if (supported) - { + if (supported) { //acknowledge the command - frame->data[0] = frame->data[0] & ~static_cast(MuxDefines ::GSM0710_CR); + frame->data[0] = frame->data[0] & ~static_cast(MuxDefines::GSM0710_CR); LOG_INFO("response MSC..."); - muxDaemon->WriteMuxFrame(0, frame->data, frame->length, static_cast(MuxDefines ::GSM0710_TYPE_UIH)); + muxDaemon->WriteMuxFrame(0, frame->data, frame->length, + static_cast(MuxDefines::GSM0710_TYPE_UIH)); LOG_INFO("response MSC"); #if 0 switch ((type & ~GSM0710_CR)){ @@ -388,19 +358,17 @@ int InputSerialWorker::HandleCtrlChannelCommands(GSM0710Frame* frame) { } #endif } - } - else - { + } else { //received ack for a command - if (GSM0710Buffer::GSM0710_COMMAND_IS(static_cast(type), static_cast(MuxDefines ::GSM0710_CONTROL_NSC))) + if (GSM0710Buffer::GSM0710_COMMAND_IS(static_cast(type), + static_cast(MuxDefines::GSM0710_CONTROL_NSC))) LOG_ERROR("The mobile station didn't support the command sent"); - else if(GSM0710Buffer::GSM0710_COMMAND_IS(static_cast(type),static_cast(MuxDefines ::GSM0710_CONTROL_MSC))) - { - LOG_INFO("Channel:%d FC:%d",(frame->data[i] & 252) >> 2,frame->data[0]&0x2); + else if (GSM0710Buffer::GSM0710_COMMAND_IS(static_cast(type), + static_cast(MuxDefines::GSM0710_CONTROL_MSC))) { + LOG_INFO("Channel:%d FC:%d", (frame->data[i] & 252) >> 2, frame->data[0] & 0x2); LOG_INFO("\n\nGET ACK FOR MSC\n\n"); //sleep(1); - } - else + } else LOG_INFO("Command acknowledged by the mobile station"); } } diff --git a/module-cellular/Modem/InputSerialWorker.hpp b/module-cellular/Modem/InputSerialWorker.hpp index ef9ea477b..6d1f4de91 100644 --- a/module-cellular/Modem/InputSerialWorker.hpp +++ b/module-cellular/Modem/InputSerialWorker.hpp @@ -23,19 +23,15 @@ void workerTaskFunction( void* ptr ); class InputSerialWorker { public: - friend void workerTaskFunction( void* ptr ); - InputSerialWorker(MuxDaemon* mux); - virtual ~InputSerialWorker(){} - - bool Init(); - bool Deinit(); - - // Pointer to muxDaemon which is owner of this worker - MuxDaemon* muxDaemon; + ~InputSerialWorker(); private: + friend void workerTaskFunction( void* ptr ); + + // Pointer to muxDaemon which is owner of this worker + MuxDaemon* muxDaemon; int ReadIncomingData(); int ExtractFrames(); diff --git a/module-cellular/Modem/MuxDaemon.cpp b/module-cellular/Modem/MuxDaemon.cpp index aeaf2b22f..500ad5b8d 100644 --- a/module-cellular/Modem/MuxDaemon.cpp +++ b/module-cellular/Modem/MuxDaemon.cpp @@ -80,7 +80,6 @@ namespace QuectelBaudrates { MuxDaemon::MuxDaemon() { cellular = bsp::Cellular::Create(); - inSerialDataWorker = std::make_unique(this); inputBuffer = std::make_unique(virtualPortsCount, frameSize, cmuxMode); } @@ -164,7 +163,7 @@ int MuxDaemon::Start() { state = States::MUX_STATE_MUXING; // Spawn input serial stream worker - inSerialDataWorker->Init(); + inSerialDataWorker = std::make_unique(this); // Create virtual channels @@ -187,7 +186,6 @@ int MuxDaemon::Start() { } int MuxDaemon::Exit() { - inSerialDataWorker->Deinit(); CloseMux(); return 0; } diff --git a/module-cellular/Modem/MuxDaemon.hpp b/module-cellular/Modem/MuxDaemon.hpp index 36a98c6d7..75af12602 100644 --- a/module-cellular/Modem/MuxDaemon.hpp +++ b/module-cellular/Modem/MuxDaemon.hpp @@ -24,11 +24,6 @@ class MuxDaemon { - friend InputSerialWorker; - friend MuxChannel; - - friend void workerTaskFunction(void *ptr); - public: MuxDaemon(); @@ -46,6 +41,12 @@ public: private: + friend InputSerialWorker; + friend MuxChannel; + + friend void workerTaskFunction(void *ptr); + + int SendAT(const char *cmd, uint32_t timeout); ssize_t WriteSerialCache(unsigned char *input, size_t length); diff --git a/module-services/service-cellular/ServiceCellular.cpp b/module-services/service-cellular/ServiceCellular.cpp index 0d6836fb7..bb68597fb 100644 --- a/module-services/service-cellular/ServiceCellular.cpp +++ b/module-services/service-cellular/ServiceCellular.cpp @@ -41,7 +41,7 @@ ServiceCellular::~ServiceCellular() { // Invoked when timer ticked void ServiceCellular::TickHandler(uint32_t id) { char* resp = "AT\r"; - muxdaemon->WriteMuxFrame(1, reinterpret_cast(resp),strlen(resp), static_cast(MuxDefines::GSM0710_TYPE_UIH)); + muxdaemon->WriteMuxFrame(2, reinterpret_cast(resp),strlen(resp), static_cast(MuxDefines::GSM0710_TYPE_UIH)); } // Invoked during initialization