~ubuntu-branches/ubuntu/saucy/argyll/saucy

« back to all changes in this revision

Viewing changes to spectro/dtp92.c

  • Committer: Package Import Robot
  • Author(s): Christian Marillat
  • Date: 2012-04-25 07:46:07 UTC
  • mfrom: (1.2.2) (13.1.15 sid)
  • Revision ID: package-import@ubuntu.com-20120425074607-yjqadetw8kum9skc
Tags: 1.4.0-4
Should Build-Depends on libusb-dev (Closes: #670329).

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include "copyright.h"
42
42
#include "aconfig.h"
43
43
#include "numlib.h"
 
44
#else   /* !SALONEINSTLIB */
 
45
#include "sa_config.h"
 
46
#include "numsup.h"
44
47
#endif /* !SALONEINSTLIB */
45
48
#include "xspect.h"
46
49
#include "insttypes.h"
53
56
/* Default flow control */
54
57
#define DEFFC fc_none
55
58
 
 
59
#define IGNORE_NEEDS_OFFSET_DRIFT_CAL_ERR
 
60
 
56
61
static inst_code dtp92_interp_code(inst *pp, int ec);
57
62
 
58
63
#define MAX_MES_SIZE 500                /* Maximum normal message reply size */
126
131
        rv = DTP92_OK;
127
132
        if (tc == '>' && ntc == 1) {
128
133
                rv = extract_ec(out);
 
134
 
129
135
#ifdef NEVER
130
136
if (strcmp(in, "0PR\r") == 0)
131
137
rv = DTP92_NEEDS_OFFSET_DRIFT_CAL;              /* Emulate 1B error */
132
138
#endif /* NEVER */
 
139
 
133
140
                if (rv > 0) {
134
141
                        rv &= inst_imask;
135
142
                        if (rv != DTP92_OK) {   /* Clear the error */
142
149
        printf("command '%s'",icoms_fix(in));
143
150
        printf(" returned '%s', value 0x%x\n",icoms_fix(out),rv);
144
151
#endif
 
152
 
 
153
#ifdef IGNORE_NEEDS_OFFSET_DRIFT_CAL_ERR
 
154
        if (strcmp(in, "0PR\r") == 0 && rv == DTP92_NEEDS_OFFSET_DRIFT_CAL) {
 
155
                static int warned = 0;
 
156
                if (!warned) {
 
157
                        warning("Got error NEEDS_OFFSET_DRIFT_CAL on instrument reset - being ignored.");
 
158
                        warned = 1;
 
159
                }
 
160
                rv = 0;
 
161
        }
 
162
#endif
145
163
        return rv;
146
164
}
147
165
 
163
181
        baud_rate brt[5] = { baud_9600, baud_19200, baud_4800, baud_2400, baud_1200 };
164
182
        char *brc[5]     = { "30BR\r",  "60BR\r",   "18BR\r",  "0CBR\r",  "06BR\r" };
165
183
        char *fcc;
166
 
        long etime;
 
184
        unsigned int etime;
167
185
        instType itype;
168
186
        int ci, bi, i, rv;
169
187
        inst_code ev = inst_ok;
236
254
 
237
255
                while (msec_time() < etime) {
238
256
 
239
 
                        if (p->debug) fprintf(stderr,"dtp92: Trying different baud rates (%ld ticks to go)\n",etime - msec_time());
 
257
                        if (p->debug) fprintf(stderr,"dtp92: Trying different baud rates (%u ticks to go)\n",etime - msec_time());
240
258
 
241
259
                        /* Until we time out, find the correct baud rate */
242
260
                        for (i = ci; msec_time() < etime;) {
511
529
        int user_trig = 0;
512
530
        int rv = inst_protocol_error;
513
531
 
 
532
        if (!p->gotcoms)
 
533
                return inst_no_coms;
 
534
        if (!p->inited)
 
535
                return inst_no_init;
 
536
 
514
537
        /* Could change SS to suite level expected. */
515
538
#ifdef NEVER
516
539
        if (p->itype == instDTP92) {
585
608
) {
586
609
        dtp92 *p = (dtp92 *)pp;
587
610
 
 
611
        if (!p->gotcoms)
 
612
                return inst_no_coms;
 
613
        if (!p->inited)
 
614
                return inst_no_init;
 
615
 
588
616
        if (mtx == NULL)
589
617
                icmSetUnity3x3(p->ccmat);
590
618
        else
599
627
inst_cal_type dtp92_needs_calibration(inst *pp) {
600
628
        dtp92 *p = (dtp92 *)pp;
601
629
 
 
630
        if (!p->gotcoms)
 
631
                return inst_no_coms;
 
632
        if (!p->inited)
 
633
                return inst_no_init;
 
634
 
602
635
        if (p->need_offset_cal)
603
636
                return inst_calt_disp_offset;
604
637
 
626
659
        inst_code rv = inst_ok;
627
660
        id[0] = '\000';
628
661
 
 
662
        if (!p->gotcoms)
 
663
                return inst_no_coms;
 
664
        if (!p->inited)
 
665
                return inst_no_init;
 
666
 
629
667
        /* Default to most likely calibration type */
630
668
        if (calt == inst_calt_all) {
631
669
                if (p->need_offset_cal)
775
813
/* Convert a machine specific error code into an abstract dtp code */
776
814
static inst_code 
777
815
dtp92_interp_code(inst *pp, int ec) {
778
 
        dtp92 *p = (dtp92 *)pp;
779
816
 
780
817
        ec &= inst_imask;
781
818
        switch (ec) {
846
883
             ;
847
884
 
848
885
        if (p->itype == instDTP94) {
849
 
                rv |= inst_emis_disp_crt;
850
 
                rv |= inst_emis_disp_lcd;
 
886
                rv |= inst_emis_disptype;
 
887
                rv |= inst_emis_disptypem;
851
888
        }
852
889
 
853
890
        return rv;
869
906
        return rv;
870
907
}
871
908
 
 
909
inst_disptypesel dtp92_disptypesel[2] = {
 
910
        {
 
911
                1,
 
912
                "c",
 
913
                "DTP92: CRT display [Default]",
 
914
                1
 
915
        },
 
916
        {
 
917
                0,
 
918
                "",
 
919
                "",
 
920
                -1
 
921
        }
 
922
};
 
923
 
 
924
inst_disptypesel dtp94_disptypesel[3] = {
 
925
        {
 
926
                1,
 
927
                "c",
 
928
                "DTP94: CRT display",
 
929
                1
 
930
        },
 
931
        {
 
932
                2,
 
933
                "l",
 
934
                "DTP94: LCD display",
 
935
                0
 
936
        },
 
937
        {
 
938
                0,
 
939
                "",
 
940
                "",
 
941
                -1
 
942
        }
 
943
};
 
944
 
 
945
/* Get mode and option details */
 
946
static inst_code dtp92_get_opt_details(
 
947
inst *pp,
 
948
inst_optdet_type m,     /* Requested option detail type */
 
949
...) {                          /* Status parameters */                             
 
950
        dtp92 *p = (dtp92 *)pp;
 
951
 
 
952
        if (m == inst_optdet_disptypesel) {
 
953
                va_list args;
 
954
                int *pnsels;
 
955
                inst_disptypesel **psels;
 
956
 
 
957
                va_start(args, m);
 
958
                pnsels = va_arg(args, int *);
 
959
                psels = va_arg(args, inst_disptypesel **);
 
960
                va_end(args);
 
961
 
 
962
                if (p->itype == instDTP94) {
 
963
                        *pnsels = 2;
 
964
                        *psels = dtp94_disptypesel;
 
965
                } else {
 
966
                        *pnsels = 1;
 
967
                        *psels = dtp92_disptypesel;
 
968
                }
 
969
                
 
970
                return inst_ok;
 
971
        }
 
972
 
 
973
        return inst_unsupported;
 
974
}
 
975
 
872
976
/* Set device measurement mode */
873
977
inst_code dtp92_set_mode(inst *pp, inst_mode m)
874
978
{
875
979
        inst_mode mm;           /* Measurement mode */
876
980
 
 
981
        if (!pp->gotcoms)
 
982
                return inst_no_coms;
 
983
        if (!pp->inited)
 
984
                return inst_no_init;
 
985
 
877
986
        /* The measurement mode portion of the mode */
878
987
        mm = m & inst_mode_measurement_mask;
879
988
 
901
1010
        char buf[MAX_MES_SIZE];
902
1011
        inst_code ev = inst_ok;
903
1012
 
904
 
        if (m == inst_opt_disp_crt) {
905
 
                if (p->itype == instDTP94) {
906
 
                        if ((ev = dtp92_command(p, "0116CF\r", buf, MAX_MES_SIZE, 0.2)) != inst_ok)
 
1013
        if (!p->gotcoms)
 
1014
                return inst_no_coms;
 
1015
        if (!p->inited)
 
1016
                return inst_no_init;
 
1017
 
 
1018
        /* Set the display type */
 
1019
        if (m == inst_opt_disp_type) {
 
1020
                va_list args;
 
1021
                int ix;
 
1022
 
 
1023
                va_start(args, m);
 
1024
                ix = va_arg(args, int);
 
1025
                va_end(args);
 
1026
 
 
1027
                if (ix == 0 && p->itype == instDTP92)
 
1028
                        return inst_ok;
 
1029
                        
 
1030
                if (ix == 1) {
 
1031
                        if (p->itype == instDTP94) {
 
1032
                                if ((ev = dtp92_command(p, "0116CF\r", buf, MAX_MES_SIZE, 0.2)) != inst_ok)
 
1033
                                        return ev;
 
1034
                        }
 
1035
                        return inst_ok;
 
1036
                } else if (ix == 2) {
 
1037
                        if (p->itype == instDTP92)
 
1038
                                return inst_unsupported;
 
1039
                        if ((ev = dtp92_command(p, "0216CF\r", buf, MAX_MES_SIZE, 0.2)) != inst_ok)
907
1040
                                return ev;
908
 
                }
909
 
                return inst_ok;
910
 
        } else if (m == inst_opt_disp_lcd) {
911
 
                if (p->itype == instDTP92)
 
1041
                        return inst_ok;
 
1042
                } else {
912
1043
                        return inst_unsupported;
913
 
                if ((ev = dtp92_command(p, "0216CF\r", buf, MAX_MES_SIZE, 0.2)) != inst_ok)
914
 
                        return ev;
915
 
                return inst_ok;
916
 
 
 
1044
                }
917
1045
        }
918
1046
 
919
1047
        /* Record the trigger mode */
934
1062
}
935
1063
 
936
1064
/* Constructor */
937
 
extern dtp92 *new_dtp92(icoms *icom, int debug, int verb)
 
1065
extern dtp92 *new_dtp92(icoms *icom, instType itype, int debug, int verb)
938
1066
{
939
1067
        dtp92 *p;
940
1068
        if ((p = (dtp92 *)calloc(sizeof(dtp92),1)) == NULL)
954
1082
        p->init_inst         = dtp92_init_inst;
955
1083
        p->capabilities      = dtp92_capabilities;
956
1084
        p->capabilities2     = dtp92_capabilities2;
 
1085
        p->get_opt_details   = dtp92_get_opt_details;
957
1086
        p->set_mode          = dtp92_set_mode;
958
1087
        p->set_opt_mode      = dtp92_set_opt_mode;
959
1088
        p->read_sample       = dtp92_read_sample;
963
1092
        p->interp_error      = dtp92_interp_error;
964
1093
        p->del               = dtp92_del;
965
1094
 
966
 
        p->itype = instUnknown;         /* Until initalisation */
 
1095
        p->itype = itype;
967
1096
 
968
1097
        return p;
969
1098
}