Concept code which launches two threads, one of which implements a Modbus Tunnel protocol to talk with an ISEM, the other which launches a Modbus RTU protocol to talk to a CPUM (most of the Modbus code has been removed prior to publishing.) A canned AC and DC spectra is provided to display wave forms on start-up however the project normally polls for spectra from the ISEM and then plots is (that functionality has been removed prior to publishing.)

Dependencies:   LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI mbed-os BSP_DISCO_F429ZI

/media/uploads/Damotclese/img_20190530_100915.jpg

Plot of the initial start-up canned AC and DC spectra.

Committer:
Damotclese
Date:
Thu May 30 05:16:27 2019 +0000
Revision:
0:387684ec9d92
Child:
1:01394e5db95b
Initial check in of working software which plots just the AC component;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Damotclese 0:387684ec9d92 1
Damotclese 0:387684ec9d92 2 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 3 // NextGen-Exerciser-Main.cpp
Damotclese 0:387684ec9d92 4 //
Damotclese 0:387684ec9d92 5 // Fredric L. Rice, May 2019
Damotclese 0:387684ec9d92 6 //
Damotclese 0:387684ec9d92 7 // o The LCD is cleared and configured
Damotclese 0:387684ec9d92 8 // o A canned AC and DC 2f water-in-ambient-air spectrum is plotted
Damotclese 0:387684ec9d92 9 // on the LCD after the spectrum is "normalized" by making each of
Damotclese 0:387684ec9d92 10 // the sample values positive and then compressed so that it fits
Damotclese 0:387684ec9d92 11 // in the display
Damotclese 0:387684ec9d92 12 // o A thread is created to perform Modbus against a CPUM device
Damotclese 0:387684ec9d92 13 // o A thread is created to perform Modbus Tunneling with foreign
Damotclese 0:387684ec9d92 14 // frames against an ISEM device
Damotclese 0:387684ec9d92 15 // o The main() thread wakes up once a second and performs whatever
Damotclese 0:387684ec9d92 16 // other functionality might be desired
Damotclese 0:387684ec9d92 17 //
Damotclese 0:387684ec9d92 18 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 19
Damotclese 0:387684ec9d92 20 #include "mbed.h" // The mbed operating system
Damotclese 0:387684ec9d92 21 #include "NextGen-Exerciser-Modbus.h" // For the CPUM Modbus thread
Damotclese 0:387684ec9d92 22 #include "NextGen-Exerciser-Tunnel.h" // For the Modbus Tunnel thread
Damotclese 0:387684ec9d92 23 #include "NextGen-Exerciser-Defines.h" // For defined constants and MACROs
Damotclese 0:387684ec9d92 24 #include "LCD_DISCO_F429ZI.h" // For controlling the LCD
Damotclese 0:387684ec9d92 25
Damotclese 0:387684ec9d92 26 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 27 // Defined constants that we will use here
Damotclese 0:387684ec9d92 28 //
Damotclese 0:387684ec9d92 29 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 30
Damotclese 0:387684ec9d92 31 #define LCD_WIDTH 240
Damotclese 0:387684ec9d92 32 #define LCD_HEIGHT 320
Damotclese 0:387684ec9d92 33
Damotclese 0:387684ec9d92 34 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 35 // Allocate local data storage
Damotclese 0:387684ec9d92 36 //
Damotclese 0:387684ec9d92 37 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 38
Damotclese 0:387684ec9d92 39 // Describe a canned 2f AC spectrum consisting of 512 floating point samples
Damotclese 0:387684ec9d92 40 // Note that the values after the decimal point are not really needed, they
Damotclese 0:387684ec9d92 41 // get discarded when the spectrum values are plotted as integer values.
Damotclese 0:387684ec9d92 42 // These values were extracted after Spectra Processor decimated a spectrum
Damotclese 0:387684ec9d92 43 // of 65536 samples. We "normalize" the values to make them all positive and
Damotclese 0:387684ec9d92 44 // later we take the 512 samples and further "decimate" by averaging every
Damotclese 0:387684ec9d92 45 // two samples, resuling in 256 final values. The 256 values get plotted on
Damotclese 0:387684ec9d92 46 // to the LCD along the "width" of the display which is 320 pixels, leaving
Damotclese 0:387684ec9d92 47 // 64 pixels to the right of the plot free to be used for other things.
Damotclese 0:387684ec9d92 48 static float f_decimatedACSpectrum[] =
Damotclese 0:387684ec9d92 49 {
Damotclese 0:387684ec9d92 50 -1.502448670,9.237028121,18.872425000,27.111267000,33.651569300,38.191074300,40.437301633,40.118068700,
Damotclese 0:387684ec9d92 51 36.992050100,30.858972544,21.569023133,9.031014442,-6.781046860,-25.823335644,-47.979820200,-73.062263400,
Damotclese 0:387684ec9d92 52 -100.812744110,-130.908676110,-162.970184330,-196.569778440,-231.243743000,-266.505157440,-301.857879000,-336.811126000,
Damotclese 0:387684ec9d92 53 -370.893982000,-403.669342000,-434.746948220,-463.794647220,-490.547790000,-514.816223110,-536.488708440,-555.534729000,
Damotclese 0:387684ec9d92 54 -572.003357000,-586.019348110,-597.776916000,-607.531311000,-615.588317000,-622.292602000,-628.014892000,-633.139160110,
Damotclese 0:387684ec9d92 55 -638.049499000,-643.118225000,-648.694641110,-655.095459000,-662.597473110,-671.431945000,-681.781494110,-693.779174000,
Damotclese 0:387684ec9d92 56 -707.509704000,-723.013183000,-740.289856000,-759.307129000,-780.007019000,-802.314636220,-826.146362330,-851.418640110,
Damotclese 0:387684ec9d92 57 -878.054870000,-905.992431000,-935.187500000,-965.618835440,-997.289367000,-1030.226684400,-1064.481080000,-1100.122430000,
Damotclese 0:387684ec9d92 58 -1137.235840000,-1175.915650000,-1216.259270000,-1258.360100000,-1302.301140000,-1348.147820000,-1395.942993300,-1445.701293300,
Damotclese 0:387684ec9d92 59 -1497.406372200,-1551.007934400,-1606.421874400,-1663.530761100,-1722.186401100,-1782.213134400,-1843.413452200,-1905.572753300,
Damotclese 0:387684ec9d92 60 -1968.465942200,-2031.863770000,-2095.539062200,-2159.272210000,-2222.855460000,-2286.097900000,-2348.825683300,-2410.885253300,
Damotclese 0:387684ec9d92 61 -2472.140130000,-2532.470214400,-2591.767090000,-2649.928460000,-2706.852294400,-2762.428950000,-2816.533440000,-2869.017333300,
Damotclese 0:387684ec9d92 62 -2919.700190000,-2968.362304400,-3014.738520000,-3058.511710000,-3099.308830000,-3136.698974400,-3170.191162200,-3199.236572200,
Damotclese 0:387684ec9d92 63 -3223.229492200,-3241.513671100,-3253.386710000,-3258.107421100,-3254.905273300,-3242.988030000,-3221.553710000,-3189.798340000,
Damotclese 0:387684ec9d92 64 -3146.928950000,-3092.171142200,-3024.780761100,-2944.051020000,-2849.322510000,-2739.990234400,-2615.509270000,-2475.402343300,
Damotclese 0:387684ec9d92 65 -2319.263183300,-2146.761962200,-1957.648560000,-1751.756340000,-1529.004510000,-1289.401733300,-1033.048700000,-760.140625000,
Damotclese 0:387684ec9d92 66 -470.970947220,-165.934036220,154.471374000,489.638946000,838.851257330,1201.276733300,1575.967041100,1961.854370000,
Damotclese 0:387684ec9d92 67 2357.750480000,2762.345940000,3174.210693300,3591.797120000,4013.442382200,4437.375480000,4861.724610000,5284.524414400,
Damotclese 0:387684ec9d92 68 5703.730950000,6117.232910000,6522.867180000,6918.436030000,7301.727050000,7670.530761100,8022.663080000,8355.986320000,
Damotclese 0:387684ec9d92 69 8668.431640000,8958.021484400,9222.888671100,9461.302734400,9671.681640000,9852.618164400,10002.893500000,10121.489200000,
Damotclese 0:387684ec9d92 70 10207.603511000,10260.660100000,10280.314400000,10266.458900000,10219.221600000,10138.971600000,10026.307611000,9882.054680000,
Damotclese 0:387684ec9d92 71 9707.252930000,9503.147460000,9271.170890000,9012.928710000,8730.179680000,8424.816400000,8098.844230000,7754.357421100,
Damotclese 0:387684ec9d92 72 7393.519531100,7018.538080000,6631.642570000,6235.063470000,5831.010742200,5421.653800000,5009.104003300,4595.396972200,
Damotclese 0:387684ec9d92 73 4182.478510000,3772.192871100,3366.271484400,2966.325440000,2573.839350000,2190.168450000,1816.535644400,1454.033320000,
Damotclese 0:387684ec9d92 74 1103.623901100,766.144043000,442.308807330,132.717117330,-162.142257000,-441.884216330,-706.220947220,-954.955566440,
Damotclese 0:387684ec9d92 75 -1187.975830000,-1405.248901100,-1606.816040000,-1792.787720000,-1963.340570000,-2118.713134400,-2259.203370000,-2385.165283300,
Damotclese 0:387684ec9d92 76 -2497.007812200,-2595.190430000,-2680.222412200,-2752.658203300,-2813.093994400,-2862.164550000,-2900.537590000,-2928.907950000,
Damotclese 0:387684ec9d92 77 -2947.991700000,-2958.517822200,-2961.222650000,-2956.839350000,-2946.091552200,-2929.683350000,-2908.292230000,-2882.560540000,
Damotclese 0:387684ec9d92 78 -2853.090080000,-2820.434082200,-2785.094482200,-2747.517333300,-2708.092041100,-2667.150140000,-2624.968500000,-2581.769770000,
Damotclese 0:387684ec9d92 79 -2537.729730000,-2492.980224400,-2447.618164400,-2401.711420000,-2355.307120000,-2308.439690000,-2261.137940000,-2213.432861100,
Damotclese 0:387684ec9d92 80 -2165.363520000,-2116.981440000,-2068.355224400,-2019.572380000,-1970.740350000,-1921.984980000,-1873.449340000,-1825.289550000,
Damotclese 0:387684ec9d92 81 -1777.670043300,-1730.759150000,-1684.721923300,-1639.715080000,-1595.880493300,-1553.340080000,-1512.190790000,-1472.501342200,
Damotclese 0:387684ec9d92 82 -1434.309570000,-1397.621210000,-1362.410760000,-1328.622680000,-1296.175292200,-1264.964600000,-1234.869873300,-1205.759880000,
Damotclese 0:387684ec9d92 83 -1177.499140000,-1149.954711100,-1123.002800000,-1096.534050000,-1070.459472200,-1044.713134400,-1019.255790000,-994.075744000,
Damotclese 0:387684ec9d92 84 -969.188293440,-944.634338330,-920.477295000,-896.798462000,-873.692077000,-851.259216330,-829.601562440,-808.814880330,
Damotclese 0:387684ec9d92 85 -788.983154220,-770.172973000,-752.429016110,-735.770691000,-720.190063440,-705.651245110,-692.091308000,-679.422546330,
Damotclese 0:387684ec9d92 86 -667.536193000,-656.307312000,-645.600402000,-635.275817000,-625.196350000,-615.233886000,-605.275512000,-595.229004000,
Damotclese 0:387684ec9d92 87 -585.027282000,-574.631591000,-564.033447220,-553.254821000,-542.346923000,-531.387756330,-520.477966330,-509.735595000,
Damotclese 0:387684ec9d92 88 -499.290527330,-489.277618440,-479.830261220,-471.073608330,-463.118743000,-456.057190000,-449.956909110,-444.859253000,
Damotclese 0:387684ec9d92 89 -440.777649000,-437.697479220,-435.577880000,-434.354522000,-433.944000220,-434.248993000,-435.164337110,-436.583465000,
Damotclese 0:387684ec9d92 90 -438.404754000,-440.537933330,-442.909454330,-445.467254000,-448.184082000,-451.059661000,-454.121124220,-457.422180110,
Damotclese 0:387684ec9d92 91 -461.040466330,-465.073761000,-469.634948000,-474.846222000,-480.832397440,-487.714386000,-495.602508000,-504.590667000,
Damotclese 0:387684ec9d92 92 -514.750915000,-526.129760000,-538.745178220,-552.586059000,-567.612426000,-583.757812440,-600.933227000,-619.031982440,
Damotclese 0:387684ec9d92 93 -637.936096110,-657.523071220,-677.673339000,-698.277160000,-719.241394000,-740.495056110,-761.993713330,-783.721740000,
Damotclese 0:387684ec9d92 94 -805.693237330,-827.950134220,-850.558349000,-873.601989000,-897.174682000,-921.369873000,-946.269043000,-971.929199220,
Damotclese 0:387684ec9d92 95 -998.369567000,-1025.558350000,-1053.400024400,-1081.723632200,-1110.273071100,-1138.698974400,-1166.554560000,-1193.292602200,
Damotclese 0:387684ec9d92 96 -1218.267211100,-1240.738770000,-1259.881470000,-1274.795280000,-1284.520751100,-1288.056152200,-1284.377800000,-1272.461420000,
Damotclese 0:387684ec9d92 97 -1251.305900000,-1219.956910000,-1177.530883300,-1123.238160000,-1056.406250000,-976.499206000,-883.136718000,-776.109497000,
Damotclese 0:387684ec9d92 98 -655.391845000,-521.151001000,-373.752929000,-213.764404220,-41.951789800,140.723938000,333.115356440,533.900024440,
Damotclese 0:387684ec9d92 99 741.594665000,954.571960440,1171.079711100,1389.261840000,1607.181152200,1822.842651100,2034.219230000,2239.276360000,
Damotclese 0:387684ec9d92 100 2435.997802200,2622.412110000,2796.617180000,2956.805420000,3101.288080000,3228.517822200,3337.110590000,3425.865234400,
Damotclese 0:387684ec9d92 101 3493.781000000,3540.073974400,3564.189453300,3565.812744400,3544.875244400,3501.559570000,3436.298820000,3349.772700000,
Damotclese 0:387684ec9d92 102 3242.901850000,3116.834472200,2972.933350000,2812.756340000,2638.033691100,2450.644531100,2252.587640000,2045.952140000,
Damotclese 0:387684ec9d92 103 1832.885253300,1615.559814400,1396.141350000,1176.755120000,959.454528000,746.191284110,538.787902000,338.913055440,
Damotclese 0:387684ec9d92 104 148.060974110,-32.465728700,-201.568542440,-358.361267000,-502.173584000,-632.550109000,-749.244995110,-852.212768000,
Damotclese 0:387684ec9d92 105 -941.595398000,-1017.705932200,-1081.010010000,-1132.105340000,-1171.699584400,-1200.587760000,-1219.629394400,-1229.727172200,
Damotclese 0:387684ec9d92 106 -1231.805170000,-1226.789910000,-1215.592890000,-1199.095330000,-1178.135864400,-1153.499633300,-1125.911621100,-1096.030510000,
Damotclese 0:387684ec9d92 107 -1064.447021100,-1031.682000000,-998.188537000,-964.353820000,-930.503479000,-896.906066000,-863.778503440,-831.291504000,
Damotclese 0:387684ec9d92 108 -799.575500440,-768.725891110,-738.808532000,-709.864502000,-681.914245000,-654.961486000,-628.996582000,-603.999267000,
Damotclese 0:387684ec9d92 109 -579.941101000,-556.787353000,-534.498901330,-513.033691440,-492.348114000,-472.398071220,-453.140289330,-434.533050000,
Damotclese 0:387684ec9d92 110 -416.537292440,-399.117187440,-382.240600000,-365.879577000,-350.010192000,-334.612487000,-319.669769220,-305.167755110,
Damotclese 0:387684ec9d92 111 -291.093566000,-277.434234000,-264.175262440,-251.299041000,-238.783386220,-226.600113000,-214.714141000,-203.082885000,
Damotclese 0:387684ec9d92 112 -191.656234000,-180.377243000,-169.183487000,-158.009185000,-146.788055440,-135.456863440,-123.959488000,-112.251495330,
Damotclese 0:387684ec9d92 113 -100.304824000,-88.112571711,-75.693458500,-63.095802300,-50.400745400,-37.724391933,-25.218734744,-13.071174622
Damotclese 0:387684ec9d92 114 } ;
Damotclese 0:387684ec9d92 115
Damotclese 0:387684ec9d92 116 // We will be using the LCD so instantiate an object locally
Damotclese 0:387684ec9d92 117 static LCD_DISCO_F429ZI st_lcd;
Damotclese 0:387684ec9d92 118
Damotclese 0:387684ec9d92 119 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 120 // MainProcessDecimatedSpectrum()
Damotclese 0:387684ec9d92 121 //
Damotclese 0:387684ec9d92 122 // This function will:
Damotclese 0:387684ec9d92 123 // o Search through the AC spectra and the DC spectra looking for
Damotclese 0:387684ec9d92 124 // the smallest and the highest numeric values in both
Damotclese 0:387684ec9d92 125 // o Convert the smallest number in to an absolute value by removing
Damotclese 0:387684ec9d92 126 // the sign bit using the ANSI absolute function
Damotclese 0:387684ec9d92 127 // o Add that now-positive smallest number to every sample in the
Damotclese 0:387684ec9d92 128 // AC and DC spectrums so that each value in the spectrums are
Damotclese 0:387684ec9d92 129 // positive values
Damotclese 0:387684ec9d92 130 // o Add that smallest value to the known largest value so that it
Damotclese 0:387684ec9d92 131 // agrees with the rest of the spectrum again
Damotclese 0:387684ec9d92 132 // o Compute a ratio derived by dividing the ;argest known value
Damotclese 0:387684ec9d92 133 // by the "width" of the screen
Damotclese 0:387684ec9d92 134 // o Goes through all 512 samples and averages them two by two,
Damotclese 0:387684ec9d92 135 // compressing the spectrum in place (in the same array of values)
Damotclese 0:387684ec9d92 136 // so that we end up with 256 samples which can fit on the LCD
Damotclese 0:387684ec9d92 137 // o Divides each of the 256 samples by the radio so that each of
Damotclese 0:387684ec9d92 138 // the samples will fit on the LCD
Damotclese 0:387684ec9d92 139 //
Damotclese 0:387684ec9d92 140 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 141 static void MainProcessDecimatedSpectrum(void)
Damotclese 0:387684ec9d92 142 {
Damotclese 0:387684ec9d92 143 uint16_t u16_searchLoop = 0;
Damotclese 0:387684ec9d92 144 uint32_t u32_sampleRatio = 0;
Damotclese 0:387684ec9d92 145 uint16_t u16_resultIndex = 0;
Damotclese 0:387684ec9d92 146 float f_smallNumber = 10000000.0f;
Damotclese 0:387684ec9d92 147 float f_largeNumber = 0.0f;
Damotclese 0:387684ec9d92 148
Damotclese 0:387684ec9d92 149 // Search through the AC spectrum for the smallest and the largest values
Damotclese 0:387684ec9d92 150 for (u16_searchLoop = 0; u16_searchLoop < 512; u16_searchLoop++)
Damotclese 0:387684ec9d92 151 {
Damotclese 0:387684ec9d92 152 if (f_decimatedACSpectrum[u16_searchLoop] < f_smallNumber)
Damotclese 0:387684ec9d92 153 {
Damotclese 0:387684ec9d92 154 // This value is the new lowest number
Damotclese 0:387684ec9d92 155 f_smallNumber = f_decimatedACSpectrum[u16_searchLoop];
Damotclese 0:387684ec9d92 156 }
Damotclese 0:387684ec9d92 157
Damotclese 0:387684ec9d92 158 if (f_decimatedACSpectrum[u16_searchLoop] > f_largeNumber)
Damotclese 0:387684ec9d92 159 {
Damotclese 0:387684ec9d92 160 // This value is the new highest number
Damotclese 0:387684ec9d92 161 f_largeNumber = f_decimatedACSpectrum[u16_searchLoop];
Damotclese 0:387684ec9d92 162 }
Damotclese 0:387684ec9d92 163 }
Damotclese 0:387684ec9d92 164
Damotclese 0:387684ec9d92 165 // Is the smallest number negative? We know that it is but we check
Damotclese 0:387684ec9d92 166 if (f_smallNumber < 0.0f)
Damotclese 0:387684ec9d92 167 {
Damotclese 0:387684ec9d92 168 // Make the value absolute so that it is positive
Damotclese 0:387684ec9d92 169 f_smallNumber = abs(f_smallNumber);
Damotclese 0:387684ec9d92 170 }
Damotclese 0:387684ec9d92 171
Damotclese 0:387684ec9d92 172 // To make all values positive, add the newly-derived positive value.
Damotclese 0:387684ec9d92 173 // This makes all numbers positive and ensures that the smallest
Damotclese 0:387684ec9d92 174 // value in the spectra is zero.
Damotclese 0:387684ec9d92 175 for (u16_searchLoop = 0; u16_searchLoop < 512; u16_searchLoop++)
Damotclese 0:387684ec9d92 176 {
Damotclese 0:387684ec9d92 177 f_decimatedACSpectrum[u16_searchLoop] += f_smallNumber;
Damotclese 0:387684ec9d92 178 }
Damotclese 0:387684ec9d92 179
Damotclese 0:387684ec9d92 180 // Also add the newly-positive number to our largest known value
Damotclese 0:387684ec9d92 181 f_largeNumber += f_smallNumber;
Damotclese 0:387684ec9d92 182
Damotclese 0:387684ec9d92 183 // Determine the ratio to use, the LCD screen is 240 by 320 so we
Damotclese 0:387684ec9d92 184 // take the highest number value in the spectra and divide by 240
Damotclese 0:387684ec9d92 185 // for the verticle plot, and we have 512 samples which will be
Damotclese 0:387684ec9d92 186 // plotted across the 320 by averaging every 2 samples to yield
Damotclese 0:387684ec9d92 187 // 256 horizontal positions. We plot with the screen laying on
Damotclese 0:387684ec9d92 188 // its side
Damotclese 0:387684ec9d92 189 u32_sampleRatio = (f_largeNumber / LCD_WIDTH);
Damotclese 0:387684ec9d92 190
Damotclese 0:387684ec9d92 191 // Go through each pairs of samples and average them and then
Damotclese 0:387684ec9d92 192 // divide the result by the ratio. Step through in twos
Damotclese 0:387684ec9d92 193 for (u16_searchLoop = 0; u16_searchLoop < 512; u16_searchLoop += 2, u16_resultIndex++)
Damotclese 0:387684ec9d92 194 {
Damotclese 0:387684ec9d92 195 // Take the next two samples and average them, putting the result
Damotclese 0:387684ec9d92 196 // in to the next result index of the same buffer we're processing
Damotclese 0:387684ec9d92 197 f_decimatedACSpectrum[u16_resultIndex] =
Damotclese 0:387684ec9d92 198 (f_decimatedACSpectrum[u16_searchLoop] + f_decimatedACSpectrum[u16_searchLoop]) / 2;
Damotclese 0:387684ec9d92 199
Damotclese 0:387684ec9d92 200 // Divide the sample value by the ratio
Damotclese 0:387684ec9d92 201 f_decimatedACSpectrum[u16_resultIndex] /= u32_sampleRatio;
Damotclese 0:387684ec9d92 202 }
Damotclese 0:387684ec9d92 203 }
Damotclese 0:387684ec9d92 204
Damotclese 0:387684ec9d92 205 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 206 // MainPlotFinalSpectrum()
Damotclese 0:387684ec9d92 207 //
Damotclese 0:387684ec9d92 208 // This function will step through the "normalized" and compressed AC
Damotclese 0:387684ec9d92 209 // and DC spectrums consisting of 256 samples and will plot a line from
Damotclese 0:387684ec9d92 210 // one sample to the next on the LCD
Damotclese 0:387684ec9d92 211 //
Damotclese 0:387684ec9d92 212 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 213 static void MainPlotFinalSpectrum(void)
Damotclese 0:387684ec9d92 214 {
Damotclese 0:387684ec9d92 215 uint16_t u16_searchLoop = 0;
Damotclese 0:387684ec9d92 216
Damotclese 0:387684ec9d92 217 // Plot the spectrum values, plotting a line from point to point
Damotclese 0:387684ec9d92 218 for (u16_searchLoop = 0; u16_searchLoop < ((512 / 2) - 1); u16_searchLoop++)
Damotclese 0:387684ec9d92 219 {
Damotclese 0:387684ec9d92 220 // Ensure that we actually fit. The sample should
Damotclese 0:387684ec9d92 221 if (f_decimatedACSpectrum[u16_searchLoop] <= LCD_WIDTH)
Damotclese 0:387684ec9d92 222 {
Damotclese 0:387684ec9d92 223 st_lcd.DrawLine(f_decimatedACSpectrum[u16_searchLoop], u16_searchLoop,
Damotclese 0:387684ec9d92 224 f_decimatedACSpectrum[u16_searchLoop + 1], u16_searchLoop + 1);
Damotclese 0:387684ec9d92 225 }
Damotclese 0:387684ec9d92 226 else
Damotclese 0:387684ec9d92 227 {
Damotclese 0:387684ec9d92 228 // Mathematically we topped-out past the maximum some how
Damotclese 0:387684ec9d92 229 st_lcd.DrawPixel(0, u16_searchLoop, LCD_COLOR_WHITE);
Damotclese 0:387684ec9d92 230 }
Damotclese 0:387684ec9d92 231 }
Damotclese 0:387684ec9d92 232 }
Damotclese 0:387684ec9d92 233
Damotclese 0:387684ec9d92 234 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 235 // MainInit()
Damotclese 0:387684ec9d92 236 //
Damotclese 0:387684ec9d92 237 // This function will:
Damotclese 0:387684ec9d92 238 // o Clear and initialize the LCD
Damotclese 0:387684ec9d92 239 // o Process the scanned decimated 2f AC and DC spectrums
Damotclese 0:387684ec9d92 240 // o Plot the processed spectrums
Damotclese 0:387684ec9d92 241 //
Damotclese 0:387684ec9d92 242 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 243 static void MainInit(void)
Damotclese 0:387684ec9d92 244 {
Damotclese 0:387684ec9d92 245 // Bring the LCD up and set its various colors
Damotclese 0:387684ec9d92 246 st_lcd.Clear(LCD_COLOR_BLACK);
Damotclese 0:387684ec9d92 247 st_lcd.SetBackColor(LCD_COLOR_BLACK);
Damotclese 0:387684ec9d92 248 st_lcd.SetTextColor(LCD_COLOR_WHITE);
Damotclese 0:387684ec9d92 249
Damotclese 0:387684ec9d92 250 // Process the decimated spectrum and then plot it
Damotclese 0:387684ec9d92 251 MainProcessDecimatedSpectrum();
Damotclese 0:387684ec9d92 252 MainPlotFinalSpectrum();
Damotclese 0:387684ec9d92 253 }
Damotclese 0:387684ec9d92 254
Damotclese 0:387684ec9d92 255 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 256 // MainThread()
Damotclese 0:387684ec9d92 257 //
Damotclese 0:387684ec9d92 258 // Called once a second.
Damotclese 0:387684ec9d92 259 //
Damotclese 0:387684ec9d92 260 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 261 static void MainThread(void)
Damotclese 0:387684ec9d92 262 {
Damotclese 0:387684ec9d92 263 }
Damotclese 0:387684ec9d92 264
Damotclese 0:387684ec9d92 265 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 266 // main()
Damotclese 0:387684ec9d92 267 //
Damotclese 0:387684ec9d92 268 // This is the main entry point which the operating system will load
Damotclese 0:387684ec9d92 269 // and execute on power-up after the OS completes its own start-up
Damotclese 0:387684ec9d92 270 // functionality.
Damotclese 0:387684ec9d92 271 //
Damotclese 0:387684ec9d92 272 // The function will:
Damotclese 0:387684ec9d92 273 // o Initialize this module's functionality
Damotclese 0:387684ec9d92 274 // o Launch the MODBUS CPUM thread
Damotclese 0:387684ec9d92 275 // o Launch the Modbus Tunnel thread
Damotclese 0:387684ec9d92 276 // o Enter in to a forever loop which should never terminate,
Damotclese 0:387684ec9d92 277 // waking up once a second to perform any additional desired
Damotclese 0:387684ec9d92 278 // functionality
Damotclese 0:387684ec9d92 279 //
Damotclese 0:387684ec9d92 280 // ----------------------------------------------------------------------
Damotclese 0:387684ec9d92 281 int main(void)
Damotclese 0:387684ec9d92 282 {
Damotclese 0:387684ec9d92 283 // Perform local module initialization, if any
Damotclese 0:387684ec9d92 284 MainInit();
Damotclese 0:387684ec9d92 285
Damotclese 0:387684ec9d92 286 // Initialize and launch the MODBUS CPUM thread
Damotclese 0:387684ec9d92 287 ModbusInit();
Damotclese 0:387684ec9d92 288
Damotclese 0:387684ec9d92 289 // Initialize and launch the MODBUS Tunnel thread
Damotclese 0:387684ec9d92 290 TunnelInit();
Damotclese 0:387684ec9d92 291
Damotclese 0:387684ec9d92 292 // Enter in to a forever loop which wakes up once a second
Damotclese 0:387684ec9d92 293 while (true)
Damotclese 0:387684ec9d92 294 {
Damotclese 0:387684ec9d92 295 // Sleep for one second
Damotclese 0:387684ec9d92 296 wait(1.0);
Damotclese 0:387684ec9d92 297
Damotclese 0:387684ec9d92 298 MainThread();
Damotclese 0:387684ec9d92 299 }
Damotclese 0:387684ec9d92 300 }
Damotclese 0:387684ec9d92 301
Damotclese 0:387684ec9d92 302 // End of file
Damotclese 0:387684ec9d92 303