zabsalahid / serialport-gsm

SerialPort-GSM is a simplified plugin for communicating with gsm modems. (Primarily for sms) (Focused in PDU mode)
MIT License
90 stars 47 forks source link

Moving the command execution logic to caller function #13

Closed karianpour closed 5 years ago

karianpour commented 5 years ago

Here the idea is to have the response processing logic close to the caller function. In order to be coordinate the refactoring with you I refactored one function for sample. Please check and tell me if we can do it for the rest of the commands.

Please read the changes done in lines 715 and 899. The idea is to add a logic function after we run executeCommand (line 899) which returns the item added to execution queue. This function will be executed in line 715 on the dataReceived function. As we are attaching the logic function to the item in the queue, this type of checking modem.queue[0].command.substr(0, 3) == 'ATH' is not needed any more.

This way adding a new command is easier and also possible for the consumer out of the repo.

SMS sending and receiving is a bit different, I suggest to not refactor them at the moment.

Please tell me you opinion and if you agree I refactor the rest of the commands (except send / receive SMS).

Beside, I do not have a possibility to check all of the commands, do you have that opportunity to test all of them after I refactored?

karianpour commented 5 years ago

So, in the close future, I will refactor the commands that I can test at my system.