void udpBarcode_t :: onBarcode( void ) { unsigned len = strlen( getBarcode() ); // printf( "barcode <%s>, len %u\n", getBarcode(), len ); if( sick_e == scannerType_ ) { if( '\x03' == barcode_[--len] ) { barcode_[--len] = '\0' ; // trim symbology } } if( 0 != strcmp( "OK", barcode_ ) ) { unsigned long const now = tickMs(); if( ( 0 != strcmp( barcode_, prevBarcode_ ) ) || ( 1000 < now-prevTick_ ) ) { char data[sizeof(udpHeader_t)+sizeof(barcode_)]; udpHeader_t &header = *(udpHeader_t *)data ; header.type_ = header.barcode ; header.length_ = len + 1 ; // include trailing NULL strcpy( data+sizeof(header), getBarcode() ); unsigned numToSend = sizeof(udpHeader_t)+header.length_ ; int numSent = sendto( udpSock_, data, numToSend, 0, (struct sockaddr *)&remote_, sizeof( remote_ ) ); if( numSent != numToSend ) perror( "barcode sendto" ); strcpy( prevBarcode_, barcode_ ); prevTick_ = now ; if( ( 0 != beepData_ ) && ( 0 != beepBytes_ ) ) { ::write( audioFd_, beepData_, beepBytes_ ); } // play beep sound } else printf( "duplicate barcode %s ignored\n", barcode_ ); } if( keyence_e == scannerType_ ) ::write( fd_, "LON\r", 4 ); }
bool LCDbWorkEntry::createRecord( LQuery cQuery, const String & reason ) { cQuery.setSQL( "Insert into c_buddy_worklist" " (machine_cid, barcode, test_cid, group_id, category_id, sample_id, range_set," " min_value, max_value, project_cid, profile_id, profile_name, buddy_read," " time_stamp, in_date, trigger_id, lower_trigger_limit, upper_trigger_limit," " buddy_result_id, private_result, status, diluent)" " values ( :mid, :bar, :tid, :grp, :cat, :sid, :rs, :mnv, :mxv, :proj, :pfid," " :pnm, 'N', 'now', :ind, :trid, :ltl, :utl, :rid, :prv, 'Q', :dil)" ); cQuery.setParam( "bar", getBarcode() ); cQuery.setParam( "grp", getGroupID() ); cQuery.setParam( "cat", getCategoryID() ); cQuery.setParam( "pfid", getProfileID() ); cQuery.setParam( "pnm", reason ); cQuery.setParam( "dil", diluent ); cQuery.setParam( "ind", getInDate() ); cQuery.setParam( "rid", getResultID() ); std::pair< int, int > specimen = getSpecimen(); cQuery.setParam( "proj", specimen.first ); cQuery.setParam( "sid", specimen.second ); cQuery.setParam( "tid", limits.getID() ); cQuery.setParam( "mid", limits.getAnalyserID() ); std::pair< double, double > range = limits.getRange().asDoubles(); if( range.first == 0 && range.second == 0 ) cQuery.setParam( "rs", 'N' ); else cQuery.setParam( "rs", 'Y' ); cQuery.setParam( "mnv", range.first ); cQuery.setParam( "mxv", range.second ); range = limits.getTriggerLimits().asDoubles(); cQuery.setParam( "trid", limits.getTriggerProfile() ); cQuery.setParam( "ltl", range.first ); cQuery.setParam( "utl", range.second ); cQuery.setParam( "prv", limits.isPrivate() ? 'Y' : 'N' ); return cQuery.execSQL() == 1; // don't add to cache - Marty's RFPs add record_no and ts_sequence }
bool LBDbWorkEntry::updateRecord( LQuery cluster, LDbWorkEntry::Stage result ) { LBDbWorkEntry * cached = LBDbWorkList::records().find( *this ); TDateTime when = Now(); String update = "set status = :sts, time_stamp = :ts"; if( !isQC() && getCategoryID() != 0 ) update = update + ", category_id = " + getCategoryID(); if( resultID != 0 && resultID != duplicate ) update = update + ", duplicate = " + resultID; String condition = "test_id = :tid and duplicate = :did and barcode = :bar"; if( duplicate == 0 ) { int analyser = limits.getAnalyserID(); if( analyser == 0 ) condition += " and machine_cid in (" + listMachineIDs() + ")"; else condition += " and machine_cid = " + String( analyser ); } cluster.setSQL( "update buddy_worklist " + update + " where " + condition ); cluster.setParam( "bar", getBarcode() ); cluster.setParam( "did", duplicate ); cluster.setParam( "tid", limits.getID() ); cluster.setParam( "sts", makeStatus( result ) ); cluster.setParam( "ts", when ); if( cluster.execSQL() != 1 ) { return false; } setStage( result ); setTimeStamp( when ); if( resultID != 0 ) duplicate = resultID; if( cached != NULL ) *cached = *this; else LBDbWorkList::records().insert( *this ); return true; }
bool LBDbWorkEntry::createRecord( LQuery cluster, String reason ) { int machine = limits.getAnalyserID(); if( machine == 0 ) { // QCs should stay on the same analyser; others on cluster machine = LCDbAnalysers::getCurrentID(); const LCDbAnalyser * an = LCDbAnalysers::records().findByID( machine ); if( an != NULL && !isQC() ) { std::set< int > machineIDs = an -> getClusterIDs(); if( !machineIDs.empty() ) machine = *(machineIDs.begin()); } limits.setAnalyserID( machine ); } if( reason.IsEmpty() && getProfileID() != 0 ) { const LPDbProfiles & profiles = LPDbProfiles::records( getProjectID() ); const LPDbProfile * pp = profiles.findByID( getProfileID() ); if( pp != NULL ) reason = pp -> getName(); } setTimeStamp( Now() ); char fromCentral = LCDbWorkEntry::NEW_RECORD; switch( getStage() ) { case NEW_ENTRY: break; case RE_RUN: resultID = nextRerun --; break; case TRIGGERED: resultID = TRIGGER_ID; break; default: fromCentral = LCDbWorkEntry::COPIED; } cluster.setSQL( "Insert into buddy_worklist (machine_cid, barcode, duplicate, test_name, test_id," " sample_id, range_set, min_value, max_value, status, project_cid, profile_name," " buddy_read, in_date, time_stamp, lower_warning, upper_warning, trigger_id," " trigger_lower_limit, trigger_upper_limit, private_result, delete_status, category_id)" " values ( :mid, :bar, :dup, :tnm, :tid, :aid, :rs, :min, :max, :sts, :prj," " :prn, :brd, :ind, :dts, :wlo, :wup, :trd, :tlo, :tup, :prv, 0, :cat )" ); cluster.setParam( "mid", machine ); cluster.setParam( "bar", getBarcode() ); cluster.setParam( "dup", resultID ); std::pair< int, int > specimen = getSpecimen(); cluster.setParam( "prj", specimen.first ); cluster.setParam( "aid", specimen.second ); const LCDbTest & test = LCDbTests::records().get( limits.getID() ); cluster.setParam( "tid", test.getID() ); cluster.setParam( "tnm", test.getName() ); cluster.setParam( "prn", reason ); std::pair< double, double > range = limits.getRange().asDoubles(); cluster.setParam( "min", range.first ); cluster.setParam( "max", range.second ); cluster.setParam( "rs", (range.first == 0 && range.second == 0) ? 'N' : 'Y' ); cluster.setParam( "sts", makeStatus( getStage() ) ); cluster.setParam( "brd", fromCentral ); cluster.setParam( "ind", getInDate() ); cluster.setParam( "dts", getTimeStamp() ); cluster.setParam( "trd", limits.getTriggerProfile() ); if( limits.getTriggerProfile() == 0 ) { cluster.setParam( "tup", "0" ); cluster.setParam( "tlo", "0" ); } else { range = limits.getTriggerLimits().asDoubles(); cluster.setParam( "tlo", range.first ); cluster.setParam( "tup", range.second ); } range = limits.getWarnLevels().asDoubles(); cluster.setParam( "wlo", range.first ); cluster.setParam( "wup", range.second ); cluster.setParam( "prv", limits.isPrivate() ? 'Y' : 'N' ); cluster.setParam( "cat", getCategoryID() ); if( cluster.execSQL() != 1 ) { return false; } duplicate = resultID; LBDbWorkList::records().insert( *this ); return true; }