Browse Source

cmSerialPort.h/c : Added cmSeSetCallback() and cmSeStart().

master
kevin.larke 4 years ago
parent
commit
08ae2446b2
2 changed files with 28 additions and 8 deletions
  1. 23
    6
      cmSerialPort.c
  2. 5
    2
      cmSerialPort.h

+ 23
- 6
cmSerialPort.c View File

282
     goto errLabel;
282
     goto errLabel;
283
   }
283
   }
284
 
284
 
285
-  if( cmThreadPause(p->_thH,0) != kOkThRC )
286
-  {
287
-    rc = cmErrMsg(&p->_err,kThreadErrSeRC,0,"Thread start failed.");
288
-    goto errLabel;
289
-  }
290
-  
291
   if( hp != NULL )
285
   if( hp != NULL )
292
     hp->h = p;
286
     hp->h = p;
293
   else
287
   else
321
   return rc;
315
   return rc;
322
 }
316
 }
323
 
317
 
318
+cmSeRC_t  cmSeSetCallback( cmSeH_t h, cmSeCallbackFunc_t cbFunc, void* cbArg  )
319
+{
320
+  cmSerialPort_t* p = _cmSePtrFromHandle(h);
321
+  p->_cbFunc  = cbFunc;
322
+  p->_cbArg   = cbArg;
323
+  return kOkSeRC;
324
+}
325
+
326
+cmSeRC_t  cmSeStart( cmSeH_t h )
327
+{
328
+  cmSerialPort_t* p = _cmSePtrFromHandle(h);
329
+  
330
+  if( cmThreadPause(p->_thH,0) != kOkThRC )
331
+    return cmErrMsg(&p->_err,kThreadErrSeRC,0,"Thread start failed.");
332
+  
333
+  return kOkSeRC;
334
+}
335
+
336
+
337
+
324
 bool cmSeIsOpen( cmSeH_t h)
338
 bool cmSeIsOpen( cmSeH_t h)
325
 {
339
 {
326
   if( h.h == NULL )
340
   if( h.h == NULL )
542
   
556
   
543
   h = cmSeCreate(ctx,&h,device,baud,serialCfgFlags,_cmSePortTestCb,NULL,pollPeriodMs);
557
   h = cmSeCreate(ctx,&h,device,baud,serialCfgFlags,_cmSePortTestCb,NULL,pollPeriodMs);
544
 
558
 
559
+  if( cmSeIsOpen(h) )
560
+    cmSeStart(h);
561
+
545
   bool quitFl = false;
562
   bool quitFl = false;
546
   printf("q=quit\n");
563
   printf("q=quit\n");
547
   while(!quitFl)
564
   while(!quitFl)

+ 5
- 2
cmSerialPort.h View File

48
 
48
 
49
   typedef cmHandle_t cmSeH_t;
49
   typedef cmHandle_t cmSeH_t;
50
     
50
     
51
-  cmSeH_t cmSeCreate( cmCtx_t* ctx, cmSeH_t* hp, const char* device, unsigned baudRate, unsigned cfgFlags, cmSeCallbackFunc_t cbFunc, void* cbArg, unsigned pollPeriodMs );
52
-  cmSeRC_t    cmSeDestroy(cmSeH_t* hp );
51
+  cmSeH_t   cmSeCreate( cmCtx_t* ctx, cmSeH_t* hp, const char* device, unsigned baudRate, unsigned cfgFlags, cmSeCallbackFunc_t cbFunc, void* cbArg, unsigned pollPeriodMs );
52
+  cmSeRC_t  cmSeDestroy(cmSeH_t* hp );
53
+
54
+  cmSeRC_t  cmSeSetCallback( cmSeH_t h, cmSeCallbackFunc_t cbFunc, void* cbArg  );
55
+  cmSeRC_t  cmSeStart( cmSeH_t h );
53
 
56
 
54
   bool cmSeIsOpen( cmSeH_t h);
57
   bool cmSeIsOpen( cmSeH_t h);
55
     
58
     

Loading…
Cancel
Save