From 5cda838a9351e1082ce166a8e4f9b85ff48103df Mon Sep 17 00:00:00 2001 From: kpl Date: Mon, 23 Mar 2020 10:41:28 -0400 Subject: [PATCH] Added 'decls' include files to hold public declarations for audio,midi,serial,socket, and websock modules. Other minor changes to prepare for integration into cwIo. In cwMidi* replaced 'byte_t' with 'uint8_t'. In cwAudioDevice* removed redundant 'device' prefix from function names. --- Makefile | 27 ++++++++++++++---------- cwAudioBuf.h | 11 ++++++---- cwAudioBufDecls.h | 16 +++++++++++++++ cwAudioDevice.cpp | 36 ++++++++++++++++---------------- cwAudioDevice.h | 48 ++++++++++++------------------------------- cwAudioDeviceDecls.h | 36 ++++++++++++++++++++++++++++++++ cwAudioDeviceTest.cpp | 42 ++++++++++++++----------------------- cwMidi.cpp | 27 ++++++++++++------------ cwMidi.h | 44 +++++++++++---------------------------- cwMidiAlsa.cpp | 16 +++++++-------- cwMidiDecls.h | 29 ++++++++++++++++++++++++++ cwMidiPort.cpp | 22 ++++++++++---------- cwMidiPort.h | 9 ++++---- cwSerialPort.h | 27 ++---------------------- cwSerialPortDecls.h | 35 +++++++++++++++++++++++++++++++ cwSocket.h | 31 +--------------------------- cwSocketDecls.h | 42 +++++++++++++++++++++++++++++++++++++ cwWebSock.cpp | 13 ++++++------ cwWebSock.h | 19 ++--------------- cwWebSockDecls.h | 26 +++++++++++++++++++++++ 20 files changed, 315 insertions(+), 241 deletions(-) create mode 100644 cwAudioBufDecls.h create mode 100644 cwAudioDeviceDecls.h create mode 100644 cwMidiDecls.h create mode 100644 cwSerialPortDecls.h create mode 100644 cwSocketDecls.h create mode 100644 cwWebSockDecls.h diff --git a/Makefile b/Makefile index 3bb6ca4..3730250 100644 --- a/Makefile +++ b/Makefile @@ -14,26 +14,31 @@ SRC += cwThread.cpp cwMutex.cpp HDR += cwWebSock.h cwWebSockSvr.h cwLib.h SRC += cwWebSock.cpp cwWebSockSvr.cpp cwLib.cpp -HDR += cwSerialPort.h cwSerialPortSrv.h -SRC += cwSerialPort.cpp cwSerialPortSrv.cpp +HDR += cwUiDecls.h cwUi.h cwUiTest.h +SRC += cwUi.cpp cwUiTest.cpp -HDR += cwMidi.h cwMidiPort.h -SRC += cwMidi.cpp cwMidiPort.cpp cwMidiAlsa.cpp +HDR += cwSerialPortDecls.h cwSerialPort.h cwSerialPortSrv.h +SRC += cwSerialPort.cpp cwSerialPortSrv.cpp + +HDR += cwMidiDecls.h cwMidi.h cwMidiPort.h +SRC += cwMidi.cpp cwMidiPort.cpp cwMidiAlsa.cpp + +HDR += cwAudioBufDecls.h cwAudioBuf.h cwAudioDeviceDecls.h cwAudioDevice.h cwAudioDeviceAlsa.h +SRC += cwAudioBuf.cpp cwAudioDevice.cpp cwAudioDeviceAlsa.cpp cwAudioDeviceTest.cpp + +HDR += cwSocketDecls.h cwSocket.h +SRC += cwSocket.cpp + +HDR += cwIo.h cwIoTest.h +SRC += cwIo.cpp cwIoTest.cpp -HDR += cwAudioBuf.h cwAudioDevice.h cwAudioDeviceAlsa.h -SRC += cwAudioBuf.cpp cwAudioDevice.cpp cwAudioDeviceAlsa.cpp cwAudioDeviceTest.cpp HDR += cwTcpSocket.h cwTcpSocketSrv.h cwTcpSocketTest.h SRC += cwTcpSocket.cpp cwTcpSocketSrv.cpp cwTcpSocketTest.cpp -HDR += cwSocket.h -SRC += cwSocket.cpp - HDR += cwMdns.h cwEuCon.h cwDnsSd.h dns_sd/dns_sd.h dns_sd/dns_sd_print.h dns_sd/dns_sd_const.h dns_sd/fader.h dns_sd/rpt.h SRC += cwMdns.cpp cwEuCon.cpp cwDnsSd.cpp dns_sd/dns_sd.cpp dns_sd/dns_sd_print.cpp dns_sd/fader.cpp dns_sd/rpt.cpp -HDR += cwIo.h cwIoTest.h -SRC += cwIo.cpp cwIoTest.cpp # -ldl = dlopen,dlclose,dlsym LIBS = -lpthread -lwebsockets -lasound -ldl diff --git a/cwAudioBuf.h b/cwAudioBuf.h index 927a069..d9c4ba5 100644 --- a/cwAudioBuf.h +++ b/cwAudioBuf.h @@ -29,8 +29,10 @@ // out - outgoing samples are filled with a 1k sine tone //) -#ifndef cmApBuf_H -#define cmApBuf_H +#ifndef cwAudioBuf_H +#define cwAudioBuf_H + +#include "cwAudioBufDecls.h" namespace cw { @@ -113,7 +115,7 @@ namespace cw // Return the meter window period as set by initialize() unsigned meterMs(handle_t h); - // Set the meter update period. THis function limits the value to between 10 and 1000. + // Set the meter update period. This function limits the value to between 10 and 1000. void setMeterMs( handle_t h, unsigned meterMs ); // Returns the channel count set via setup(). @@ -211,7 +213,8 @@ namespace cw // 3) This function just returns audio information it does not // change any internal states. // 4) The timestamp pointers are optional. - void getIO( handle_t h, unsigned iDevIdx, sample_t* iBufArray[], unsigned iBufChCnt, time::spec_t* iTimeStampPtr, + void getIO( handle_t h, + unsigned iDevIdx, sample_t* iBufArray[], unsigned iBufChCnt, time::spec_t* iTimeStampPtr, unsigned oDevIdx, sample_t* oBufArray[], unsigned oBufChCnt, time::spec_t* oTimeStampPtr ); diff --git a/cwAudioBufDecls.h b/cwAudioBufDecls.h new file mode 100644 index 0000000..69674d6 --- /dev/null +++ b/cwAudioBufDecls.h @@ -0,0 +1,16 @@ +#ifndef cwAudioBufDecls_H +#define cwAudioBufDecls_H + +namespace cw +{ + namespace audio + { + namespace buf + { + + } + } +} + + +#endif diff --git a/cwAudioDevice.cpp b/cwAudioDevice.cpp index cbd2b7e..88e04ec 100644 --- a/cwAudioDevice.cpp +++ b/cwAudioDevice.cpp @@ -112,19 +112,19 @@ cw::rc_t cw::audio::device::registerDriver( handle_t h, driver_t* drv ) return kOkRC; } -unsigned cw::audio::device::deviceCount( handle_t h ) +unsigned cw::audio::device::count( handle_t h ) { device_t* p = _handleToPtr(h); return p->nextDrvIdx; } -unsigned cw::audio::device::deviceLabelToIndex( handle_t h, const char* label ) +unsigned cw::audio::device::labelToIndex( handle_t h, const char* label ) { - unsigned n = deviceCount(h); + unsigned n = count(h); unsigned i; for(i=0; i -c -b -f -i -o -t -p -h \n" "\n" "-r = sample rate\n" - "-a = first channel\n" - "-c = audio channels\n" "-b = count of buffers\n" "-f = count of samples per buffer\n" "-i = input device index\n" @@ -119,16 +113,10 @@ cw::rc_t cw::audio::device::test( int argc, const char** argv ) if( _cmApGetOpt(argc,argv,"-h",0,true) ) _cmApPrintUsage(); - - runFl = _cmApGetOpt(argc,argv,"-p",0,true)?false:true; + runFl = _cmApGetOpt(argc,argv,"-p",0,true) ? false : true; r.srate = _cmApGetOpt(argc,argv,"-r",44100); - //r.chIdx = _cmApGetOpt(argc,argv,"-a",0); - //r.chCnt = _cmApGetOpt(argc,argv,"-c",2); r.bufCnt = _cmApGetOpt(argc,argv,"-b",3); r.framesPerCycle = _cmApGetOpt(argc,argv,"-f",512); - //r.bufFrmCnt = (r.bufCnt*r.framesPerCycle); - //r.bufSmpCnt = (r.chCnt * r.bufFrmCnt); - //r.logCnt = 100; r.meterMs = 50; r.inDevIdx = _cmGlobalInDevIdx = _cmApGetOpt(argc,argv,"-i",0); @@ -161,9 +149,9 @@ cw::rc_t cw::audio::device::test( int argc, const char** argv ) } // report the current audio device configuration - for(i=0; i> 7; d1Ref = v & 0x7f; } -int cw::midi::toPbend( byte_t d0, byte_t d1 ) +int cw::midi::toPbend( uint8_t d0, uint8_t d1 ) { int v = to14Bits(d0,d1); return v - 8192; } -void cw::midi::splitPbend( int v, byte_t& d0Ref, byte_t& d1Ref ) +void cw::midi::splitPbend( int v, uint8_t& d0Ref, uint8_t& d1Ref ) { unsigned uv = v + 8192; split14Bits(uv,d0Ref,d1Ref); } //==================================================================================================== -const char* cw::midi::midiToSciPitch( byte_t pitch, char* label, unsigned labelCharCnt ) +const char* cw::midi::midiToSciPitch( uint8_t pitch, char* label, unsigned labelCharCnt ) { static char buf[ kMidiSciPitchCharCnt ]; @@ -214,7 +215,7 @@ const char* cw::midi::midiToSciPitch( byte_t pitch, char* label, unsigned la } -cw::midi::byte_t cw::midi::sciPitchToMidiPitch( char pitch, int acc, int octave ) +uint8_t cw::midi::sciPitchToMidiPitch( char pitch, int acc, int octave ) { int idx = -1; @@ -240,7 +241,7 @@ cw::midi::byte_t cw::midi::sciPitchToMidiPitch( char pitch, int acc, int octa } -cw::midi::byte_t cw::midi::sciPitchToMidi( const char* sciPitchStr ) +uint8_t cw::midi::sciPitchToMidi( const char* sciPitchStr ) { const char* cp = sciPitchStr; bool sharpFl = false; diff --git a/cwMidi.h b/cwMidi.h index b708654..98dc41a 100644 --- a/cwMidi.h +++ b/cwMidi.h @@ -77,8 +77,6 @@ namespace cw }; - typedef unsigned char byte_t; - typedef struct timespec timestamp_t; //=============================================================================================== // Utility Functions @@ -103,42 +101,24 @@ namespace cw template< typename T> bool isPedalDown( T s, T d0, T d1 ) { return ( cmMidiIsPedal(s,d0) && (d1)>=64 ); } template< typename T> bool isPedalUp( T s, T d0, T d1 ) { return ( cmMidiIsPedal(s,d0) && (d1)<64 ); } + - const char* statusToLabel( byte_t status ); - const char* metaStatusToLabel( byte_t metaStatus ); - const char* pedalLabel( byte_t d0 ); + const char* statusToLabel( uint8_t status ); + const char* metaStatusToLabel( uint8_t metaStatus ); + const char* pedalLabel( uint8_t d0 ); // Returns kInvalidMidiByte if status is not a valid status byte - byte_t statusToByteCount( byte_t status ); + uint8_t statusToByteCount( uint8_t status ); - unsigned to14Bits( byte_t d0, byte_t d1 ); - void split14Bits( unsigned v, byte_t& d0Ref, byte_t& d1Ref ); - int toPbend( byte_t d0, byte_t d1 ); - void splitPbend( int v, byte_t& d0Ref, byte_t& d1Ref ); + unsigned to14Bits( uint8_t d0, uint8_t d1 ); + void split14Bits( unsigned v, uint8_t& d0Ref, uint8_t& d1Ref ); + int toPbend( uint8_t d0, uint8_t d1 ); + void splitPbend( int v, uint8_t& d0Ref, uint8_t& d1Ref ); //=============================================================================================== // MIDI Communication data types // - typedef struct msg_str - { - //unsigned deltaUs; // time since last MIDI msg in microseconds - timestamp_t timeStamp; - byte_t status; // midi status byte - byte_t d0; // midi data byte 0 - byte_t d1; // midi data byte 1 - byte_t pad; - } msg_t; - - typedef struct packet_str - { - void* cbDataPtr; // application supplied reference value from mdParserCreate() - unsigned devIdx; // the device the msg originated from - unsigned portIdx; // the port index on the source device - msg_t* msgArray; // pointer to an array of 'msgCnt' mdMsg records or NULL if sysExMsg is non-NULL - byte_t* sysExMsg; // pointer to a sys-ex msg or NULL if msgArray is non-NULL (see note below) - unsigned msgCnt; // count of mdMsg records or sys-ex bytes - } packet_t; // Notes: If the sys-ex message can be contained in a single msg then // then the first msg byte is kSysExMdId and the last is kSysComEoxMdId. @@ -150,12 +130,12 @@ namespace cw // buffer is returned. If label[] is given the it // should have at least 5 (kMidiPitchCharCnt) char's (including the terminating zero). // If 'pitch' is outside of the range 0-127 then a blank string is returned. - const char* midiToSciPitch( byte_t pitch, char* label, unsigned labelCharCnt ); + const char* midiToSciPitch( uint8_t pitch, char* label, unsigned labelCharCnt ); // Convert a scientific pitch to MIDI pitch. acc == 1 == sharp, acc == -1 == flat. // The pitch character must be in the range 'A' to 'G'. Upper or lower case is valid. // Return kInvalidMidiPitch if the arguments are not valid. - byte_t sciPitchToMidiPitch( char pitch, int acc, int octave ); + uint8_t sciPitchToMidiPitch( char pitch, int acc, int octave ); // Scientific pitch string: [A-Ga-g][#b][#] where # may be -1 to 9. @@ -163,7 +143,7 @@ namespace cw // scientific pitch string. This function will convert C-1 to G9 to // valid MIDI pitch values 0 to 127. Scientific pitch strings outside // of this range will be returned as kInvalidMidiPitch. - byte_t sciPitchToMidi( const char* sciPitchStr ); + uint8_t sciPitchToMidi( const char* sciPitchStr ); } } diff --git a/cwMidiAlsa.cpp b/cwMidiAlsa.cpp index 7b0a18c..e9be04f 100644 --- a/cwMidiAlsa.cpp +++ b/cwMidiAlsa.cpp @@ -2,8 +2,8 @@ #include "cwLog.h" #include "cwCommonImpl.h" #include "cwMem.h" -#include "cwMidi.h" #include "cwTime.h" +#include "cwMidi.h" #include "cwTextBuf.h" #include "cwMidiPort.h" #include "cwThread.h" @@ -111,7 +111,7 @@ namespace cw } - void _cmMpSplit14Bits( unsigned v, byte_t* d0, byte_t* d1 ) + void _cmMpSplit14Bits( unsigned v, uint8_t* d0, uint8_t* d1 ) { *d0 = (v & 0x3f80) >> 7; *d1 = v & 0x7f; @@ -156,9 +156,9 @@ namespace cw unsigned microSecs1 = (ev->time.time.tv_sec * 1000000) + (ev->time.time.tv_nsec/1000); //unsigned deltaMicroSecs = p->prvTimeMicroSecs==0 ? 0 : microSecs1 - p->prvTimeMicroSecs; - byte_t d0 = 0xff; - byte_t d1 = 0xff; - byte_t status = 0; + uint8_t d0 = 0xff; + uint8_t d1 = 0xff; + uint8_t status = 0; switch(ev->type) { @@ -244,7 +244,7 @@ namespace cw if( status != 0 ) { - byte_t ch = ev->data.note.channel; + uint8_t ch = ev->data.note.channel; time::spec_t ts; ts.tv_sec = p->baseTimeStamp.tv_sec + ev->time.time.tv_sec; ts.tv_nsec = p->baseTimeStamp.tv_nsec + ev->time.time.tv_nsec; @@ -709,7 +709,7 @@ const char* cw::midi::device::portName( handle_t h, unsigned devIdx, unsign } -cw::rc_t cw::midi::device::send( handle_t h, unsigned devIdx, unsigned portIdx, byte_t status, byte_t d0, byte_t d1 ) +cw::rc_t cw::midi::device::send( handle_t h, unsigned devIdx, unsigned portIdx, uint8_t status, uint8_t d0, uint8_t d1 ) { rc_t rc = kOkRC; snd_seq_event_t ev; @@ -797,7 +797,7 @@ cw::rc_t cw::midi::device::send( handle_t h, unsigned devIdx, unsigned portIdx, return rc; } -cw::rc_t cw::midi::device::sendData( handle_t h, unsigned devIdx, unsigned portIdx, const byte_t* dataPtr, unsigned byteCnt ) +cw::rc_t cw::midi::device::sendData( handle_t h, unsigned devIdx, unsigned portIdx, const uint8_t* dataPtr, unsigned byteCnt ) { return cwLogError(kInvalidOpRC,"cmMpDeviceSendData() has not yet been implemented for ALSA."); } diff --git a/cwMidiDecls.h b/cwMidiDecls.h new file mode 100644 index 0000000..b606cf8 --- /dev/null +++ b/cwMidiDecls.h @@ -0,0 +1,29 @@ +#ifndef cwMidiDecls_H +#define cwMidiDecls_H + +namespace cw +{ + namespace midi + { + typedef struct msg_str + { + //unsigned deltaUs; // time since last MIDI msg in microseconds + time::spec_t timeStamp; + uint8_t status; // midi status byte + uint8_t d0; // midi data byte 0 + uint8_t d1; // midi data byte 1 + uint8_t pad; + } msg_t; + + typedef struct packet_str + { + void* cbDataPtr; // application supplied reference value from mdParserCreate() + unsigned devIdx; // the device the msg originated from + unsigned portIdx; // the port index on the source device + msg_t* msgArray; // pointer to an array of 'msgCnt' mdMsg records or NULL if sysExMsg is non-NULL + uint8_t* sysExMsg; // pointer to a sys-ex msg or NULL if msgArray is non-NULL (see note below) + unsigned msgCnt; // count of mdMsg records or sys-ex bytes + } packet_t; + } +} +#endif diff --git a/cwMidiPort.cpp b/cwMidiPort.cpp index 3349f38..24ca11a 100644 --- a/cwMidiPort.cpp +++ b/cwMidiPort.cpp @@ -2,8 +2,8 @@ #include "cwLog.h" #include "cwCommonImpl.h" #include "cwMem.h" -#include "cwMidi.h" #include "cwTime.h" +#include "cwMidi.h" #include "cwTextBuf.h" #include "cwMidiPort.h" @@ -43,11 +43,11 @@ namespace cw unsigned state; // parser state id unsigned errCnt; // accumlated error count - byte_t status; // running status - byte_t data0; // data byte 0 + uint8_t status; // running status + uint8_t data0; // data byte 0 unsigned dataCnt; // data byte cnt for current status unsigned dataIdx; // index (0 or 1) of next data byte - byte_t* buf; // output buffer + uint8_t* buf; // output buffer unsigned bufByteCnt; // output buffer byte cnt unsigned bufIdx; // next output buffer index unsigned msgCnt; // count of channel messages in the buffer @@ -95,7 +95,7 @@ namespace cw } - void _cmMpParserStoreChMsg( parser_t* p, const time::spec_t* timeStamp, byte_t d ) + void _cmMpParserStoreChMsg( parser_t* p, const time::spec_t* timeStamp, uint8_t d ) { // if there is not enough room left in the buffer then transmit // the current messages @@ -176,7 +176,7 @@ cw::rc_t cw::midi::parser::create( handle_t& hRef, unsigned devIdx, unsigned por //p->cbChain->cbDataPtr = cbDataPtr; //p->cbChain->linkPtr = NULL; p->cbChain = NULL; - p->buf = mem::allocZ( bufByteCnt ); + p->buf = mem::allocZ( bufByteCnt ); p->bufByteCnt = bufByteCnt; p->bufIdx = 0; p->msgCnt = 0; @@ -227,7 +227,7 @@ unsigned cw::midi::parser::errorCount( handle_t h ) } -void cw::midi::parser::parseMidiData( handle_t h, const time::spec_t* timeStamp, const byte_t* iBuf, unsigned iByteCnt ) +void cw::midi::parser::parseMidiData( handle_t h, const time::spec_t* timeStamp, const uint8_t* iBuf, unsigned iByteCnt ) { parser_t* p = _handleToPtr(h); @@ -235,8 +235,8 @@ void cw::midi::parser::parseMidiData( handle_t h, const time::spec_t* timeStamp, if( p == NULL ) return; - const byte_t* ip = iBuf; - const byte_t* ep = iBuf + iByteCnt; + const uint8_t* ip = iBuf; + const uint8_t* ep = iBuf + iByteCnt; for(; ip < ep; ++ip ) { @@ -354,11 +354,11 @@ void cw::midi::parser::parseMidiData( handle_t h, const time::spec_t* timeStamp, } -cw::rc_t cw::midi::parser::midiTriple( handle_t h, const time::spec_t* timeStamp, byte_t status, byte_t d0, byte_t d1 ) +cw::rc_t cw::midi::parser::midiTriple( handle_t h, const time::spec_t* timeStamp, uint8_t status, uint8_t d0, uint8_t d1 ) { rc_t rc = kOkRC; parser_t* p = _handleToPtr(h); - byte_t mb = 0xff; // a midi triple may never have a status of 0xff + uint8_t mb = 0xff; // a midi triple may never have a status of 0xff if( d0 == 0xff ) p->dataCnt = 0; diff --git a/cwMidiPort.h b/cwMidiPort.h index 13e5eb8..733bff4 100644 --- a/cwMidiPort.h +++ b/cwMidiPort.h @@ -1,6 +1,7 @@ #ifndef cwMidiPort_H #define cwMidiPort_H +#include "cwMidiDecls.h" namespace cw { @@ -37,13 +38,13 @@ namespace cw rc_t create( handle_t& hRef, unsigned devIdx, unsigned portIdx, cbFunc_t cbFunc, void* cbArg, unsigned bufByteCnt ); rc_t destroy( handle_t& hRef ); unsigned errorCount( handle_t h ); - void parseMidiData( handle_t h, const time::spec_t* timestamp, const byte_t* buf, unsigned bufByteCnt ); + void parseMidiData( handle_t h, const time::spec_t* timestamp, const uint8_t* buf, unsigned bufByteCnt ); // The following two functions are intended to be used togetther. // Use midiTriple() to insert pre-parsed msg's to the output buffer, // and then use transmit() to send the buffer via the parsers callback function. // Set the data bytes to 0xff if they are not used by the message. - rc_t midiTriple( handle_t h, const time::spec_t* timestamp, byte_t status, byte_t d0, byte_t d1 ); + rc_t midiTriple( handle_t h, const time::spec_t* timestamp, uint8_t status, uint8_t d0, uint8_t d1 ); rc_t transmit( handle_t h ); // Install/Remove additional callbacks. @@ -79,8 +80,8 @@ namespace cw unsigned portCount( handle_t h, unsigned devIdx, unsigned flags ); const char* portName( handle_t h, unsigned devIdx, unsigned flags, unsigned portIdx ); unsigned portNameToIndex( handle_t h, unsigned devIdx, unsigned flags, const char* portName ); - rc_t send( handle_t h, unsigned devIdx, unsigned portIdx, byte_t st, byte_t d0, byte_t d1 ); - rc_t sendData( handle_t h, unsigned devIdx, unsigned portIdx, const byte_t* dataPtr, unsigned byteCnt ); + rc_t send( handle_t h, unsigned devIdx, unsigned portIdx, uint8_t st, uint8_t d0, uint8_t d1 ); + rc_t sendData( handle_t h, unsigned devIdx, unsigned portIdx, const uint8_t* dataPtr, unsigned byteCnt ); // Set devIdx to -1 to assign the callback to all devices. // Set portIdx to -1 to assign the callback to all ports on the specified devices. diff --git a/cwSerialPort.h b/cwSerialPort.h index 0eed4bf..d67990d 100644 --- a/cwSerialPort.h +++ b/cwSerialPort.h @@ -1,35 +1,12 @@ #ifndef cwSerialPort_H #define cwSerialPort_H +#include "cwSerialPortDecls.h" + namespace cw { namespace serialPort { - enum - { - kDataBits5Fl = 0x0001, - kDataBits6Fl = 0x0002, - kDataBits7Fl = 0x0004, - kDataBits8Fl = 0x0008, - kDataBitsMask = 0x000f, - - k1StopBitFl = 0x0010, - k2StopBitFl = 0x0020, - - kEvenParityFl = 0x0040, - kOddParityFl = 0x0080, - kNoParityFl = 0x0000, - /* - kCTS_OutFlowCtlFl = 0x0100, - kRTS_InFlowCtlFl = 0x0200, - kDTR_InFlowCtlFl = 0x0400, - kDSR_OutFlowCtlFl = 0x0800, - kDCD_OutFlowCtlFl = 0x1000 - */ - - kDefaultCfgFlags = kDataBits8Fl | k1StopBitFl | kNoParityFl - }; - typedef handle handle_t; typedef void (*callbackFunc_t)( void* cbArg, unsigned userId, const void* byteA, unsigned byteN ); diff --git a/cwSerialPortDecls.h b/cwSerialPortDecls.h new file mode 100644 index 0000000..fce42f6 --- /dev/null +++ b/cwSerialPortDecls.h @@ -0,0 +1,35 @@ +#ifndef cwSerialPortDecls_H +#define cwSerialPortDecls_H + +namespace cw +{ + namespace serialPort + { + enum + { + kDataBits5Fl = 0x0001, + kDataBits6Fl = 0x0002, + kDataBits7Fl = 0x0004, + kDataBits8Fl = 0x0008, + kDataBitsMask = 0x000f, + + k1StopBitFl = 0x0010, + k2StopBitFl = 0x0020, + + kEvenParityFl = 0x0040, + kOddParityFl = 0x0080, + kNoParityFl = 0x0000, + /* + kCTS_OutFlowCtlFl = 0x0100, + kRTS_InFlowCtlFl = 0x0200, + kDTR_InFlowCtlFl = 0x0400, + kDSR_OutFlowCtlFl = 0x0800, + kDCD_OutFlowCtlFl = 0x1000 + */ + + kDefaultCfgFlags = kDataBits8Fl | k1StopBitFl | kNoParityFl + }; + } +} + +#endif diff --git a/cwSocket.h b/cwSocket.h index 2bbe92d..2e34d7a 100644 --- a/cwSocket.h +++ b/cwSocket.h @@ -1,47 +1,18 @@ #ifndef cwSocket_H #define cwSocket_H +#include "cwSocketDecls.h" namespace cw { namespace sock { typedef handle< struct mgr_str > handle_t; - typedef uint16_t portNumber_t; - - typedef enum - { - kReceiveCbId, - kConnectCbId, - kDisconnectCbId - } cbId_t; - - // userId is the id assigned to the receiving socket // connId is an automatically assigned id which represents the remote endpoint which is connected to 'userId'. typedef void (*callbackFunc_t)( void* cbArg, cbId_t cbId, unsigned userId, unsigned connId, const void* byteA, unsigned byteN, const struct sockaddr_in* srcAddr ); - enum - { - kNonBlockingFl = 0x000, // Create a non-blocking socket. - kBlockingFl = 0x001, // Create a blocking socket. - kTcpFl = 0x002, // Create a TCP socket rather than a UDP socket. - kBroadcastFl = 0x004, // - kReuseAddrFl = 0x008, // - kReusePortFl = 0x010, // - kMultiCastTtlFl = 0x020, // - kMultiCastLoopFl = 0x040, // - kListenFl = 0x080, // Use this socket to listen for incoming connections - kStreamFl = 0x100, // Connected stream (not Datagram) - }; - - enum - { - // port 0 is reserved by and is therefore a convenient invalid port number - kInvalidPortNumber = 0 - }; - rc_t createMgr( handle_t& hRef, unsigned recvBufByteN, unsigned maxSocketN ); rc_t destroyMgr( handle_t& hRef ); diff --git a/cwSocketDecls.h b/cwSocketDecls.h new file mode 100644 index 0000000..09f9c45 --- /dev/null +++ b/cwSocketDecls.h @@ -0,0 +1,42 @@ +#ifndef cwSocketDecls_H +#define cwSocketDecls_H + +namespace cw +{ + namespace sock + { + typedef uint16_t portNumber_t; + + typedef enum + { + kReceiveCbId, + kConnectCbId, + kDisconnectCbId + } cbId_t; + + + + enum + { + kNonBlockingFl = 0x000, // Create a non-blocking socket. + kBlockingFl = 0x001, // Create a blocking socket. + kTcpFl = 0x002, // Create a TCP socket rather than a UDP socket. + kBroadcastFl = 0x004, // + kReuseAddrFl = 0x008, // + kReusePortFl = 0x010, // + kMultiCastTtlFl = 0x020, // + kMultiCastLoopFl = 0x040, // + kListenFl = 0x080, // Use this socket to listen for incoming connections + kStreamFl = 0x100, // Connected stream (not Datagram) + }; + + enum + { + // port 0 is reserved by and is therefore a convenient invalid port number + kInvalidPortNumber = 0 + }; + + } +} + +#endif diff --git a/cwWebSock.cpp b/cwWebSock.cpp index 1d4da1e..0eaf5e9 100644 --- a/cwWebSock.cpp +++ b/cwWebSock.cpp @@ -25,19 +25,20 @@ namespace cw typedef struct websock_str { - cbFunc_t _cbFunc; - void* _cbArg; + cbFunc_t _cbFunc; // + void* _cbArg; // struct lws_context* _ctx = nullptr; // struct lws_protocols* _protocolA = nullptr; // Websocket internal protocol state array - unsigned _protocolN = 0; // Count of protocol records in _protocolA[]. - unsigned _nextSessionId = 0; // Next session id. - unsigned _connSessionN = 0; // Count of connected sessions. + unsigned _protocolN = 0; // Count of protocol records in _protocolA[]. + unsigned _nextSessionId = 0; // Next session id. + unsigned _connSessionN = 0; // Count of connected sessions. struct lws_http_mount* _mount = nullptr; // MpScNbQueue* _q; // Thread safe, non-blocking, protocol independent msg queue. } websock_t; - inline websock_t* _handleToPtr(handle_t h){ return handleToPtr(h); } + inline websock_t* _handleToPtr(handle_t h) + { return handleToPtr(h); } // Internal session record. diff --git a/cwWebSock.h b/cwWebSock.h index d664033..d179686 100644 --- a/cwWebSock.h +++ b/cwWebSock.h @@ -26,29 +26,14 @@ need to make the protocol state queue thread-safe. */ +#include "cwWebSockDecls.h" namespace cw { namespace websock { - typedef handle handle_t; - - typedef struct protocol_str - { - const char* label; // unique label identifying this protocol - unsigned id; // unique id identifying this protocol - unsigned rcvBufByteN; // larger rcv'd packages will be broken into multiple parts - unsigned xmtBufByteN; // larger xmt'd packages are broken into multiple parts - } protocol_t; - - typedef enum - { - kConnectTId, - kDisconnectTId, - kMessageTId - } msgTypeId_t; - + typedef handle handle_t; typedef void (*cbFunc_t)( void* cbArg, unsigned protocolId, unsigned connectionId, msgTypeId_t msg_type, const void* msg, unsigned byteN ); diff --git a/cwWebSockDecls.h b/cwWebSockDecls.h new file mode 100644 index 0000000..6fa5bef --- /dev/null +++ b/cwWebSockDecls.h @@ -0,0 +1,26 @@ +#ifndef cwWebSockDecls_H +#define cwWebSockDecls_H + +namespace cw +{ + namespace websock + { + typedef struct protocol_str + { + const char* label; // unique label identifying this protocol + unsigned id; // unique id identifying this protocol + unsigned rcvBufByteN; // larger rcv'd packages will be broken into multiple parts + unsigned xmtBufByteN; // larger xmt'd packages are broken into multiple parts + } protocol_t; + + typedef enum + { + kConnectTId, + kDisconnectTId, + kMessageTId + } msgTypeId_t; + + } +} + +#endif