Skip to content

Commit

Permalink
esp32 speed enhancements that half-work, and flow control enhancement…
Browse files Browse the repository at this point in the history
…s i can't test.

git-svn-id: svn://192.168.1.10/public/Zimodem@16962 0d6f1817-ed0e-0410-87c9-987e46238f29
  • Loading branch information
bozimmerman committed Jul 30, 2018
1 parent 78b29d1 commit 32d3bd7
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 60 deletions.
17 changes: 17 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ size_t availableForWrite();

** Both versions of the firmware are built with SPIFFS enabled.

* NOTES*
True RS232 25 pin connector
PIN Name Desc
1 Ground
2 Tx Computer->Modem
3 Rx Modem->Computer
4 RTS Computer->Modem (RTS is a Modem INPUT, Computer OUTPUT)
5 CTS Modem->Computer (CTS is a Modem OUTPUT, Computer INPUT)
6 DSR Modem->Computer
7 Ground
8 DCD Modem->Computer
20 DTR Computer->Modem
22 R.I. Modem->Computer

In my source code, RTS and CTS are reverse named. I'm aware of this. I'll fix it eventually.

Using:
------
Upon initialization, or any time the ESP module is reset, the modem will display its version, and some information about the host hardware, and then read a configuration file from the internal SPIFFS to re-establish the previously set baud rate, and to attempt to re-connect to the previously connected wireless router. The first time it is run, the firmware will set a baud rate of 1200 and display INITALIZED to let you know that no previous wifi configuration was found. Once the serial terminal displays READY, it is ready to receive commands.
Expand Down Expand Up @@ -198,6 +214,7 @@ ATS55=n : Changes DTR pin number, n=12 is default (N/A on ESP01)
ATS56=n : Changes DSR status. n=0 is default DSR=HIGH=active. n=1 is RTS=LOW=active. n=2 always HIGH. n=3 always LOW. (N/A on ESP01)
ATS57=n : Changes DSR pin number, n=13 is default (N/A on ESP01)
ATS60=n : When n > 0, immediately saves existing listeners and automatically restores them later. n=0 to clear.

+++ : With a 1 second pause with no other characters afterwards, this will disconnect the current opened connection.

ATT"[MESSAGE]" : Transmit the given text string, with \r\n at the end, on the current connection.
Expand Down
33 changes: 31 additions & 2 deletions zimodem/serout.ino
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ static int serialOutBufferBytesRemaining()

static void enqueSerialOut(uint8_t c)
{
debugPrintf("q\n");
TBUF[TBUFtail] = c;
TBUFtail++;
if(TBUFtail >= SER_WRITE_BUFSIZE)
Expand Down Expand Up @@ -116,8 +115,38 @@ void ZSerial::setFlowControlType(FlowControlType type)
#ifdef ZIMODEM_ESP32
if(flowControlType == FCT_RTSCTS)
{
uart_set_hw_flow_ctrl(UART_NUM_2,UART_HW_FLOWCTRL_DISABLE,0);
uint32_t invertMask = 0;
if(pinSupport[pinCTS])
{
uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, pinCTS, /*cts_io_num*/UART_PIN_NO_CHANGE);
// cts is input to me, output to true RS232
if(ctsActive == 0)
invertMask = invertMask | UART_INVERSE_RTS;
}
if(pinSupport[pinRTS])
{
uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, /*rts_io_num*/UART_PIN_NO_CHANGE, pinRTS);
s_pinWrite(pinRTS, rtsActive);
// rts is output to me, input to true RS232
if(rtsActive == 0)
invertMask = invertMask | UART_INVERSE_CTS;
}
uart_set_line_inverse(UART_NUM_2, invertMask);

debugPrintf("invert=%d\n",invertMask); //BZ:DELME

//uart_set_hw_flow_ctrl(UART_NUM_2,UART_HW_FLOWCTRL_DISABLE,0);
uart_set_hw_flow_ctrl(UART_NUM_2,UART_HW_FLOWCTRL_CTS_RTS,SER_BUFSIZE);
if(pinSupport[pinRTS])
{
if(pinSupport[pinCTS])
uart_set_hw_flow_ctrl(UART_NUM_2,UART_HW_FLOWCTRL_CTS_RTS,SER_BUFSIZE);
else
uart_set_hw_flow_ctrl(UART_NUM_2,UART_HW_FLOWCTRL_RTS,SER_BUFSIZE);
}
else
if(pinSupport[pinCTS])
uart_set_hw_flow_ctrl(UART_NUM_2,UART_HW_FLOWCTRL_RTS,SER_BUFSIZE);
}
else
uart_set_hw_flow_ctrl(UART_NUM_2,UART_HW_FLOWCTRL_DISABLE,0);
Expand Down
12 changes: 4 additions & 8 deletions zimodem/wificlientnode.ino
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ int WiFiClientNode::flushOverflowBuffer()
if(bufWrite >= overflowBufLen)
{
overflowBufLen = 0;
if(pinSupport[pinRTS])
digitalWrite(pinRTS,rtsActive);
s_pinWrite(pinRTS,rtsActive);
// fall-through
}
else
Expand All @@ -215,8 +214,7 @@ int WiFiClientNode::flushOverflowBuffer()
overflowBuf[i-bufWrite]=overflowBuf[i];
overflowBufLen -= bufWrite;
}
if(pinSupport[pinRTS])
digitalWrite(pinRTS,rtsInactive);
s_pinWrite(pinRTS,rtsInactive);
return bufWrite;
}
}
Expand All @@ -229,8 +227,7 @@ size_t WiFiClientNode::write(const uint8_t *buf, size_t size)
{
if(overflowBufLen>0)
{
if(pinSupport[pinRTS])
digitalWrite(pinRTS,rtsActive);
s_pinWrite(pinRTS,rtsActive);
}
overflowBufLen=0;
return 0;
Expand All @@ -248,8 +245,7 @@ size_t WiFiClientNode::write(const uint8_t *buf, size_t size)
{
for(int i=written;i<size && overflowBufLen<OVERFLOW_BUF_SIZE;i++,overflowBufLen++)
overflowBuf[overflowBufLen]=buf[i];
if(pinSupport[pinRTS])
digitalWrite(pinRTS,rtsInactive);
s_pinWrite(pinRTS,rtsInactive);
}
return written;
}
Expand Down
80 changes: 36 additions & 44 deletions zimodem/zcommand.ino
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,10 @@ void ZCommand::setConfigDefaults()
pinMode(pinDSR,OUTPUT);
if(pinSupport[pinRI])
pinMode(pinRI,OUTPUT);
if(pinSupport[pinRTS])
digitalWrite(pinRTS,rtsActive);
if(pinSupport[pinDCD])
digitalWrite(pinDCD,dcdStatus);
if(pinSupport[pinDSR])
digitalWrite(pinDSR,dsrActive);
if(pinSupport[pinRI])
digitalWrite(pinRI,riInactive);
s_pinWrite(pinRTS,rtsActive);
s_pinWrite(pinDCD,dcdStatus);
s_pinWrite(pinDSR,dsrActive);
s_pinWrite(pinRI,riInactive);
suppressResponses=false;
numericResponses=false;
longResponses=true;
Expand Down Expand Up @@ -333,8 +329,7 @@ void ZCommand::setOptionsFromSavedConfig(String configArguments[])
pinMode(pinDCD,OUTPUT);
dcdStatus=dcdInactive;
}
if(pinSupport[pinDCD])
digitalWrite(pinDCD,dcdStatus);
s_pinWrite(pinDCD,dcdStatus);
if(configArguments[CFG_CTSPIN].length()>0)
{
pinCTS = atoi(configArguments[CFG_CTSPIN].c_str());
Expand All @@ -347,22 +342,17 @@ void ZCommand::setOptionsFromSavedConfig(String configArguments[])
if(pinSupport[pinRTS])
pinMode(pinRTS,OUTPUT);
}
if(pinSupport[pinRTS])
digitalWrite(pinRTS,rtsActive);
s_pinWrite(pinRTS,rtsActive);
#ifdef ZIMODEM_ESP32
if(pinSupport[pinCTS])
uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, pinCTS, /*cts_io_num*/UART_PIN_NO_CHANGE);
if(pinSupport[pinRTS])
uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, /*rts_io_num*/UART_PIN_NO_CHANGE, pinRTS);
serial.setFlowControlType(serial.getFlowControlType());
#endif
if(configArguments[CFG_RIPIN].length()>0)
{
pinRI = atoi(configArguments[CFG_RIPIN].c_str());
if(pinSupport[pinRI])
pinMode(pinRI,OUTPUT);
}
if(pinSupport[pinRI])
digitalWrite(pinRI,riInactive);
s_pinWrite(pinRI,riInactive);
if(configArguments[CFG_DTRPIN].length()>0)
{
pinDTR = atoi(configArguments[CFG_DTRPIN].c_str());
Expand All @@ -375,8 +365,7 @@ void ZCommand::setOptionsFromSavedConfig(String configArguments[])
if(pinSupport[pinDSR])
pinMode(pinDSR,OUTPUT);
}
if(pinSupport[pinDSR])
digitalWrite(pinDSR,dsrActive);
s_pinWrite(pinDSR,dsrActive);
if(configArguments[CFG_S0_RINGS].length()>0)
ringCounter = atoi(configArguments[CFG_S0_RINGS].c_str());
if(configArguments[CFG_S41_STREAM].length()>0)
Expand Down Expand Up @@ -2153,16 +2142,15 @@ ZResult ZCommand::doSerialCommand()
pinModeDecoder(sval,&dcdActive,&dcdInactive,DEFAULT_DCD_HIGH,DEFAULT_DCD_LOW);
dcdStatus = wasActive?dcdActive:dcdInactive;
result=ZOK;
if(pinSupport[pinDCD])
digitalWrite(pinDCD,dcdStatus);
s_pinWrite(pinDCD,dcdStatus);
break;
}
case 47:
if((sval >= 0) && (sval <= MAX_PIN_NO) && pinSupport[sval])
{
pinDCD=sval;
pinMode(pinDCD,OUTPUT);
digitalWrite(pinDCD,dcdStatus);
s_pinWrite(pinDCD,dcdStatus);
result=ZOK;
}
else
Expand All @@ -2178,7 +2166,7 @@ ZResult ZCommand::doSerialCommand()
pinCTS=sval;
pinMode(pinCTS,INPUT);
#ifdef ZIMODEM_ESP32
uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, pinCTS, /*cts_io_num*/UART_PIN_NO_CHANGE);
serial.setFlowControlType(serial.getFlowControlType());
#endif
result=ZOK;
}
Expand All @@ -2188,35 +2176,45 @@ ZResult ZCommand::doSerialCommand()
case 50:
pinModeDecoder(sval,&rtsActive,&rtsInactive,DEFAULT_RTS_HIGH,DEFAULT_RTS_LOW);
if(pinSupport[pinRTS])
digitalWrite(pinRTS,rtsActive);
{
#ifdef ZIMODEM_ESP32
serial.setFlowControlType(serial.getFlowControlType());
#endif
s_pinWrite(pinRTS,rtsActive);
}
result=ZOK;
break;
case 51:
if((sval >= 0) && (sval <= MAX_PIN_NO) && pinSupport[sval])
{
pinRTS=sval;
pinMode(pinRTS,OUTPUT);
digitalWrite(pinRTS,rtsActive);
result=ZOK;
#ifdef ZIMODEM_ESP32
uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, /*rts_io_num*/UART_PIN_NO_CHANGE, pinRTS);
serial.setFlowControlType(serial.getFlowControlType());
#endif
s_pinWrite(pinRTS,rtsActive);
result=ZOK;
}
else
result=ZERROR;
break;
case 52:
pinModeDecoder(sval,&riActive,&riInactive,DEFAULT_RI_HIGH,DEFAULT_RI_LOW);
if(pinSupport[pinRI])
digitalWrite(pinRI,riInactive);
{
#ifdef ZIMODEM_ESP32
serial.setFlowControlType(serial.getFlowControlType());
#endif
s_pinWrite(pinRI,riInactive);
}
result=ZOK;
break;
case 53:
if((sval >= 0) && (sval <= MAX_PIN_NO) && pinSupport[sval])
{
pinRI=sval;
pinMode(pinRI,OUTPUT);
digitalWrite(pinRTS,riInactive);
s_pinWrite(pinRTS,riInactive);
result=ZOK;
}
else
Expand All @@ -2238,16 +2236,15 @@ ZResult ZCommand::doSerialCommand()
break;
case 56:
pinModeDecoder(sval,&dsrActive,&dsrInactive,DEFAULT_DSR_HIGH,DEFAULT_DSR_LOW);
if(pinSupport[pinDSR])
digitalWrite(pinDSR,dsrActive);
s_pinWrite(pinDSR,dsrActive);
result=ZOK;
break;
case 57:
if((sval >= 0) && (sval <= MAX_PIN_NO) && pinSupport[sval])
{
pinDSR=sval;
pinMode(pinDSR,OUTPUT);
digitalWrite(pinDSR,dsrActive);
s_pinWrite(pinDSR,dsrActive);
result=ZOK;
}
else
Expand Down Expand Up @@ -2525,7 +2522,7 @@ ZResult ZCommand::doSerialCommand()
result = ZERROR;
else
{
digitalWrite(pinNum,sval);
s_pinWrite(pinNum,sval);
serial.printf("Pin %d FORCED %s.%s",pinNum,(sval==LOW)?"LOW":(sval==HIGH)?"HIGH":"UNK",EOLN.c_str());
}
}
Expand Down Expand Up @@ -3034,8 +3031,7 @@ void ZCommand::acceptNewConnection()
WiFiClientNode *newClientNode = new WiFiClientNode(newClient, serv->flagsBitmap, futureRings * 2);
setCharArray(&(newClientNode->delimiters),serv->delimiters);
setCharArray(&(newClientNode->maskOuts),serv->maskOuts);
if(pinSupport[pinRI])
digitalWrite(pinRI,riActive);
s_pinWrite(pinRI,riActive);
serial.prints(numericResponses?"2":"RING");
serial.prints(EOLN);
lastServerClientId = newClientNode->id;
Expand Down Expand Up @@ -3069,8 +3065,7 @@ void ZCommand::acceptNewConnection()
int rings=conn->ringsRemaining(-1);
if(rings <= 0)
{
if(pinSupport[pinRI])
digitalWrite(pinRI,riInactive);
s_pinWrite(pinRI,riInactive);
if(ringCounter > 0)
{
serial.prints(numericResponses?"2":"RING");
Expand All @@ -3091,22 +3086,19 @@ void ZCommand::acceptNewConnection()
else
if((rings % 2) == 0)
{
if(pinSupport[pinRI])
digitalWrite(pinRI,riActive);
s_pinWrite(pinRI,riActive);
serial.prints(numericResponses?"2":"RING");
serial.prints(EOLN);
}
else
if(pinSupport[pinRI])
digitalWrite(pinRI,riInactive);
s_pinWrite(pinRI,riInactive);
}
}
conn = nextConn;
}
if(checkOpenConnections()==0)
{
if(pinSupport[pinRI])
digitalWrite(pinRI,riInactive);
s_pinWrite(pinRI,riInactive);
}
}

Expand Down
21 changes: 15 additions & 6 deletions zimodem/zimodem.ino
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ static void doNothing(const char* format, ...)
{
}

static void s_pinWrite(uint8_t pinNo, uint8_t value)
{
if(pinSupport[pinNo])
{
digitalWrite(pinNo, value);
if(pinNo == pinRTS)
debugPrintf("pinRTS=%d = %d\n",pinNo,value);
if(pinNo == pinCTS)
debugPrintf("pinCTS=%d = %d\n",pinNo,value);
}
}

static bool connectWifi(const char* ssid, const char* password)
{
if(WiFi.status() == WL_CONNECTED)
Expand Down Expand Up @@ -277,8 +289,7 @@ static int checkOpenConnections()
&&(dcdStatus != dcdInactive))
{
dcdStatus = dcdInactive;
if(pinSupport[pinDCD])
digitalWrite(pinDCD,dcdStatus);
s_pinWrite(pinDCD,dcdStatus);
if(baudState == BS_SWITCHED_TEMP)
baudState = BS_SWITCH_NORMAL_NEXT;
if(currMode == &commandMode)
Expand All @@ -291,8 +302,7 @@ static int checkOpenConnections()
&&(dcdStatus != dcdActive))
{
dcdStatus = dcdActive;
if(pinSupport[pinDCD])
digitalWrite(pinDCD,dcdStatus);
s_pinWrite(pinDCD,dcdStatus);
if((tempBaud > 0) && (baudState == BS_NORMAL))
baudState = BS_SWITCH_TEMP_NEXT;
}
Expand Down Expand Up @@ -339,8 +349,7 @@ void setup()
commandMode.loadConfig();
PhoneBookEntry::loadPhonebook();
dcdStatus = dcdInactive;
if(pinSupport[pinDCD])
digitalWrite(pinDCD,dcdStatus);
s_pinWrite(pinDCD,dcdStatus);
flushSerial();
}

Expand Down

0 comments on commit 32d3bd7

Please sign in to comment.