cc
Diff: SPWFSA01.cpp
- Revision:
- 25:6b79352bc1fa
- Parent:
- 24:419285201dba
- Child:
- 26:70852d26853e
--- a/SPWFSA01.cpp Tue Nov 22 14:36:25 2016 +0000 +++ b/SPWFSA01.cpp Mon Jan 02 14:46:40 2017 +0000 @@ -250,13 +250,13 @@ Timer timer; timer.start(); socket_closed = 0; - + if(!_parser.send("AT+S.SOCKON=%s,%d,%s,ind", addr, port, type)) { debug_if(dbg_on, "SPWF> error opening socket\r\n"); return false; } - + while(1) { if( _parser.recv(" ID: %d", id) @@ -272,7 +272,6 @@ //TODO: deal with errors like "ERROR: Failed to resolve name" //TODO: deal with errors like "ERROR: Data mode not available" } - return true; } @@ -393,3 +392,102 @@ { return _serial.writeable(); } + +int32_t SPWFSA01::settime(time_t ctTime) +{ + _parser.flush(); + //May take a second try if device is busy or error is returned + for (unsigned i = 0; i < 2; i++) { + if (_parser.send("AT+S.SETTIME=%d", ctTime) + && _parser.recv("OK")) { + return true; + } + else + { + debug_if(dbg_on, "SPWF> ERROR!!!!\r\n"); + return false; + } + } + return false; +} + +int32_t SPWFSA01::setTLScertificate(char * cert, unsigned int size, CertType_t type) +{ + _parser.flush(); + const char * cert_type="ca"; + switch (type) { + case RAM_CA_ROOT_CERT: + printf ("RAM_CA_ROOT_CERT\n\r"); + cert_type="ca"; + break; + case RAM_CLIENT_CERT: + cert_type="cert"; + break; + case RAM_CLIENT_PRIV_KEY: + cert_type="key"; + break; + case FLASH_CA_ROOT_CERT: + cert_type="f_ca"; + break; + case FLASH_CLIENT_CERT: + cert_type="f_cert"; + break; + case FLASH_CLIENT_PRIV_KEY: + cert_type="f_key"; + break; + default: + printf ("Error Unknown certificate type\n\r"); + return false; + } + + //May take a second try if device is busy or error is returned + for (unsigned i = 0; i < 2; i++) { + if (_parser.send("AT+S.TLSCERT=%s,%d\r%s", cert_type, size, cert) + && _parser.recv("OK")) { +// printf ("SET CERT cert_type %s, cert: %s\n\r", cert_type, cert); + return true; + } + else + { + printf ("SET CERT ERROR cert_type %s, cert: %s\n\r", cert_type, cert); + debug_if(dbg_on, "SPWF> ERROR!!!!\r\n"); + return false; + } + } + return false; + +} + +int32_t SPWFSA01::setTLSSRVdomain(char * domain, CertType_t type) +{ + if (type == FLASH_DOMAIN) + { + if (_parser.send("AT+S.TLSDOMAIN=f_domain,%s", domain)) { +// printf ("domain set %s\n\r", domain); + return true; + } else { + printf ("ERROR domain not set \n\r"); + return false; + } + + } else { + return false; + } +} + +int32_t SPWFSA01::cleanTLScertificate(CertType_t type) +{ + if (type == ALL) + { + if (_parser.send("AT+S.TLSCERT2=all")) { + return true; + } else { + printf ("ERROR cleaned \n\r"); + return false; + } + + } else { + return false; + } + +} \ No newline at end of file