storing variables in single array for transmission
Dependencies: SDFileSystem dspmodified mbed
Fork of FTPGET_Merged by
merged_code.cpp@20:764af4c48cf2, 2015-06-23 (annotated)
- Committer:
- pravinmagar
- Date:
- Tue Jun 23 12:36:20 2015 +0000
- Revision:
- 20:764af4c48cf2
- Parent:
- 18:4e3aa33674c8
- Child:
- 21:9e71641aeac8
Iteration function added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jaspreetsingh | 0:f2467c077504 | 1 | /* |
jaspreetsingh | 0:f2467c077504 | 2 | Designed to work from year 2015 to 2020 |
jaspreetsingh | 0:f2467c077504 | 3 | */ |
jaspreetsingh | 0:f2467c077504 | 4 | |
jaspreetsingh | 0:f2467c077504 | 5 | #include "mbed.h" |
jaspreetsingh | 0:f2467c077504 | 6 | #include "arm_math.h" |
jaspreetsingh | 0:f2467c077504 | 7 | #include "SDFileSystem.h" |
jaspreetsingh | 0:f2467c077504 | 8 | #include "arm_common_tables.h" |
jaspreetsingh | 0:f2467c077504 | 9 | #define freq 1 |
jaspreetsingh | 0:f2467c077504 | 10 | #define fft_points 16384 |
jaspreetsingh | 0:f2467c077504 | 11 | #define dur_sec 16.384 |
lalitkumar | 17:824537d9204b | 12 | #define module_name "TFT2" //enter module name here |
jaspreetsingh | 0:f2467c077504 | 13 | |
jaspreetsingh | 0:f2467c077504 | 14 | Serial pc(USBTX, USBRX); |
jaspreetsingh | 0:f2467c077504 | 15 | Serial gsm(D1, D0); |
jaspreetsingh | 0:f2467c077504 | 16 | AnalogIn AC_input(A0); |
jaspreetsingh | 0:f2467c077504 | 17 | AnalogIn AC2_input(A1); |
jaspreetsingh | 0:f2467c077504 | 18 | AnalogIn DC_input(A2); |
jaspreetsingh | 0:f2467c077504 | 19 | AnalogIn DC_Detect(A3); |
jaspreetsingh | 0:f2467c077504 | 20 | AnalogIn TC1(A4); |
jaspreetsingh | 0:f2467c077504 | 21 | AnalogIn TC2(A5); |
jaspreetsingh | 0:f2467c077504 | 22 | SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); |
jaspreetsingh | 0:f2467c077504 | 23 | DigitalOut gsm_rst(D7); |
jaspreetsingh | 0:f2467c077504 | 24 | |
FahdAnsary | 9:7965c3bc3199 | 25 | char sitename[10] =module_name; |
jaspreetsingh | 0:f2467c077504 | 26 | char filename[100] = ""; |
jaspreetsingh | 0:f2467c077504 | 27 | char filepath[100] = ""; |
FahdAnsary | 9:7965c3bc3199 | 28 | char timestamp[20]=""; |
jaspreetsingh | 0:f2467c077504 | 29 | char time_stamp[20]=""; |
FahdAnsary | 9:7965c3bc3199 | 30 | char timestampold[20]=""; |
jaspreetsingh | 0:f2467c077504 | 31 | char main_dir[100] =""; |
jaspreetsingh | 0:f2467c077504 | 32 | char hour_dir[100] =""; |
jaspreetsingh | 0:f2467c077504 | 33 | char pathAC[100] =""; |
jaspreetsingh | 0:f2467c077504 | 34 | char pathDC[100] =""; |
lalitkumar | 17:824537d9204b | 35 | //char pathDCdetect[100] =""; |
jaspreetsingh | 0:f2467c077504 | 36 | char pathfft[100]=""; |
jaspreetsingh | 0:f2467c077504 | 37 | //char putpathname[100]=""; |
jaspreetsingh | 0:f2467c077504 | 38 | char filenameAC[100] =""; |
jaspreetsingh | 0:f2467c077504 | 39 | char filenameDC[100] =""; |
jaspreetsingh | 0:f2467c077504 | 40 | char filenamefft[100] =""; |
jaspreetsingh | 0:f2467c077504 | 41 | char clk_response[100] =""; |
FahdAnsary | 9:7965c3bc3199 | 42 | char ftpget[100]=""; // For FTPGET Function |
FahdAnsary | 9:7965c3bc3199 | 43 | char ftpget1[100]=""; // For FTPGET Function |
jaspreetsingh | 16:622629b0cf3c | 44 | char ftpget2[100]=""; // For FTPGET Function |
FahdAnsary | 9:7965c3bc3199 | 45 | char mod_reset[50]= "NVIC_SystemReset();"; // For FTPGET Function |
jaspreetsingh | 16:622629b0cf3c | 46 | char incoming_data[150]=""; // For FTPGET Function |
FahdAnsary | 9:7965c3bc3199 | 47 | char dest[100]=""; // For FTPGET Function |
FahdAnsary | 9:7965c3bc3199 | 48 | const char s[2] = "!"; // For FTPGET Function |
FahdAnsary | 9:7965c3bc3199 | 49 | char src[100]=""; // For FTPGET Function |
FahdAnsary | 9:7965c3bc3199 | 50 | //char ftp_timestamp[20]=""; // For Timestamp.txt filename |
FahdAnsary | 9:7965c3bc3199 | 51 | char ftpputpathname[100]=""; // For FTPPUTHPATH NAME |
FahdAnsary | 9:7965c3bc3199 | 52 | char timestampname_old[30]=""; // For sending past hour info file |
FahdAnsary | 9:7965c3bc3199 | 53 | char timestamppath_old[30]=""; // For sending past hour info file |
FahdAnsary | 9:7965c3bc3199 | 54 | char timestampname[30]=""; |
FahdAnsary | 9:7965c3bc3199 | 55 | char timestamppath[30]=""; |
FahdAnsary | 9:7965c3bc3199 | 56 | int maxfreq = 0; // For Timestamp Function |
jaspreetsingh | 0:f2467c077504 | 57 | |
jaspreetsingh | 0:f2467c077504 | 58 | int m=0,mfinal; |
jaspreetsingh | 0:f2467c077504 | 59 | int date, month, year, hour, minute, second,minuteold, secondold, temp = 0; |
jaspreetsingh | 0:f2467c077504 | 60 | unsigned long var = 0; |
jaspreetsingh | 0:f2467c077504 | 61 | unsigned long currentMillis = 0; |
jaspreetsingh | 0:f2467c077504 | 62 | int gsmerr=0; |
jaspreetsingh | 4:668d7227d060 | 63 | |
jaspreetsingh | 0:f2467c077504 | 64 | time_t previous; |
jaspreetsingh | 0:f2467c077504 | 65 | |
jaspreetsingh | 0:f2467c077504 | 66 | int fft_array[32768];//={37767, 34339, 31062, 28224, 26011, 24245, 22588, 21757, 22460, 24288, 27136, 30535, 33829, 36639, 38848, 40598, 42239, 43047, 42302, 40468, 37592, 34182, 30924, 28082, 25922, 24153, 22509, 21739, 22534, 24403, 27302, 30689, 33965, 36774, 38946, 40688, 42324, 43064, 42222, 40351, 37424, 34013, 30787, 27940, 25834, 24067, 22432, 21742, 22605, 24522, 27466, 30863, 34102, 36908, 39018, 40773, 42396, 43057, 42166, 40210, 37256, 33851, 30656, 27800, 25746, 23996, 22353, 21752, 22675, 24648, 27636, 31024, 34230, 37052, 39113, 40859, 42468, 43052, 42090, 40095, 37085, 33682, 30524, 27675, 25656, 23904, 22285, 21744, 22739, 24772, 27811, 31199, 34377, 37176, 39206, 40933, 42546, 43037, 42017, 39960, 36916, 33518, 30383, 27553, 25570, 23822, 22218, 21765, 22825, 24910, 27970, 31355, 34516, 37293, 39292, 41021, 42615, 43033, 41936, 39822, 36733, 33359, 30240, 27444, 25487, 23731, 22146, 21769, 22897, 25052, 28145, 31520, 34655, 37403, 39378, 41105, 42682, 43039, 41858, 39687, 36566, 33192, 30094, 27327, 25399, 23655, 22073, 21777, 22989, 25194, 28323, 31692, 34805, 37512, 39456, 41191, 42744, 43019, 41768, 39560, 36389, 33026, 29941, 27223, 25317, 23580, 22016, 21803, 23077, 25320, 28498, 31841, 34950, 37621, 39537, 41268, 42797, 42995, 41686, 39427, 36223, 32858, 29798, 27112, 25246, 23496, 21971, 21828, 23160, 25454, 28663, 32023, 35091, 37721, 39618, 41345, 42840, 42979, 41595, 39295, 36042, 32717, 29648, 27010, 25158, 23417, 21929, 21846, 23241, 25591, 28832, 32141, 35248, 37826, 39716, 41415, 42890, 42949, 41508, 39157, 35874, 32582, 29495, 26901, 25076, 23346, 21884, 21888, 23343, 25723, 28993, 32307, 35390, 37934, 39790, 41488, 42925, 42903, 41406, 39030, 35723, 32404, 29355, 26803, 24986, 23272, 21852, 21935, 23436, 25863, 29158, 32473, 35530, 38037, 39868, 41566, 42958, 42852, 41319, 38884, 35553, 32248, 29201, 26701, 24900, 23188, 21834, 21983, 23515, 26001, 29320, 32636, 35672, 38141, 39962, 41655, 42972, 42810, 41229, 38759, 35378, 32087, 29059, 26601, 24811, 23105, 21809, 22027, 23618, 26136, 29491, 32806, 35820, 38239, 40047, 41727, 42999, 42757, 41130, 38608, 35221, 31912, 28911, 26501, 24729, 23032, 21794, 22089, 23713, 26298, 29641, 32995, 35956, 38344, 40128, 41805, 43016, 42688, 41028, 38463, 35065, 31730, 28779, 26413, 24643, 22931, 21778, 22154, 23809, 26440, 29802, 33164, 36082, 38442, 40227, 41899, 43025, 42627, 40930, 38304, 34903, 31562, 28651, 26320, 24546, 22839, 21770, 22224, 23914, 26596, 29971, 33327, 36205, 38539, 40315, 41985, 43031, 42559, 40833, 38153, 34719, 31410, 28515, 26226, 24450, 22763, 21755, 22291, 24021, 26764, 30153, 33492, 36334, 38624, 40409, 42068, 43033, 42473, 40722, 37981, 34554, 31252, 28403, 26130, 24361, 22680, 21756, 22360, 24149, 26928, 30318, 33645, 36465, 38732, 40493, 42148, 43048, 42416, 40609, 37804, 34390, 31095, 28260, 26034, 24272, 22605, 21748, 22438, 24252, 27087, 30487, 33780, 36596, 38826, 40578, 42212, 43049, 42342, 40491, 37644, 34223, 30958, 28119, 25949, 24193, 22538, 21743, 22516, 24371, 27257, 30645, 33927, 36742, 38915, 40661, 42298, 43058, 42254, 40377, 37472, 34056, 30822, 27973, 25853, 24095, 22461, 21736, 22578, 24485, 27427, 30817, 34064, 36885, 39007, 40754, 42379, 43062, 42186, 40250, 37306, 33892, 30686, 27834, 25766, 24012, 22381, 21740, 22661, 24613, 27601, 30971, 34198, 37003, 39098, 40823, 42451, 43054, 42107, 40122, 37132, 33733, 30548, 27703, 25675, 23923, 22298, 21749, 22723, 24738, 27767, 31154, 34344, 37149, 39177, 40920, 42527, 43053, 42035, 39999, 36967, 33570, 30405, 27579, 25589, 23843, 22226, 21750, 22802, 24872, 27942, 31312, 34487, 37275, 39276, 41002, 42602, 43044, 41964, 39853, 36775, 33388, 30267, 27468, 25508, 23758, 22161, 21760, 22876, 25017, 28132, 31492, 34625, 37377, 39353, 41087, 42673, 43035, 41879, 39724, 36611, 33232, 30123, 27356, 25420, 23671, 22082, 21769, 22960, 25153, 28291, 31655, 34762, 37497, 39436, 41171, 42730, 43030, 41794, 39586, 36427, 33073, 29978, 27247, 25331, 23593, 22025, 21781, 23052, 25286, 28463, 31814, 34918, 37592, 39524, 41247, 42785, 43012, 41708, 39453, 36258, 32912, 29822, 27138, 25249, 23517, 21973, 21799, 23135, 25424, 28629, 31970, 35073, 37709, 39615, 41330, 42836, 42995, 41620, 39315, 36077, 32745, 29669, 27034, 25191, 23437, 21925, 21830, 23222, 25563, 28797, 32137, 35208, 37821, 39688, 41407, 42877, 42958, 41574, 39183, 35908, 32593, 29529, 26921, 25084, 23355, 21888, 21872, 23324, 25701, 28966, 32285, 35359, 37917, 39785, 41486, 42912, 42925, 41440, 39041, 35744, 32444, 29380, 26820, 24997, 23274, 21860, 21910, 23410, 25839, 29133, 32438, 35505, 38025, 39853, 41550, 42945, 42870, 41341, 38904, 35579, 32292, 29225, 26720, 24921, 23208, 21831, 21969, 23510, 25982, 29290, 32604, 35645, 38122, 39944, 41627, 42969, 42826, 41248, 38768, 35416, 32127, 29075, 26612, 24827, 23121, 21808, 22020, 23602, 26115, 29461, 32775, 35796, 38225, 40030, 41719, 42997, 42763, 41142, 38629, 35248, 31935, 28938, 26524, 24743, 23039, 21794, 22084, 23698, 26271, 29616, 32967, 35921, 38322, 40109, 41798, 43001, 42705, 41053, 38484, 35095, 31768, 28794, 26428, 24644, 22954, 21781, 22136, 23800, 26431, 29785, 33142, 36060, 38435, 40209, 41877, 43022, 42645, 40950, 38308, 34923, 31600, 28677, 26330, 24564, 22862, 21770, 22201, 23898, 26577, 29947, 33302, 36191, 38527, 40297, 41974, 43032, 42572, 40839, 38160, 34763, 31432, 28541, 26241, 24472, 22770, 21758, 22280, 24004, 26741, 30117, 33465, 36324, 38619, 40393, 42062, 43043, 42494, 40738, 37996, 34606, 31268, 28406, 26148, 24377, 22685, 21747, 22359, 24116, 26903, 30292, 33626, 36453, 38702, 40486, 42145, 43042, 42427, 40636, 37828, 34424, 31128, 28272, 26056, 24292, 22617, 21749, 22425, 24226, 27060, 30455, 33772, 36579, 38811, 40569, 42216, 43047, 42343, 40526, 37652, 34251, 30980, 28134, 25962, 24203, 22538, 21748, 22497, 24334, 27233, 30636, 33906, 36731, 38904, 40654, 42294, 43050, 42264, 40407, 37493, 34083, 30850, 27979, 25871, 24104, 22462, 21741, 22562, 24463, 27400, 30800, 34050, 36873, 38991, 40745, 42376, 43057, 42203, 40274, 37323, 33913, 30717, 27836, 25778, 24018, 22392, 21740, 22638, 24593, 27572, 30958, 34182, 36999, 39082, 40827, 42444, 43052, 42130, 40147, 37185, 33751, 30579, 27712, 25689, 23936, 22315, 21733, 22711, 24726, 27744, 31128, 34319, 37133, 39174, 40909, 42518, 43057, 42048, 40013, 36980, 33586, 30433, 27596, 25607, 23852, 22242, 21745, 22786, 24858, 27913, 31304, 34444, 37266, 39251, 40995, 42605, 43048, 41967, 39876, 36817, 33397, 30313, 27467, 25520, 23781, 22152, 21755, 22872, 24990, 28082, 31479, 34590, 37369, 39344, 41070, 42676, 43042, 41893, 39750, 36644, 33236, 30159, 27364, 25434, 23698, 22082, 21773, 22947, 25129, 28256, 31645, 34733, 37483, 39438, 41138, 42741, 43021, 41815, 39606, 36470, 33074, 30011, 27247, 25338, 23619, 22018, 21788, 23038, 25281, 28427, 31804, 34883, 37589, 39528, 41222, 42799, 42991, 41711, 39466, 36293, 32914, 29851, 27159, 25256, 23543, 21963, 21813, 23117, 25421, 28599, 31966, 35030, 37699, 39604, 41310, 42845, 42987, 41633, 39326, 36117, 32761, 29696, 27048, 25178, 23459, 21913, 21853, 23210, 25559, 28764, 32121, 35190, 37790, 39668, 41375, 42891, 42946, 41534, 39196, 35949, 32611, 29544, 26944, 25086, 23384, 21880, 21891, 23304, 25696, 28940, 32274, 35340, 37896, 39778, 41450, 42930, 42891, 41455, 39054, 35780, 32455, 29402, 26845, 25003, 23305, 21850, 21941, 23385, 25829, 29108, 32414, 35493, 37998, 39867, 41538, 42960, 42853, 41372, 38918, 35598, 32301, 29237, 26740, 24905, 23236, 21825, 21996, 23478, 25973, 29276, 32578, 35636, 38101, 39955, 41603, 42981, 42798, 41270, 38769, 35438, 32147, 29090, 26644, 24818, 23154, 21803, 22046, 23577, 26105, 29437, 32753, 35780, 38195, 40046, 41686, 43002, 42748, 41181, 38637, 35270, 31972, 28946, 26540, 24729, 23070, 21784, 22090, 23672, 26263, 29600, 32928, 35923, 38303, 40124, 41763, 43022, 42692, 41074, 38488, 35109, 31792, 28800, 26454, 24644, 22979, 21767, 22160, 23766, 26411, 29762, 33111, 36054, 38392, 40214, 41858, 43034, 42628, 40970, 38337, 34937, 31640, 28662, 26374, 24554, 22888, 21760, 22224, 23871, 26565, 29936, 33262, 36188, 38484, 40306, 41949, 43044, 42549, 40874, 38187, 34765, 31476, 28537, 26273, 24458, 22797, 21755, 22293, 23971, 26718, 30114, 33422, 36324, 38589, 40397, 42037, 43050, 42478, 40765, 38012, 34592, 31319, 28415, 26174, 24365, 22716, 21745, 22364, 24083, 26880, 30288, 33579, 36444, 38683, 40478, 42111, 43051, 42411, 40659, 37853, 34422, 31166, 28287, 26072, 24290, 22645, 21746, 22435, 24200, 27051, 30456, 33727, 36587, 38777, 40564, 42188, 43061, 42332, 40544, 37684, 34241, 31023, 28138, 25979, 24202, 22562, 21736, 22510, 24316, 27218, 30627, 33874, 36717, 38881, 40650, 42271, 43065, 42262, 40418, 37516, 34082, 30883, 27986, 25891, 24115, 22486, 21733, 22586, 24440, 27373, 30778, 34011, 36848, 38970, 40727, 42351, 43061, 42184, 40293, 37352, 33921, 30749, 27849, 25801, 24030, 22397, 21741, 22656, 24573, 27550, 30960, 34144, 36988, 39050, 40808, 42427, 43053, 42104, 40173, 37190, 33759, 30618, 27727, 25713, 23956, 22321, 21745, 22723, 24686, 27700, 31121, 34273, 37127, 39155, 40906, 42515, 43054, 42049, 40037, 37003, 33582, 30481, 27603, 25618, 23870, 22244, 21752, 22795, 24834, 27881, 31283, 34419, 37241, 39239, 40965, 42587, 43046, 41970, 39910, 36842, 33427, 30336, 27486, 25523, 23788, 22167, 21763, 22859, 24982, 28056, 31458, 34565, 37359, 39331, 41051, 42660, 43038, 41897, 39754, 36671, 33251, 30189, 27381, 25450, 23713, 22092, 21772, 22943, 25119, 28232, 31625, 34711, 37462, 39413, 41133, 42725, 43020, 41806, 39631, 36497, 33078, 30038, 27270, 25363, 23622, 22030, 21793, 23027, 25251, 28398, 31795, 34858, 37568, 39494, 41218, 42791, 43005, 41728, 39486, 36319, 32923, 29880, 27167, 25279, 23547, 21975, 21823, 23112, 25387, 28584, 31967, 35015, 37671, 39590, 41304, 42840, 42977, 41646, 39350, 36129, 32761, 29723, 27061, 25181, 23463, 21923, 21847, 23198, 25542, 28753, 32110, 35175, 37780, 39687, 41367, 42888, 42965, 41554, 39192, 35956, 32615, 29574, 26952, 25099, 23395, 21886, 21885, 23295, 25686, 28923, 32259, 35320, 37886, 39766, 41449, 42924, 42905, 41452, 39062, 35787, 32454, 29411, 26846, 25005, 23314, 21849, 21935, 23394, 25824, 29094, 32420, 35480, 37982, 39864, 41529, 42962, 42850, 41378, 38922, 35613, 32315, 29255, 26748, 24908, 23231, 21817, 21979, 23463, 25980, 29265, 32573, 35635, 38092, 39954, 41609, 42983, 42806, 41284, 38788, 35444, 32154, 29102, 26647, 24831, 23158, 21803, 22038, 23562, 26104, 29426, 32740, 35778, 38189, 40035, 41672, 43003, 42758, 41188, 38646, 35286, 31986, 28959, 26548, 24738, 23078, 21785, 22092, 23659, 26251, 29596, 32920, 35918, 38289, 40114, 41760, 43019, 42695, 41085, 38501, 35119, 31809, 28814, 26461, 24658, 22986, 21771, 22143, 23759, 26388, 29759, 33093, 36053, 38386, 40210, 41850, 43032, 42629, 40981, 38356, 34947, 31639, 28684, 26371, 24555, 22896, 21758, 22219, 23855, 26546, 29922, 33252, 36181, 38485, 40299, 41940, 43041, 42539, 40899, 38186, 34776, 31492, 28569, 26280, 24470, 22814, 21750, 22279, 23963, 26709, 30091, 33420, 36319, 38589, 40392, 42029, 43051, 42496, 40762, 38023, 34613, 31330, 28419, 26178, 24374, 22723, 21744, 22345, 24068, 26866, 30262, 33563, 36441, 38680, 40488, 42113, 43056, 42422, 40670, 37860, 34441, 31170, 28291, 26083, 24288, 22650, 21739, 22429, 24180, 27038, 30440, 33720, 36585, 38781, 40566, 42190, 43051, 42349, 4055}; |
jaspreetsingh | 0:f2467c077504 | 67 | unsigned short ACdata[fft_points]; |
jaspreetsingh | 0:f2467c077504 | 68 | unsigned short DCdata[fft_points]; |
jaspreetsingh | 0:f2467c077504 | 69 | unsigned short DC_Detect_data[10]; |
jaspreetsingh | 0:f2467c077504 | 70 | unsigned short Temp_data[10]; |
jaspreetsingh | 0:f2467c077504 | 71 | uint32_t dataLength = dur_sec*freq*1000; |
lalitkumar | 18:4e3aa33674c8 | 72 | int avg_dc_detect[2]; |
lalitkumar | 18:4e3aa33674c8 | 73 | int avg_temp[2]; |
jaspreetsingh | 0:f2467c077504 | 74 | |
jaspreetsingh | 0:f2467c077504 | 75 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 76 | // Module reset // |
jaspreetsingh | 0:f2467c077504 | 77 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 78 | void reset_mod() |
jaspreetsingh | 0:f2467c077504 | 79 | { |
jaspreetsingh | 0:f2467c077504 | 80 | NVIC_SystemReset(); |
jaspreetsingh | 0:f2467c077504 | 81 | } |
jaspreetsingh | 0:f2467c077504 | 82 | |
pravinmagar | 20:764af4c48cf2 | 83 | |
pravinmagar | 20:764af4c48cf2 | 84 | |
pravinmagar | 20:764af4c48cf2 | 85 | |
pravinmagar | 20:764af4c48cf2 | 86 | |
jaspreetsingh | 0:f2467c077504 | 87 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 88 | // Send AT Command (1 response with clk variable) // |
jaspreetsingh | 0:f2467c077504 | 89 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 90 | int sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout, int clk_flag) |
jaspreetsingh | 0:f2467c077504 | 91 | { |
jaspreetsingh | 0:f2467c077504 | 92 | int grs=0; |
FahdAnsary | 12:0ab0a2578025 | 93 | int answer=0; //x=0 and answer=0, if not put, AT+CCLK?\r is not executed |
jaspreetsingh | 0:f2467c077504 | 94 | char response[300]; |
jaspreetsingh | 0:f2467c077504 | 95 | memset(response, '\0', 100); // Initialize the string |
jaspreetsingh | 0:f2467c077504 | 96 | wait_ms(100); |
jaspreetsingh | 0:f2467c077504 | 97 | previous = time(NULL); |
jaspreetsingh | 0:f2467c077504 | 98 | char dummy; |
FahdAnsary | 9:7965c3bc3199 | 99 | do |
FahdAnsary | 9:7965c3bc3199 | 100 | { |
FahdAnsary | 9:7965c3bc3199 | 101 | if(gsm.readable()!=0) |
FahdAnsary | 9:7965c3bc3199 | 102 | { |
jaspreetsingh | 0:f2467c077504 | 103 | dummy=gsm.getc(); |
jaspreetsingh | 0:f2467c077504 | 104 | //pc.putc(dummy); |
FahdAnsary | 9:7965c3bc3199 | 105 | } |
FahdAnsary | 9:7965c3bc3199 | 106 | } |
FahdAnsary | 12:0ab0a2578025 | 107 | while((time(NULL) - previous) < 1); // Clean the input buffer |
jaspreetsingh | 0:f2467c077504 | 108 | //pc.printf("\r\n"); |
jaspreetsingh | 0:f2467c077504 | 109 | gsm.printf("%s \r", ATcommand); // Send the AT command |
jaspreetsingh | 0:f2467c077504 | 110 | grs = 0; |
jaspreetsingh | 0:f2467c077504 | 111 | previous = time(NULL); |
FahdAnsary | 9:7965c3bc3199 | 112 | do |
FahdAnsary | 12:0ab0a2578025 | 113 | { // this loop waits for the answer |
FahdAnsary | 9:7965c3bc3199 | 114 | if(gsm.readable() != 0) |
FahdAnsary | 9:7965c3bc3199 | 115 | { |
FahdAnsary | 12:0ab0a2578025 | 116 | response[grs] = gsm.getc(); // if there are data in the UART input buffer, reads it and checks for the asnwer |
jaspreetsingh | 0:f2467c077504 | 117 | pc.putc(response[grs]); |
jaspreetsingh | 0:f2467c077504 | 118 | grs++; |
FahdAnsary | 9:7965c3bc3199 | 119 | if (strstr(response, expected_answer) != NULL) |
FahdAnsary | 12:0ab0a2578025 | 120 | { // check if the desired answer is in the response of the module |
jaspreetsingh | 0:f2467c077504 | 121 | if(clk_flag==2) answer=2; |
jaspreetsingh | 0:f2467c077504 | 122 | else answer=1; |
jaspreetsingh | 0:f2467c077504 | 123 | } |
FahdAnsary | 9:7965c3bc3199 | 124 | } |
FahdAnsary | 12:0ab0a2578025 | 125 | } while((answer !=1) && ((time(NULL) - previous) < timeout)); // Waits for the asnwer with time out |
FahdAnsary | 9:7965c3bc3199 | 126 | if(clk_flag == 1) |
FahdAnsary | 9:7965c3bc3199 | 127 | { |
jaspreetsingh | 0:f2467c077504 | 128 | //pc.printf("\r\nclock updated\r\n"); |
jaspreetsingh | 0:f2467c077504 | 129 | sprintf(timestamp,response); |
FahdAnsary | 12:0ab0a2578025 | 130 | pc.printf("%s",timestamp); //copies response to timestamp for further processing |
jaspreetsingh | 0:f2467c077504 | 131 | } |
jaspreetsingh | 0:f2467c077504 | 132 | //pc.printf("\r\nanswer %d\r\n",answer); |
jaspreetsingh | 0:f2467c077504 | 133 | return answer; |
jaspreetsingh | 0:f2467c077504 | 134 | } |
pravinmagar | 20:764af4c48cf2 | 135 | |
pravinmagar | 20:764af4c48cf2 | 136 | //--------------------------------------------------------------------------------------------------// |
pravinmagar | 20:764af4c48cf2 | 137 | // iteration |
pravinmagar | 20:764af4c48cf2 | 138 | //--------------------------------------------------------------------------------------------------// |
pravinmagar | 20:764af4c48cf2 | 139 | |
pravinmagar | 20:764af4c48cf2 | 140 | bool iteration_send_ATcommand(char* ATcommand, char* expected_answer, unsigned int timeout, int clk_flag,int attempts) |
pravinmagar | 20:764af4c48cf2 | 141 | { |
pravinmagar | 20:764af4c48cf2 | 142 | for(int i=0; i < attempts; i++) |
pravinmagar | 20:764af4c48cf2 | 143 | { |
pravinmagar | 20:764af4c48cf2 | 144 | if(sendATcommand(ATcommand,expected_answer,timeout,clk_flag)) |
pravinmagar | 20:764af4c48cf2 | 145 | { |
pravinmagar | 20:764af4c48cf2 | 146 | return 1; |
pravinmagar | 20:764af4c48cf2 | 147 | } |
pravinmagar | 20:764af4c48cf2 | 148 | } |
pravinmagar | 20:764af4c48cf2 | 149 | return 0 ; |
pravinmagar | 20:764af4c48cf2 | 150 | } |
FahdAnsary | 9:7965c3bc3199 | 151 | //--------------------------------------------------------------------------------------------------// |
FahdAnsary | 9:7965c3bc3199 | 152 | // Getting Timestamp Function // |
FahdAnsary | 9:7965c3bc3199 | 153 | //--------------------------------------------------------------------------------------------------// |
FahdAnsary | 9:7965c3bc3199 | 154 | |
FahdAnsary | 9:7965c3bc3199 | 155 | void GetTime() |
FahdAnsary | 9:7965c3bc3199 | 156 | { |
jaspreetsingh | 0:f2467c077504 | 157 | sendATcommand("AT+CCLK?\r", "OK", 5,1); |
jaspreetsingh | 0:f2467c077504 | 158 | //sprintf(response,timestamp); |
jaspreetsingh | 0:f2467c077504 | 159 | int x=20; |
jaspreetsingh | 0:f2467c077504 | 160 | year = 10*(timestamp[x+1]-48) + (timestamp[x+2]-48); |
jaspreetsingh | 0:f2467c077504 | 161 | month = (timestamp[x+4]-48)*10+(timestamp[x+5]-48); |
jaspreetsingh | 0:f2467c077504 | 162 | date = (timestamp[x+7]-48)*10+(timestamp[x+8]-48); |
jaspreetsingh | 0:f2467c077504 | 163 | hour = (timestamp[x+10]-48)*10+(timestamp[x+11]-48); |
jaspreetsingh | 0:f2467c077504 | 164 | minute = (timestamp[x+13]-48)*10+(timestamp[x+14]-48); |
jaspreetsingh | 0:f2467c077504 | 165 | second = (timestamp[x+16]-48)*10+(timestamp[x+17]-48); |
jaspreetsingh | 0:f2467c077504 | 166 | |
jaspreetsingh | 0:f2467c077504 | 167 | sprintf(time_stamp,"%02d%02d%02d%02d%02d%02d",year,month,date,hour,minute,second); |
FahdAnsary | 12:0ab0a2578025 | 168 | //pc.printf("Get time result:%s.....",time_stamp); |
FahdAnsary | 9:7965c3bc3199 | 169 | } |
jaspreetsingh | 8:12b4c521c033 | 170 | |
jaspreetsingh | 0:f2467c077504 | 171 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 172 | // Getting File Directories and names // |
jaspreetsingh | 0:f2467c077504 | 173 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 174 | void GetFileDir() |
jaspreetsingh | 0:f2467c077504 | 175 | { |
jaspreetsingh | 0:f2467c077504 | 176 | int attempt_cnt=0; |
jaspreetsingh | 0:f2467c077504 | 177 | char month_dir[100]=""; |
jaspreetsingh | 0:f2467c077504 | 178 | char date_dir[100] =""; |
jaspreetsingh | 0:f2467c077504 | 179 | GetTime(); |
FahdAnsary | 9:7965c3bc3199 | 180 | while(year<15||year>20) |
FahdAnsary | 9:7965c3bc3199 | 181 | { |
jaspreetsingh | 0:f2467c077504 | 182 | //pc.printf("%d\r\n",year); |
jaspreetsingh | 0:f2467c077504 | 183 | GetTime(); |
jaspreetsingh | 0:f2467c077504 | 184 | attempt_cnt++; |
jaspreetsingh | 0:f2467c077504 | 185 | if(attempt_cnt>4) break; |
jaspreetsingh | 0:f2467c077504 | 186 | } |
FahdAnsary | 12:0ab0a2578025 | 187 | if(year>14&&year<21&&month<13) |
FahdAnsary | 9:7965c3bc3199 | 188 | { |
FahdAnsary | 9:7965c3bc3199 | 189 | if((minute!=minuteold)||(second!=secondold)) |
FahdAnsary | 9:7965c3bc3199 | 190 | { |
jaspreetsingh | 0:f2467c077504 | 191 | sprintf(timestampold,timestamp); |
FahdAnsary | 12:0ab0a2578025 | 192 | |
FahdAnsary | 12:0ab0a2578025 | 193 | pc.printf("\r\nold time stamp is%s\r\n",timestampold); |
jaspreetsingh | 0:f2467c077504 | 194 | minuteold=minute; |
jaspreetsingh | 0:f2467c077504 | 195 | secondold=second; |
jaspreetsingh | 0:f2467c077504 | 196 | sprintf(main_dir,"/sd/%s",sitename); |
jaspreetsingh | 0:f2467c077504 | 197 | sprintf(month_dir,"%s/%s%02d%02d",main_dir,sitename,year,month); |
jaspreetsingh | 0:f2467c077504 | 198 | sprintf(date_dir,"%s/%s%02d%02d%02d",month_dir,sitename,year,month,date); |
jaspreetsingh | 0:f2467c077504 | 199 | sprintf(hour_dir,"%s/%s%02d%02d%02d%02d",date_dir,sitename,year,month,date,hour); |
jaspreetsingh | 0:f2467c077504 | 200 | sprintf(filepath,"%s/%s%02d%02d%02d%02d%02d%02d",hour_dir,sitename,year,month,date,hour,minute,second); |
jaspreetsingh | 0:f2467c077504 | 201 | sprintf(filename,"%s%02d%02d%02d%02d%02d%02d",sitename,year,month,date,hour,minute,second); |
jaspreetsingh | 13:73d6de10d15c | 202 | sprintf(ftpputpathname,"%s/%02d%02d/%02d/%02d",module_name,year,month,date,hour); // For FTPPUTPATHNAME feature |
jaspreetsingh | 5:11c455ebcc34 | 203 | //pc.printf("Ftpputpathname is %s\r\n",ftpputpathname); // For FTPPUTPATHNAME feature |
jaspreetsingh | 0:f2467c077504 | 204 | gsmerr=0; |
jaspreetsingh | 0:f2467c077504 | 205 | mkdir(main_dir,0777); |
jaspreetsingh | 0:f2467c077504 | 206 | mkdir(month_dir,0777); |
jaspreetsingh | 0:f2467c077504 | 207 | mkdir(date_dir,0777); |
jaspreetsingh | 0:f2467c077504 | 208 | mkdir(hour_dir,0777); |
FahdAnsary | 9:7965c3bc3199 | 209 | } |
FahdAnsary | 9:7965c3bc3199 | 210 | else |
FahdAnsary | 9:7965c3bc3199 | 211 | { |
jaspreetsingh | 0:f2467c077504 | 212 | sprintf(filepath,"%s/%s%02d%02d%02d%02d%02d%02dErr%03d",hour_dir,sitename,year,month,date,hour,minute,second,gsmerr); |
jaspreetsingh | 0:f2467c077504 | 213 | sprintf(filename,"%s%02d%02d%02d%02d%02d%02dErr%03d",sitename,year,month,date,hour,minute,second,gsmerr); |
jaspreetsingh | 0:f2467c077504 | 214 | gsmerr++; |
jaspreetsingh | 0:f2467c077504 | 215 | } |
FahdAnsary | 9:7965c3bc3199 | 216 | } |
FahdAnsary | 9:7965c3bc3199 | 217 | else |
FahdAnsary | 9:7965c3bc3199 | 218 | { |
jaspreetsingh | 0:f2467c077504 | 219 | sprintf(timestamp,timestampold); |
FahdAnsary | 12:0ab0a2578025 | 220 | //pc.printf("\r\nTimestamp......%s\r\n",timestamp); |
FahdAnsary | 12:0ab0a2578025 | 221 | |
FahdAnsary | 12:0ab0a2578025 | 222 | sprintf(filepath,"%s/%s%02d%02dErr%03d",hour_dir,sitename,minuteold,secondold,gsmerr); |
FahdAnsary | 12:0ab0a2578025 | 223 | sprintf(filename,"%s%02d%02dErr%03d",sitename,minuteold,secondold,gsmerr); |
jaspreetsingh | 0:f2467c077504 | 224 | gsmerr++; |
jaspreetsingh | 0:f2467c077504 | 225 | } |
jaspreetsingh | 0:f2467c077504 | 226 | } |
jaspreetsingh | 0:f2467c077504 | 227 | |
jaspreetsingh | 0:f2467c077504 | 228 | //--------------------------------------------------------------------------------------------------// |
lalitkumar | 18:4e3aa33674c8 | 229 | // DC & Temp Detect // |
jaspreetsingh | 0:f2467c077504 | 230 | //--------------------------------------------------------------------------------------------------// |
lalitkumar | 18:4e3aa33674c8 | 231 | void DC_TC_Detection(short int k) //k limited by array size of avg_dc_detect & avg_temp |
jaspreetsingh | 0:f2467c077504 | 232 | { |
jaspreetsingh | 0:f2467c077504 | 233 | Timer t; |
jaspreetsingh | 0:f2467c077504 | 234 | int j=0; |
jaspreetsingh | 7:3d5fd645c11d | 235 | ADC0_CFG2=ADC0_CFG2||0x10; |
jaspreetsingh | 0:f2467c077504 | 236 | t.start(); |
FahdAnsary | 9:7965c3bc3199 | 237 | while(j<10) |
FahdAnsary | 9:7965c3bc3199 | 238 | { |
FahdAnsary | 9:7965c3bc3199 | 239 | if((int)(t.read()*50*freq*1000)%100 == 0) |
FahdAnsary | 9:7965c3bc3199 | 240 | { |
jaspreetsingh | 0:f2467c077504 | 241 | DC_Detect_data[j] = DC_Detect.read_u16(); |
jaspreetsingh | 7:3d5fd645c11d | 242 | Temp_data[j] = TC1.read_u16(); |
jaspreetsingh | 0:f2467c077504 | 243 | ++j; |
jaspreetsingh | 0:f2467c077504 | 244 | } |
jaspreetsingh | 0:f2467c077504 | 245 | } |
jaspreetsingh | 0:f2467c077504 | 246 | t.stop(); |
FahdAnsary | 9:7965c3bc3199 | 247 | //pc.printf("\r\nTemp Time Taken %f \n\r", t.read()); |
jaspreetsingh | 0:f2467c077504 | 248 | t.reset(); |
lalitkumar | 18:4e3aa33674c8 | 249 | avg_dc_detect[k]=0; |
lalitkumar | 18:4e3aa33674c8 | 250 | avg_temp[k]=0; |
lalitkumar | 18:4e3aa33674c8 | 251 | for(int i=0; i<10; i++) |
lalitkumar | 18:4e3aa33674c8 | 252 | { |
lalitkumar | 18:4e3aa33674c8 | 253 | avg_dc_detect[k]=avg_dc_detect[k]+int(DC_Detect_data[i]); |
lalitkumar | 18:4e3aa33674c8 | 254 | avg_temp[k]=avg_temp[k]+int(Temp_data[i]); |
lalitkumar | 18:4e3aa33674c8 | 255 | } |
lalitkumar | 18:4e3aa33674c8 | 256 | avg_dc_detect[k]=avg_dc_detect[k]/10; |
lalitkumar | 18:4e3aa33674c8 | 257 | avg_temp[k]=avg_temp[k]/10; |
jaspreetsingh | 0:f2467c077504 | 258 | // pc.printf("Total Samples %d\r\n",j); |
jaspreetsingh | 0:f2467c077504 | 259 | } |
jaspreetsingh | 0:f2467c077504 | 260 | |
jaspreetsingh | 0:f2467c077504 | 261 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 262 | // AC-DC Sampling // |
jaspreetsingh | 0:f2467c077504 | 263 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 264 | void calculate_ADC() |
jaspreetsingh | 0:f2467c077504 | 265 | { |
jaspreetsingh | 0:f2467c077504 | 266 | Timer t; |
jaspreetsingh | 0:f2467c077504 | 267 | int j=0; |
jaspreetsingh | 0:f2467c077504 | 268 | pc.printf("\n\rStarting Reading \n\r"); |
jaspreetsingh | 0:f2467c077504 | 269 | t.start(); |
FahdAnsary | 9:7965c3bc3199 | 270 | while(j<dataLength) |
FahdAnsary | 9:7965c3bc3199 | 271 | { |
FahdAnsary | 9:7965c3bc3199 | 272 | if((int)(t.read()*100*freq*1000)%100 == 0) |
FahdAnsary | 9:7965c3bc3199 | 273 | { |
jaspreetsingh | 0:f2467c077504 | 274 | ACdata[j] = AC_input.read_u16(); |
jaspreetsingh | 0:f2467c077504 | 275 | DCdata[j] = DC_input.read_u16(); |
jaspreetsingh | 0:f2467c077504 | 276 | ++j; |
jaspreetsingh | 0:f2467c077504 | 277 | } |
jaspreetsingh | 0:f2467c077504 | 278 | } |
jaspreetsingh | 0:f2467c077504 | 279 | t.stop(); |
jaspreetsingh | 0:f2467c077504 | 280 | //pc.printf("Time Taken %f \n\r", t.read()); |
jaspreetsingh | 0:f2467c077504 | 281 | t.reset(); |
jaspreetsingh | 0:f2467c077504 | 282 | //pc.printf("Total Samples %d\r\n",j); |
jaspreetsingh | 0:f2467c077504 | 283 | } |
jaspreetsingh | 0:f2467c077504 | 284 | |
jaspreetsingh | 0:f2467c077504 | 285 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 286 | // Sampling Function // |
jaspreetsingh | 0:f2467c077504 | 287 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 288 | |
jaspreetsingh | 0:f2467c077504 | 289 | void sampling() |
jaspreetsingh | 0:f2467c077504 | 290 | { |
jaspreetsingh | 0:f2467c077504 | 291 | pc.printf("\r\nSampling attempt"); |
lalitkumar | 18:4e3aa33674c8 | 292 | DC_TC_Detection(0); |
jaspreetsingh | 0:f2467c077504 | 293 | calculate_ADC(); |
lalitkumar | 18:4e3aa33674c8 | 294 | DC_TC_Detection(1); |
jaspreetsingh | 0:f2467c077504 | 295 | } |
FahdAnsary | 9:7965c3bc3199 | 296 | //--------------------------------------------------------------------------------------------------// |
FahdAnsary | 9:7965c3bc3199 | 297 | // FFT Function // |
FahdAnsary | 9:7965c3bc3199 | 298 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 299 | |
jaspreetsingh | 0:f2467c077504 | 300 | void fft(short N, short start_index, short step, int loop) |
jaspreetsingh | 0:f2467c077504 | 301 | { |
FahdAnsary | 9:7965c3bc3199 | 302 | if(N==2048) |
FahdAnsary | 9:7965c3bc3199 | 303 | { |
jaspreetsingh | 0:f2467c077504 | 304 | float input_2048[2048]; |
FahdAnsary | 9:7965c3bc3199 | 305 | for (short i=0; i<2048; i++) |
FahdAnsary | 9:7965c3bc3199 | 306 | { |
jaspreetsingh | 0:f2467c077504 | 307 | input_2048[i]=float(fft_array[(start_index+i*step)]); |
jaspreetsingh | 0:f2467c077504 | 308 | } |
jaspreetsingh | 0:f2467c077504 | 309 | float output_4096[4096]; |
jaspreetsingh | 0:f2467c077504 | 310 | arm_rfft_instance_f32 SR; |
jaspreetsingh | 0:f2467c077504 | 311 | arm_cfft_radix4_instance_f32 SR_CFFT; |
jaspreetsingh | 0:f2467c077504 | 312 | arm_status status=arm_rfft_init_f32(&SR, &SR_CFFT, 2048, 0, 1); |
jaspreetsingh | 0:f2467c077504 | 313 | arm_rfft_f32(&SR, input_2048, output_4096); |
FahdAnsary | 9:7965c3bc3199 | 314 | for (short i=0; i<4096; i++) |
FahdAnsary | 9:7965c3bc3199 | 315 | { |
jaspreetsingh | 0:f2467c077504 | 316 | fft_array[start_index+i*step]=int(output_4096[i]); |
jaspreetsingh | 0:f2467c077504 | 317 | } |
jaspreetsingh | 0:f2467c077504 | 318 | return; |
FahdAnsary | 9:7965c3bc3199 | 319 | } |
FahdAnsary | 9:7965c3bc3199 | 320 | else |
FahdAnsary | 9:7965c3bc3199 | 321 | { |
jaspreetsingh | 0:f2467c077504 | 322 | fft(N/2, start_index, step*2,0); |
jaspreetsingh | 0:f2467c077504 | 323 | fft(N/2, start_index+step, step*2,0); |
jaspreetsingh | 0:f2467c077504 | 324 | float output_data1[2]; |
jaspreetsingh | 0:f2467c077504 | 325 | float output_data2[2]; |
jaspreetsingh | 0:f2467c077504 | 326 | float output_data3[2]; |
jaspreetsingh | 0:f2467c077504 | 327 | float output_data4[2]; |
jaspreetsingh | 0:f2467c077504 | 328 | output_data3[0]=fft_array[start_index]; |
jaspreetsingh | 0:f2467c077504 | 329 | output_data3[1]=fft_array[start_index+2*step]; |
jaspreetsingh | 0:f2467c077504 | 330 | output_data4[0]=fft_array[start_index+step]; |
jaspreetsingh | 0:f2467c077504 | 331 | output_data4[1]=fft_array[start_index+3*step]; |
jaspreetsingh | 0:f2467c077504 | 332 | fft_array[start_index]=output_data3[0]+output_data4[0]; |
jaspreetsingh | 0:f2467c077504 | 333 | fft_array[start_index+step]=output_data3[1]+output_data4[1]; |
FahdAnsary | 9:7965c3bc3199 | 334 | for(int i=1; i<N/2; i++) |
FahdAnsary | 9:7965c3bc3199 | 335 | { |
jaspreetsingh | 0:f2467c077504 | 336 | output_data1[0]=float(fft_array[start_index+4*(i)*step]); |
jaspreetsingh | 0:f2467c077504 | 337 | output_data1[1]=float(fft_array[start_index+(4*(i)+2)*step]); |
jaspreetsingh | 0:f2467c077504 | 338 | output_data2[0]=float(fft_array[start_index+(4*(i)+1)*step]); |
jaspreetsingh | 0:f2467c077504 | 339 | output_data2[1]=float(fft_array[start_index+(4*(i)+3)*step]); |
jaspreetsingh | 0:f2467c077504 | 340 | fft_array[start_index+2*i*step]=int(output_data1[0]+(output_data2[0]*cos(2*i*3.142/N))-(output_data2[1]*sin(-2*i*3.142/N))); |
jaspreetsingh | 0:f2467c077504 | 341 | fft_array[start_index+(2*i+1)*step]=int(output_data1[1]+(output_data2[0]*sin(-2*i*3.142/N))+(output_data2[1]*cos(2*i*3.142/N))); |
jaspreetsingh | 0:f2467c077504 | 342 | } |
jaspreetsingh | 0:f2467c077504 | 343 | fft_array[start_index+N*step]=output_data3[0]-output_data4[0]; |
jaspreetsingh | 0:f2467c077504 | 344 | fft_array[start_index+(N+1)*step]=output_data3[1]-output_data4[1]; |
FahdAnsary | 9:7965c3bc3199 | 345 | if(loop==0) |
FahdAnsary | 9:7965c3bc3199 | 346 | { |
FahdAnsary | 9:7965c3bc3199 | 347 | for(int i=N/2+1; i<N; i++) |
FahdAnsary | 9:7965c3bc3199 | 348 | { |
jaspreetsingh | 0:f2467c077504 | 349 | fft_array[start_index+2*i*step]=fft_array[start_index+2*(N-i)*step]; |
jaspreetsingh | 0:f2467c077504 | 350 | fft_array[start_index+(2*i+1)*step]=-1*fft_array[start_index+(2*(N-i)+1)*step]; |
jaspreetsingh | 0:f2467c077504 | 351 | } |
jaspreetsingh | 0:f2467c077504 | 352 | } |
FahdAnsary | 9:7965c3bc3199 | 353 | if(loop==1) |
FahdAnsary | 9:7965c3bc3199 | 354 | { |
FahdAnsary | 9:7965c3bc3199 | 355 | for(short i=0; i<8193; i++) |
FahdAnsary | 9:7965c3bc3199 | 356 | { |
jaspreetsingh | 0:f2467c077504 | 357 | fft_array[i]=int(sqrt((double(fft_array[2*i])*double(fft_array[2*i]))+(double(fft_array[2*i+1])*double(fft_array[2*i+1])))); |
jaspreetsingh | 0:f2467c077504 | 358 | } |
jaspreetsingh | 0:f2467c077504 | 359 | } |
jaspreetsingh | 0:f2467c077504 | 360 | return; |
jaspreetsingh | 0:f2467c077504 | 361 | } |
jaspreetsingh | 0:f2467c077504 | 362 | } |
FahdAnsary | 9:7965c3bc3199 | 363 | //--------------------------------------------------------------------------------------------------// |
FahdAnsary | 9:7965c3bc3199 | 364 | // FFT Max Function // |
FahdAnsary | 9:7965c3bc3199 | 365 | //--------------------------------------------------------------------------------------------------// |
FahdAnsary | 9:7965c3bc3199 | 366 | |
jaspreetsingh | 0:f2467c077504 | 367 | void fft_max(int start_index, int number_count, int maximal_count, uint32_t* maximum_index, float* maximum_value) |
jaspreetsingh | 0:f2467c077504 | 368 | { |
jaspreetsingh | 0:f2467c077504 | 369 | float maximal_array[number_count]; |
FahdAnsary | 9:7965c3bc3199 | 370 | for (int i=0; i<number_count; i++) |
FahdAnsary | 9:7965c3bc3199 | 371 | { |
jaspreetsingh | 0:f2467c077504 | 372 | maximal_array[i]=float(fft_array[start_index+i]); |
jaspreetsingh | 0:f2467c077504 | 373 | } |
FahdAnsary | 9:7965c3bc3199 | 374 | for(int i=0; i<maximal_count; i++) |
FahdAnsary | 9:7965c3bc3199 | 375 | { |
jaspreetsingh | 0:f2467c077504 | 376 | arm_max_f32(maximal_array,number_count,&maximum_value[i],&maximum_index[i]); |
jaspreetsingh | 0:f2467c077504 | 377 | maximal_array[maximum_index[i]]=0; |
jaspreetsingh | 0:f2467c077504 | 378 | maximum_index[i]=start_index+maximum_index[i]; |
jaspreetsingh | 0:f2467c077504 | 379 | } |
jaspreetsingh | 0:f2467c077504 | 380 | } |
FahdAnsary | 9:7965c3bc3199 | 381 | //--------------------------------------------------------------------------------------------------// |
FahdAnsary | 9:7965c3bc3199 | 382 | // FFT Array Prepare // |
FahdAnsary | 9:7965c3bc3199 | 383 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 384 | |
jaspreetsingh | 0:f2467c077504 | 385 | void prepare_fft_array(int* start_index, int* points_count, int* maximas_required, int segments, int fft_type) |
jaspreetsingh | 0:f2467c077504 | 386 | { |
jaspreetsingh | 0:f2467c077504 | 387 | int max_points_count=0; |
FahdAnsary | 9:7965c3bc3199 | 388 | for (int i=0; i<segments; i++) |
FahdAnsary | 9:7965c3bc3199 | 389 | { |
jaspreetsingh | 0:f2467c077504 | 390 | max_points_count=max_points_count+maximas_required[i]; |
jaspreetsingh | 0:f2467c077504 | 391 | } |
jaspreetsingh | 0:f2467c077504 | 392 | uint32_t index[max_points_count]; |
jaspreetsingh | 0:f2467c077504 | 393 | float maxima[max_points_count]; |
jaspreetsingh | 0:f2467c077504 | 394 | int j=0; |
FahdAnsary | 9:7965c3bc3199 | 395 | for (int i=0; i<segments; i++) |
FahdAnsary | 9:7965c3bc3199 | 396 | { |
jaspreetsingh | 0:f2467c077504 | 397 | fft_max(start_index[i],points_count[i],maximas_required[i],&index[j],&maxima[j]); |
jaspreetsingh | 0:f2467c077504 | 398 | j=j+maximas_required[i]; |
jaspreetsingh | 0:f2467c077504 | 399 | } |
jaspreetsingh | 0:f2467c077504 | 400 | FILE *fp = fopen(pathfft, "a"); |
FahdAnsary | 9:7965c3bc3199 | 401 | if(fp == NULL) |
FahdAnsary | 9:7965c3bc3199 | 402 | { |
jaspreetsingh | 0:f2467c077504 | 403 | pc.printf("Could not open file for write\n\r"); |
FahdAnsary | 12:0ab0a2578025 | 404 | mkdir("/sd/jas",0777); |
jaspreetsingh | 0:f2467c077504 | 405 | //reset_mod(); |
FahdAnsary | 9:7965c3bc3199 | 406 | } |
FahdAnsary | 9:7965c3bc3199 | 407 | else |
FahdAnsary | 9:7965c3bc3199 | 408 | { |
jaspreetsingh | 0:f2467c077504 | 409 | //fprintf(fp, "\r\n%s",timestamp); |
FahdAnsary | 9:7965c3bc3199 | 410 | for(int i=0; i<max_points_count; i++) |
FahdAnsary | 9:7965c3bc3199 | 411 | { |
jaspreetsingh | 8:12b4c521c033 | 412 | |
jaspreetsingh | 14:83b823fdcdd0 | 413 | fprintf(fp,"\n%d %d",index[i], int(maxima[i])); |
FahdAnsary | 9:7965c3bc3199 | 414 | //pc.printf("\r\n %d %d",index[i], int(maxima[i])); |
jaspreetsingh | 0:f2467c077504 | 415 | } |
jaspreetsingh | 8:12b4c521c033 | 416 | if(fft_type==0) |
jaspreetsingh | 8:12b4c521c033 | 417 | { |
jaspreetsingh | 8:12b4c521c033 | 418 | fprintf(fp,"\r\n\r\n"); |
jaspreetsingh | 8:12b4c521c033 | 419 | maxfreq= index[1]; |
jaspreetsingh | 8:12b4c521c033 | 420 | } |
jaspreetsingh | 0:f2467c077504 | 421 | else fprintf(fp,"\r\nEOF"); |
jaspreetsingh | 0:f2467c077504 | 422 | fclose(fp); |
jaspreetsingh | 0:f2467c077504 | 423 | } |
jaspreetsingh | 0:f2467c077504 | 424 | } |
FahdAnsary | 9:7965c3bc3199 | 425 | //--------------------------------------------------------------------------------------------------// |
FahdAnsary | 9:7965c3bc3199 | 426 | // Remove File from Directory // |
FahdAnsary | 9:7965c3bc3199 | 427 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 8:12b4c521c033 | 428 | |
jaspreetsingh | 3:726f275f04ac | 429 | void do_remove(const char *fsrc) |
jaspreetsingh | 3:726f275f04ac | 430 | { |
jaspreetsingh | 3:726f275f04ac | 431 | pc.printf("\r\n Deleting... \r\n"); |
jaspreetsingh | 3:726f275f04ac | 432 | DIR *d = opendir(fsrc); |
jaspreetsingh | 4:668d7227d060 | 433 | if(d==NULL) |
jaspreetsingh | 4:668d7227d060 | 434 | { |
jaspreetsingh | 4:668d7227d060 | 435 | pc.printf("\r\n NULL Condition\r\n"); |
jaspreetsingh | 4:668d7227d060 | 436 | return; |
jaspreetsingh | 4:668d7227d060 | 437 | } |
jaspreetsingh | 4:668d7227d060 | 438 | else |
jaspreetsingh | 4:668d7227d060 | 439 | { |
jaspreetsingh | 4:668d7227d060 | 440 | struct dirent *p; |
jaspreetsingh | 4:668d7227d060 | 441 | char path[100] = {0}; |
FahdAnsary | 9:7965c3bc3199 | 442 | while((p = readdir(d)) != NULL) |
FahdAnsary | 9:7965c3bc3199 | 443 | { |
jaspreetsingh | 3:726f275f04ac | 444 | strcpy(path, fsrc); |
jaspreetsingh | 3:726f275f04ac | 445 | strcat(path, "/"); |
jaspreetsingh | 3:726f275f04ac | 446 | strcat(path, p->d_name); |
jaspreetsingh | 3:726f275f04ac | 447 | remove(path); |
FahdAnsary | 9:7965c3bc3199 | 448 | } |
jaspreetsingh | 4:668d7227d060 | 449 | } |
jaspreetsingh | 3:726f275f04ac | 450 | closedir(d); |
jaspreetsingh | 3:726f275f04ac | 451 | remove(fsrc); |
jaspreetsingh | 3:726f275f04ac | 452 | } |
jaspreetsingh | 0:f2467c077504 | 453 | |
jaspreetsingh | 0:f2467c077504 | 454 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 455 | // Storage // |
jaspreetsingh | 0:f2467c077504 | 456 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 457 | void store() |
jaspreetsingh | 0:f2467c077504 | 458 | { |
jaspreetsingh | 0:f2467c077504 | 459 | GetFileDir(); |
FahdAnsary | 9:7965c3bc3199 | 460 | // AC Sample storage |
jaspreetsingh | 0:f2467c077504 | 461 | sprintf(filenameAC,"%sAC.txt",filename); |
jaspreetsingh | 0:f2467c077504 | 462 | sprintf(pathAC,"%sAC.txt",filepath); |
jaspreetsingh | 7:3d5fd645c11d | 463 | //pc.printf("\r\nFilename-AC\t%s", pathAC); |
jaspreetsingh | 0:f2467c077504 | 464 | FILE *fp = fopen(pathAC, "w"); |
FahdAnsary | 12:0ab0a2578025 | 465 | |
FahdAnsary | 9:7965c3bc3199 | 466 | if(fp == NULL) |
FahdAnsary | 9:7965c3bc3199 | 467 | { |
jaspreetsingh | 7:3d5fd645c11d | 468 | //pc.printf("Could not open file for write\n\r"); |
jaspreetsingh | 0:f2467c077504 | 469 | //reset_mod(); |
FahdAnsary | 9:7965c3bc3199 | 470 | } |
FahdAnsary | 9:7965c3bc3199 | 471 | else |
FahdAnsary | 9:7965c3bc3199 | 472 | { |
jaspreetsingh | 0:f2467c077504 | 473 | //pc.printf("attempting to save file\n\r"); |
FahdAnsary | 9:7965c3bc3199 | 474 | for(int k=0; k<dataLength; k++) |
FahdAnsary | 9:7965c3bc3199 | 475 | { |
jaspreetsingh | 0:f2467c077504 | 476 | fprintf(fp, "%d.", ACdata[k]); |
jaspreetsingh | 0:f2467c077504 | 477 | } |
jaspreetsingh | 0:f2467c077504 | 478 | fprintf(fp, "EOF"); |
jaspreetsingh | 0:f2467c077504 | 479 | fclose(fp); |
jaspreetsingh | 0:f2467c077504 | 480 | } |
FahdAnsary | 9:7965c3bc3199 | 481 | // DC Sample storage |
jaspreetsingh | 0:f2467c077504 | 482 | sprintf(filenameDC,"%sDC.txt",filename); |
jaspreetsingh | 0:f2467c077504 | 483 | sprintf(pathDC,"%sDC.txt",filepath); |
jaspreetsingh | 7:3d5fd645c11d | 484 | //pc.printf("\r\nFilename-DC\t%s", pathDC); |
jaspreetsingh | 0:f2467c077504 | 485 | fp = fopen(pathDC, "w"); |
FahdAnsary | 9:7965c3bc3199 | 486 | if(fp == NULL) |
FahdAnsary | 9:7965c3bc3199 | 487 | { |
jaspreetsingh | 0:f2467c077504 | 488 | //pc.printf("Could not open file for write\n\r"); |
jaspreetsingh | 0:f2467c077504 | 489 | //reset_mod(); |
FahdAnsary | 9:7965c3bc3199 | 490 | } |
FahdAnsary | 9:7965c3bc3199 | 491 | else |
FahdAnsary | 9:7965c3bc3199 | 492 | { |
FahdAnsary | 9:7965c3bc3199 | 493 | for(int k=0; k<dataLength; k++) |
FahdAnsary | 9:7965c3bc3199 | 494 | { |
jaspreetsingh | 0:f2467c077504 | 495 | fprintf(fp, "%d.", DCdata[k]); |
jaspreetsingh | 0:f2467c077504 | 496 | } |
jaspreetsingh | 0:f2467c077504 | 497 | fprintf(fp, "EOF"); |
jaspreetsingh | 0:f2467c077504 | 498 | fclose(fp); |
jaspreetsingh | 0:f2467c077504 | 499 | } |
lalitkumar | 17:824537d9204b | 500 | //Rushabh: DCD storage deemed unnecessary as avg values stored twice |
lalitkumar | 17:824537d9204b | 501 | /* DC Detect storage |
jaspreetsingh | 0:f2467c077504 | 502 | sprintf(pathDCdetect,"%sData.txt",hour_dir); |
FahdAnsary | 12:0ab0a2578025 | 503 | //pc.printf("\r\nFilename-DCD\t%s", pathDCdetect); |
jaspreetsingh | 0:f2467c077504 | 504 | fp = fopen(pathDCdetect, "w"); |
FahdAnsary | 9:7965c3bc3199 | 505 | if(fp == NULL) |
FahdAnsary | 9:7965c3bc3199 | 506 | { |
jaspreetsingh | 0:f2467c077504 | 507 | //pc.printf("Could not open file for write\n\r"); |
jaspreetsingh | 0:f2467c077504 | 508 | //reset_mod(); |
FahdAnsary | 9:7965c3bc3199 | 509 | } |
FahdAnsary | 9:7965c3bc3199 | 510 | else |
FahdAnsary | 9:7965c3bc3199 | 511 | { |
jaspreetsingh | 0:f2467c077504 | 512 | fprintf(fp, "\r\n%s",time_stamp); |
FahdAnsary | 9:7965c3bc3199 | 513 | for(int k=0; k<10; k++) |
FahdAnsary | 9:7965c3bc3199 | 514 | { |
jaspreetsingh | 0:f2467c077504 | 515 | fprintf(fp, "\r\nDC-%d",DC_Detect_data[k]); |
jaspreetsingh | 0:f2467c077504 | 516 | } |
jaspreetsingh | 0:f2467c077504 | 517 | fclose(fp); |
jaspreetsingh | 0:f2467c077504 | 518 | } |
lalitkumar | 17:824537d9204b | 519 | */ |
lalitkumar | 18:4e3aa33674c8 | 520 | |
FahdAnsary | 9:7965c3bc3199 | 521 | //FFT starts |
jaspreetsingh | 7:3d5fd645c11d | 522 | //pc.printf("\r\nfftstart"); |
jaspreetsingh | 0:f2467c077504 | 523 | //pc.printf("\r\nfftstage1"); |
jaspreetsingh | 0:f2467c077504 | 524 | sprintf(filenamefft,"%sft.txt",filename); |
jaspreetsingh | 8:12b4c521c033 | 525 | //sprintf(ftp_timestamp,"%s",filename); // For FTP Timestamp |
jaspreetsingh | 0:f2467c077504 | 526 | sprintf(pathfft,"%sft.txt",filepath); |
jaspreetsingh | 7:3d5fd645c11d | 527 | //pc.printf("\r\nFilename-FFT\t%s", pathfft); |
jaspreetsingh | 0:f2467c077504 | 528 | |
jaspreetsingh | 0:f2467c077504 | 529 | int fft_segments=4; |
jaspreetsingh | 0:f2467c077504 | 530 | int fft_start_index[4]= {0,760,1520,2280}; |
jaspreetsingh | 0:f2467c077504 | 531 | int fft_points_count[4]= {4,120,240,360}; |
jaspreetsingh | 0:f2467c077504 | 532 | int fft_maximas_required[4]= {1,20,8,8}; |
jaspreetsingh | 7:3d5fd645c11d | 533 | float AC_rms_value=0; |
jaspreetsingh | 7:3d5fd645c11d | 534 | float AC_mean_value=0; |
jaspreetsingh | 7:3d5fd645c11d | 535 | float DC_rms_value=0; |
jaspreetsingh | 7:3d5fd645c11d | 536 | float DC_mean_value=0; |
jaspreetsingh | 7:3d5fd645c11d | 537 | |
FahdAnsary | 9:7965c3bc3199 | 538 | //AC fft |
FahdAnsary | 9:7965c3bc3199 | 539 | for(int i=0; i<fft_points; i++) |
FahdAnsary | 9:7965c3bc3199 | 540 | { |
jaspreetsingh | 0:f2467c077504 | 541 | fft_array[i]=int(ACdata[i]); |
jaspreetsingh | 7:3d5fd645c11d | 542 | AC_mean_value=AC_mean_value+fft_array[i]; |
jaspreetsingh | 0:f2467c077504 | 543 | //pc.printf("%d %d %d\r\n", i, i+int(fft_points), fft_array[i]); |
jaspreetsingh | 0:f2467c077504 | 544 | fft_array[(i+int(fft_points))]=0; |
jaspreetsingh | 0:f2467c077504 | 545 | } |
FahdAnsary | 9:7965c3bc3199 | 546 | //AC RMS |
jaspreetsingh | 7:3d5fd645c11d | 547 | AC_mean_value=AC_mean_value/fft_points; |
FahdAnsary | 9:7965c3bc3199 | 548 | for(int i=0; i<fft_points; i++) |
FahdAnsary | 9:7965c3bc3199 | 549 | { |
jaspreetsingh | 7:3d5fd645c11d | 550 | AC_rms_value=AC_rms_value+((AC_mean_value-fft_array[i])*(AC_mean_value-fft_array[i])/10000); |
jaspreetsingh | 7:3d5fd645c11d | 551 | } |
lalitkumar | 18:4e3aa33674c8 | 552 | //FFT file write |
jaspreetsingh | 7:3d5fd645c11d | 553 | fp = fopen(pathfft, "w"); |
FahdAnsary | 12:0ab0a2578025 | 554 | //pc.printf("\r\nopened path fft\r\n"); |
FahdAnsary | 9:7965c3bc3199 | 555 | if(fp == NULL) |
FahdAnsary | 9:7965c3bc3199 | 556 | { |
FahdAnsary | 12:0ab0a2578025 | 557 | //pc.printf("Could not open file for write pathfft\n\r"); |
jaspreetsingh | 7:3d5fd645c11d | 558 | //reset_mod(); |
jaspreetsingh | 7:3d5fd645c11d | 559 | } |
FahdAnsary | 9:7965c3bc3199 | 560 | else |
FahdAnsary | 9:7965c3bc3199 | 561 | { |
FahdAnsary | 9:7965c3bc3199 | 562 | fprintf(fp, "%s",time_stamp); |
lalitkumar | 18:4e3aa33674c8 | 563 | fprintf(fp, " %d",avg_dc_detect[0]); |
lalitkumar | 18:4e3aa33674c8 | 564 | fprintf(fp, " %d",avg_dc_detect[1]); |
lalitkumar | 18:4e3aa33674c8 | 565 | fprintf(fp, " %d",avg_temp[0]); |
lalitkumar | 18:4e3aa33674c8 | 566 | fprintf(fp, " %d",avg_temp[1]); |
FahdAnsary | 9:7965c3bc3199 | 567 | fprintf(fp, " %.0f",AC_rms_value); |
jaspreetsingh | 7:3d5fd645c11d | 568 | fclose(fp); |
jaspreetsingh | 7:3d5fd645c11d | 569 | } |
FahdAnsary | 9:7965c3bc3199 | 570 | fft(fft_points,0,1,1); |
FahdAnsary | 9:7965c3bc3199 | 571 | maxfreq=0; |
FahdAnsary | 9:7965c3bc3199 | 572 | prepare_fft_array(fft_start_index,fft_points_count,fft_maximas_required,fft_segments,0); |
FahdAnsary | 9:7965c3bc3199 | 573 | |
FahdAnsary | 9:7965c3bc3199 | 574 | //TIME STAMP FILE WRITE FUNCTION |
FahdAnsary | 12:0ab0a2578025 | 575 | if(gsmerr==0) |
FahdAnsary | 12:0ab0a2578025 | 576 | { |
FahdAnsary | 12:0ab0a2578025 | 577 | |
FahdAnsary | 12:0ab0a2578025 | 578 | sprintf(timestampname,"TS%s%02d%02d%02d%02d.txt",sitename,year,month,date,hour); |
FahdAnsary | 12:0ab0a2578025 | 579 | sprintf(timestamppath,"/sd/%s",timestampname); |
FahdAnsary | 12:0ab0a2578025 | 580 | } |
FahdAnsary | 12:0ab0a2578025 | 581 | else |
FahdAnsary | 12:0ab0a2578025 | 582 | { |
FahdAnsary | 12:0ab0a2578025 | 583 | |
FahdAnsary | 12:0ab0a2578025 | 584 | sprintf(timestampname,"TS%sErr.txt",sitename); |
FahdAnsary | 12:0ab0a2578025 | 585 | //pc.printf("\r\n%s",timestampname); |
FahdAnsary | 12:0ab0a2578025 | 586 | sprintf(timestamppath,"/sd/%s",timestampname); |
FahdAnsary | 12:0ab0a2578025 | 587 | |
FahdAnsary | 12:0ab0a2578025 | 588 | } |
FahdAnsary | 12:0ab0a2578025 | 589 | //pc.printf("\r\n Timestampname is %s\r\n",timestampname); |
FahdAnsary | 9:7965c3bc3199 | 590 | FILE *fp13 = fopen(timestamppath,"a"); |
FahdAnsary | 9:7965c3bc3199 | 591 | |
FahdAnsary | 12:0ab0a2578025 | 592 | if(fp == NULL) |
FahdAnsary | 12:0ab0a2578025 | 593 | { |
FahdAnsary | 12:0ab0a2578025 | 594 | //pc.printf("Could not open file for write pathfft\n\r"); |
FahdAnsary | 12:0ab0a2578025 | 595 | //reset_mod(); |
FahdAnsary | 12:0ab0a2578025 | 596 | } |
FahdAnsary | 12:0ab0a2578025 | 597 | else |
FahdAnsary | 12:0ab0a2578025 | 598 | { |
lalitkumar | 18:4e3aa33674c8 | 599 | fprintf(fp13,"\r\n%02d%02d %d %.0f %d",minute,second,avg_dc_detect[1]/100,AC_rms_value/100000,maxfreq); //Rushabh: avg_dc_detect[2] missing, need to accomodate |
FahdAnsary | 12:0ab0a2578025 | 600 | //pc.printf("Value is \r\n%02d%02d %d %.0f %d",minute,second,avg_dc_detect,AC_rms_value,maxfreq); |
FahdAnsary | 12:0ab0a2578025 | 601 | fclose(fp13); |
FahdAnsary | 12:0ab0a2578025 | 602 | } |
jaspreetsingh | 8:12b4c521c033 | 603 | pc.printf("\r\nTimestamp.txt Storage Done\n\r"); |
FahdAnsary | 9:7965c3bc3199 | 604 | |
FahdAnsary | 9:7965c3bc3199 | 605 | //DC fft |
FahdAnsary | 9:7965c3bc3199 | 606 | for(int i=0; i<fft_points; i++) |
FahdAnsary | 9:7965c3bc3199 | 607 | { |
jaspreetsingh | 0:f2467c077504 | 608 | fft_array[i]=int(DCdata[i]); |
jaspreetsingh | 7:3d5fd645c11d | 609 | DC_mean_value=DC_mean_value+fft_array[i]; |
jaspreetsingh | 0:f2467c077504 | 610 | //pc.printf("%d %d %d\r\n", i, i+int(fft_points), fft_array[i]); |
jaspreetsingh | 0:f2467c077504 | 611 | fft_array[(i+int(fft_points))]=0; |
jaspreetsingh | 0:f2467c077504 | 612 | } |
FahdAnsary | 9:7965c3bc3199 | 613 | //DC RMS |
jaspreetsingh | 7:3d5fd645c11d | 614 | DC_mean_value=DC_mean_value/fft_points; |
FahdAnsary | 9:7965c3bc3199 | 615 | for(int i=0; i<fft_points; i++) |
FahdAnsary | 9:7965c3bc3199 | 616 | { |
FahdAnsary | 9:7965c3bc3199 | 617 | DC_rms_value=DC_rms_value+((DC_mean_value-fft_array[i])*(DC_mean_value-fft_array[i])/10000); |
jaspreetsingh | 7:3d5fd645c11d | 618 | } |
jaspreetsingh | 7:3d5fd645c11d | 619 | fp = fopen(pathfft, "a"); |
FahdAnsary | 9:7965c3bc3199 | 620 | if(fp == NULL) |
FahdAnsary | 9:7965c3bc3199 | 621 | { |
jaspreetsingh | 7:3d5fd645c11d | 622 | //pc.printf("Could not open file for write\n\r"); |
jaspreetsingh | 7:3d5fd645c11d | 623 | //reset_mod(); |
jaspreetsingh | 7:3d5fd645c11d | 624 | } |
FahdAnsary | 9:7965c3bc3199 | 625 | else |
FahdAnsary | 9:7965c3bc3199 | 626 | { |
FahdAnsary | 9:7965c3bc3199 | 627 | fprintf(fp, "%.0f",DC_rms_value); |
jaspreetsingh | 7:3d5fd645c11d | 628 | fclose(fp); |
jaspreetsingh | 7:3d5fd645c11d | 629 | } |
jaspreetsingh | 7:3d5fd645c11d | 630 | |
jaspreetsingh | 0:f2467c077504 | 631 | fft(fft_points,0,1,1); |
jaspreetsingh | 0:f2467c077504 | 632 | prepare_fft_array(fft_start_index,fft_points_count,fft_maximas_required,fft_segments,1); |
jaspreetsingh | 0:f2467c077504 | 633 | |
jaspreetsingh | 0:f2467c077504 | 634 | } |
jaspreetsingh | 0:f2467c077504 | 635 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 636 | // GSM Initialization // |
jaspreetsingh | 0:f2467c077504 | 637 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 638 | void gsm_init() |
jaspreetsingh | 0:f2467c077504 | 639 | { |
jaspreetsingh | 0:f2467c077504 | 640 | int cnt = 0; |
FahdAnsary | 9:7965c3bc3199 | 641 | while((sendATcommand("AT+CREG?", "+CREG: 1,1", 10,2) || sendATcommand("AT+CREG?", "+CREG: 1,5", 5,0)) == 0) |
FahdAnsary | 9:7965c3bc3199 | 642 | { |
FahdAnsary | 9:7965c3bc3199 | 643 | if(sendATcommand("AT+CREG=1", "+CREG:1", 5,0)) |
FahdAnsary | 9:7965c3bc3199 | 644 | { |
jaspreetsingh | 0:f2467c077504 | 645 | pc.printf("creg is 1"); |
jaspreetsingh | 0:f2467c077504 | 646 | return; |
FahdAnsary | 9:7965c3bc3199 | 647 | } |
FahdAnsary | 9:7965c3bc3199 | 648 | else if(sendATcommand("AT+CREG=1", "+CREG:5", 5,0)) |
FahdAnsary | 9:7965c3bc3199 | 649 | { |
jaspreetsingh | 0:f2467c077504 | 650 | pc.printf("creg is 5"); |
jaspreetsingh | 0:f2467c077504 | 651 | return; |
FahdAnsary | 9:7965c3bc3199 | 652 | } |
jaspreetsingh | 0:f2467c077504 | 653 | ++cnt; |
FahdAnsary | 9:7965c3bc3199 | 654 | if(cnt > 5) |
FahdAnsary | 9:7965c3bc3199 | 655 | { |
jaspreetsingh | 0:f2467c077504 | 656 | pc.printf("GSM registration failed"); |
jaspreetsingh | 0:f2467c077504 | 657 | reset_mod(); |
jaspreetsingh | 0:f2467c077504 | 658 | return; |
jaspreetsingh | 0:f2467c077504 | 659 | } |
jaspreetsingh | 0:f2467c077504 | 660 | } |
jaspreetsingh | 0:f2467c077504 | 661 | } |
jaspreetsingh | 0:f2467c077504 | 662 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 663 | // FTP Connect function // |
jaspreetsingh | 0:f2467c077504 | 664 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 15:f2a7003fcea1 | 665 | |
jaspreetsingh | 0:f2467c077504 | 666 | bool ftp_connect() |
jaspreetsingh | 0:f2467c077504 | 667 | { |
jaspreetsingh | 0:f2467c077504 | 668 | int ftp_close_attempt=0; |
jaspreetsingh | 0:f2467c077504 | 669 | /*if(sendATcommand("AT+SAPBR=2,1", "+SAPBR: 1,3,\"0.0.0.0\"", 5,0)) { |
jaspreetsingh | 0:f2467c077504 | 670 | } else {*/ |
FahdAnsary | 9:7965c3bc3199 | 671 | while(!sendATcommand("AT+SAPBR=2,1", "+SAPBR: 1,3,\"0.0.0.0\"", 5,0)) |
FahdAnsary | 9:7965c3bc3199 | 672 | { |
jaspreetsingh | 0:f2467c077504 | 673 | sendATcommand("AT+SAPBR=0,1","OK",5,0); |
jaspreetsingh | 0:f2467c077504 | 674 | ftp_close_attempt++; |
jaspreetsingh | 0:f2467c077504 | 675 | //pc.printf("\r\nclose attempt %d\r\n", ftp_close_attempt); |
FahdAnsary | 9:7965c3bc3199 | 676 | if(ftp_close_attempt>3) |
FahdAnsary | 9:7965c3bc3199 | 677 | { |
jaspreetsingh | 0:f2467c077504 | 678 | //pc.printf("\r\nunable to close bearer\r\n"); |
jaspreetsingh | 0:f2467c077504 | 679 | return 0; |
jaspreetsingh | 0:f2467c077504 | 680 | } |
jaspreetsingh | 0:f2467c077504 | 681 | } |
jaspreetsingh | 0:f2467c077504 | 682 | int ftp_connect_attempt=0; |
jaspreetsingh | 0:f2467c077504 | 683 | //} |
FahdAnsary | 9:7965c3bc3199 | 684 | do |
FahdAnsary | 9:7965c3bc3199 | 685 | { |
jaspreetsingh | 0:f2467c077504 | 686 | sendATcommand("AT+SAPBR=1,1", "OK", 15,0); |
jaspreetsingh | 0:f2467c077504 | 687 | //pc.printf("\r\nopen attempt %d\r\n",ftp_connect_attempt); |
FahdAnsary | 9:7965c3bc3199 | 688 | if(ftp_connect_attempt>3) |
FahdAnsary | 9:7965c3bc3199 | 689 | { |
jaspreetsingh | 0:f2467c077504 | 690 | //pc.printf("\r\nunable to open bearer"); |
jaspreetsingh | 0:f2467c077504 | 691 | return 0; |
FahdAnsary | 9:7965c3bc3199 | 692 | } |
jaspreetsingh | 0:f2467c077504 | 693 | ftp_connect_attempt++; |
FahdAnsary | 9:7965c3bc3199 | 694 | } |
jaspreetsingh | 0:f2467c077504 | 695 | while(sendATcommand("AT+SAPBR=2,1", "+SAPBR: 1,3,\"0.0.0.0\"", 5,0)); |
jaspreetsingh | 0:f2467c077504 | 696 | wait(3); |
FahdAnsary | 9:7965c3bc3199 | 697 | if(sendATcommand("AT+FTPTYPE=\"I\"", "OK", 5,0)) |
FahdAnsary | 9:7965c3bc3199 | 698 | { |
jaspreetsingh | 13:73d6de10d15c | 699 | if(sendATcommand("AT+FTPSERV=\"ftp.panchsheel.biz\"", "OK", 10,0)) |
FahdAnsary | 9:7965c3bc3199 | 700 | { |
jaspreetsingh | 13:73d6de10d15c | 701 | if(sendATcommand("AT+FTPUN=\"hardware@panchsheel.biz\"", "OK\r", 10,0)) |
FahdAnsary | 9:7965c3bc3199 | 702 | { |
jaspreetsingh | 13:73d6de10d15c | 703 | if(sendATcommand("AT+FTPPW=\"DAStest123\"", "OK\r", 10,0)) return 1; |
jaspreetsingh | 0:f2467c077504 | 704 | } |
jaspreetsingh | 0:f2467c077504 | 705 | } |
FahdAnsary | 9:7965c3bc3199 | 706 | } |
jaspreetsingh | 0:f2467c077504 | 707 | return 0; |
jaspreetsingh | 0:f2467c077504 | 708 | } |
jaspreetsingh | 0:f2467c077504 | 709 | |
jaspreetsingh | 0:f2467c077504 | 710 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 711 | // FTP Send Function // |
jaspreetsingh | 0:f2467c077504 | 712 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 713 | |
jaspreetsingh | 0:f2467c077504 | 714 | void ftp_put(int ftp_type) // For FTPGET Function |
jaspreetsingh | 0:f2467c077504 | 715 | { |
jaspreetsingh | 0:f2467c077504 | 716 | |
jaspreetsingh | 0:f2467c077504 | 717 | char ftpfilename[30]=""; |
jaspreetsingh | 0:f2467c077504 | 718 | char ftpfilepath[100]=""; |
jaspreetsingh | 0:f2467c077504 | 719 | |
jaspreetsingh | 0:f2467c077504 | 720 | if (ftp_type==0) |
jaspreetsingh | 0:f2467c077504 | 721 | { |
jaspreetsingh | 0:f2467c077504 | 722 | sprintf(ftpfilename,"%s",filenamefft); |
jaspreetsingh | 0:f2467c077504 | 723 | sprintf(ftpfilepath,"%s",pathfft); |
jaspreetsingh | 0:f2467c077504 | 724 | } |
jaspreetsingh | 0:f2467c077504 | 725 | else if (ftp_type==1) // For FTPGET Function |
jaspreetsingh | 0:f2467c077504 | 726 | { |
jaspreetsingh | 0:f2467c077504 | 727 | pc.printf("Sending Requested file\r\n"); |
jaspreetsingh | 0:f2467c077504 | 728 | |
jaspreetsingh | 0:f2467c077504 | 729 | sprintf(ftpfilename,"%s",ftpget); // For Request of multiple file path logic refer abc.text |
FahdAnsary | 9:7965c3bc3199 | 730 | sprintf(ftpfilepath,"%s",ftpget1); |
jaspreetsingh | 16:622629b0cf3c | 731 | sprintf(ftpputpathname,"%s",ftpget2); |
jaspreetsingh | 0:f2467c077504 | 732 | } |
jaspreetsingh | 0:f2467c077504 | 733 | else if (ftp_type==2) |
jaspreetsingh | 0:f2467c077504 | 734 | { |
jaspreetsingh | 0:f2467c077504 | 735 | // For Timestamp text file |
jaspreetsingh | 0:f2467c077504 | 736 | sprintf(ftpfilename,"%s.txt",ftpget); |
jaspreetsingh | 0:f2467c077504 | 737 | sprintf(ftpfilepath,"/sd/%s.txt",ftpget); |
jaspreetsingh | 0:f2467c077504 | 738 | } |
jaspreetsingh | 0:f2467c077504 | 739 | |
jaspreetsingh | 0:f2467c077504 | 740 | char command1[40]; |
jaspreetsingh | 0:f2467c077504 | 741 | char result1[20]; |
jaspreetsingh | 0:f2467c077504 | 742 | char command2 [100]; |
jaspreetsingh | 0:f2467c077504 | 743 | //char result2 [20]; |
jaspreetsingh | 0:f2467c077504 | 744 | |
jaspreetsingh | 0:f2467c077504 | 745 | sprintf(command1,"%s\"%s\"", "AT+FTPPUTNAME=", ftpfilename); |
jaspreetsingh | 0:f2467c077504 | 746 | sprintf(result1,"%s", "OK"); |
jaspreetsingh | 0:f2467c077504 | 747 | pc.printf("ftpfilepath is \n\r %s \n\r",ftpfilepath); |
jaspreetsingh | 0:f2467c077504 | 748 | |
jaspreetsingh | 0:f2467c077504 | 749 | //sd card |
jaspreetsingh | 0:f2467c077504 | 750 | int char_cnt=0; |
jaspreetsingh | 0:f2467c077504 | 751 | char file_data[1294]; |
jaspreetsingh | 0:f2467c077504 | 752 | FILE *fp8 = fopen(ftpfilepath, "r"); |
FahdAnsary | 9:7965c3bc3199 | 753 | if(fp8==NULL) |
FahdAnsary | 9:7965c3bc3199 | 754 | { |
jaspreetsingh | 0:f2467c077504 | 755 | pc.printf("\n\r NULL Condition\r\n"); |
jaspreetsingh | 0:f2467c077504 | 756 | return; |
FahdAnsary | 9:7965c3bc3199 | 757 | } |
FahdAnsary | 9:7965c3bc3199 | 758 | else |
FahdAnsary | 9:7965c3bc3199 | 759 | { |
FahdAnsary | 9:7965c3bc3199 | 760 | for(int i=0; i<1294; i++) |
FahdAnsary | 9:7965c3bc3199 | 761 | { |
jaspreetsingh | 0:f2467c077504 | 762 | file_data[i] = fgetc(fp8); |
jaspreetsingh | 0:f2467c077504 | 763 | char_cnt= char_cnt++; |
FahdAnsary | 9:7965c3bc3199 | 764 | if( feof(fp8) ) |
FahdAnsary | 9:7965c3bc3199 | 765 | { |
jaspreetsingh | 0:f2467c077504 | 766 | break ; |
jaspreetsingh | 0:f2467c077504 | 767 | } |
jaspreetsingh | 0:f2467c077504 | 768 | }//size calculation loop ends |
jaspreetsingh | 0:f2467c077504 | 769 | fclose(fp8); |
jaspreetsingh | 0:f2467c077504 | 770 | } |
FahdAnsary | 9:7965c3bc3199 | 771 | for(int putname_attempt=0; putname_attempt<2; putname_attempt++) |
FahdAnsary | 9:7965c3bc3199 | 772 | { |
jaspreetsingh | 0:f2467c077504 | 773 | //pc.printf("\r\nftp_put attempt\n\r"); |
jaspreetsingh | 0:f2467c077504 | 774 | // pc.printf("\r\nChar count %d\n\r",char_cnt); |
FahdAnsary | 9:7965c3bc3199 | 775 | if(sendATcommand(command1,result1, 10,0)) |
FahdAnsary | 9:7965c3bc3199 | 776 | { |
jaspreetsingh | 5:11c455ebcc34 | 777 | sprintf(command2,"%s/%s/\"", "AT+FTPPUTPATH=\"", ftpputpathname); // For FTPPUTPATHNAME Feature |
jaspreetsingh | 0:f2467c077504 | 778 | //sprintf(result2,"%s", "OK"); |
jaspreetsingh | 0:f2467c077504 | 779 | sendATcommand(command2,"OK", 10,0); |
FahdAnsary | 9:7965c3bc3199 | 780 | if((sendATcommand("AT+FTPPUT=1", "OK", 10,2))==2) |
FahdAnsary | 9:7965c3bc3199 | 781 | { |
jaspreetsingh | 0:f2467c077504 | 782 | //wait(8); |
jaspreetsingh | 0:f2467c077504 | 783 | // pc.printf("in loop"); |
jaspreetsingh | 0:f2467c077504 | 784 | // pc.printf("\n\r %s",ftpfilepath); |
jaspreetsingh | 0:f2467c077504 | 785 | /*FILE *fp9 = fopen(ftpfilepath, "r"); |
jaspreetsingh | 0:f2467c077504 | 786 | if(fp9==NULL)return; |
jaspreetsingh | 0:f2467c077504 | 787 | else |
jaspreetsingh | 0:f2467c077504 | 788 | {*/ |
jaspreetsingh | 0:f2467c077504 | 789 | int trialcount=0; |
jaspreetsingh | 0:f2467c077504 | 790 | int allowedtrials=3; |
jaspreetsingh | 0:f2467c077504 | 791 | char command[40]; |
jaspreetsingh | 0:f2467c077504 | 792 | char result[30]; |
jaspreetsingh | 0:f2467c077504 | 793 | sprintf(command,"%s%d", "AT+FTPPUT=2,",char_cnt); |
jaspreetsingh | 0:f2467c077504 | 794 | sprintf(result,"%s%d", "+FTPPUT:2,",char_cnt); |
FahdAnsary | 9:7965c3bc3199 | 795 | while(trialcount<allowedtrials) |
FahdAnsary | 9:7965c3bc3199 | 796 | { |
FahdAnsary | 9:7965c3bc3199 | 797 | if(sendATcommand(command,result, 10,0)) |
FahdAnsary | 9:7965c3bc3199 | 798 | { |
FahdAnsary | 9:7965c3bc3199 | 799 | for(int i=0; i<char_cnt; i++) |
FahdAnsary | 9:7965c3bc3199 | 800 | { |
jaspreetsingh | 0:f2467c077504 | 801 | gsm.printf("%c", file_data[i]); |
jaspreetsingh | 0:f2467c077504 | 802 | } |
jaspreetsingh | 0:f2467c077504 | 803 | trialcount=allowedtrials+4; |
jaspreetsingh | 0:f2467c077504 | 804 | wait(5); |
jaspreetsingh | 0:f2467c077504 | 805 | } else trialcount++; |
jaspreetsingh | 0:f2467c077504 | 806 | } |
jaspreetsingh | 0:f2467c077504 | 807 | } |
jaspreetsingh | 0:f2467c077504 | 808 | } |
FahdAnsary | 9:7965c3bc3199 | 809 | for(int ftp_close_attempt=0; ftp_close_attempt<2; ftp_close_attempt++) |
FahdAnsary | 9:7965c3bc3199 | 810 | { |
jaspreetsingh | 0:f2467c077504 | 811 | //pc.printf("\r\nftp_close\r\n"); |
FahdAnsary | 9:7965c3bc3199 | 812 | if(sendATcommand("AT+FTPPUT=2,0", "OK", 5,0)) |
FahdAnsary | 9:7965c3bc3199 | 813 | { |
jaspreetsingh | 0:f2467c077504 | 814 | ftp_close_attempt=6; |
jaspreetsingh | 0:f2467c077504 | 815 | } |
jaspreetsingh | 0:f2467c077504 | 816 | } |
jaspreetsingh | 0:f2467c077504 | 817 | return; |
jaspreetsingh | 0:f2467c077504 | 818 | |
jaspreetsingh | 0:f2467c077504 | 819 | } |
jaspreetsingh | 0:f2467c077504 | 820 | |
jaspreetsingh | 0:f2467c077504 | 821 | } |
jaspreetsingh | 0:f2467c077504 | 822 | |
jaspreetsingh | 15:f2a7003fcea1 | 823 | |
jaspreetsingh | 0:f2467c077504 | 824 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 825 | // FTP GET FUNCTION // |
jaspreetsingh | 0:f2467c077504 | 826 | //--------------------------------------------------------------------------------------------------// |
jaspreetsingh | 0:f2467c077504 | 827 | |
jaspreetsingh | 0:f2467c077504 | 828 | void downloadFTP() |
jaspreetsingh | 0:f2467c077504 | 829 | |
jaspreetsingh | 0:f2467c077504 | 830 | { |
jaspreetsingh | 0:f2467c077504 | 831 | int x = 0; |
jaspreetsingh | 14:83b823fdcdd0 | 832 | char command3[40]; |
jaspreetsingh | 2:e5b9aefbcdeb | 833 | |
jaspreetsingh | 0:f2467c077504 | 834 | wait(10); |
jaspreetsingh | 0:f2467c077504 | 835 | ftp_connect(); |
jaspreetsingh | 0:f2467c077504 | 836 | |
jaspreetsingh | 0:f2467c077504 | 837 | sendATcommand("AT+FTPGETNAME=\"Final.txt\"", "OK", 5,0); |
jaspreetsingh | 14:83b823fdcdd0 | 838 | //sendATcommand("AT+FTPGETPATH=\"/\"", "OK", 5,0); |
jaspreetsingh | 14:83b823fdcdd0 | 839 | sprintf(command3,"%s/%s/\"", "AT+FTPGETPATH=\"", module_name); |
jaspreetsingh | 14:83b823fdcdd0 | 840 | sendATcommand(command3,"OK",5,0); |
jaspreetsingh | 0:f2467c077504 | 841 | |
jaspreetsingh | 0:f2467c077504 | 842 | if (sendATcommand("AT+FTPGET=1\r", "+FTPGET:1,1", 20,0) == 1) |
jaspreetsingh | 0:f2467c077504 | 843 | { |
jaspreetsingh | 0:f2467c077504 | 844 | for(int ftp_get_attempt=0; ftp_get_attempt<2; ftp_get_attempt++) { |
jaspreetsingh | 0:f2467c077504 | 845 | if (sendATcommand("AT+FTPGET=2,300", "+FTPGET:2,", 10,0) == 1) |
jaspreetsingh | 0:f2467c077504 | 846 | { |
jaspreetsingh | 0:f2467c077504 | 847 | int previous = time(NULL); |
jaspreetsingh | 0:f2467c077504 | 848 | // this loop waits for the answer |
FahdAnsary | 9:7965c3bc3199 | 849 | do |
FahdAnsary | 9:7965c3bc3199 | 850 | { |
jaspreetsingh | 0:f2467c077504 | 851 | if(gsm.readable() == 1) |
jaspreetsingh | 0:f2467c077504 | 852 | { |
jaspreetsingh | 0:f2467c077504 | 853 | // if there are data in the UART input buffer, reads it and checks for the asnwer |
jaspreetsingh | 0:f2467c077504 | 854 | incoming_data[x] = gsm.getc(); |
jaspreetsingh | 0:f2467c077504 | 855 | x++; |
jaspreetsingh | 0:f2467c077504 | 856 | } |
jaspreetsingh | 0:f2467c077504 | 857 | |
FahdAnsary | 9:7965c3bc3199 | 858 | // Waits for the asnwer with time out |
FahdAnsary | 9:7965c3bc3199 | 859 | }while((time(NULL) - previous) < 5); |
jaspreetsingh | 0:f2467c077504 | 860 | |
jaspreetsingh | 0:f2467c077504 | 861 | pc.printf("Incoming_Data is %s\r\n",incoming_data); |
jaspreetsingh | 0:f2467c077504 | 862 | sprintf(dest,"%s",incoming_data); |
jaspreetsingh | 0:f2467c077504 | 863 | pc.printf("\r\n Download finished"); |
jaspreetsingh | 4:668d7227d060 | 864 | wait(15); |
jaspreetsingh | 5:11c455ebcc34 | 865 | |
jaspreetsingh | 0:f2467c077504 | 866 | char *token; |
jaspreetsingh | 0:f2467c077504 | 867 | token = strtok(dest, s); |
jaspreetsingh | 0:f2467c077504 | 868 | token = strtok(NULL,s); |
jaspreetsingh | 0:f2467c077504 | 869 | pc.printf("\r\nToken is %s\r\n",token); |
jaspreetsingh | 0:f2467c077504 | 870 | |
jaspreetsingh | 0:f2467c077504 | 871 | //NO FTGET REQUIRED Case : 0 |
jaspreetsingh | 0:f2467c077504 | 872 | if(atoi(token)==NULL) |
jaspreetsingh | 0:f2467c077504 | 873 | { |
jaspreetsingh | 0:f2467c077504 | 874 | return; |
jaspreetsingh | 0:f2467c077504 | 875 | } |
jaspreetsingh | 0:f2467c077504 | 876 | //RESET THE MODULE Case : 1 |
jaspreetsingh | 0:f2467c077504 | 877 | else if(atoi(token)==1) |
jaspreetsingh | 0:f2467c077504 | 878 | { |
jaspreetsingh | 0:f2467c077504 | 879 | pc.printf("\r\nModule reset\r\n"); |
jaspreetsingh | 0:f2467c077504 | 880 | reset_mod(); |
jaspreetsingh | 0:f2467c077504 | 881 | |
jaspreetsingh | 0:f2467c077504 | 882 | } |
jaspreetsingh | 0:f2467c077504 | 883 | //Request Particular Path File Case : 2 |
jaspreetsingh | 0:f2467c077504 | 884 | else if(atoi(token) == 2) |
jaspreetsingh | 0:f2467c077504 | 885 | { |
jaspreetsingh | 0:f2467c077504 | 886 | token = strtok(NULL,s); |
jaspreetsingh | 0:f2467c077504 | 887 | sprintf(ftpget,"%s",token); |
jaspreetsingh | 0:f2467c077504 | 888 | pc.printf("Ftpget is %s\r\n",ftpget); |
jaspreetsingh | 0:f2467c077504 | 889 | token = strtok(NULL,s); |
jaspreetsingh | 0:f2467c077504 | 890 | sprintf(ftpget1,"%s",token); |
jaspreetsingh | 0:f2467c077504 | 891 | pc.printf("Ftpget1 is %s\r\n",ftpget1); |
jaspreetsingh | 16:622629b0cf3c | 892 | token = strtok(NULL,s); |
jaspreetsingh | 16:622629b0cf3c | 893 | sprintf(ftpget2,"%s",token); |
jaspreetsingh | 16:622629b0cf3c | 894 | pc.printf("Ftpget2 is %s\r\n",ftpget2); |
jaspreetsingh | 0:f2467c077504 | 895 | ftp_connect(); |
jaspreetsingh | 0:f2467c077504 | 896 | wait(5); |
jaspreetsingh | 0:f2467c077504 | 897 | ftp_put(1); |
jaspreetsingh | 0:f2467c077504 | 898 | } |
jaspreetsingh | 0:f2467c077504 | 899 | //Request Timestamp File Case : 3 |
jaspreetsingh | 0:f2467c077504 | 900 | else if(atoi(token)==3) |
jaspreetsingh | 0:f2467c077504 | 901 | { |
jaspreetsingh | 0:f2467c077504 | 902 | pc.printf("\r\n Timestamp Sending\r\n"); |
jaspreetsingh | 0:f2467c077504 | 903 | token = strtok(NULL,s); |
jaspreetsingh | 0:f2467c077504 | 904 | sprintf(ftpget,"%s",token); |
jaspreetsingh | 0:f2467c077504 | 905 | pc.printf("Ftpget is %s\r\n",ftpget); |
jaspreetsingh | 0:f2467c077504 | 906 | ftp_connect(); |
jaspreetsingh | 0:f2467c077504 | 907 | wait(5); |
jaspreetsingh | 0:f2467c077504 | 908 | ftp_put(2); |
jaspreetsingh | 0:f2467c077504 | 909 | } |
jaspreetsingh | 1:56e7680a6339 | 910 | // Delete the particular Folder Case : 4 |
jaspreetsingh | 0:f2467c077504 | 911 | else if(atoi(token) ==4) |
jaspreetsingh | 0:f2467c077504 | 912 | { |
jaspreetsingh | 0:f2467c077504 | 913 | //FOR DELETING THE SELECTED FILE |
jaspreetsingh | 3:726f275f04ac | 914 | char removefile[100]=""; |
jaspreetsingh | 1:56e7680a6339 | 915 | token = strtok(NULL,s); |
jaspreetsingh | 3:726f275f04ac | 916 | sprintf(removefile,"%s",token); |
jaspreetsingh | 3:726f275f04ac | 917 | pc.printf("Folder to be removed is %s",removefile); |
jaspreetsingh | 3:726f275f04ac | 918 | |
jaspreetsingh | 0:f2467c077504 | 919 | if(removefile==NULL) |
jaspreetsingh | 0:f2467c077504 | 920 | { |
jaspreetsingh | 0:f2467c077504 | 921 | pc.printf("\r\n NULL Condition\r\n"); |
jaspreetsingh | 0:f2467c077504 | 922 | return; |
jaspreetsingh | 0:f2467c077504 | 923 | } |
jaspreetsingh | 0:f2467c077504 | 924 | else |
jaspreetsingh | 0:f2467c077504 | 925 | { |
jaspreetsingh | 0:f2467c077504 | 926 | pc.printf("\r\n Deleting requested file\r\n"); |
jaspreetsingh | 15:f2a7003fcea1 | 927 | do_remove(removefile); |
jaspreetsingh | 0:f2467c077504 | 928 | pc.printf("\r\n File Deleted\r\n"); |
jaspreetsingh | 3:726f275f04ac | 929 | } |
jaspreetsingh | 0:f2467c077504 | 930 | } |
jaspreetsingh | 2:e5b9aefbcdeb | 931 | /* |
jaspreetsingh | 0:f2467c077504 | 932 | else if(atoi(token)==5) |
jaspreetsingh | 0:f2467c077504 | 933 | { |
jaspreetsingh | 0:f2467c077504 | 934 | pc.printf("\r\n Remote Configuration\r\n"); |
jaspreetsingh | 0:f2467c077504 | 935 | } |
jaspreetsingh | 2:e5b9aefbcdeb | 936 | // wait(5); |
jaspreetsingh | 2:e5b9aefbcdeb | 937 | |
jaspreetsingh | 0:f2467c077504 | 938 | FILE *fp1 = fopen("/sd/Query.txt","w"); |
jaspreetsingh | 0:f2467c077504 | 939 | fprintf(fp1,"%s",ftpget); |
jaspreetsingh | 0:f2467c077504 | 940 | fclose(fp1); |
jaspreetsingh | 0:f2467c077504 | 941 | */ |
jaspreetsingh | 0:f2467c077504 | 942 | |
jaspreetsingh | 0:f2467c077504 | 943 | } |
jaspreetsingh | 0:f2467c077504 | 944 | else |
jaspreetsingh | 0:f2467c077504 | 945 | { |
jaspreetsingh | 0:f2467c077504 | 946 | pc.printf("Error getting the file"); |
jaspreetsingh | 0:f2467c077504 | 947 | } |
jaspreetsingh | 0:f2467c077504 | 948 | |
jaspreetsingh | 0:f2467c077504 | 949 | ftp_get_attempt=6; |
jaspreetsingh | 0:f2467c077504 | 950 | } |
jaspreetsingh | 0:f2467c077504 | 951 | |
jaspreetsingh | 0:f2467c077504 | 952 | } |
jaspreetsingh | 0:f2467c077504 | 953 | else |
jaspreetsingh | 0:f2467c077504 | 954 | { |
jaspreetsingh | 0:f2467c077504 | 955 | return; |
jaspreetsingh | 0:f2467c077504 | 956 | } |
jaspreetsingh | 0:f2467c077504 | 957 | |
jaspreetsingh | 0:f2467c077504 | 958 | } |
jaspreetsingh | 0:f2467c077504 | 959 | |
jaspreetsingh | 0:f2467c077504 | 960 | void FTP_Fun() |
jaspreetsingh | 0:f2467c077504 | 961 | { |
jaspreetsingh | 0:f2467c077504 | 962 | /*tid6 = osThreadGetId(); |
jaspreetsingh | 0:f2467c077504 | 963 | |
jaspreetsingh | 0:f2467c077504 | 964 | while(true) |
jaspreetsingh | 0:f2467c077504 | 965 | { |
jaspreetsingh | 0:f2467c077504 | 966 | osSignalWait(0x1, osWaitForever);*/ |
FahdAnsary | 9:7965c3bc3199 | 967 | if(ftp_connect()) |
FahdAnsary | 9:7965c3bc3199 | 968 | { |
jaspreetsingh | 0:f2467c077504 | 969 | ftp_put(0); |
jaspreetsingh | 0:f2467c077504 | 970 | //downloadFTP(); // For FTPGET Function |
jaspreetsingh | 0:f2467c077504 | 971 | } |
jaspreetsingh | 0:f2467c077504 | 972 | return; |
jaspreetsingh | 0:f2467c077504 | 973 | //} |
jaspreetsingh | 0:f2467c077504 | 974 | } |
jaspreetsingh | 0:f2467c077504 | 975 | |
jaspreetsingh | 0:f2467c077504 | 976 | //----------------------------------------------------- MAIN LOOP ----------------------------------------------------------- |
jaspreetsingh | 0:f2467c077504 | 977 | |
jaspreetsingh | 0:f2467c077504 | 978 | int main() |
jaspreetsingh | 0:f2467c077504 | 979 | { |
jaspreetsingh | 0:f2467c077504 | 980 | |
jaspreetsingh | 0:f2467c077504 | 981 | gsm_rst=0; |
jaspreetsingh | 0:f2467c077504 | 982 | wait(1); |
jaspreetsingh | 0:f2467c077504 | 983 | gsm_rst=1; |
FahdAnsary | 9:7965c3bc3199 | 984 | wait(8); |
jaspreetsingh | 0:f2467c077504 | 985 | gsm_init(); |
jaspreetsingh | 0:f2467c077504 | 986 | mkdir("/sd/jas",0777); |
FahdAnsary | 12:0ab0a2578025 | 987 | int old_hour=100,loopcount=0; |
jaspreetsingh | 0:f2467c077504 | 988 | pc.printf("\r\nHelloWorld\r\n"); |
jaspreetsingh | 0:f2467c077504 | 989 | sendATcommand("AT+CLTS=1\r", "OK", 15,2); |
jaspreetsingh | 0:f2467c077504 | 990 | //wait(10); |
jaspreetsingh | 0:f2467c077504 | 991 | GetFileDir(); |
jaspreetsingh | 0:f2467c077504 | 992 | FILE *fp = fopen("/sd/SiteInfo.txt","a"); |
FahdAnsary | 9:7965c3bc3199 | 993 | if(fp == NULL) |
FahdAnsary | 9:7965c3bc3199 | 994 | { |
jaspreetsingh | 0:f2467c077504 | 995 | FILE *fp = fopen("/sd/SiteInfo.txt","w"); |
jaspreetsingh | 0:f2467c077504 | 996 | fprintf(fp, "\r\n%s",time_stamp); |
jaspreetsingh | 0:f2467c077504 | 997 | |
FahdAnsary | 9:7965c3bc3199 | 998 | } |
FahdAnsary | 9:7965c3bc3199 | 999 | else |
FahdAnsary | 9:7965c3bc3199 | 1000 | { |
jaspreetsingh | 0:f2467c077504 | 1001 | fprintf(fp, "\r\n%s",time_stamp); |
jaspreetsingh | 0:f2467c077504 | 1002 | pc.printf("\r\n%s",time_stamp); |
jaspreetsingh | 0:f2467c077504 | 1003 | fclose(fp); |
jaspreetsingh | 0:f2467c077504 | 1004 | } |
jaspreetsingh | 0:f2467c077504 | 1005 | pc.printf("\r\n Timestamp saved"); |
FahdAnsary | 9:7965c3bc3199 | 1006 | |
FahdAnsary | 9:7965c3bc3199 | 1007 | |
FahdAnsary | 9:7965c3bc3199 | 1008 | while(1) |
FahdAnsary | 9:7965c3bc3199 | 1009 | { |
FahdAnsary | 9:7965c3bc3199 | 1010 | pc.printf("\r\n%d\t%d\r\n",hour,old_hour); |
lalitkumar | 10:9184e2fb5974 | 1011 | sampling(); |
lalitkumar | 10:9184e2fb5974 | 1012 | store(); |
lalitkumar | 10:9184e2fb5974 | 1013 | FTP_Fun(); |
jaspreetsingh | 16:622629b0cf3c | 1014 | //downloadFTP(); // For testing purpose |
FahdAnsary | 12:0ab0a2578025 | 1015 | if (old_hour!=100 && hour!=old_hour && hour<24) |
FahdAnsary | 9:7965c3bc3199 | 1016 | { |
FahdAnsary | 9:7965c3bc3199 | 1017 | pc.printf("\r\nhour changed"); |
FahdAnsary | 9:7965c3bc3199 | 1018 | if(ftp_connect()) |
FahdAnsary | 9:7965c3bc3199 | 1019 | { |
FahdAnsary | 9:7965c3bc3199 | 1020 | sprintf(filenamefft,"%s",timestampname_old); |
FahdAnsary | 9:7965c3bc3199 | 1021 | sprintf(pathfft,"%s",timestamppath_old); |
FahdAnsary | 9:7965c3bc3199 | 1022 | ftp_put(0); |
FahdAnsary | 9:7965c3bc3199 | 1023 | } |
jaspreetsingh | 16:622629b0cf3c | 1024 | downloadFTP(); // For FTPGET Function |
FahdAnsary | 9:7965c3bc3199 | 1025 | } |
lalitkumar | 10:9184e2fb5974 | 1026 | pc.printf("\r\n Complete Done"); |
FahdAnsary | 9:7965c3bc3199 | 1027 | old_hour=hour; |
FahdAnsary | 9:7965c3bc3199 | 1028 | sprintf(timestampname_old,timestampname); |
jaspreetsingh | 16:622629b0cf3c | 1029 | sprintf(timestamppath_old,timestamppath); |
FahdAnsary | 12:0ab0a2578025 | 1030 | if(hour%2>0 || loopcount>120) |
FahdAnsary | 9:7965c3bc3199 | 1031 | { |
FahdAnsary | 12:0ab0a2578025 | 1032 | if((minute>3 && minute<6)||(loopcount>120)) |
FahdAnsary | 9:7965c3bc3199 | 1033 | { |
FahdAnsary | 12:0ab0a2578025 | 1034 | loopcount=0; |
FahdAnsary | 9:7965c3bc3199 | 1035 | reset_mod(); |
FahdAnsary | 9:7965c3bc3199 | 1036 | } |
jaspreetsingh | 0:f2467c077504 | 1037 | } |
jaspreetsingh | 0:f2467c077504 | 1038 | //wait(10); |
jaspreetsingh | 0:f2467c077504 | 1039 | } |
FahdAnsary | 9:7965c3bc3199 | 1040 | |
jaspreetsingh | 0:f2467c077504 | 1041 | } |