Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*****Can someone convert this to C++??? ***** #set pin 40 as output #pin = 40 #GPIO.setup(pin, GPIO.OUT) #get current date date = datetime.datetime.utcnow().strftime(%Y%j) #open transmission

*****Can someone convert this to C++??? *****

#set pin 40 as output #pin = 40 #GPIO.setup(pin, GPIO.OUT) #get current date date = datetime.datetime.utcnow().strftime("%Y%j") #open transmission log for current day transmissions = open('/root/transmissions/transmission_log_' + date + '.txt', 'a') #write to transmission log time - turning on iridium modem transmissions.write(' ' + datetime.datetime.utcnow().strftime("%H:%M:%S") + ' turning on iridium modem ') #turn on modem modem = GPIO("J4.11", "OUTPUT") modem.on() send_dir = '/root/shortlist' count = 0 buffer = 512 #buffer = 256 try: if len(os.listdir(send_dir)) > 0: send_files = True #set pin to high #GPIO.output(pin, GPIO.HIGH) print "Waiting for modem to power on..." time.sleep(5) else: send_files = False while send_files: # Configure serial connection to 9522B try: ser.close() except (RuntimeError, TypeError, NameError): pass ser = serial.Serial('/dev/ttyS2', 19200, timeout=1) print ser.name # Query Signal Strength, and print strength. If it is strong enough, move on # Can only initiate a call is signal strength is greater or equal to 4 current_sig_strength = 0 #write to transmission log time that signal querying began transmissions.write(' ' + datetime.datetime.utcnow().strftime("%H:%M:%S") + ' checking signal strength ') print "Waiting for signal >4...." while (current_sig_strength <4): ser.write("AT+CSQ ") while(ser.inWaiting() <= 8): pass response = ser.readlines() print response try: current_sig_strength = int(response[1][-3]) #current_sig_strength = int(response[2][-3]) print "Current signal strength: " + str(current_sig_strength) if (current_sig_strength >3): transmissions.write(datetime.datetime.utcnow().strftime('%H:%M:%S.%f') + " signal strength " + str(current_sig_strength) + " ") print "Signal strength good. Starting config for call" except IndexError: continue # configuration, please verify, read off random online manual transmissions.write(datetime.datetime.utcnow().strftime('%H:%M:%S') + " configuring call ") ser.write("AT&F0 S0=1 &D0 +IPR=6,0 V0 &K0 &W0 &Y0 ") response = ser.read(100) print response ser.write("AT+CBST=71,0,1") response = ser.read(100) print response # Verify settings or something, probably not necessary for procedure ser.write("AT&V ") response = ser.read(1000) print response # Dial connection to server print "dialing..." ser.write("atdt0088160000500 ") #write to transmission log time dialing/redialing began transmissions.write(datetime.datetime.utcnow().strftime("%H:%M:%S") + ' dialing/redialing ') # Interference starts here #power_file.write('1 , ' + str(time.time() )) # Reads connection for port opening then proceeds, will hang here if can't connect, # Manual break/kill (ctrl+c) may be necessary and restart script. x = 0 counter = 0 count_not_connected = 0 while (x == 0): time.sleep(1) response = ser.readline() print response o = response.rstrip(' ') if (o == "Trying 192.52.61.41, 6566 ... Open"): #write to transmission log time call connected transmissions.write(datetime.datetime.utcnow().strftime("%H:%M:%S") + ' Connected ') print "We're connected!" x = 1 else: #print "==:"+o+":==" + "attempt " + str(count_not_connected) count_not_connected = count_not_connected+1; if (count_not_connected >10): print "redialing..." #ser.write("atdt0088160000500 ") #count number of times tried dialing without connecting count_not_connected =+ 1 #count_not_connected = 0 #make list of files in directory os.chdir(send_dir) file_list = os.listdir(send_dir) file_list.sort() file_number = len(file_list) if file_number == 0: send_files = False for file_to_send in file_list: #get checksum of each file file_to_check = open(file_to_send, 'r') check_file = file_to_check.read() file_to_check.close() checksum = hashlib.md5(check_file).hexdigest() #send filename ser.write("File") transmissions.write(datetime.datetime.utcnow().strftime('%H:%M:%S') + " sending filename ") time.sleep(1) ser.write(file_to_send) time.sleep(3) #get logging info size = os.stat(file_to_send).st_size bits = size * 8 start_date = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f') start_time = time.time() #send file transmissions.write(datetime.datetime.utcnow().strftime('%H:%M:%S') + " sending file ") f = open(file_to_send, 'rb') l = f.read(buffer) b_count = 0 while l: print "Sending " print file_to_send resp1 = ser.readline() ser.write(l) resp2 = ser.readline() time.sleep(2) l = f.read(buffer) elapsed_time = time.time() - start_time #if elapsed_time >= 155.0: #break if resp1 != "" or resp2 != "": in_call = False print "bad file resp1= " + str(resp1) + " resp2=" + str(resp2) break else: b_count = b_count + buffer #close sent file transmissions.write(datetime.datetime.utcnow().strftime('%H:%M:%S') + " closing file ") print "Completed sending file: " print file_to_send time.sleep(5) ser.write("closefile") time.sleep(5) f.close() #log file info total_time = time.time() - start_time bps = int(round(b_count * 8 / total_time, 0)) end_date = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f') today = datetime.datetime.utcnow().strftime('%Y%j') time_file = open('/root/time_logs/time_log_' + today + '.txt', 'a') time_file.write(" " + str(file_to_send) + ", " + str(size)+ " bytes, " + start_date + " UTC, " + end_date + " UTC, " + str(total_time) + " seconds, " + str(bps) + " bps, ") #send checksum transmissions.write(datetime.datetime.utcnow().strftime('%H:%M:%S') + " sending checksum ") ser.write("CS") time.sleep(1) ser.write(checksum) print "Sending checksum..." time.sleep(3) check = ser.readline() print check #compare checksums transmissions.write(datetime.datetime.utcnow().strftime('%H:%M:%S') + " comparing checksums ") if check == "1": print "Checksums match!" #os.rename(file_to_send, '../archive/' + file_to_send) time_file.write("Checksums match!") time_file.close() count += 1 elif check == "0": time_file.write("Checksums don't match") time_file.close() break else: time_file.close() break if count >= 1: send_files = False break #close call #if len(os.listdir(send_dir)) == 0: print "Closing call" #time.sleep(5) ser.write("closecall") #write to transmission log time of call hangup transmissions.write(datetime.datetime.utcnow().strftime("%H:%M:%S") + ' End call ') #transmissions.close() #time.sleep(5) ser.close() #time.sleep(5) break #clean up gpio if user quits before script ends except KeyboardInterrupt: #GPIO.output(pin, GPIO.LOW) #GPIO.cleanup() print "Cleaning up gpio pins..." #write to transmission log time - turning on iridium modem transmissions.write(' ' + datetime.datetime.utcnow().strftime("%H:%M:%S") + ' turning off iridium ') transmissions.close() modem.off() #time.sleep(2) #subprocess.call(['pkill', '-f', '-2', 'power_monitor.py']) else: #clean up gpio at the end of script #GPIO.output(40, GPIO.LOW) #GPIO.cleanup() print "Cleaning up gpio pins..." #write to transmission log time - turning on iridium modem transmissions.write(' ' + datetime.datetime.utcnow().strftime("%H:%M:%S") + ' turning off iridium ') transmissions.close() modem.off() #time.sleep(2) #subprocess.call(['pkill', '-f', '-2', 'power_monitor.py'])

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Linked Data A Geographic Perspective

Authors: Glen Hart, Catherine Dolbear

1st Edition

1000218910, 9781000218916

More Books

Students also viewed these Databases questions