Changeset 527763f in subsurface for core/configuredivecomputerthreads.cpp


Ignore:
Timestamp:
May 4, 2017, 10:50:15 AM (8 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
5a4e1a5
Parents:
4cbf64b
git-author:
Anton Lundin <glance@…> (04/27/17 11:35:02)
git-committer:
Dirk Hohndel <dirk@…> (05/04/17 10:50:15)
Message:

Start to read/write and present some OSTC4 settings

This is mostly copy-paste from the ostc3 case, but there are some minor
differences. Some minor things have different meaning, and there's a
slightly different command set, but I couldn't figure out a sane way of
joining them.

Signed-off-by: Anton Lundin <glance@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/configuredivecomputerthreads.cpp

    r4cbf64b r527763f  
    364364static dc_status_t read_ostc4_settings(dc_device_t *device, DeviceDetails *m_deviceDetails, dc_event_callback_t progress_cb, void *userdata)
    365365{
     366        // This code is really similar to the OSTC3 code, but there are minor
     367        // differences in what the data means, and how to communicate with the
     368        // device. If anyone can find a good way to harmonize the two, be my guest.
    366369        dc_status_t rc = DC_STATUS_SUCCESS;
    367370        dc_event_progress_t progress;
    368371        progress.current = 0;
    369         progress.maximum = 1;
     372        progress.maximum = 19;
    370373        unsigned char hardware[1];
    371374
    372375        EMIT_PROGRESS();
    373376
     377        //Read gas mixes
     378        gas gas1;
     379        gas gas2;
     380        gas gas3;
     381        gas gas4;
     382        gas gas5;
     383        unsigned char gasData[4] = { 0, 0, 0, 0 };
     384
     385        rc = hw_ostc3_device_config_read(device, OSTC3_GAS1, gasData, sizeof(gasData));
     386        if (rc != DC_STATUS_SUCCESS)
     387                return rc;
     388        gas1.oxygen = gasData[0];
     389        gas1.helium = gasData[1];
     390        gas1.type = gasData[2];
     391        gas1.depth = gasData[3];
     392        EMIT_PROGRESS();
     393
     394        rc = hw_ostc3_device_config_read(device, OSTC3_GAS2, gasData, sizeof(gasData));
     395        if (rc != DC_STATUS_SUCCESS)
     396                return rc;
     397        gas2.oxygen = gasData[0];
     398        gas2.helium = gasData[1];
     399        gas2.type = gasData[2];
     400        gas2.depth = gasData[3];
     401        EMIT_PROGRESS();
     402
     403        rc = hw_ostc3_device_config_read(device, OSTC3_GAS3, gasData, sizeof(gasData));
     404        if (rc != DC_STATUS_SUCCESS)
     405                return rc;
     406        gas3.oxygen = gasData[0];
     407        gas3.helium = gasData[1];
     408        gas3.type = gasData[2];
     409        gas3.depth = gasData[3];
     410        EMIT_PROGRESS();
     411
     412        rc = hw_ostc3_device_config_read(device, OSTC3_GAS4, gasData, sizeof(gasData));
     413        if (rc != DC_STATUS_SUCCESS)
     414                return rc;
     415        gas4.oxygen = gasData[0];
     416        gas4.helium = gasData[1];
     417        gas4.type = gasData[2];
     418        gas4.depth = gasData[3];
     419        EMIT_PROGRESS();
     420
     421        rc = hw_ostc3_device_config_read(device, OSTC3_GAS5, gasData, sizeof(gasData));
     422        if (rc != DC_STATUS_SUCCESS)
     423                return rc;
     424        gas5.oxygen = gasData[0];
     425        gas5.helium = gasData[1];
     426        gas5.type = gasData[2];
     427        gas5.depth = gasData[3];
     428        EMIT_PROGRESS();
     429
     430        m_deviceDetails->gas1 = gas1;
     431        m_deviceDetails->gas2 = gas2;
     432        m_deviceDetails->gas3 = gas3;
     433        m_deviceDetails->gas4 = gas4;
     434        m_deviceDetails->gas5 = gas5;
     435        EMIT_PROGRESS();
     436
     437        //Read Dil Values
     438        gas dil1;
     439        gas dil2;
     440        gas dil3;
     441        gas dil4;
     442        gas dil5;
     443        unsigned char dilData[4] = { 0, 0, 0, 0 };
     444
     445        rc = hw_ostc3_device_config_read(device, OSTC3_DIL1, dilData, sizeof(dilData));
     446        if (rc != DC_STATUS_SUCCESS)
     447                return rc;
     448        dil1.oxygen = dilData[0];
     449        dil1.helium = dilData[1];
     450        dil1.type = dilData[2];
     451        dil1.depth = dilData[3];
     452        EMIT_PROGRESS();
     453
     454        rc = hw_ostc3_device_config_read(device, OSTC3_DIL2, dilData, sizeof(dilData));
     455        if (rc != DC_STATUS_SUCCESS)
     456                return rc;
     457        dil2.oxygen = dilData[0];
     458        dil2.helium = dilData[1];
     459        dil2.type = dilData[2];
     460        dil2.depth = dilData[3];
     461        EMIT_PROGRESS();
     462
     463        rc = hw_ostc3_device_config_read(device, OSTC3_DIL3, dilData, sizeof(dilData));
     464        if (rc != DC_STATUS_SUCCESS)
     465                return rc;
     466        dil3.oxygen = dilData[0];
     467        dil3.helium = dilData[1];
     468        dil3.type = dilData[2];
     469        dil3.depth = dilData[3];
     470        EMIT_PROGRESS();
     471
     472        rc = hw_ostc3_device_config_read(device, OSTC3_DIL4, dilData, sizeof(dilData));
     473        if (rc != DC_STATUS_SUCCESS)
     474                return rc;
     475        dil4.oxygen = dilData[0];
     476        dil4.helium = dilData[1];
     477        dil4.type = dilData[2];
     478        dil4.depth = dilData[3];
     479        EMIT_PROGRESS();
     480
     481        rc = hw_ostc3_device_config_read(device, OSTC3_DIL5, dilData, sizeof(dilData));
     482        if (rc != DC_STATUS_SUCCESS)
     483                return rc;
     484        dil5.oxygen = dilData[0];
     485        dil5.helium = dilData[1];
     486        dil5.type = dilData[2];
     487        dil5.depth = dilData[3];
     488        EMIT_PROGRESS();
     489
     490        m_deviceDetails->dil1 = dil1;
     491        m_deviceDetails->dil2 = dil2;
     492        m_deviceDetails->dil3 = dil3;
     493        m_deviceDetails->dil4 = dil4;
     494        m_deviceDetails->dil5 = dil5;
     495
     496        //Read setpoint Values
     497        setpoint sp1;
     498        setpoint sp2;
     499        setpoint sp3;
     500        setpoint sp4;
     501        setpoint sp5;
     502        unsigned char spData[4] = { 0, 0, 0, 0};
     503
     504        rc = hw_ostc3_device_config_read(device, OSTC3_SP1, spData, sizeof(spData));
     505        if (rc != DC_STATUS_SUCCESS)
     506                return rc;
     507        sp1.sp = spData[0];
     508        sp1.depth = spData[1];
     509        EMIT_PROGRESS();
     510
     511        rc = hw_ostc3_device_config_read(device, OSTC3_SP2, spData, sizeof(spData));
     512        if (rc != DC_STATUS_SUCCESS)
     513                return rc;
     514        sp2.sp = spData[0];
     515        sp2.depth = spData[1];
     516        EMIT_PROGRESS();
     517
     518        rc = hw_ostc3_device_config_read(device, OSTC3_SP3, spData, sizeof(spData));
     519        if (rc != DC_STATUS_SUCCESS)
     520                return rc;
     521        sp3.sp = spData[0];
     522        sp3.depth = spData[1];
     523        EMIT_PROGRESS();
     524
     525        rc = hw_ostc3_device_config_read(device, OSTC3_SP4, spData, sizeof(spData));
     526        if (rc != DC_STATUS_SUCCESS)
     527                return rc;
     528        sp4.sp = spData[0];
     529        sp4.depth = spData[1];
     530        EMIT_PROGRESS();
     531
     532        rc = hw_ostc3_device_config_read(device, OSTC3_SP5, spData, sizeof(spData));
     533        if (rc != DC_STATUS_SUCCESS)
     534                return rc;
     535        sp5.sp = spData[0];
     536        sp5.depth = spData[1];
     537        EMIT_PROGRESS();
     538
     539        m_deviceDetails->sp1 = sp1;
     540        m_deviceDetails->sp2 = sp2;
     541        m_deviceDetails->sp3 = sp3;
     542        m_deviceDetails->sp4 = sp4;
     543        m_deviceDetails->sp5 = sp5;
     544
     545        //Read other settings
     546        unsigned char uData[4] = { 0 };
     547
     548#define READ_SETTING(_OSTC4_SETTING, _DEVICE_DETAIL)                                            \
     549        do {                                                                                    \
     550                rc = hw_ostc3_device_config_read(device, _OSTC4_SETTING, uData, sizeof(uData)); \
     551                if (rc != DC_STATUS_SUCCESS)                                                    \
     552                        return rc;                                                              \
     553                m_deviceDetails->_DEVICE_DETAIL = uData[0];                                     \
     554                EMIT_PROGRESS();                                                                \
     555        } while (0)
     556
     557#undef READ_SETTING
     558
     559        rc = hw_ostc3_device_config_read(device, OSTC3_PRESSURE_SENSOR_OFFSET, uData, sizeof(uData));
     560        if (rc != DC_STATUS_SUCCESS)
     561                return rc;
     562        // OSTC3 stores the pressureSensorOffset in two-complement
     563        m_deviceDetails->pressureSensorOffset = (signed char)uData[0];
     564        EMIT_PROGRESS();
     565
     566        rc = hw_ostc3_device_config_read(device, OSTC3_TEMP_SENSOR_OFFSET, uData, sizeof(uData));
     567        if (rc != DC_STATUS_SUCCESS)
     568                return rc;
     569        // OSTC3 stores the tempSensorOffset in two-complement
     570        m_deviceDetails->tempSensorOffset = (signed char)uData[0];
     571        EMIT_PROGRESS();
     572
     573        //read firmware settings
     574        unsigned char fData[64] = { 0 };
     575        rc = hw_ostc3_device_version(device, fData, sizeof(fData));
     576        if (rc != DC_STATUS_SUCCESS)
     577                return rc;
     578        int serial = fData[0] + (fData[1] << 8);
     579        m_deviceDetails->serialNo = QString::number(serial);
     580        unsigned char X, Y, Z, beta;
     581        unsigned int firmwareOnDevice = (fData[3] << 8) + fData[2];
     582        X = (firmwareOnDevice & 0xF800) >> 11;
     583        Y = (firmwareOnDevice & 0x07C0) >> 6;
     584        Z = (firmwareOnDevice & 0x003E) >> 1;
     585        beta = firmwareOnDevice & 0x0001;
     586        m_deviceDetails->firmwareVersion = QString("%1.%2.%3%4").arg(X).arg(Y).arg(Z).arg(beta?" beta":"");
     587        QByteArray ar((char *)fData + 4, 60);
     588        m_deviceDetails->customText = ar.trimmed();
     589        EMIT_PROGRESS();
     590
    374591        return rc;
    375592}
     
    377594static dc_status_t write_ostc4_settings(dc_device_t *device, DeviceDetails *m_deviceDetails, dc_event_callback_t progress_cb, void *userdata)
    378595{
     596        // This code is really similar to the OSTC3 code, but there are minor
     597        // differences in what the data means, and how to communicate with the
     598        // device. If anyone can find a good way to harmonize the two, be my guest.
    379599        dc_status_t rc = DC_STATUS_SUCCESS;
    380600        dc_event_progress_t progress;
    381601        progress.current = 0;
    382         progress.maximum = 1;
     602        progress.maximum = 18;
     603
     604        //write gas values
     605        unsigned char gas1Data[4] = {
     606                m_deviceDetails->gas1.oxygen,
     607                m_deviceDetails->gas1.helium,
     608                m_deviceDetails->gas1.type,
     609                m_deviceDetails->gas1.depth
     610        };
     611
     612        unsigned char gas2Data[4] = {
     613                m_deviceDetails->gas2.oxygen,
     614                m_deviceDetails->gas2.helium,
     615                m_deviceDetails->gas2.type,
     616                m_deviceDetails->gas2.depth
     617        };
     618
     619        unsigned char gas3Data[4] = {
     620                m_deviceDetails->gas3.oxygen,
     621                m_deviceDetails->gas3.helium,
     622                m_deviceDetails->gas3.type,
     623                m_deviceDetails->gas3.depth
     624        };
     625
     626        unsigned char gas4Data[4] = {
     627                m_deviceDetails->gas4.oxygen,
     628                m_deviceDetails->gas4.helium,
     629                m_deviceDetails->gas4.type,
     630                m_deviceDetails->gas4.depth
     631        };
     632
     633        unsigned char gas5Data[4] = {
     634                m_deviceDetails->gas5.oxygen,
     635                m_deviceDetails->gas5.helium,
     636                m_deviceDetails->gas5.type,
     637                m_deviceDetails->gas5.depth
     638        };
     639        //gas 1
     640        rc = hw_ostc3_device_config_write(device, OSTC3_GAS1, gas1Data, sizeof(gas1Data));
     641        if (rc != DC_STATUS_SUCCESS)
     642                return rc;
     643        EMIT_PROGRESS();
     644        //gas 2
     645        rc = hw_ostc3_device_config_write(device, OSTC3_GAS2, gas2Data, sizeof(gas2Data));
     646        if (rc != DC_STATUS_SUCCESS)
     647                return rc;
     648        EMIT_PROGRESS();
     649        //gas 3
     650        rc = hw_ostc3_device_config_write(device, OSTC3_GAS3, gas3Data, sizeof(gas3Data));
     651        if (rc != DC_STATUS_SUCCESS)
     652                return rc;
     653        EMIT_PROGRESS();
     654        //gas 4
     655        rc = hw_ostc3_device_config_write(device, OSTC3_GAS4, gas4Data, sizeof(gas4Data));
     656        if (rc != DC_STATUS_SUCCESS)
     657                return rc;
     658        EMIT_PROGRESS();
     659        //gas 5
     660        rc = hw_ostc3_device_config_write(device, OSTC3_GAS5, gas5Data, sizeof(gas5Data));
     661        if (rc != DC_STATUS_SUCCESS)
     662                return rc;
     663        EMIT_PROGRESS();
     664
     665        //write setpoint values
     666        unsigned char sp1Data[4] = {
     667                m_deviceDetails->sp1.sp,
     668                m_deviceDetails->sp1.depth
     669        };
     670
     671        unsigned char sp2Data[4] = {
     672                m_deviceDetails->sp2.sp,
     673                m_deviceDetails->sp2.depth
     674        };
     675
     676        unsigned char sp3Data[4] = {
     677                m_deviceDetails->sp3.sp,
     678                m_deviceDetails->sp3.depth
     679        };
     680
     681        unsigned char sp4Data[4] = {
     682                m_deviceDetails->sp4.sp,
     683                m_deviceDetails->sp4.depth
     684        };
     685
     686        unsigned char sp5Data[4] = {
     687                m_deviceDetails->sp5.sp,
     688                m_deviceDetails->sp5.depth
     689        };
     690
     691        //sp 1
     692        rc = hw_ostc3_device_config_write(device, OSTC3_SP1, sp1Data, sizeof(sp1Data));
     693        if (rc != DC_STATUS_SUCCESS)
     694                return rc;
     695        EMIT_PROGRESS();
     696        //sp 2
     697        rc = hw_ostc3_device_config_write(device, OSTC3_SP2, sp2Data, sizeof(sp2Data));
     698        if (rc != DC_STATUS_SUCCESS)
     699                return rc;
     700        EMIT_PROGRESS();
     701        //sp 3
     702        rc = hw_ostc3_device_config_write(device, OSTC3_SP3, sp3Data, sizeof(sp3Data));
     703        if (rc != DC_STATUS_SUCCESS)
     704                return rc;
     705        EMIT_PROGRESS();
     706        //sp 4
     707        rc = hw_ostc3_device_config_write(device, OSTC3_SP4, sp4Data, sizeof(sp4Data));
     708        if (rc != DC_STATUS_SUCCESS)
     709                return rc;
     710        EMIT_PROGRESS();
     711        //sp 5
     712        rc = hw_ostc3_device_config_write(device, OSTC3_SP5, sp5Data, sizeof(sp5Data));
     713        if (rc != DC_STATUS_SUCCESS)
     714                return rc;
     715        EMIT_PROGRESS();
     716
     717        //write dil values
     718        unsigned char dil1Data[4] = {
     719                m_deviceDetails->dil1.oxygen,
     720                m_deviceDetails->dil1.helium,
     721                m_deviceDetails->dil1.type,
     722                m_deviceDetails->dil1.depth
     723        };
     724
     725        unsigned char dil2Data[4] = {
     726                m_deviceDetails->dil2.oxygen,
     727                m_deviceDetails->dil2.helium,
     728                m_deviceDetails->dil2.type,
     729                m_deviceDetails->dil2.depth
     730        };
     731
     732        unsigned char dil3Data[4] = {
     733                m_deviceDetails->dil3.oxygen,
     734                m_deviceDetails->dil3.helium,
     735                m_deviceDetails->dil3.type,
     736                m_deviceDetails->dil3.depth
     737        };
     738
     739        unsigned char dil4Data[4] = {
     740                m_deviceDetails->dil4.oxygen,
     741                m_deviceDetails->dil4.helium,
     742                m_deviceDetails->dil4.type,
     743                m_deviceDetails->dil4.depth
     744        };
     745
     746        unsigned char dil5Data[4] = {
     747                m_deviceDetails->dil5.oxygen,
     748                m_deviceDetails->dil5.helium,
     749                m_deviceDetails->dil5.type,
     750                m_deviceDetails->dil5.depth
     751        };
     752        //dil 1
     753        rc = hw_ostc3_device_config_write(device, OSTC3_DIL1, dil1Data, sizeof(gas1Data));
     754        if (rc != DC_STATUS_SUCCESS)
     755                return rc;
     756        EMIT_PROGRESS();
     757        //dil 2
     758        rc = hw_ostc3_device_config_write(device, OSTC3_DIL2, dil2Data, sizeof(dil2Data));
     759        if (rc != DC_STATUS_SUCCESS)
     760                return rc;
     761        EMIT_PROGRESS();
     762        //dil 3
     763        rc = hw_ostc3_device_config_write(device, OSTC3_DIL3, dil3Data, sizeof(dil3Data));
     764        if (rc != DC_STATUS_SUCCESS)
     765                return rc;
     766        EMIT_PROGRESS();
     767        //dil 4
     768        rc = hw_ostc3_device_config_write(device, OSTC3_DIL4, dil4Data, sizeof(dil4Data));
     769        if (rc != DC_STATUS_SUCCESS)
     770                return rc;
     771        EMIT_PROGRESS();
     772        //dil 5
     773        rc = hw_ostc3_device_config_write(device, OSTC3_DIL5, dil5Data, sizeof(dil5Data));
     774        if (rc != DC_STATUS_SUCCESS)
     775                return rc;
     776        EMIT_PROGRESS();
     777
     778        //write general settings
     779        //custom text
     780        rc = hw_ostc3_device_customtext(device, m_deviceDetails->customText.toUtf8().data());
     781        if (rc != DC_STATUS_SUCCESS)
     782                return rc;
     783        EMIT_PROGRESS();
     784
     785        unsigned char data[4] = { 0 };
     786#define WRITE_SETTING(_OSTC4_SETTING, _DEVICE_DETAIL)                                          \
     787        do {                                                                                   \
     788                data[0] = m_deviceDetails->_DEVICE_DETAIL;                                     \
     789                rc = hw_ostc3_device_config_write(device, _OSTC4_SETTING, data, sizeof(data)); \
     790                if (rc != DC_STATUS_SUCCESS)                                                   \
     791                        return rc;                                                             \
     792                EMIT_PROGRESS();                                                               \
     793        } while (0)
     794
     795#undef WRITE_SETTING
     796
     797        // OSTC3 stores the pressureSensorOffset in two-complement
     798        data[0] = (unsigned char)m_deviceDetails->pressureSensorOffset;
     799        rc = hw_ostc3_device_config_write(device, OSTC3_PRESSURE_SENSOR_OFFSET, data, sizeof(data));
     800        if (rc != DC_STATUS_SUCCESS)
     801                return rc;
     802        EMIT_PROGRESS();
     803
     804        // OSTC3 stores the tempSensorOffset in two-complement
     805        data[0] = (unsigned char)m_deviceDetails->tempSensorOffset;
     806        rc = hw_ostc3_device_config_write(device, OSTC3_TEMP_SENSOR_OFFSET, data, sizeof(data));
     807        if (rc != DC_STATUS_SUCCESS)
     808                return rc;
     809        EMIT_PROGRESS();
     810
     811
     812        //sync date and time
     813        if (m_deviceDetails->syncTime) {
     814                dc_datetime_t now;
     815                dc_datetime_localtime(&now, dc_datetime_now());
     816
     817                rc = hw_ostc3_device_clock(device, &now);
     818        }
    383819
    384820        EMIT_PROGRESS();
Note: See TracChangeset for help on using the changeset viewer.