From bbc95c654c138318cfe0d801fd1ef40560aa698a Mon Sep 17 00:00:00 2001 From: Mateusz Date: Wed, 3 Jul 2019 14:25:08 +0200 Subject: [PATCH] WiP: GSM cmux implementation bug hunting Preparation to cellular service --- module-cellular/Modem/CommunicationMuxChannel.cpp | 5 +++++ module-cellular/Modem/CommunicationMuxChannel.hpp | 2 ++ module-cellular/Modem/GSM0710.cpp | 4 ++-- module-cellular/Modem/InputSerialWorker.cpp | 2 +- module-cellular/Modem/MuxChannel.cpp | 2 +- module-cellular/Modem/MuxChannel.hpp | 15 +++++++++++---- source/main.cpp | 4 ++-- 7 files changed, 24 insertions(+), 10 deletions(-) diff --git a/module-cellular/Modem/CommunicationMuxChannel.cpp b/module-cellular/Modem/CommunicationMuxChannel.cpp index d8a97a5fe..4bd0c9b90 100644 --- a/module-cellular/Modem/CommunicationMuxChannel.cpp +++ b/module-cellular/Modem/CommunicationMuxChannel.cpp @@ -10,6 +10,7 @@ #include "CommunicationMuxChannel.hpp" +#include "MuxDaemon.hpp" CommunicationMuxChannel::CommunicationMuxChannel(MuxDaemon* mux): @@ -24,4 +25,8 @@ CommunicationMuxChannel::~CommunicationMuxChannel() { int CommunicationMuxChannel::ParseInMessage(MuxChannel::MuxChannelMsg *msg) { LOG_FATAL((name + " received message: " + msg->m_data).c_str()); +} + +ssize_t CommunicationMuxChannel::SendCommand(const char *cmd, uint32_t timeout) { + //mux->WritesiMuxFrame(GetChannelNumber(), cmd,strlen(cmd), static_cast(MuxDefines::GSM0710_TYPE_UIH)); } \ No newline at end of file diff --git a/module-cellular/Modem/CommunicationMuxChannel.hpp b/module-cellular/Modem/CommunicationMuxChannel.hpp index d38137937..2cb111d11 100644 --- a/module-cellular/Modem/CommunicationMuxChannel.hpp +++ b/module-cellular/Modem/CommunicationMuxChannel.hpp @@ -23,6 +23,8 @@ public: int ParseInMessage(MuxChannelMsg* msg) override final; + + ssize_t SendCommand(const char* cmd,uint32_t timeout = 1000); }; diff --git a/module-cellular/Modem/GSM0710.cpp b/module-cellular/Modem/GSM0710.cpp index b7a2d1bc2..04a5d2085 100644 --- a/module-cellular/Modem/GSM0710.cpp +++ b/module-cellular/Modem/GSM0710.cpp @@ -86,8 +86,8 @@ GSM0710Frame* GSM0710Buffer::GetCompleteFrame(GSM0710Frame* frame) { //caused if we would expect a long frame because of an //error in length field. volatile uint32_t err =0; - //Inc(); - currentFrame->length += 1; + Inc(); + currentFrame->length += (*readp*128); /*Frame header 2nd length-byte read*/ fcs = crcTable[fcs ^ *readp]; } diff --git a/module-cellular/Modem/InputSerialWorker.cpp b/module-cellular/Modem/InputSerialWorker.cpp index 0b6d23793..f26163782 100644 --- a/module-cellular/Modem/InputSerialWorker.cpp +++ b/module-cellular/Modem/InputSerialWorker.cpp @@ -140,7 +140,7 @@ int InputSerialWorker::ExtractFrames() { MuxChannel::State::Opened) {//reopening, discard the data // Send received message to virtual channel for further processing - write_result = muxDaemon->channels[frame->channel].Send(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; diff --git a/module-cellular/Modem/MuxChannel.cpp b/module-cellular/Modem/MuxChannel.cpp index c37802333..7e62c677d 100644 --- a/module-cellular/Modem/MuxChannel.cpp +++ b/module-cellular/Modem/MuxChannel.cpp @@ -97,7 +97,7 @@ int MuxChannel::Close() { } -int MuxChannel::Send(uint8_t *data, size_t size) { +int MuxChannel::DistributeMsg(uint8_t *data, size_t size) { MuxChannelMsg *msg = new MuxChannelMsg(data, size); xQueueSend(workerQueueHandle, &msg, 500); diff --git a/module-cellular/Modem/MuxChannel.hpp b/module-cellular/Modem/MuxChannel.hpp index 0dc92608d..34ad22e90 100644 --- a/module-cellular/Modem/MuxChannel.hpp +++ b/module-cellular/Modem/MuxChannel.hpp @@ -25,8 +25,6 @@ class MuxDaemon; class MuxChannel { - friend void MuxChannelWorker(void* pvp); - public: enum class State{ @@ -58,10 +56,14 @@ public: MuxChannel(MuxDaemon* mux,uint32_t logicalNumber,MuxChannelType type,const char* name="Default",uint32_t stackSize=1024,uint32_t queueSize=4); virtual ~MuxChannel(); + // Open mux channel int Open(); + // Close mux channel int Close(); - int Send(uint8_t* data, size_t size); - virtual int ParseInMessage(MuxChannelMsg* msg); + // Send message to specific mux channel thread + int DistributeMsg(uint8_t* data, size_t size); + virtual ssize_t SendCommand(const char* cmd,uint32_t timeout = 1000){} + std::string& GetName(){ return name; @@ -84,6 +86,9 @@ public: int disc_ua_pending; private: + + friend void MuxChannelWorker(void* pvp); + uint32_t workerQueueSize; uint32_t workerStackSize; // in bytes @@ -95,6 +100,8 @@ private: MuxChannelType type; protected: + virtual int ParseInMessage(MuxChannelMsg* msg); + std::string name; MuxDaemon* mux; diff --git a/source/main.cpp b/source/main.cpp index bef1646e3..be1fae968 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -84,8 +84,8 @@ public: //sys::Bus::SendUnicast(msg,"Blinky",this); LOG_DEBUG("Blinky service tick!"); - char* resp = "AT\r"; - //muxdaemon->WriteMuxFrame(1, reinterpret_cast(resp),strlen(resp), static_cast(MuxDefines::GSM0710_TYPE_UIH)); + char* resp = "ATI\r"; + muxdaemon->WriteMuxFrame(1, reinterpret_cast(resp),strlen(resp), static_cast(MuxDefines::GSM0710_TYPE_UIH)); } // Invoked during initialization