Android Open Source - tnc1-android-config Firmware






From Project

Back to project page tnc1-android-config.

License

The source code is released under:

Apache License

If you think the Android project tnc1-android-config listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2013 Mobilinkd LLC// w  w w  . ja  va 2 s. c o m
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mobilinkd.tncconfig;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import android.util.Log;

public class Firmware {

  // Debugging
  private static final String TAG = "Firmware";
  private static final boolean D = false;


  public class Segment {
    public char memoryType;
    public int address;
    public byte[] data;
    
    public Segment(char type, int addr, byte[] d) {
      memoryType = type;
      address = addr;
      data = d;
      if (D) Log.i(TAG, "segment address: " + Integer.toHexString(address));
    }
  }
  
  private List<Segment> segments;
  
  Firmware(String urlPath) throws IOException, IllegalArgumentException {
    segments = new ArrayList<Segment>();
    InputStream stream = null;
    int address = 0;
    try {
      URL url = new URL(urlPath);
      stream = url.openConnection().getInputStream();
      BufferedReader reader = new BufferedReader(
          new InputStreamReader(stream));
        String line = null;
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        while ((line = reader.readLine()) != null) {
          IntelHexRecord record = new IntelHexRecord(line);
          
          if (record.type() == 1) break;
          
          // Append all adjoining records into one.
          if (record.address() != address) {
          if (D) Log.i(TAG, "expected address: " + Integer.toHexString(address));
          if (D) Log.i(TAG, "record address: " + Integer.toHexString(record.address()));
            
          byte[] segmentData = buffer.toByteArray();
          
            if (segmentData.length != 0) {
              if (segmentData.length % 2 != 0)
              {
                throw new IllegalArgumentException("bad segment alignment");
              }
              Segment segment = new Segment(
                  'F', address - segmentData.length, segmentData);
              segments.add(segment);
              address = record.address();
            }
            buffer.reset();
          }
          buffer.write(record.data());
          address += record.length();
        }
        
      byte[] segmentData = buffer.toByteArray();
       Segment segment = new Segment(
          'F', address - segmentData.length, segmentData);
      segments.add(segment);
      
    } catch (IOException x) {
        System.err.format("IOException: %s%n", x);
        throw(x);
    } catch (IllegalArgumentException x) {
      System.err.format("IllegalArgumentException: %s%n", x);
      throw(x);
    }
  }
  
  List<Segment> getSegments() {
    return segments;
  }
}




Java Source Code List

com.google.speech.levelmeter.BarLevelDrawable.java
com.mobilinkd.tncconfig.AboutActivity.java
com.mobilinkd.tncconfig.AudioInputFragment.java
com.mobilinkd.tncconfig.AudioOutputFragment.java
com.mobilinkd.tncconfig.Avr109.java
com.mobilinkd.tncconfig.BluetoothTncService.java
com.mobilinkd.tncconfig.DeviceListActivity.java
com.mobilinkd.tncconfig.FirmwareUpdateActivity.java
com.mobilinkd.tncconfig.Firmware.java
com.mobilinkd.tncconfig.IntelHexRecord.java
com.mobilinkd.tncconfig.KissFragment.java
com.mobilinkd.tncconfig.ModemFragment.java
com.mobilinkd.tncconfig.NumberPickerFragment.java
com.mobilinkd.tncconfig.PowerFragment.java
com.mobilinkd.tncconfig.TncConfigApplication.java
com.mobilinkd.tncconfig.TncConfigDefaults.java
com.mobilinkd.tncconfig.TncConfig.java
com.mobilinkd.tncconfig.util.SystemUiHiderBase.java
com.mobilinkd.tncconfig.util.SystemUiHiderHoneycomb.java
com.mobilinkd.tncconfig.util.SystemUiHider.java